r - 调试 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 ?
解决方案
推荐阅读
- ios - PLCrashReporter 未在 Xcode 10 beta 5 中编译
- css - 在 twitter bootstrap 的谷歌地图上浮动一个 div
- pervasive - 普遍的 SQL 在 Group By 之后忽略 Order By
- xamarin.forms - Xamarin Forms:ImageCircle 包在 UWP 发布模式下不起作用
- c# - 计算巨大的排列 - 计算元素并获得第 n 个元素
- javascript - 我想在我的可移动 div 中创建一个 div 就像一个窗口
- google-cloud-platform - 启动脚本未在启用自动缩放的 GCP Compute Engine Windows 服务器上运行
- php - 将 JSON 代码附加到从 MySQL 和 PHP 创建的 JSON
- android - Kotlin:检查是否为空并直接转换
- pubnub - 如何使用 pubnub php v4 sdk 禁用来自 pubnub 的返回消息