doSNOWとdoSMPの比較(考察なし)

id:teramonagiこの記事とR-statistics Blogのこの記事を読んで、doSNOWとかdoSMPとか色々あるけどどれが速いんだろうという気になったのでコピペで比較してみる。
とりあえずは速度比較だけ。考察はまた今度。(2月9日に追記)

> library(foreach)
> 
> N <- 10^4
> 
> #これを基準にする
> system.time(foreach(i = 1:N,.combine = "cbind") %do% {
+ sum(rnorm(N))
+ })
   ユーザ   システム       経過  
     15.35       0.00      15.35 
> 
> #doSNOWの場合
> library(doSNOW)
> cl <- makeCluster(2, type = "SOCK")
> registerDoSNOW(cl)
> 
> system.time(foreach(i = 1:N,.combine = "cbind") %dopar% {
+    sum(rnorm(N))
+ })
   ユーザ   システム       経過  
      6.97       0.34      12.59 
> 
> stopCluster(cl)
> 
> 
> #doSMPの場合
> library(doSMP)
> workers <- startWorkers(2)
> registerDoSMP(workers)
> 
> system.time(foreach(i = 1:N,.combine = "cbind") %dopar% {
+    sum(rnorm(N))
+ })
   ユーザ   システム       経過  
      6.87       0.00       7.73 
> 
> stopWorkers(workers)

これだけみるとdoSMPの方が速いようで。

(2011/2/9追記)

revolutionAnalytics(RevolutionRを出してる会社)のレポートを読むと以下のような記述がある(22ページ目)。

The doNWS and doSNOW packages are parallel backends for clusters of workstations; they can be used on a single multi-core or multi-processor computer, but they are not optimized for such use.
The doSMP and doMC packages are parallel backends for foreach that are intended for parallel processing on a single computer with multiple cores or processors. The doSMP package is available on all platforms, while doMC, which depends on the multicore packages, is currently available only on Mac and Linux systems.

最適化されている方向が違うようで。doSMPはマシンは一台だけどマルチコアのような場合に最適化しているとのこと。

結論:個人ユーザーはdoSMPを使いましょう