Fast ODE45 with for-loops

6 vues (au cours des 30 derniers jours)
Paul
Paul le 23 Août 2013
Hello,
I have a coupled first order ODE to solve of the form
dy = f(t, x) dx = d(f, x)
which depends on a common parameter which I have to solve for over some range. I can solve the system using ODE45 and a for loops which increments the parameter of interest at each loop, however, this is very slow. Can I avoid solving this problem in loops? Or what is best practice with problems of this type.

Réponse acceptée

Marc
Marc le 24 Août 2013
The infamous double post.... Asked in Newsgroup and answered. Try parfor in the parallel toolbox. If your computer has multicores, you can run 2+ simulations at the same time.
Should help.
Just as a follow up, how long does running ODE45 take? Are we talking seconds or minutes?
Is your function large? I run a simulation with ~3000 odes, using ode15s and this takes between 100-1000 seconds depending on the input parameters. This was a 10x speed up after I used the profiler on my function, NOT on the whole script. Found that I was spending a lot of time passing large structures between functions within the main function. Mostly because I was lazy. Trimmed this up and got much better results.
Add parfor with 12 cores and I was able to get through my DOEs in days rather than weeks.

Plus de réponses (1)

Paul
Paul le 24 Août 2013
Sorry about : I posted this late last night and honestly cannot remember posting twice. How rude of me :)
My problem is non-stiff and no particularly large. My overall task is to invert a characteristic function via direct integration. So if the grid in the frequency domain in length(2^N) then this is the number of times I need to simulate the system above.
It turns out that I need 25,000 + odes to recover the density accurately. I need between 200 - 1000 seconds depending. Funny you say about profiling the function not the script - I was doing EXACTLY the same thing.
I will try parfor thanks. Otherwise did you consider writing a fortan / C MEX file for integrating the ODES?
  1 commentaire
Marc
Marc le 25 Août 2013
I have compared limex in fortran with ode15s and cvode from Sundials in Matlab and find Matlab to be close to fortran. I did not try to optimize the fortran code, simply tested as is.
You already have available what you are asking. cvode and ida codes, part of the Sundials package have already been "mexed" and packaged for Matlab. This is from Lawrence Livermore National lab. Cvode has some nice features and requires you to format things a bit differently. Not sure if you'll get a speed up.
Limex, lsode, cvode, ida are codes I have compared to ode45 and ode15s over the years and found the Matlab codes to hold up.
So, I think you are stuck from the integrator standpoint.
My only comment would be try running your parameter maybe 5 times, say at the min, max and three intermediate points to see if you can minimize that 25,000 runs. Maybe there is something special about your system, but I tend to believe if you pick say 32 points and randomize the runs, you should get a good enough picture of what is going on.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by