From: Sean Crowell on 8 Apr 2010 15:04 Is it possible to parallelize a for loop that contains a while loop? I have code that has a large number of iterations for the inner loop, because each instance of the outer for loop has a different number of iterations to reach a threshold. Is it possible to do this in parallel?
From: Rune Allnor on 8 Apr 2010 15:11 On 8 apr, 21:04, "Sean Crowell" <sean.m.crow...(a)gmail.com> wrote: > Is it possible to parallelize a for loop that contains a while loop? I have code that has a large number of iterations for the inner loop, because each instance of the outer for loop has a different number of iterations to reach a threshold. Is it possible to do this in parallel? It depends entirely on the termination condition. In my experience, each iteration of FOR loops are often independent of the others, which means they can be parallelized. WHILE loops, on the other hand, tend to terminate depending on the result of some interrnal computation in the iteration. Which makes it hard to parallelize. So you need to check the computations to see if the algorithm is parallelizable. It might not be. Rune
From: Sean on 8 Apr 2010 21:22 Rune, Thanks for your reply. The conditions for termination in my while loop depend only on the particular instance of the outer for loop, not on any others. So theoretically there should be no issues, but it seems as if Matlab is complaining. My loop looks like for i = 1:nx0 x(i,1) = x0(i) j = 2 while (f(x(i,j)) > 1e-7) ..... j = j+1 end end Thanks! Sean
From: Steven Lord on 9 Apr 2010 11:05 "Sean " <mathleet(a)gmail.com> wrote in message news:hplvfu$glv$1(a)fred.mathworks.com... > Rune, > > Thanks for your reply. The conditions for termination in my while loop > depend only on the particular instance of the outer for loop, not on any > others. So theoretically there should be no issues, but it seems as if > Matlab is complaining. .... and that "complaint" (which I assume means error) is? > My loop looks like > > for i = 1:nx0 > > x(i,1) = x0(i) > j = 2 > while (f(x(i,j)) > 1e-7) > .... > j = j+1 > end > end There's no PARFOR statement in this code. If you want help troubleshooting the problem, you'll need to show ALL the code (or at least all that's necessary to reproduce the problem -- if the code is really long, try to simplify it down to a small example that still demonstrates the error, so that people don't have to wade through pages of unnecessary "background" to get to the meat of the problem that's causing difficulty for you.) -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Pages: 1 Prev: Making vector global and local Next: quad using integers |