Monday, 12 August 2013

What is the cause of "Error in .C("unlock solver")" Error in deSolve Package?

What is the cause of "Error in .C("unlock solver")" Error in deSolve Package?

I have been using the deSolve package in a MCMC algorithm to estimate
parameters in an ODE and wrote the functions used in the solver in C to
speed up the algorithm. Sometimes, but not always I get the error Error in
.C("unlock solver") when running the ode function. I am able to
successfully compile and link the C files using the commands
system("R CMD SHLIB [insert-file-path]")
dyn.load("[dll-file-path]")
but when I try to solve the ODE using the dll file, the error is thrown.
Then, even when running a simple script like the one below, I get the same
error. I think the issue is related to using the compiled code, but I
don't know how and cannot find any references on this error.
> require(deSolve)
> initVal <- c(y=1)
> times <- seq(0, 1, 0.001)
> parms <- c(k=1)
> model1 <- function(t, y, parms){
+ with(as.list(c(y, parms)),{
+ dy <- -k*y;
+ list(c(dy))
+ })
+ }
> out <- ode(y=initVal, times=times, parms=parms, func=model1)
Error in .C("unlock_solver") :
"unlock_solver" not resolved from current namespace (deSolve)

No comments:

Post a Comment