How to let a lab tell if another lab is idle or not in a spmd block at that time : isidle(labindex)

7 views (last 30 days)
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)
for i=1:100
if labindex == 1
break % if lab1 break and idle early,lab2 's labReceive(1) will catch error.
elseif labindex == 2
msg1 = labReceive(1);
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
msg2 = labReceive(1);
catch ME
disp(['lab 1 result:', msg2]);

Accepted Answer

raym on 28 Mar 2022
labProbe can solve this problem.

More Answers (1)

Edric Ellis
Edric Ellis on 29 Mar 2022
I can think of a few ways around this:
  1. As you suggest, labProbe can tell you if there's an incoming message ready to be received
  2. 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
  3. 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.

Community Treasure Hunt

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

Start Hunting!