Effacer les filtres
Effacer les filtres

parallel execution of loop

1 vue (au cours des 30 derniers jours)
D_coder
D_coder le 22 Mar 2019
Commenté : Walter Roberson le 23 Mar 2019
I have the following structure
for i = 1:N
%some lines of code
for j = 1:M
%some lines of code and M<N
end
end
How do I perform following parallel execution : i = 1 perform j = 1, i = 2 perform j = 1, i = 3 perform j = 1 and then i = 2 perform j = 1 and so on ?
  2 commentaires
Adam
Adam le 22 Mar 2019
I'm not sure I really get your description at the bottom. That basically just boils down to the for loops as you have shown them that you want parallelising?
If you have the Parallel Computing Toolbox then
doc parfor
can do this, depending what is in the body of the for loops. You would usually want to put the parfor on the outer loop. for obvious reasons you can't make both loops parfors.
Walter Roberson
Walter Roberson le 23 Mar 2019
Performing the iterations in the order you request would not be equivalent to doing them in serial.
A = 0;
for i = 1 : 10
B = 0;
for j = 1 : 5
A = A + 1;
B = B + 1;
end
end
When i = 2, j = 1, then A has to be 5 if you executed in serial mode. But if all of the j = 1 iterations for each possible i are executed first, as you request, then A would have been incremented to 10.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements 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