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!