Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to improve speed in ODE solvers from matlab? (ode45 ode15s etc)

Tags:

matlab

ode

I wrote a code to solve a system using ode45 and ode15s in matlab. I am wondering if I can improve the speed of the code using multiple core (or parallel code) in my script.

Anyone have tried this ??

Thanks

like image 746
Nikko Avatar asked May 13 '13 17:05

Nikko


2 Answers

No, you can't.

All numerical integrators, ode45 and friends included, use some form of iterative scheme to solve the user-implemented (coupled) non-linear (partial) differential equations.

Each new step in the iterative schemes of ode45/15s/.. (to compute the new state of the system) depends on the previous step (the old state of the system), therefore, these numerical integrators cannot be parallelized effectively.

The only speedup you can do that's likely to have a big impact is to optimize your implementation of the differential equation.

like image 146
Rody Oldenhuis Avatar answered Nov 15 '22 04:11

Rody Oldenhuis


From my experience, the only way to use multiple cores for ODE suite solvers in MATLAB is to use "parfor loop" to start multiple computations together at the same time, your single computation not be any faster, but you can start many with different parameters and have multiple solutions after that long wait. So if you need to start ODE many times that might speed up your work.

To speed up one ODE function it also a good idea to play with RelTol and AbsTol settings (changes time form seconds to hours), using Jpattern option can also be very helpful (my almost tridiagonal pattern made it run twice as fast). If your differential equation is simple maybe try to compile it first, or at least vectorize (I used to write some part of code in Java and then point MATLAB to use compiled .class file). Obviously the length of your solution vector plays important role, so don't make it more than a few hounded.

like image 34
Piotr Kusmierczyk Avatar answered Nov 15 '22 03:11

Piotr Kusmierczyk