I have an R code that involves several foreach workers to perform some tasks in parallel. I am using foreach and doMC for this purpose. I want to let each of the foreach workers recruits some new workers and distribute some parts of their code, which is parallelizable, to them.
The current code looks like:
require(doMC)
require(foreach)
registerDoMC(cores = 8)
foreach (i = (1:8)) %dopar% {
<<some code here>>
for (j in c(1:4)) {
<<some other code here>>
}
}
I am looking for an ideal code that would look like:
require(doMC)
require(foreach)
registerDoMC(cores = 8)
foreach (i = (1:8)) %dopar% {
<<some code here>>
foreach (j = (1:4)) %dopar% {
<<some other code here>>
}
}
I saw an example of multi-paradigm parallelism using doSNOW and doMC here (https://www.rmetrics.org/files/Meielisalp2009/Presentations/Lewis.pdf#page=17). However, I do not know whether it does what I want or not.
Also, it seems Nested foreach is not applicable because it requires merging the two loops (see here), while in my case this is not preferred; the second loop only helps the first one for a portion of the code. Please correct me if I am wrong.
Thanks.
foreach
expressions: cran.r-project.org/web/packages/foreach/vignettes/nested.pdf . I don't know about recruiting more workers within the loops, however. – Brainwashing