小编Jbi*_*ill的帖子

R - 并行化错误,checkCluster(cl) - 不是有效的集群

这段代码给我带来了一个错误: 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)
Run Code Online (Sandbox Code Playgroud)

如果没有并行化尝试,这完全可以正常工作:

res.mat <- lapply(1:10, function(x) my.fun(x))
Run Code Online (Sandbox Code Playgroud)

这个例子也很有效:

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))
Run Code Online (Sandbox Code Playgroud)

我该如何解决我的问题?

我发现例如

class(cl)
[1] "SOCKcluster" "cluster"  
Run Code Online (Sandbox Code Playgroud)

cl 是:

cl
socket cluster with 8 nodes on host ‘localhost’
Run Code Online (Sandbox Code Playgroud)

parallel-processing r

5
推荐指数
1
解决办法
3481
查看次数

标签 统计

parallel-processing ×1

r ×1