[R-sig-dyn-mod] lsoda FASTER than ode45 (was: lsoda (deSolve) order of magnitude slower than ode45)

Johannes Ranke jranke at uni-bremen.de
Wed Nov 22 13:18:26 CET 2017


Hi,

Karline has once written a nice package called ccSolve for that, which you can 
find on r-forge (at least the source code=). However, it never made it to CRAN 
unfortunately.

I have used her code and thankfully had some help from her (as I am not used 
to working wich C) to implement automatic generation of C code for ODEs in my 
mkin package:

https://github.com/jranke/mkin/blob/master/R/mkinmod.R#L277

which has been working nicely for me, giving a performance improvement of a 
factor around 8.

https://pkgdown.jrwb.de/mkin/articles/compiled_models.html

I have also tried different approaches, one of them involving the package 
odeintr. But with that approach, compiling the models took so long that I got 
frustrated by it, so I went back to generating C code which is being compiled 
in no time.

Kind regards,

Johannes

Am Mittwoch, 22. November 2017, 12:05:41 CET schrieb Maciek Jacek Swat:
> OK, I have found links to useful examples in the deSolve manual: "in
> Fortran or C (../doc/dynload, ../doc/dynload-dede)"
> 
> But the question remains: are there converters for ODEs from R to FORTRAN
> or C?
> (If not, it would be a nice and relatively simple student project,
> potentially attracting new users to deSolve/R)
> 
> 
> On Wed, Nov 22, 2017 at 11:42 AM, Maciek Jacek Swat <maciej.swat at gmail.com>
> 
> wrote:
> > Thanks Andras, but I create the R code 'on the fly' as part of a workflow,
> > is there a way to automatically create the C/FORTRAN code as well?
> > Any pointers would be welcome,. M
> > 
> > On Wed, Nov 22, 2017 at 11:34 AM, Andras Farkas <motyocska at yahoo.com>
> > 
> > wrote:
> >> As Thomas have mentioned implement it in C or Fortran, will do wonders to
> >> speed
> >> 
> >> 
> >> Andras
> >> 
> >> Sent from Yahoo Mail on Android
> >> <https://overview.mail.yahoo.com/mobile/?.src=Android>
> >> 
> >> On Wed, Nov 22, 2017 at 6:30 AM, Maciek Jacek Swat
> >> <maciej.swat at gmail.com> wrote:
> >> Thanks Thomas, much appreciated!
> >> 
> >> However, the Nanda model was only used to learn how to use deSolve most
> >> effectively.
> >> Unfortunately, for a real, very stiff, model with 130 ODEs, which I
> >> cannot
> >> share, I have the following stats
> >> - 'lsoda' - 320 seconds
> >> - 'vode' - 150 seconds
> >> - 'bdf'  - 430 seconds
> >> while ode15s takes 5 (five) seconds.
> >> 
> >> I'm trying now to find the new bottleneck (after correcting the 'times'
> >> setting Karline and you pointed out) ...
> >> 
> >> Best, Maciej
> >> 
> >> 
> >> On Wed, Nov 22, 2017 at 10:47 AM, Thomas Petzoldt <
> >> 
> >> thomas.petzoldt at tu-dresden.de> wrote:
> >> > Hi Maciek,
> >> > 
> >> > I've made a small benchmark with your example (i5 4690, 3.5-3.9GHz, R
> >> > 3.4.2, deSolve 1.21, Windows 10,  average of 10 simulations each):
> >> > 
> >> > dt = 0.01
> >> > 
> >> >    lsoda: 2.85s
> >> > 
> >> > dt = 1
> >> > 
> >> >    ode45: 0.135
> >> >    lsoda: 0.039
> >> >    bdf:  0.025
> >> >    vode:  0.024
> >> > 
> >> > The plot of all simulations looks identical. B_CLL shows a steep change
> >> 
> >> at
> >> 
> >> > the beginning, that's why dedicated solvers for stiff systems (bdf,
> >> 
> >> vode)
> >> 
> >> > can be minimally faster than the automatic lsoda.
> >> > 
> >> > Finally, R/deSolve allows to use compiled C or Fortran models and there
> >> > are now several packages that support creation of such code ...
> >> > 
> >> > Thomas
> >> > 
> >> > 
> >> > gc() # clean up memory to make benchmark more reproducible
> >> > times <- seq(0, 300, by = 1)
> >> > N <- 10
> >> > system.time(
> >> > 
> >> >  for (i in 1:N)
> >> >  
> >> >    out <- ode(y = state, times = times, func = Nanda,
> >> >    
> >> >      method="vode", parms = parameters)
> >> > 
> >> > )/N
> >> > 
> >> > 
> >> > plot(out)
> >> > 
> >> > 
> >> > --
> >> > Dr. Thomas Petzoldt
> >> > Technische Universitaet Dresden
> >> > Faculty of Environmental Sciences
> >> > Institute of Hydrobiology
> >> > 01062 Dresden, Germany
> >> > 
> >> > E-Mail: thomas.petzoldt at tu-dresden.de
> >> > http://tu-dresden.de/Members/thomas.petzoldt
> >> > 
> >>     [[alternative HTML version deleted]]
> >> 
> >> _______________________________________________
> >> R-sig-dynamic-models mailing list
> >> R-sig-dynamic-models at r-project.org
> >> https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-dynamic-models mailing list
> R-sig-dynamic-models at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models


-- 
PD Dr. Johannes Ranke
Grenzach-Wyhlen



More information about the R-sig-dynamic-models mailing list