How can you initialize workers using doSMP?

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.

+5
source share
2 answers

foreach ..., . , iter .

w <- startWorkers(workerCount = 4)
registerDoSMP(w)

foreach(x=iter(x),y=iter(y),z=iter(z) ) %dopar% (x*y*z)

:

foreach(1:10 ) %dopar% (x*y*z)  # Somewhat repetitious # 

zed <- 20:1
foreach(x=iter(x) ) %dopar% (x*zed)
+1

:

library(doSMP)
library(foreach)
w <- startWorkers(workerCount = 4)
registerDoSMP(w)
foreach(i = 1:3) %dopar% sqrt(i)

doSNOW

registerDoSNOW(cl)

http://cran.r-project.org/web/packages/doSNOW/doSNOW.pdf

, doMC ( Windows)

library(doMC)
registerDoMC()
foreach(i = 1:3) %dopar% sqrt(i)

2.14, , , .

0

All Articles