问题描述
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 (将#修改为@)