필터 지우기
필터 지우기

why does parfor execute loops in a random order?

조회 수: 3 (최근 30일)
Michael
Michael 2013년 2월 28일
I can't see any reason why, and if my PC crashes during a 20,000 loop iteration, it's a pain to figure out which iterations are still to be done.
Cheers Mike

채택된 답변

Jason Ross
Jason Ross 2013년 2월 28일
Just to be clear -- parfor loops are of independent of iteration order, and do not guarantee deterministic results. It's not random.
The functional reason for this is if iteration 2 finishes before iteration 1 then iteration 3 can start work, and so on, since each iteration is independent of the other.
  댓글 수: 4
Michael
Michael 2013년 3월 1일
Thanks.
I suppose a vector of zeros (to be switched to 1's on completion) would automatically register which iterations are completed. It's not something I thought about before!
Jason Ross
Jason Ross 2013년 3월 1일
You might also want to investigate using the job/task interface, which gives you more control over the iterations and tracking down errors. A simple example:
c=parcluster();
alloutputs = [];
for ii=1:10
job = c.createJob;
for jj=1:10
createTask(job,@rand, 1, {3,3});
end
job.submit;
job.wait;
outputs = job.fetchOutputs;
alloutputs = [alloutputs ; outputs];
disp(ii);
job.destroy;
end
Note that things like preallocation, fancy formatting and error checking have been left out. Things that will likely be interesting to you:
  • The job object contains the Task ID of errors. You could use this information to know what failed.
  • You will likely need to figure out what work for you in terms of iteration display, number of tasks per job, dealing with the returns, etc.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by