I want to full fill different tasks in parallel using doMC
and foreach
. My work stream looks like the following:
I want to start six task in parallel, which works fine. The tricky point is that one of these tasks contain sub tasks which could be also parallelized. Is this possible? My code looks the following:
library(foreach) ##https://stackoverflow.com/questions/31137842/run-multiple-r-scripts-simultaneously
library(doMC)
registerDoMC(9)
modelList <- list("a.R","b.R","c.R","d.R","e.R","f.R")
out <- foreach(x=modelList, .verbose=TRUE) %dopar%{
source(x)
}
Whereas a.R
contains also a foreach
:
task.list <- c("task1","task2","task3")
registerDoMC(3)
result.list <- foreach(c = 1:length(country),.verbose = TRUE) %dopar%{
some crazy stuff
}
If this makes sense. How and at which point should I register the number of cores? Allover I need nine. So should I allocate them only at the beginning and leave it at in a.R
?
Thank you for your help.