parfor schedule not very smart?

I noticed that the parfor scheduler isn't distributing the tasks smartly. For example, why does the following simple code take 250 sec to execute? My guess is that a single worker is hogging both loops 1 and 2 while the remaining 7 sit idle. Why should that be the case? Since it takes the 7 workers no time to finish executing loops 3 to 16, one would expect that one of them gets assigned loop 2, in which case it would probably take only 130 sec to finish the job.
Is anyone else seeing this? or am I deluded...
% code
matlabpool open 8
tic
answer = cell(16,1);
parfor ii = 1:16,
if (ii == 1 || ii == 2)
pause(120);
end
answer{ii} = ii;
end
toc
> Elapsed time is 257.125697 seconds.

댓글 수: 1

William Smith
William Smith 2017년 3월 14일
The scheduler appears to pre-assign blocks of work to the individual workers, presumably because the communication overhead to send individual tasks to workers is deemed too heavy.
I also see many cases when I'd appreciate a better allocation of work to workers for heterogeneous workloads.

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

답변 (3개)

Matt J
Matt J 2013년 8월 28일
편집: Matt J 2013년 8월 28일

0 개 추천

Splitting work the "smart" way would require that parfor know a priori the outcome of expressions and commands within the body of the loop for all ii, in this case the logical expressions
(ii == 1 || ii == 2)
Doing a pre-analysis like that would essentially mean running the entire loop serially prior to doing any parallelization, killing the intended benefit of parfor.
Edric Ellis
Edric Ellis 2013년 8월 28일

0 개 추천

The PARFOR scheduler divides loop iterations up in a fixed way to try and achieve a good balance for 'normal' workloads. In particular, it tries to send out decent sized chunks of work to overcome data transmission overhead. Pathological cases like this will always exist. If your long-running cases vastly exceed the time taken by the 'quick' cases, you might just be better off submitting a series of batch jobs and letting the cluster schedule each iteration individually.
Spencer Chen
Spencer Chen 2013년 8월 28일

0 개 추천

Thanks, Matt and Edric. Yes, indeed, Edric. I was hoping not have to move that way. Really, parfor can be a bit smarter and reschedule unfinished loops to idle workers.

댓글 수: 1

Matt J
Matt J 2013년 8월 28일
편집: Matt J 2013년 8월 28일
That can require reslicing and/or re-broadcasting data in some cases, which would add overhead. Seems to me that it would be hard for parfor to know when it is optimal to do so.

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

카테고리

도움말 센터File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

태그

질문:

2013년 8월 28일

댓글:

2017년 3월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by