anonymous functions and parfor

Hi,
I would like to transform a for loop into a parfor loop. In the for loop I am solving a delayed differential equation via heun method, which means that i am sending the function to be solved as an argument to the heun method.
for nRuns = 1:Nr_runs
res = heunDDE(@function_to_solve, t0, tf, tau,rand, Npoints);
end
With the for loop, i obtain the solution to the DDE without correctly. However, whenever i transform the loop into a parfor, i get:
?? Error using ==> parallel_function at 598
Error in ==> function_to_solve at 9
Index exceeds matrix dimensions.
So what may be my problem here?
Thanks for your help,
Marta

 Accepted Answer

Titus Edelhofer
Titus Edelhofer on 7 Dec 2011
Hi Marta,
difficult to say. Since the code fails in line 9 of function_to_solve you might put a disp(size()) commands of variables involved in the computation in line 9 to find out what's the difference when calling using for and parfor ...
Titus

1 Comment

Hi Titus,
thanks a lot for your answer, your intuition was totally right (was emptying the variable somewhere in between the runs).
Million thanks!
Marta

Sign in to comment.

More Answers (0)

Categories

Find more on Parallel Computing Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!