这段代码给我带来了一个错误:Error in checkCluster(cl): not a valid cluster
library(parallel)
numWorkers <-8
cl <-makeCluster(numWorkers, type="PSOCK")
res.mat <- parLapply(1:10, function(x) my.fun(x))
stopCluster(cl)
如果没有并行化尝试,这完全可以正常工作:
res.mat <- lapply(1:10, function(x) my.fun(x))
这个例子也很有效:
workerFunc <- function(n){return(n^2)}
library(parallel)
numWorkers <-8
cl <-makeCluster(numWorkers, type ="PSOCK")
res <- parLapply(cl, 1:100, workerFunc)
stopCluster(cl)
print(unlist(res))
我该如何解决我的问题?
我发现例如
class(cl)
[1] "SOCKcluster" "cluster"
cl 是:
cl
socket cluster with 8 nodes on host ‘localhost’
最佳答案
library(parallel)
numWorkers <- 8
cl <-makeCluster(numWorkers, type="PSOCK")
res.mat <- parLapply(cl,1:10, function(x) my.fun(x))
stopCluster(cl)
关于R - 并行化错误,checkCluster(cl) - 不是有效的集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46503873/