并行R比串行慢?

时间:2013-04-12 02:50:24

标签: r parallel-processing

我正在使用R parallel包在我的笔记本电脑上进行并行计算:

> library(parallel)
> x = matrix(rep(1,2000), nrow=2)
> cl <- makeCluster(getOption("cl.cores", 8))
> system.time(replicate(5000, parApply(cl, x, 1, paste, collapse="-")))
   user  system elapsed 
  7.950   0.966  13.562 
> stopCluster(cl)
> system.time(replicate(5000, apply(x, 1, paste, collapse="-")))
   user  system elapsed 
  8.357   0.001   8.355

我在这里犯了什么错吗?我唯一不确定的是如何使用makeCluster

更新:为了降低并行化的开销成本,请在基准测试中使用更大的矩阵x并删除replicate;然而,并行和串行之间的差异非常小,有时并行速度较慢。

0 个答案:

没有答案
相关问题