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

Graham W Griffiths graham at griffiths1.com
Wed Nov 22 21:05:43 CET 2017


Hi Maciek,

Another consideration is to drop the use of with() in the derivative
function Nanda(). I stopped using this for large or computationally
demanding problems some time ago.

Reformulating the problem without using with(), and including the parameters
within Nanda(), the code runs much faster. For example, with only these
changes, on my old PC the code completes in the following times,


                dt= 0.01      dt=1
                --------      ----
original code:    6.11s       0.18s
no use of with(): 0.91s       0.09s 

This compares to the Matlab code  that completes in 0.16s

Also, I employed the JIT compiler as:

   require(compiler)
   enableJIT(3)

However, this gave no appreciable improvement on performance for this
problem, although I have found it does speed up the computation for some
dynamic problems.

These changes may not be appropriate for your particular problem, but they
may be worth considering.

Regards,

Graham W Griffiths
City, University of London
www.pdecomp.net



 

-----Original Message-----
From: R-sig-dynamic-models
[mailto:r-sig-dynamic-models-bounces at r-project.org] On Behalf Of John
Harrold
Sent: 22 November 2017 16:10
To: Special Interest Group for Dynamic Simulation Models in R
Subject: Re: [R-sig-dyn-mod] lsoda FASTER than ode45 (was: lsoda (deSolve)
order of magnitude slower than ode45)

Hello Maciek,

I go back and forth between Matlab and R. In Matlab I run my models in C
through Simulink as an S-function. In R I use the compiled C that Thomas
mentions above. It took me some experimentation, but I've managed to get
things to run at comparable speeds in both Matlab and R. I've put a bit more
effort in optimizing my R code, and I actually have R running faster in some
instances.

John

On Wed, Nov 22, 2017 at 2: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
>
> _______________________________________________
> R-sig-dynamic-models mailing list
> R-sig-dynamic-models at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models
>



--
-------------------------------------
John M. Harrold
john.m.harrold _at_gmail
-------------------------------------

	[[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



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