[R-sig-dyn-mod] deSolve with compiled code and varying size of parms

Setzer, Woodrow Setzer.Woodrow at epa.gov
Wed Mar 29 16:32:14 CEST 2017


You might also look at the GNU package MCSim:
 https://www.gnu.org/software/mcsim/ 
It includes a dynamic modeling language definition and interpreter, and can produce compiled code (and some R helper objects and functions) that are compatible with deSolve.

Woody Setzer
National Center for Computational Toxicology
US Environmental Protection Agency

-----Original Message-----
From: R-sig-dynamic-models [mailto:r-sig-dynamic-models-bounces at r-project.org] On Behalf Of Daniel Kaschek
Sent: Tuesday, March 28, 2017 4:15 PM
To: r-sig-dynamic-models at r-project.org
Subject: Re: [R-sig-dyn-mod] deSolve with compiled code and varying size of parms

Dear Rampal,

I am not sure whether it is possible to do what you want. At least not if you rely on the odeparms function. Perhaps Thomas and Karline will know better.

You could write a small R function based on sink() to generate your C code with the correct value for lx "on the fly". This would be a compromise.

By the way, there are some packages around working with deSolve and autogenerating C code or FORTRAN code, e.g., cOde and rodeo.

Best regards,
Daniel


On Tue, 2017-03-28 at 17:12 +0200, Rampal S. Etienne wrote:
> Dear all,
> 
> I have been using the deSolve package with R functions, but now want 
> to speed up the calculations by using compiled C code. I read the 
> deSolve vignette on this, and it works when you specify the size of 
> the parms vector in the C-code. My questions is: how can I infer this 
> size from parms in the c-code rather than set it?
> 
> For example, in the code pasted below I must define lx to be 10 in the 
> second line. I would like lx to be inferred from either the size of 
> parms, or - if necessary - as an additional, first, element of the 
> parms vector. Interestingly, the derivs function does have an argument 
> like this, namely *neq, but initmod1 does not.
> 
> Kind regards,
> 
> Rampal Etienne
> 
> /* file mymod1.c */
> #include <R.h>
> #define lx 10
> static double parms[lx * lx];
> 
> /* initializer */
> void initmod1(void (* odeparms)(int *, double *)) {
>    int N = lx * lx;
>    odeparms(&N, parms);
> }
> 
> /* Derivatives */
> void derivs (int *neq, double *t, double *y, double *ydot, double 
> *yout, double *ip) {
>   int i, j;
>   for(i = 0; i < *neq; i++) {
>     ydot[i] = 0;
>     for(j = 0; j < *neq; j++) {
>       ydot[i] = ydot[i] + parms[i * (*neq) + j] * y[j];
>     }
>   }
> }
> /* END file mymod1.c */
> 
> _______________________________________________
> R-sig-dynamic-models mailing list
> R-sig-dynamic-models at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models

_______________________________________________
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