1

我一直在探索并行包中的 parSapply() 函数。

在 sapply() 函数中,我们可以这样做:

result = sapply(1:10, function(x){print('haha'); return(x)})

这会在每次迭代中打印“哈哈”并将 1:10 存储在“结果”中。

当我尝试使用 parSapply() 做同样的事情时:

cores = detectCores() - 1
cl = makeCluster(cores)
result = parSapply(cl,1:10, function(x){print('haha'); return(x)})

结果中仅存储了 1:10,但未打印“哈哈”。想知道如何解决这个问题?谢谢!

4

0 回答 0