When running the following script in 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)
I would like to know how to reuse the threads of the first foreach
when running the second one, so that the whole script always runs using 3 cores.