Is there a way to initialize a doSMP cluster similar to clusterEvalQand clusterExportin a snow packet? For instance:
x <- 1:10
y <- 10:1
z <- rnorm(10)
cl <- makeSOCKcluster(2)
clusterEvalQ(cl, library(quantmod))
clusterExport(cl, list("x","y","z"))
clusterEvalQ(cl, ls())
clusterEvalQ(cl, search())
There is an option initEnvirfor doSMP, but ?doSMPsays
‘initEnvir’ is a function to be executed by each worker before any
tasks are executed associated with a foreach. Its purpose is to
initialize the execution environment, or the worker in general.
It is only executed by a worker if that worker executes at least
one task associated with the foreach.
Every employee needs a copy of several large objects in order to execute the expression that I send to foreach. In addition, I need to call foreachseveral hundred times with identical versions of these large objects. It would be inefficient to copy these objects for each call foreach.
Even if there is no ready-made way to do this, I would appreciate kludge.
source
share