[R-sig-dyn-mod] compiled code and parallel computing with deSolve

Simeon Lisovski simeon.lisovski at googlemail.com
Thu Nov 9 14:18:17 CET 2017


Hallo,

 

I am having problems with some of my code that uses compiled code (C) within
the "ode" function.

 

For an optimization routine, I need to run a particular ODE in each
iteration and with multiple parameters to find a solution that is then
incorporated in the main function. To speed things up I was trying to run
this step in parallel (using the parallel package). However, I cannot find a
way to export the compiled code to the nodes so that it`ll become available
for the ode function. On a mac the mcmcApply function is doing the trick,
but I cannot get it to work on a windows computer.

 

The basic idea for code (not reproducible since that would require very long
code):

 

dyn.load(model.dll) ## c-code with functions "dem", "initforc" and "event"

 

event_times <- c(1,5,10,15)

t_fnc              <- function(t) {.}

 

parallel::makeCluster(nr.cores)

parallel::clusterSetRNGStream(mycl)

parallel::clusterEvalQ(mycl, library("deSolve"))

parallel::clusterExport(mycl,c("event_times", "t_fnc"), envir=environment())

 

mu <- seq(0.01, 0.1, length = 100)

 

fnc <- function(x, ..) {

     parms <- c(alpha = x, . )

out <-  ode(y = xstart, t, func = "popM", parms = parms,

                      dllname = "dem", initforc = "initforc",

                             forcings = list(t, t_fnc(t)),

                                   initfunc = "initmod", nout = 0,

                                   events = list(func = "event", times =
event_times),

                                  method = rkMethod("rk34f")

     out

}

 

parallel::parSapply(mycl, mu, FUN = fnc, .)

 

 

This won`t work  and R complains that event$func should be loaded.

 

Any thoughts?

 

Thanks,

Simeon

 


	[[alternative HTML version deleted]]



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