R中doMC和doParallel的区别 [英] the difference between doMC and doParallel in R
问题描述
doParallel
和 doMC
在 R 中的 foreach
函数有什么区别?doParallel
支持 windows,unix-like,而 doMC
只支持 unix-like.换句话说,为什么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
之上,本质上是 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
现在像 doParallel
一样使用 parallel
.我没有亲自运行任何基准测试来确定是否存在显着差异以及何时存在显着差异.
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屋!