parfor and nested loop

2 Ansichten (letzte 30 Tage)
huda nawaf
huda nawaf am 23 Jan. 2014
Kommentiert: huda nawaf am 24 Jan. 2014
hi,
can I use parfor with nested loop?
for ex.
parfor i=1:5
for j=1:2
%%whatever
end
end
should I use par with each for or with one.
please, I need somebody can solve my problem.
Thanks in advance

Antworten (2)

Mischa Kim
Mischa Kim am 23 Jan. 2014
Hello huda, there are no nested parfor loops. Parallelization with parfor only works on the outermost loop.
  1 Kommentar
huda nawaf
huda nawaf am 24 Jan. 2014
thanks,
ok, do u mean it is not problem if i use parfor for outermost loop and the inside loop stay as it.
I just wonder because when I used parfor for only outermost loop, I did not find any improvement in terms of running time.
Please, I badly need that.

Melden Sie sich an, um zu kommentieren.


Matt J
Matt J am 23 Jan. 2014
Bearbeitet: Matt J am 23 Jan. 2014
To combine the loops into a single parfor loop,
parfor k=1:10
[i,j]=ind2sub([5,2],k);
%%whatever
end
  3 Kommentare
Matt J
Matt J am 24 Jan. 2014
The effectiveness of parfor depends a lot on what you're doing inside the loop.
huda nawaf
huda nawaf am 24 Jan. 2014
yes, but I read if I have large array it is best to use spmd.
this function will distribute the array among workers.
but I have problem. Also I used pmode .
I did not find the efficiency of these functions. I hope to find simple example show me the difference between parallel and serial processing.
thanks

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by