Effacer les filtres
Effacer les filtres

How can I know which worker performs each iteration of the parfor loop?

7 vues (au cours des 30 derniers jours)
Policarpo Abascal
Policarpo Abascal le 2 Mai 2024
I want to know if it is possible to determine which worker performs each iteration of the parfor loop or if it is possible to assign each iteration to a worker.
  2 commentaires
Thomas Ibbotson
Thomas Ibbotson le 2 Mai 2024
We would usually advise against this, so it would be good to know why you want to do this. I will answer your question in detail below.
Policarpo Abascal
Policarpo Abascal le 6 Mai 2024
Thank you. I have found the answer to my question in the suggestions you provided with 'getcurrentworker'.

Connectez-vous pour commenter.

Réponses (2)

Thomas Ibbotson
Thomas Ibbotson le 2 Mai 2024
You can find out which worker is running your code using the following function: https://uk.mathworks.com/help/parallel-computing/getcurrentworker.html
You can achieve more control over how iterations are divided amongst worker using parforOptions: https://uk.mathworks.com/help/parallel-computing/parforoptions.html

Edric Ellis
Edric Ellis le 2 Mai 2024
Modifié(e) : Edric Ellis le 2 Mai 2024
You can use getCurrentTask (if you're using a process pool rather than a thread pool). This has a field ID which tells you which task is operating, like this:
parfor i = 1:N
t = getCurrentTask();
fprintf('Iteration %d on task %d\n', i, t.ID);
end
It's not possible with parfor to assign iterations to workers. You can have more control with spmd - but we'd need to know more about what it is you're trying to achieve.
  1 commentaire
Policarpo Abascal
Policarpo Abascal le 6 Mai 2024
Thank you. This is the command I didn't know about and that solves what I wanted to address.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange

Produits


Version

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by