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

조회 수: 1 (최근 30일)
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
Edric Ellis
Edric Ellis 2024년 11월 25일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Hitesh
Hitesh 2024년 11월 25일
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:

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by