Behaviour ofparfeval depends on debugging state (Bug?)

3 ビュー (過去 30 日間)
tommsch
tommsch 2021 年 1 月 29 日
回答済み: Edric Ellis 2021 年 1 月 29 日
I have the following function, which should return false. If I set a breakpoint at the first line, and then step through the program, I get the message:
Analyzing and transferring files to the workers ...done
and the function returns false. But when I just execute the function, no message is issued and the function returns true. Is this a bug?
function ret = testparfeval;
F = parfeval( gcp(), @afssasgdd, 0 ); %this is a non-existent function
while( isequal(F(1).State,'queued') );
pause( 0.1 ); end;
ret = isempty( F.Error );

採用された回答

Edric Ellis
Edric Ellis 2021 年 1 月 29 日
I suspect this is because when you don't stop in the debugger, the function can return as soon as F gets into state 'running', i.e. before it gets to state 'finished'. Rather than polling the State property, I'd recommend using the wait method, like this:
F = parfeval(gcp(), @afssasgdd, 0);
wait(F);
didError = ~isempty(F.Error)
The wait method can take an optional timeout if you wish.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by