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.
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?