Why is the timeout not triggering using Wait(F, state, timeout) for a parallel process?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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:
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 commentaire
Edric Ellis
le 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.
Réponses (1)
Hitesh
le 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:
0 commentaires
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!