I have a case where foreach
using doMC
as a backend produces different behaviors on different machines.
On a linux server running Ubuntu 12.04.4 LTS the following code (adapted from the foreach vingette) runs 5 jobs simultaneously on a single core, which is not the desired behavior.
library(foreach)
library(doMC)
registerDoMC(cores=5)
getDoParWorkers()
x <- iris[which(iris[,5] != "setosa"), c(1,5)]
trials <- 10000
r <- foreach(icount(trials), .combine=cbind) %dopar% {
ind <- sample(100, 100, replace=TRUE)
result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
coefficients(result1)
}
Session info:
> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C LC_COLLATE=C LC_MONETARY=C
[6] LC_MESSAGES=C LC_PAPER=C LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=C LC_IDENTIFICATION=C
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] doMC_1.3.3 iterators_1.0.7 foreach_1.4.2
loaded via a namespace (and not attached):
[1] codetools_0.2-8 compiler_3.1.0 tools_3.1.0
The same code run on a Mac running OSX 10.7.5 produces the desired and expected behavior of running 5 jobs on 5 different cores.
Session info:
> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] C
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] doMC_1.3.2 iterators_1.0.6 foreach_1.4.1
loaded via a namespace (and not attached):
[1] codetools_0.2-8 compiler_3.0.1 tools_3.0.1
I have also observed the same behavior using other parallel backends. Both machines have 20+ cores. Any ideas on what's going on?