sdwfrost / liblsoda

The LSODA algorithm for differential equations as a shared library
MIT License
32 stars 16 forks source link

Speed slowdown compared to original LSODA? #12

Closed mattfidler closed 6 years ago

mattfidler commented 6 years ago

I have implemented the liblsoda in R for the RxODE package to take advantage of it's OpenMP threaded capabilities;

RxODE translates an ODE mini-language to C code, compiles the C code and runs the routines through one of 3 ODE solvers:

The same problem run in a single thread (compared to some running 2 threads and 1 threads) took approximately 2x as long in libslsoda as the original LSODA. Is this expected on the move from FORTAN to C?

Still, the OpenMP make the overall the threaded liblsoda faster than single threaded LSODA in certain problems, but the gains are not as much as I expected since the solver itself seems a bit slower.

Here are the results of my test and its timing:

v | OK F W S | Context
v | 17       | Test Parallel/Multi-subject Solve (liblsoda) [20.5 s]
v | 17       | Test Parallel/Multi-subject Solve (dop853) [7.5 s]
v | 17       | Test Parallel/Multi-subject Solve (lsoda) [7.4 s]

Is this known/expected?

mattfidler commented 6 years ago

I'm also curious what you think @richfitz since you were working on a liblsoda R package.

By the way my code/package where the routines are found is:

https://github.com/nlmixrdevelopment/RxODE/tree/a00c3d4adb6b913fb06201bc9087b48ae445654e

And the liblsoda implementation(s) are found in

https://github.com/nlmixrdevelopment/RxODE/blob/ec393b090dd313a063b6324eba47e27a817341d4/src/par_solve.c#L519

mattfidler commented 6 years ago

I ran again changing the order and the timing is similar; I forgot to account for compile time:

v | 17       | Test Parallel/Multi-subject Solve (dop853) [22.2 s]
v | 17       | Test Parallel/Multi-subject Solve (liblsoda) [7.6 s]
v | 17       | Test Parallel/Multi-subject Solve (lsoda) [7.0 s]

It is a bit slower, but not much. It probably has to do with memory allocation, which I can try to fix.

Thank you for the awesome package.