Parfeval blocks parfor loop evaluation

2 ビュー (過去 30 日間)
Michael
Michael 2019 年 5 月 30 日
コメント済み: Michael 2019 年 6 月 3 日
The existance of any parfeval job blocks the execution of a parfor loop. This occurs even when available pool workers are available, and should be free to execute the parfor loop.
On my machine, with 32 cores, running this:
function testParallelBlocking
nIter = 3;
pool = gcp;
j = parfeval(pool,@backgroundFcn,1);
for i = 1:nIter
forLoopTime(i) = now;
end
parfor i = 1:nIter
parforLoopTime(i) = now;
end
disp(['Parfeval completed at ' datestr(j.fetchOutputs,'HH:MM:SS:FFF')]);
for i = 1:nIter
disp(['For loop completed at ' datestr(forLoopTime(nIter),'HH:MM:SS:FFF')]);
end
for i = 1:nIter
disp(['Parfor loop completed at ' datestr(parforLoopTime(nIter),'HH:MM:SS:FFF')]);
end
end
function out = backgroundFcn
pause(5);
out = now;
end
produces this output:
Parfeval completed at 15:15:25:244
For loop completed at 15:15:20:232
For loop completed at 15:15:20:232
For loop completed at 15:15:20:232
Parfor loop completed at 15:15:25:269
Parfor loop completed at 15:15:25:269
Parfor loop completed at 15:15:25:269
showing that while the rest of the code continues to run, the parfor loop does not begin until the parfeval job has completed.
Is there any way to have the parfor loop execute while the parfeval job is also running in the background? I have tried limiting the number of parfeval workers by changing
parfor i = 1:nIter
to
parfor (i = 1:nIter,nWorkers)
where nWorkers < (number of cores - number of pending parfeval jobs) but it does not change the behavior.
Thanks for your help.

採用された回答

Edric Ellis
Edric Ellis 2019 年 6 月 3 日
This is expected behaviour. Unfortunately, there is currently no way to overlap parfeval and parfor. Your best bet is probably to adapt your parfor loop to use parfeval instead (I appreciate that this might not be terribly convenient).
  1 件のコメント
Michael
Michael 2019 年 6 月 3 日
Edric,
Thank you for your response - yes, it is not really feasable for me to rewrite all parfor loops as parfeval loops.
Is this something that is on the Mathworks timeline for a fix?
Is there a way to check if any parfeval tasks are executing? If I set the numWorkers argument to the parfor loop to 0, the loop will run as a simple "for" loop and not get blocked by parfeval.
What I'd like to do is something like:
pool = gcp;
if PENDING_PARFEVAL_TASKS
nWorkers = 0;
else
nWorkers = pool.NumWorkers;
end
parfor (i=1:N,nWorkers)
.
.
.
end
The lack of interoperability of parfeval and parfor really limits the functionality of parfeval.
Thanks,
Michael

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAsynchronous Parallel Programming についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by