R中doMC和doParallel之间的区别 [英] the difference between doMC and doParallel in R

查看:530
本文介绍了R中doMC和doParallel之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R中有关foreach功能的doParalleldoMC有什么区别? 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本质上是multicoresnow的合并,并自动为您的系统使用适当的工具.结果,我们可以使用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软件包是doSNOWdoMC的合并,就像parallelsnowmulticore的合并一样.但是,尽管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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆