Dylan Childs
2005-Nov-06 19:39 UTC
[R] Problem defining a system of odes as a C library with lsoda
I have been trying to make use of the odesolve library on my university's Linux grid - currently R version 2.0.1 is installed and the system runs 64-bit Scientific Linux based on Redhat. I cannot seem to get lsoda working when I define the model as a shared C library. For example, the following snippet uses the mymod.c example bundled with the package: ### START rm(list=ls()) setwd("~/projects/test_odesolve") invisible(file.remove("mymod.o","mymod.so")) system("R CMD SHLIB mymod.c") dyn.load("mymod.so") require(odesolve) parms <- c(k1 = 0.04, k2 = 1e4, k3=3e7) my.atol <- c(1e-6, 1e-10, 1e-6) times <- c(0, 4*10^(-1:10)) print(system.time( out1 <- lsoda(c(1.0,0.0,0.0),times,"myderivs", parms, rtol=1e-4,atol=my.atol,jacfunc="myjac", dllname="mymod") ) ) ### END When I run this mymod.c compiles without any errors or warnings and the mymod.so library seems to load fine via dyn.load (the call is.loaded("mymod") returns TRUE for example). However, the call to lsoda fails with the following error: Error in lsoda(c(1, 0, 0), times, "myderivs", parms, rtol = 1e-04, atol = my.atol, : Confusion over the length of parms This seems a very odd error message as the length of the parameter vector is definitely correct and if I run exactly the same script on my Mac everything works fine. Have I missed something obvious - is this something to do with using an older version of R for example? Dr. Dylan Z. Childs Department of Animal and Plant Sciences, University of Sheffield, Sheffield, S10 2TN, UK.
Woodrow Setzer
2005-Nov-07 14:42 UTC
[R] Problem defining a system of odes as a C library with lsoda
I think the problem is in odesolve (something I thought I'd already fixed). I don't have a 64-bit system to test on, so could you try these changes and let me know (offline) if they fix the problem? There is a type mismatch in odesolve; I want to know if that is the cause of your problem. In any case, I'll get an updated version of odesolve on CRAN ASAP. in mymod.c: change the line mymod(void(* odeparms)(int *, double *)) to mymod(void(* odeparms)(long int *, double *)) and the line int N=3; to long int N=3; Woody -----Original Message----- From: Dylan Childs <D.Childs at sheffield.ac.uk> Sent: Nov 6, 2005 2:39 PM To: r-help at stat.math.ethz.ch Subject: [R] Problem defining a system of odes as a C library with lsoda I have been trying to make use of the odesolve library on my university's Linux grid - currently R version 2.0.1 is installed and the system runs 64-bit Scientific Linux based on Redhat. ... [deleted] However, the call to lsoda fails with the following error: Error in lsoda(c(1, 0, 0), times, "myderivs", parms, rtol = 1e-04, atol = my.atol, : Confusion over the length of parms ... [deleted] Dr. Dylan Z. Childs Department of Animal and Plant Sciences, University of Sheffield, Sheffield, S10 2TN, UK. ______________________________________________ R-help at stat.math.ethz.ch mailing list stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! R-project.org/posting-guide.html Woodrow Setzer National Center for Computational Toxicology US Environmental Protection Agency Research Triangle Park, NC 27711