After optimizing my code, my ode solver, ode45, takes a long time to finish. But the server only allows me to have a walltime of 24 hours. I cannot request longer walltime. I know how to do checkpointing for for
loop. But How to do checkpointing for ode45
, efficiently?
An integration interval can be divided into parts. For example,
[t1,x1] = ode45(f,[0 1],x0); % integrate from 0 to 1
save('data.mat'); % save workspace to file
% now you can turn off your computer
load('data.mat'); % load workspace from file
last = x1(end,:); % obtain the last state (the last row of x1)
[t2,x2] = ode45(f,[1 2],last); % integrate from 1 to 2
t = [t1;t2]; % concatenate results
x = [x1;x2];
is equivalent to
[t,x] = ode45(f,[0 2],x0); % integrate from 0 to 2
So you can integrate over the first part of the interval and save results, next time you can continue integrating from the last point, etc.