What's the difference between doParallel
and doMC
in R concerning foreach
function? doParallel
supports windows, unix-like, while doMC
supports unix-like only. In other words, why doParallel
cannot replace doMC
directly? Thank you.
Update:
doParallel
is built on parallel
, which is essentially a merger of multicore
and snow
and automatically uses the appropriate tool for your system. As a result, we can use doParallel
to support multi systems. In other words, we can use doParallel
to replace doMC
.
ref: http://michaeljkoontz.weebly.com/uploads/1/9/9/4/19940979/parallel.pdf
BTW, what is the difference between registerDoParallel(ncores=3)
and
cl <- makeCluster(3)
registerDoParallel(cl)
It seems registerDoParallel(ncores=3)
can stop cluster automatically, while the second do not stop automatically and needs stopCluster(cl)
.
ref: http://cran.r-project.org/web/packages/doParallel/vignettes/gettingstartedParallel.pdf
The
doParallel
package is a merger ofdoSNOW
anddoMC
, much asparallel
is a merger ofsnow
andmulticore
. But althoughdoParallel
has all the features ofdoMC
, I was told by Rich Calaway of Revolution Analytics that they wanted to keepdoMC
around because it was more efficient in certain circumstances, even thoughdoMC
now usesparallel
just likedoParallel
. I haven't personally run any benchmarks to determine if and when there is a significant difference.I tend to use
doMC
on a Linux or Mac OS X computer,doParallel
on a Windows computer, anddoMPI
on a Linux cluster, butdoParallel
does work on all of those platforms.As for the different registration methods, if you execute:
on a Windows machine, it will create a cluster object implicitly for later use with
clusterApplyLB
, whereas on Linux and Mac OS X, no cluster object is created or used. The number of cores is simply remembered and used as the value of themc.cores
argument later when callingmclapply
.If you execute:
then the registered cluster object will be used with
clusterApplyLB
regardless of the platform. You are correct that in this case, it is your responsibility to shutdown the cluster object since you created it, whereas the implicit cluster object is automatically shutdown.