使用SNOW的MPI并行化速度很慢 [英] MPI parallelization using SNOW is slow

查看:128
本文介绍了使用SNOW的MPI并行化速度很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的尝试并行化继续.最初,我在安装Rmpi时遇到困难,但是我做到了(我需要sudo apt-get).我应该说我在使用Ubuntu 10.10的计算机上运行.

My foray into parallelization continues. I initially had difficulty installing Rmpi, but I got that going (I needed to sudo apt-get it). I should say that I'm running a machine with Ubuntu 10.10.

我进行的仿真与我的上一个问题相同.分别调用未集群和SNOW SOCK集群的系统时间:

I ran the same simulation as my previous question. Recall the system times for the unclustered and SNOW SOCK cluster respectively:

> system.time(CltSim(nSims=10000, size=100))
   user  system elapsed 
  0.476   0.008   0.484 
> system.time(ParCltSim(cluster=cl, nSims=10000, size=100))
   user  system elapsed 
  0.028   0.004   0.375 

现在,使用MPI集群,相对于不集群,我得到了一个减速的速度:

Now, using an MPI cluster, I get a speed slowdown relative to not clustering:

> stopCluster(cl)
> cl <- getMPIcluster()
> system.time(ParCltSim(cluster=cl, nSims=10000, size=100))
   user  system elapsed 
  0.088   0.196   0.604 

不确定这是否有用,但以下是有关已创建集群的信息:

Not sure whether this is useful, but here's info on the cluster created:

> cl
[[1]]
$rank
[1] 1

$RECVTAG
[1] 33

$SENDTAG
[1] 22

$comm
[1] 1

attr(,"class")
[1] "MPInode"

[[2]]
$rank
[1] 2

$RECVTAG
[1] 33

$SENDTAG
[1] 22

$comm
[1] 1

attr(,"class")
[1] "MPInode"

attr(,"class")
[1] "spawnedMPIcluster" "MPIcluster"        "cluster"          

关于这里可能发生什么的任何想法?感谢您在我尝试这些并行化选项时的帮助.

Any idea about what could be going on here? Thanks for your assistance as I try out these parallelization options.

通常, 查理

推荐答案

与您的其他问题有点相同:集群中节点之间的通信比实际功能要花更多的时间.

It's a bit the same as with your other question : the communication between the nodes in the cluster is taking up more time than the actual function.

这可以通过更改功能来说明:

This can be illustrated by changing your functions :

library(snow)
cl <- makeCluster(2)

SnowSim <- function(cluster, nSims=10,n){
  parSapply(cluster, 1:nSims, function(x){
    Sys.sleep(n)
    x
  })
}



library(foreach)
library(doSNOW)
registerDoSNOW(cl)

ForSim <- function(nSims=10,n) {
  foreach(i=1:nSims, .combine=c) %dopar% {
      Sys.sleep(n)
      i
  }
}

这样,我们可以在不同数量的模拟中模拟长计算和短计算功能.让我们来考虑两种情况,一种情况是1秒的计算和10个循环,另一种情况是1ms的计算和10000个循环.两者都应持续10秒:

This way we can simulate a long-calculating and a short-calculating function in different numbers of simulations. Let's take two cases, one where you have 1 sec calculation and 10 loops, and one with 1ms calculation and 10000 loops. Both should last 10sec :

> system.time(SnowSim(cl,10,1))
   user  system elapsed 
      0       0       5 

> system.time(ForSim(10,1))
   user  system elapsed 
   0.03    0.00    5.03 

> system.time(SnowSim(cl,10000,0.001))
   user  system elapsed 
   0.02    0.00    9.78 

> system.time(ForSim(10000,0.001))
   user  system elapsed 
  10.04    0.00   19.81 

基本上,您看到的是,对于长计算功能和低仿真度,并行化版本将计算时间干净地减少了一半.

Basically what you see, is that for long-calculating functions and low simulations, the parallelized versions cleanly cut the calculation time in half as expected.

现在,您进行的模拟是第二种情况.在那里,您可以看到snow解决方案实际上并没有什么不同,并且foreach解决方案甚至需要两倍.这仅仅是由于与节点之间以及节点之间的通信开销以及对返回数据的处理所造成的.如我对上一个问题的回答所示,foreach的开销比snow大得多.

Now the simulations you do are of the second case. There you see that the snow solution doesn't really make a difference any more, and that the foreach solution even needs twice as much. This is simply due to the overhead of communication to and between nodes, and handling of the data that gets returned. The overhead of foreach is a lot bigger than with snow, as shown in my answer to your previous question.

我没有启动Ubuntu来尝试使用MPI集群,但这基本上是相同的.根据通信所需的时间,不同类型的群集之间存在细微的差异,部分原因是底层软件包之间的差异.

I didn't fire up my Ubuntu to try with an MPI cluster, but it's basically the same story. There are subtle differences between the different types of clusters according to time needed for communication, partly due to differences between the underlying packages.

这篇关于使用SNOW的MPI并行化速度很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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