An error in one job contaminates others with mclapply

依然范特西╮ 提交于 2019-12-05 15:36:32

The trick is to set mc.preschedule = FALSE

mclapply(1:3, test, mc.cores = 2, mc.preschedule = FALSE)
#[[1]]
#[1] 1

#[[2]]
#[1] 2

#[[3]]
#[1] "Error in FUN(X[[nexti]], ...[cut]
#Warning message:
#In mclapply(1:3, test, mc.cores = 2, mc.preschedule = FALSE) :
#  1 function calls resulted in an error

This works because by default mclapply seems to divide X into mc.cores groups and applies a vectorized version of FUN to each group. As a result if any member of the group yields an error, all values in that group will yield the same error (but values in other groups are unaffected).

Setting mc.preschedule = FALSE has adverse effects and may make it impossible to reproduce a sequence of pseudo-random numbers where the same job always receives the same number in the sequence, see ?mcparallel under the heading Random numbers.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!