建立分布式ipython/ipyparallel MPI clus

2024-05-16 15:49:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力理解如何使用ipython/ipyparallel建立分布式MPI集群。我没有很强的MPI背景。在

我遵循了ipyparallel文档(Using ipcluster in mpiexec/mpirun mode)中的以下说明,对于在单节点计算机上分布计算来说,这很好。因此,创建一个mpi概要文件,按照上面的说明配置它,然后启动集群

$ ipython profile create --parallel --profile=mpi
$ vim ~/.ipython/profile_mpi/ipcluster_config.py

然后在主机A上启动控制器和4个MPI引擎:

^{pr2}$

运行以下代码段:

from ipyparallel import Client
from mpi4py import MPI

c = Client(profile='mpi')
view = c[:]

print("Client MPI.COMM_WORLD.Get_size()=%s" % MPI.COMM_WORLD.Get_size())
print("Client engine ids %s" % c.ids)

def _get_rank():
    from mpi4py import MPI
    return MPI.COMM_WORLD.Get_rank()

def _get_size():
    from mpi4py import MPI
    return MPI.COMM_WORLD.Get_size()

print("Remote COMM_WORLD ranks %s" % view.apply_sync(_get_rank))
print("Remote COMM_WORLD size %s" % view.apply_sync(_get_size))

收益率

Client MPI.COMM_WORLD.Get_size()=1
Client engine ids [0, 1, 2, 3]
Remote COMM_WORLD ranks [1, 0, 2, 3]
Remote COMM_WORLD size [4, 4, 4, 4]

然后在主机B上启动4个MPI引擎。我再次运行这个片段

Client MPI.COMM_WORLD.Get_size()=1
Client engine ids [0, 1, 2, 3, 4, 5, 6, 7]
Remote COMM_WORLD ranks [1, 0, 2, 3, 2, 3, 0, 1]
Remote COMM_WORLD size [4, 4, 4, 4, 4, 4, 4, 4]

似乎来自每个ipcluster命令的引擎被分组到单独的通信器或大小4中,因此有重复的列。客户端只有一个MPI进程。在

问题:

  1. ipython/ipyparallel似乎没有在主机之间建立MPI连接。ipyparallel应该处理MPI设置,还是应该像"IPython MPI with a Machinefile"建议的那样,作为用户创建MPI设置?我想我的假设是ipyparallel会自动处理事情,但事实似乎并非如此。在
  2. 有没有关于如何使用ipyparallel设置分布式MPI的文档?我在谷歌上搜索了一下,但没有发现明显的东西。在
  3. 根据上述情况,ipython/ipyparallel是否仅设计用于处理本地MPI连接,以避免控制器和引擎之间的数据传输?在

编辑

  1. 第一个问题的答案似乎是所有MPI节点都必须同时启动。这是因为:

    • Dynamic Nodes in OpenMPI表示不可能在启动后添加节点。在
    • MPI - Add/remove node while program is running表明 子节点可以通过MPI_Comm_spawn添加。然而,根据MPI_Comm_spawn

      MPI_Comm_spawn tries to start maxprocs identical copies of the MPI program specified by command, establishing communication with them and returning an intercommunicator. The spawned processes are referred to as children. The children have their own MPI_COMM_WORLD, which is separate from that of the parents.

      快速grep通过ipyparallel代码表明没有使用这个功能。

  2. 第二个问题的部分答案是需要使用machinefile,以便MPI知道它可以在哪些远程计算机上创建进程。在

    这里的含义是每个远程上的设置都是同质的,这是由Torque/SLURM等集群系统提供的。否则,如果一个人试图使用随机远程,就必须做一些工作来确保mpiexec正在执行的环境是同质的。

  3. 第三个问题的部分答案是否定的,ipyparallel大概可以与远程MPI进程一起工作,但是每个MPI进程需要创建一个ipyparall引擎。


Tags: from引擎importclientworldsizegetremote
1条回答
网友
1楼 · 发布于 2024-05-16 15:49:01

当您在IPython parallel中使用MPI启动引擎时,它最终归结为一个调用:

mpiexec [-n N] ipengine

它不配置MPI。如果在不同的主机上启动多个引擎组,则每个组将位于其自己的MPI领域中,这就是您所看到的。首先要做的是确保在将IPython parallel引入其中之前,只需对mpiexec进行一次调用,确保一切正常。在

IPython parallel with a machine file中所述,要使用多主机MPI,通常需要一个machinefile来指定在多个主机上启动多个引擎。例如:

^{pr2}$

您可以使用简单的测试脚本进行诊断:

# test_mpi.py
import os
import socket
from mpi4py import MPI

MPI = MPI.COMM_WORLD

print("{host}[{pid}]: {rank}/{size}".format(
    host=socket.gethostname(),
    pid=os.getpid(),
    rank=MPI.rank,
    size=MPI.size,
))

然后运行它:

$ mpiexec -machinefile ~/mpi_hosts -n 8 python test_mpi.py 
machine1[32292]: 0/8
machine1[32293]: 1/8
machine1[32294]: 2/8
machine1[32295]: 3/8
machine2[32296]: 4/8
machine2[32297]: 5/8
machine2[32298]: 6/8
machine2[32299]: 7/8

一旦工作正常,您可以添加

c.MPILauncher.mpi_args = ["-machinefile", "~/mpi_hosts"]

启动引擎

ipcluster start -n 8

相关问题 更多 >