我试图在4个节点上并行化一个代码(type= "SOCK")。这是我的密码。
library(itertools)
library(foreach)
library(doParallel)
library(parallel)
workers <- ip address of 4 nodes
cl = makePSOCKcluster(workers, master="ip address of master")
registerDoParallel(cl)
z <- read.csv("ProcessedData.csv", header=TRUE, as.is=TRUE)
z <- as.matrix(z)
system.time({
chunks <- getDoParWorkers()
b <- foreach (these = isplitIndices(nrow(z),
chunks=chunks),
.combine = c) %dopar% {
a <- rep(0, length(these))
for (i in 1:length(these)) {
a[i] <- mean(z[these[i],])
}
a
}
})
我知道这个错误:
4个节点产生错误;第一个错误:找不到对象'.doSnowGlobals‘。
如果我使用doMC,即使用同一台机器的内核,则此代码运行良好。但是,当我试图使用其他计算机进行并行计算时,就会出现上述错误。当我将其更改为registerDoSNOW时,错误仍然存在。
雪和DoSNOW在一个集群中工作吗?我可以使用雪花在本地主机上创建节点,但不能在集群上创建节点。有人在外面玩雪吗?
发布于 2014-09-15 18:15:43
如果任何工作人员无法加载doParallel包,则可以获得此错误。您可以通过将doParallel安装到某个目录并通过“.libPaths”指向主目录来实现这一点:
> .libPaths('~/R/lib.test')
> library(doParallel)
> cl <- makePSOCKcluster(3, outfile='')
starting worker pid=26240 on localhost:11566 at 13:47:59.470
starting worker pid=26248 on localhost:11566 at 13:47:59.667
starting worker pid=26256 on localhost:11566 at 13:47:59.864
> registerDoParallel(cl)
> foreach(i=1:10) %dopar% i
Warning: namespace ‘doParallel’ is not available and has been replaced
by .GlobalEnv when processing object ‘’
Warning: namespace ‘doParallel’ is not available and has been replaced
by .GlobalEnv when processing object ‘’
Warning: namespace ‘doParallel’ is not available and has been replaced
by .GlobalEnv when processing object ‘’
Error in checkForRemoteErrors(lapply(cl, recvResult)) :
3 nodes produced errors; first error: object '.doSnowGlobals' not found
当一个来自doParallel的函数被反序列化到一个工作人员上时,就会发生警告。当函数执行并尝试访问在.doSnowGlobal命名空间中定义的doParallel (而不是.GlobalEnv )时,就会发生错误。
还可以通过执行以下命令来验证工作人员是否可以使用doParallel:
> clusterEvalQ(cl, library(doParallel))
Error in checkForRemoteErrors(lapply(cl, recvResult)) :
3 nodes produced errors; first error: there is no package called ‘doParallel’
发布于 2016-10-19 18:34:33
若要在每个工作人员上设置库路径,可以运行:
clusterEvalQ(cl, .libPaths("Your library path"))
发布于 2016-04-27 21:48:04
@Steve回答的一个具体案例是,您的员工无法加载给定的包(例如doParallel),因为包在Packrat项目中。将软件包安装到系统库中,或将其安装到工作人员能够找到的其他地方。
https://stackoverflow.com/questions/25079527
复制相似问题