do I still need to makeCluster if I'm already doing registerDoParallel(cl)

可紊 提交于 2019-12-11 10:45:18

问题


Reading the vignette for 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}

Is above just the same as this:

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

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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/45779447/do-i-still-need-to-makecluster-if-im-already-doing-registerdoparallelcl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!