【发布时间】:2018-09-22 01:09:05
【问题描述】:
我想比较两种方法在同一数据集上的性能。为了在它们之间进行多重比较,我使用的是 Bootstrap,所以我认为使用并行计算可能是个好主意。由于引导程序的数量是 50,所以我分配了 50 个核心来完成这项工作。伪代码如下:
num.round <- 50 # number of bootstrap, which means I'll generate 50 subsets of the original dataset to do 50 comparison between the two methods
rounds.btsp <- seq(1, num.round)
BootStrap <- function(round.btsp) {
result1 <- METHOD1(round.btsp)
result2 <- METHOD2(round.btsp)
return(list(result1 = result1, result2 = result2))
}
results.btsp <- mclapply(rounds.btsp, BootStrap, mc.cores = num.round)
for (round.btsp in rounds.btsp){
result1 <- results.btsp[[round.btsp]]$result1
result2 <- results.btsp[[round.btsp]]$result2
COMPARE(result1, result2) # do the comparison here, and this will be repeated 50 times
}
我在“COMPARE”这一步出错了,当我查看它时,我发现当round.btsp = 10时,result1或result2中什么都没有。所以我尝试将round.btsp设置为10并运行函数“BootStrap”内部的内容,但一切都很好。然后我再次重复整个脚本,同样的错误再次发生。但和上次不同的是,现在round.btsp = 20(这10和20只是举例)。
我们的服务器上共有 80 个内核。但也有其他用户不时使用某些内核。
关于我观察到的和我们核心的情况,我猜原因是当我需要50个核心但有时对我来说不够用时,一些线程将无法正常运行,因此我'不会从该线程中得到任何信息。
【问题讨论】:
标签: r parallel-processing