gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 17:16:15 24 4
gpt4 key购买 nike

这段代码给我带来了一个错误: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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com