【问题标题】:Error in unserialize(socklist[[n]]) : error reading from connection on Unix反序列化错误(socklist[[n]]):从 Unix 上的连接读取错误
【发布时间】:2014-08-11 04:53:27
【问题描述】:

我尝试在具有 20 个 CPU 的 Unix 机器上运行以下代码,使用 R foreach、parallel、doParallel 和 party 包(我的目标是让 party / varimp 函数运行多个 CPU 并行):

parallel_compute_varimp <- function (object, mincriterion = 0, conditional = FALSE, threshold = 0.2, 
    nperm = 1, OOB = TRUE, pre1.0_0 = conditional) 
{
    response <- object@responses
    input <- object@data@get("input")
    xnames <- colnames(input)
    inp <- initVariableFrame(input, trafo = NULL)
    y <- object@responses@variables[[1]]
    error <- function(x, oob) mean((levels(y)[sapply(x, which.max)] != y)[oob])

    w <- object@initweights
    perror <- matrix(0, nrow = nperm * length(object@ensemble), ncol = length(xnames))
    colnames(perror) <- xnames

    data = foreach(b = 1:length(object@ensemble), .packages = c("party","stats"), .combine = rbind) %dopar%
    {
        try({
            tree <- object@ensemble[[b]]
            oob <- object@weights[[b]] == 0

            p <- .Call("R_predict", tree, inp, mincriterion, -1L, PACKAGE = "party")

            eoob <- error(p, oob)

            for (j in unique(varIDs(tree))) {
                for (per in 1:nperm) {
                    if (conditional || pre1.0_0) {
                      tmp <- inp
                      ccl <- create_cond_list(conditional, threshold, xnames[j], input)
                      if (is.null(ccl)) {
                        perm <- sample(which(oob))
                      }
                      else {
                        perm <- conditional_perm(ccl, xnames, input, tree, oob)
                      }
                      tmp@variables[[j]][which(oob)] <- tmp@variables[[j]][perm]
                      p <- .Call("R_predict", tree, tmp, mincriterion, -1L, PACKAGE = "party")
                    }
                    else {
                      p <- .Call("R_predict", tree, inp, mincriterion, as.integer(j), PACKAGE = "party")
                    }
                    perror[b, j] <- (error(p, oob) - eoob)
                }
            }

            ########
            # return data to the %dopar% loop data variable
            perror[b, ]
            ########

        }) # END OF TRY
    } # END OF LOOP WITH PARALLEL COMPUTING

    perror = data
    perror <- as.data.frame(perror)
    return(MeanDecreaseAccuracy = colMeans(perror))
}

environment(parallel_compute_varimp) <- asNamespace('party')


cl <- makeCluster(detectCores())
registerDoParallel(cl, cores = detectCores())
<...>
system.time(data.cforest.varimp <- parallel_compute_varimp(data.cforest, conditional = TRUE))

但我收到一个错误:

> system.time(data.cforest.varimp <- parallel_compute_varimp(data.cforest, conditional = TRUE))
Error in unserialize(socklist[[n]]) : error reading from connection
Timing stopped at: 58.302 13.197 709.307

代码在 4 个 CPU 上使用较小的数据集。

我的想法不多了。有人可以建议一种方法来实现我在并行 CPU 上运行派对包 varimp 函数的目标吗?

【问题讨论】:

  • 你发现这个问题了吗?
  • 我不这么认为。反正我都忘了:)

标签: r foreach parallel-processing


【解决方案1】:

错误:

Error in unserialize(socklist[[n]]) : error reading from connection

表示主进程在调用反序列化以从套接字连接读取到其中一个工作人员时出错。这可能意味着相应的工作人员死亡,从而丢弃了套接字连接的结束。不幸的是,它可能因多种原因而死亡,其中许多是系统特定的。

您通常可以通过使用 makeCluster "outfile" 选项来找出 worker 死亡的原因,这样 worker 生成的错误消息就不会被丢弃。我通常建议使用outfile="",如in this answer 所述。请注意,“outfile”选项在 snow 和 parallel 包中的工作方式相同。

您还可以通过注册顺序后端来验证您的 foreach 循环在顺序执行时是否正常工作:

registerDoSEQ()

如果幸运的话,foreach 循环在顺序执行时会失败,因为通常更容易找出问题所在。

【讨论】:

    猜你喜欢
    • 2018-09-24
    • 2016-02-15
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 2015-01-19
    • 2012-05-03
    相关资源
    最近更新 更多