gpt4 book ai didi

R 并行处理错误 `Error in checkForRemoteErrors(val) : 6 nodes produced errors; first error: subscript out of bounds`

转载 作者:行者123 更新时间:2023-12-05 07:30:08 26 4
gpt4 key购买 nike

我正在学习并行处理,以此来处理一些庞大的数据集。

我有一些预定义的变量如下:

CV <- function(mean, sd) {(sd / mean) * 100} 
distThreshold <- 5 # Distance threshold
CVThreshold <- 20 # CV threshold

LocalCV <- list()
Num.CV <- list()

然后加载parallel库,将基变量和库分配给集群:

library(parallel)
clust_cores <- makeCluster(detectCores(logical = T) )
clusterExport(clust_cores, c("i","YieldData2rd","CV", "distThreshold", "CVThreshold"))
clusterEvalQ(clust_cores, library(sp))

然后传递集群参数clust_coresparSapply :

for (i in seq(YieldData2rd)) {
LocalCV[[i]] = parSapply(clust_cores, X = 1:length(YieldData2rd[[i]]),
FUN = function(pt) {
d = spDistsN1(YieldData2rd[[i]], YieldData2rd[[i]][pt,])
ret = CV(mean = mean(YieldData2rd[[i]][d < distThreshold, ]$yield),
sd = sd(YieldData2rd[[i]][d < distThreshold, ]$yield))
return(ret)
}) # calculate CV in the local neighbour
}

stopCluster(clust_cores)

然后我得到 Error in checkForRemoteErrors(val) : 6 nodes produced errors; first error: subscript out of bounds除了warning messages:
1: closing unused connection (<-localhost:11688)
.

请告诉我如何解决这个问题。

为了可重现的示例,我创建了一个大列表对象,它在原始 for 中运行良好没有并行处理组件的循环。

library('rgdal')

Yield1 <- data.frame(yield=rnorm(460, mean = 10), x1=rnorm(460, mean = 1843235), x2=rnorm(460,mean = 5802532))
Yield2 <- data.frame(yield=rnorm(408, mean = 10), x1=rnorm(408, mean = 1843235), x2=rnorm(408, mean = 5802532))
Yield3 <- data.frame(yield=rnorm(369, mean = 10), x1=rnorm(369, mean = 1843235), x2=rnorm(369, mean = 5802532))

coordinates(Yield1) <- c('x1', 'x2')
coordinates(Yield2) <- c('x1', 'x2')
coordinates(Yield3) <- c('x1', 'x2')

YieldData2rd <- list(Yield1, Yield2, Yield3)

最佳答案

感谢@Omry Atia 的评论,我开始研究 foreach 包并进行了第一次尝试。

library(foreach)
library(doParallel)

#setup parallel backend to use many processors
cores=detectCores()
clust_cores <- makeCluster(cores[1]-1) #not to overload your computer
registerDoParallel(clust_cores)

LocalCV = foreach(i = seq(YieldData2rd), .combine=list, .multicombine=TRUE) %dopar% {
LocalCV[[i]] = sapply(X = 1:length(YieldData2rd[[i]]),
FUN = function(pt) {
d = spDistsN1(YieldData2rd[[i]], YieldData2rd[[i]][pt,])
ret = CV(mean = mean(YieldData2rd[[i]][d < distThreshold, ]$yield),
sd = sd(YieldData2rd[[i]][d < distThreshold, ]$yield))
return(ret)
}) # calculate CV in the local neighbour
}

stopCluster(clust_cores)

无需将 LocalCV 放在 foreach 的前面,它就会打印出全部内容。

它将在一些巨大的数据集上尝试新代码,看看它能达到多快。

引用:run a for loop in parallel in R

关于R 并行处理错误 `Error in checkForRemoteErrors(val) : 6 nodes produced errors; first error: subscript out of bounds`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52425012/

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