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

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

raym
raym el 28 de Mzo. de 2022
labProbe can solve this problem.

Más respuestas (1)

Edric Ellis
Edric Ellis el 29 de Mzo. de 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.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by