Parallel computation: Loading packages in each thread only once

让人想犯罪 __ 提交于 2019-12-04 10:55:40

The doParallel package inherits some handy low level functions from parallel including clusterCall which executes the function once on each node.

I had the exact same problem and solved it by doing:

library(doParallel)
myCluster = makeCluster(6)
registerDoParallel(myCluster)
clusterCall(myCluster, function() library(magrittr))

You can also use the argument .packages:

foreach(i = 1:5, .packages = "magrittr") %dopar% {i %>% runif}
user56134

You could try this:

foreach(i = randomData,.packages=c("magrittr")) %dopar% {
  i %>% randomFunction
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!