r - 多次迭代后出现 %dopar% 错误

标签 r domc

我一直在尝试在 R 中运行一个并行化的 foreach 循环,它在大约十次迭代后工作正常,但随后崩溃,显示错误:

Error in { : task 7 failed - "missing value where TRUE/FALSE needed"
Calls: %dopar% -> <Anonymous>
Execution halted

我将每个循环的结果附加到一个文件中,该文件确实显示了预期的输出。我的脚本如下,使用来自 this post 的 combn_sub 函数:

LBRA <- fread(
 input      = "LBRA.012",
 data.table = FALSE)
str_bra <- nrow(LBRA)

br1sums <- colSums(LBRA)
b1non <- which(br1sums == 0)

LBRA_trim <- LBRA[,-b1non]

library(foreach)
library(doMC)
registerDoMC(28)

foreach(X = seq(2, (nrow(LBRA)-1))) %dopar% {
  com <- combn_sub(
   x    = nrow(LBRA),
   m    = X,
   nset = 1000)

  out_in <- matrix(
   ncol = 2,
   nrow = 1)
   colnames(out) <- c("SNPs", "k")

    for (A in seq(1, ncol(com))){
      rowselect <- com[, A]

      sub <- LBRA_trim[rowselect, ]
      subsum <- colSums(sub)

      length <- length(which(subsum != 0)) - 1
      out_in <- rbind(out_in, c(length, X))
    }

  write.table(
   file   = "plateau.csv",
   sep    = "\t",
   x      = out_in,
   append = TRUE)
}

最佳答案

我的 foreach 调用也有类似的问题...

tmpcol <- foreach(j = idxs:idxe, .combine=cbind) %dopar% { imp(j) }

Error in { : task 18 failed - "missing value where TRUE/FALSE needed"

改变.errorhandling参数只忽略错误

tmpcol <- foreach(j = idxs:idxe, .combine=cbind, .errorhandling="pass") %dopar% { imp(j) }

Warning message:
In fun(accum, result.18) :
  number of rows of result is not a multiple of vector length (arg 2)

我建议在 X=7 的 foreach 调用中运行该函数。在我的案例中,问题是我的函数 imp(j) 抛出一个错误(对于 j=18,它卡在 NA 计算上)导致 foreach 的输出模糊。

关于r - 多次迭代后出现 %dopar% 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35273971/

相关文章:

r - 使用 tidyr 收集多个日期/值列

r - 修改色标图例指南以匹配 ggplot2 中的线条大小

r - ggplot 中的条形图,每组条数不同

R foreach 不使用多核

r - doMC vs doSNOW vs doSMP vs doMPI : why aren't the various parallel backends for 'foreach' functionally equivalent?

r - R中doMC和doParallel的区别

r - 在 R 中使用多核和 doMC 时如何标记我的子进程以进行日志记录

r - 使用 ggplot2 的 stat_function 绘制泊松分布

r - 检查包名称是否属于 CRAN 归档包

r - 是否可以使用 foreach 和后端的 "multicore-kind"获取进度条