elapsed time in parfor
Mostrar comentarios más antiguos
I'm running a parameter optimisation routine, which involved running an ODE model (ode15s) with a range of parameters sampled from the parameter space. For some parameters the problem is stiff and takes very long time to integrate. So I'd like to ignore a combination of parameters if the solution takes too long.
Initially I tried to do this by declaring a global or persistent variable for the time in the function that the ODE solver is calling and break if it exceeds a max_time.
Example:
MAXTIME = 100; %Max time in seconds global elapsedtime
if isempty(elapsedtime) elapsedtime = tic; end
if toc(elapsedtime) > MAXTIME error('Stopped. Taking too long.') end
In parfor global variables cannot be used and I'm looking for another solution.
Can someone help?
Respuestas (1)
Edric Ellis
el 5 de Ag. de 2014
You should be able to solve this problem simply by parameterising your function, a bit like this:
function dy = simWithTimeout(t, y, timer, maxtime)
if toc(timer) > maxtime
error('Timeout!');
end
... calculate dy ...
end
And then invoking it like this:
timer = tic;
MAXTIME = 100;
[T, Y] = ode15s(@(t, y) simWithTimeout(t, y, timer, MAXTIME), ...);
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!