Parallelize instructions inside for

1 vue (au cours des 30 derniers jours)
Thales
Thales le 28 Déc 2017
Commenté : Walter Roberson le 28 Déc 2017
Is there a way to parallelize independent instructions within a for loop? The loops themselves aren't independent, so parfor is not really an option.
What I would like to do is something like:
for ii=1:N
% initial stuff
[...]
% instructions 1
[...]
% instructions 2
[...]
% instructions 3
[...]
% instructions 4
[...]
% more stuff
[...]
end
The instructions1, instructions2 etc are all independent instructions, so they should be able to parallelize. Each loop in the for, however, is not independent, so is not just change the for to a parfor. Is there any way to do it in Matlab?

Réponses (1)

Matt J
Matt J le 28 Déc 2017
You could make scripts for each set of instructions and launch them (within the loop) on different workers using the batch command.
  1 commentaire
Walter Roberson
Walter Roberson le 28 Déc 2017
Or parfeval() instead of batch()

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by