Send for loop iterations to multiprocessors

조회 수: 1 (최근 30일)
Daniel Stanaway
Daniel Stanaway 2011년 5월 24일
Hello, My code consists of two parts, an outer portion that is independent and an inner portion that is dependent. I want to send the outer for loop to different processors to speed it up, but the inner loop needs to be run serially. At the end, I need to combine the results of the independent loop into one matrix.
Essentially the code can be visualized as for ii = 1:4 for i = 1:1000 a(i) = f(b) end A(ii) = a(i) end
If this makes sense, the ii loop is independent but the i loop is dependent. I want to send the ii loop to different processors so that i can be computed serially. I have not had very much luck with parfor in this instance.
Is what I am asking not possible? I estimate that if I cannot use multiple processors to execute the code, it will run for 1.5-2 days.
Thank you for any insight, Dan Stanaway
  댓글 수: 3
Sean de Wolski
Sean de Wolski 2011년 5월 24일
What do you mean by "I did not have very much luck"?
Daniel Stanaway
Daniel Stanaway 2011년 5월 24일
I meant that I was unable to index the variables that need to be compiled in a way that would allow the parfor loop to execute. The errors I am receiving are 1) Parfor loop cannot be run dur to way variable is used, and 2) valid indices for variables are restricted in parfor loops.

댓글을 달려면 로그인하십시오.

채택된 답변

Jason Ross
Jason Ross 2011년 5월 24일
Try putting your inner loop in a function and calling the function instead.
e.g.:
parfor ii = 1:4
somethingout = myloopfunction
end
then in myloopfunction you have the inner for loop.
If that doesn't work, you might also want to look into the spmd functionality.
  댓글 수: 1
Daniel Stanaway
Daniel Stanaway 2011년 5월 24일
Thanks Jason, even in using the function, I have an error saying value is non deterministic, but I think the spmd functionality is what I am looking for. I appreciate your answer.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by