Why is the timeout not triggering using Wait(F, state, timeout) for a parallel process?

2 Ansichten (letzte 30 Tage)
Hello everyone.
I have to implement a timeout function for a simulation sweep, so that I can stop non-converging solutions when the computation times gets too long and then I just skip to the next set of parameters.
I however noticed that the timeout was not triggering, so I made a simpler code to test it out.
The parallel process simply waits 5 seconds, and I set a timeout at 4s.
From the documentation:
tf = wait(F,state,timeout) blocks execution for a maximum of timeout seconds.
If each element of the Future array F finishes before timeout seconds elapse, tf is true. Otherwise, tf is false.
So after f is called, the code waits for F to finish or for 4 seconds to elaps, at which point it will return either 1 or 0, but the code always runs for 5 seconds+, and timeout is always true.
Am I missing something?
Thank you in advance
timeout = 4;
startTime = tic;
f = parfeval(@t, 1, 5);
timeout = wait(f, 'finished', timeout);
elapsedTime = toc(startTime);
disp(elapsedTime);
if ~timeout
disp('Did not finish in time.')
cancel(f);
else
disp('finished on time.')
out = fetchOutputs(f);
end
function out = t(i)
pause(i)
out = i;
end
  1 Kommentar
Edric Ellis
Edric Ellis am 25 Nov. 2024
Which release and which OS are you seeing a problem on? I just tried R2022b and R2024b on Linux, and things worked correctly. Have you turned off "Auto create parallel pool"? In that case, the parfeval body can run in the client, and when that happens, the wait always has to wait for the execution to complete.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Hitesh
Hitesh am 25 Nov. 2024
I too have encountered the same issue, the workaround that worked for me was updating the MATLAB to R2024b version. I have executed your sample code and it is giving the expected result. I have attached an image of the output for your reference.
For more information regarding the "wait" function, kindly refer to the following MATLAB documentation:

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by