R 并行中的错误:checkForRemoteErrors(val) 中的错误:2 个节点产生错误;第一个错误:无法打开连接

2024-03-17

我写了一个函数来并行运行R,但它似乎不起作用。代码是 '''

rm(list=ls())
square<-function(x){
  library(Iso)
  y=ufit(x,lmode<-2,x<-c(1:length(x)),type="b")[[2]]
  return(y)
}
num<-c(1,2,1,4)
cl <- makeCluster(getOption("cl.cores",2))
clusterExport(cl,"square")
results<-parLapply(cl,num,square)
stopCluster(cl)

''' 错误是: checkForRemoteErrors(val) 中的错误: 2个节点产生错误;第一个错误:无法打开连接 我认为可能的原因是我在函数中使用了Iso包。但我不知道如何解决。


如果您想并行执行,则必须将函数/整个包导出到每个集群:

library(doSNOW)
## the rest is the same
rm(list=ls())
square<-function(x){
  y=ufit(x,lmode<-2,x<-c(1:length(x)),type="b")[[2]]
  return(y)
}
num<-c(1,2,1,4)
cl <- makeCluster(getOption("cl.cores",2))
clusterExport(cl,"square")
clusterEvalQ(cl,library(Iso))
## here you should see smth like this, where each cluster prints attached libraries
[[1]]
[1] "Iso"       "snow"      "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"   "base"     

[[2]]
[1] "Iso"       "snow"      "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"   "base" 

## then just call the same as with parallel

results<-parLapply(cl,num,square)
stopCluster(cl)


## alternative is to use Iso::ufit
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

R 并行中的错误:checkForRemoteErrors(val) 中的错误:2 个节点产生错误;第一个错误:无法打开连接 的相关文章

随机推荐