【发布时间】:2014-02-13 22:18:43
【问题描述】:
在 R 中运行以下脚本时:
library(doMC)
registerDoMC(cores=3)
# First foreach
# This runs in 3 threads
foreach(i=1:3) %dopar% sqrt(i)
# Second foreach
# This add 3 threads to the previous ones (now inactive but still consuming memory), totalling 6 threads
foreach(i=1:3) %dopar% sqrt(i)
我想知道在运行第二个的时候如何复用第一个foreach的线程,让整个脚本始终使用3个核心运行。
【问题讨论】:
-
您应该将您的编辑转换为答案,以便于查找和理解。
-
完成(见下面的答案)
标签: r parallel-processing domc