如果我已经在做registerDoParallel(cl),我还需要makeCluster吗? [英] do I still need to makeCluster if I'm already doing registerDoParallel(cl)

查看:680
本文介绍了如果我已经在做registerDoParallel(cl),我还需要makeCluster吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读 doparallel 的小插图.

以下两个代码块是否相同?

Are the following two code blocks one and the same?

library(doparallel)
  no_cores <- 8
  cl <- makeCluster(no_cores) 
  registerDoParallel(cl)
pieces <- foreach(i = seq_len(length(pieces))) %dopar% { # do stuff}

上面的内容与此相同:

library(doparallel)
  registerDoParallel(cores = 8)
pieces <- foreach(i = seq_len(length(pieces))) %dopar% { # do stuff}

如果要使用多核,必须在使用doparallel时使用makeCluster()吗?还是单行足够registerDoParallel(cores = 8)

Must I makeCluster() when using doparallel if I want to use multiple cores? or is the single line enough registerDoParallel(cores = 8)

推荐答案

在Windows计算机上,这两个示例基本上是等效的.唯一的区别是,第一个示例使用显式群集对象,第二个示例使用在执行registerDoParallel时创建的隐式群集对象.这两个示例的性能应该相同.

On a Windows machine, these two examples are basically equivalent. The only difference is that the first example uses an explicit cluster object and the second uses an implicit cluster object that is created when you execute registerDoParallel. The performance of the two examples should be the same.

在Mac或Linux计算机上,第一个示例使用snow派生的后端(与Windows计算机上的完全相同),最终使用clusterApplyLB执行并行计算.第二个示例使用multicore派生的后端(Windows上从未提供过),最终使用mclapply来执行并行计算,这可能比第一个示例更有效.

On a Mac or Linux machine, the first example uses the snow derived backend (exactly the same as on a Windows machine), ultimately using clusterApplyLB to perform the parallel computations. The second example uses the multicore derived backend (which was never available on Windows), ultimately using mclapply to perform the parallel computations which will probably be somewhat more efficient than the first example.

这篇关于如果我已经在做registerDoParallel(cl),我还需要makeCluster吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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