在 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 个内核运行。