调试 R 并行 mclapply

问题描述

mclapply错误代码很难调试,因为一个作业的所有值都会受到影响。

我准备了一个简单的例子。

library(parallel)
library(dplyr)

data(iris)

## Parallel Version
parFun <- function(i){
  print(i)
  ## Generate a random subset of the iris data set
  daf <- iris[sample(1:nrow(iris),10),]
  
  ## Bug in iteration number of 39,some internal function returned NULL
  if(i == 39){
    daf <- NULL
  }
  
  ## dplyr produces an error,needs an if test for NULL
  res <- daf %>% group_by("Species") %>% slice_min(order_by = Petal.Width,n = 2)
  
  return(res)
}

## Do the call which returns error code
## Scheduled core 3 encountered error in user code,all values of the job will be affected
resList <- mclapply(1:50,parFun,mc.cores=12)
idx <- sapply(resList,function(x){is.null(nrow(x))})

## Depending on the number of cores a sequence of jobs is affected
which(idx == TRUE)

如何在 1000 次迭代中调试此类代码?如何找到导致错误的单个 i ?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...