使用Python(mpi4py)在Google Cloud Engine上进行分布式编程 [英] Distributed Programming on Google Cloud Engine using Python (mpi4py)

查看:158
本文介绍了使用Python(mpi4py)在Google Cloud Engine上进行分布式编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用mpi4py软件包使用python进行分布式编程。出于测试原因,我通过Google容器引擎设置了一个5节点集群,并相应地更改了代码。但是现在,我的下一步是什么?如何使我的代码在所有5个VM上运行并正常工作?



我试图从群集中通过ssh连接到一个VM并运行代码,但是很明显,代码并未分发,而是停留在同一台机器上:( [请参见下面的示例]





代码:



 从mpi4py导入MPI 

size = MPI.COMM_WORLD.Get_size( )
等级= MPI.COMM_WORLD.Get_rank()
名称= MPI.Get_processor_name()

print( Hello,World!我正在处理/排名{},{}在{} .\n .format(等级,大小,名称)上



输出:




mpiexec -n 5 python 5_test.py


世界,您好!我在gke-cluster-1-000000cd-node-mgff上处理5位中的第0位。 / p>

世界,您好!我正在处理/在gke-cluster-1-000000cd-node-mgff上排名1/5。



你好,世界!我是处理/在gke-cluster-1-000000cd-node-mgff上的5中排名2。



世界,您好!我是gke-cluster-1-000000cd-node-mgff上的进程/排名3,共5。



您好,世界!我在gke-cluster-1-000000cd-node-mgff上的处理等级为5,排名4。




解决方案

所以,我弄清楚了我出了什么问题,我认为应该为可能有类似问题的人提供答案。



结果是,我应该更好地阅读mpi4py的文档:D



命令 mpirun -np 5 python 5_test.py 用于在单个进程上在不同进程上运行该程序。



但是,我想将任务分配到各个主机上。因此,我需要命令 mpirun --hostfile< hostfile>。 python 5_test.py 。并且< hostfile> 必须是如下所示的文件:

  -hostfile-

host1插槽= 4

host2插槽= 4

host3插槽= 4

' --------------



有用的链接: https://github.com/jbornschein/mpi4py-examples


I want to do distributed programming with python using the mpi4py package. For testing reasons, I set up a 5-node cluster via Google container engine, and changed my code accordingly. But now, what are my next steps? How do I get my code running and working on all 5 VMs?

I tried to just ssh-connect into one VM from my cluster and run the code, but it was obvious that the code was not getting distributed, but instead stayed on the same machine :( [see example below]

.

Code:

from mpi4py import MPI

size = MPI.COMM_WORLD.Get_size()
rank = MPI.COMM_WORLD.Get_rank()
name = MPI.Get_processor_name()

print("Hello, World! I am process/rank {} of {} on {}.\n".format(rank, size,name))

.

Output:

mpiexec -n 5 python 5_test.py

Hello, World! I am process/rank 0 of 5 on gke-cluster-1-000000cd-node-mgff.

Hello, World! I am process/rank 1 of 5 on gke-cluster-1-000000cd-node-mgff.

Hello, World! I am process/rank 2 of 5 on gke-cluster-1-000000cd-node-mgff.

Hello, World! I am process/rank 3 of 5 on gke-cluster-1-000000cd-node-mgff.

Hello, World! I am process/rank 4 of 5 on gke-cluster-1-000000cd-node-mgff.

解决方案

So, I figured out what I got wrong, and I think I should post the answer for someone who might has a similar question.

Turns out, I should have read the documentation of mpi4py better :D

The command mpirun -np 5 python 5_test.py is for running the program an a single, multi-core host on different processes.

However, I wanted to distribute the task across various host. Therefore I needed the command mpirun --hostfile <hostfile> python 5_test.py. And <hostfile> must be a file looking like this:

-- hostfile --

host1   slots=4

host2   slots=4

host3   slots=4

'--------------


.

Useful Link: https://github.com/jbornschein/mpi4py-examples

这篇关于使用Python(mpi4py)在Google Cloud Engine上进行分布式编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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