2
当运行在R中的以下脚本:使用doMC库并行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)
我想知道如何在运行第二个时,使整个脚本始终运行使用3芯重用第一foreach
的线程。
您应该将编辑转换为答案,以便于查找和理解。 –
完成(见下面的答案) – Marcelo