How to let a lab tell if another lab is idle or not in a spmd block at that time : isidle(labindex)
3 ビュー (過去 30 日間)
古いコメントを表示
Hello,
Is there a way to let lab 2 know if a lab 1 is idle or not in a specific timepoint:
% an example (not related to reality, but for demo only, so please do not question the meaning. I know this demo is not that much useful)
spmd
for i=1:100
if labindex == 1
try
labSend(1,'hello,start')
dosomething_ErrorProne_but_takes_less_than_2s();
labSend(1,'succeed')
catch
break % if lab1 break and idle early,lab2 's labReceive(1) will catch error.
end
elseif labindex == 2
msg1 = labReceive(1);
disp(msg1);
pause(3);% wait for lab1 finish
enquiryLab = 1;
if isidle(enquiryLab);
% NOTE: if lab1 has that error in that function, lab1 will be idle immediately without sending data(a data can make lab2 not idle until sent),
% later if lab2 call labReceive to an idle lab1, will be
% error: The other lab became idle during labReceive.
% so I need a isidle() to pre-check before call labReceive
try
msg2 = labReceive(1);
catch ME
end
disp(['lab 1 result:', msg2]);
end
end
end
end
0 件のコメント
採用された回答
その他の回答 (1 件)
Edric Ellis
2022 年 3 月 29 日
I can think of a few ways around this:
- As you suggest, labProbe can tell you if there's an incoming message ready to be received
- You could just call labReceive anyway. spmd (in the default setup) has error detection enabled that will cause the labReceive to throw an error if the worker for which it is waiting reaches the end of the spmd block without sending a message
- You could use try/catch around just the error-prone function and then ensure that you always call labSend. You could choose to send different data to indicate that an error had been encountered.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!