R中doMC和doParallel之间的区别 [英] the difference between doMC and doParallel in R
问题描述
R中有关foreach
功能的doParallel
和doMC
有什么区别? doParallel
支持类似Unix的Windows,而doMC
仅支持类似Unix的窗口.换句话说,为什么doParallel
无法直接替换doMC
?谢谢.
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.
更新:
doParallel
建立在parallel
之上,而parallel
本质上是multicore
和snow
的合并,并自动为您的系统使用适当的工具.结果,我们可以使用doParallel
支持多系统.换句话说,我们可以使用doParallel
替换doMC
.
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
顺便说一句,registerDoParallel(ncores=3)
和
cl <- makeCluster(3)
registerDoParallel(cl)
registerDoParallel(ncores=3)
似乎可以自动停止群集,而第二个不能自动停止,并且需要stopCluster(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
推荐答案
doParallel
软件包是doSNOW
和doMC
的合并,就像parallel
是snow
和multicore
的合并一样.但是,尽管doParallel
具有doMC
的所有功能,但是Revolution Analytics的Rich Calaway告诉我,他们希望保留doMC
,因为在某些情况下doMC
效率更高,即使doMC
现在使用doParallel
一样.我个人还没有运行任何基准来确定是否以及何时存在显着差异.
The doParallel
package is a merger of doSNOW
and doMC
, much as parallel
is a merger of snow
and multicore
. But although doParallel
has all the features of doMC
, I was told by Rich Calaway of Revolution Analytics that they wanted to keep doMC
around because it was more efficient in certain circumstances, even though doMC
now uses parallel
just like doParallel
. I haven't personally run any benchmarks to determine if and when there is a significant difference.
我倾向于在Linux或Mac OS X计算机上使用doMC
,在Windows计算机上使用doParallel
,在Linux群集上使用doMPI
,但是doParallel
确实可以在所有这些平台上使用.
I tend to use doMC
on a Linux or Mac OS X computer, doParallel
on a Windows computer, and doMPI
on a Linux cluster, but doParallel
does work on all of those platforms.
对于不同的注册方法,请执行以下操作:
As for the different registration methods, if you execute:
registerDoParallel(cores=3)
在Windows机器上,
会隐式创建一个群集对象,以供以后与clusterApplyLB
一起使用,而在Linux和Mac OS X上,则不会创建或使用任何群集对象.只需记住内核数,然后在调用mclapply
时将其用作mc.cores
参数的值.
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 the mc.cores
argument later when calling mclapply
.
如果执行:
cl <- makeCluster(3)
registerDoParallel(cl)
然后,无论平台如何,已注册的群集对象将与clusterApplyLB
一起使用.您是正确的,在这种情况下,自创建群集对象以来,您有责任关闭群集对象,而隐式群集对象将自动关闭.
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.
这篇关于R中doMC和doParallel之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!