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

 采纳的回答

Titus Edelhofer
Titus Edelhofer 2011-12-7

0 个投票

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 个评论

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

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Parallel Computing Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by