生成 mpi4py 进程后的障碍
Barrier after spawned mpi4py process
我有一段代码使用 mpi4py 生成多个 mpi 可执行实例。我希望代码在这些进程完成时停止,然后调用第二组相同的可执行文件。
问题是所有对 mpi 可执行文件的调用都会立即产生。
似乎没有办法使用屏障来防止这种情况发生。有谁知道这是否正确,如果正确,有没有人知道我需要的结果。
#!/usr/bin/env python
from mpi4py import MPI
import numpy
import sys
import os
rank = MPI.COMM_WORLD.Get_rank()
new_comm = MPI.COMM_WORLD.Split(color=rank, key=rank)
print(new_comm.Get_rank())
cwd=os.getcwd()
directory=os.path.join(cwd,str(rank))
print(rank,directory)
os.chdir(directory)
new_comm.Spawn("SOME_F90_MPI_EXECUTABLE",
args=None,
maxprocs=4)
'''I want to pause here until the spawned processes finish running...'''
new_comm.Barrier()
MPI.COMM_WORLD.Barrier()
print(new_comm.Get_rank())
cwd=os.getcwd()
directory=os.path.join(cwd,str(rank))
print(rank,directory)
os.chdir(directory+"_2")
new_comm.Spawn("SOME_F90_MPI_EXECUTABLE",
args=["> output"],
maxprocs=4)
new_comm.Disconnect()
print("All finished here.....")
谢谢!
您必须使用 内部通讯器 由 Spawn
:
返回
child_comm = MPI.COMM_WORLD.Spawn("./spawnchild.py", args=None, maxprocs=2)
child_comm.Barrier()
对于 child,获取 parent intercommunicator(在 Fortran 中类似):
parent = MPI.COMM_WORLD.Get_parent()
assert(parent != MPI.COMM_NULL)
parent.Barrier();
请注意,由两组进程组成的 intercommunicator 的行为不同于传统的 intercommunicator。例如。对于屏障,以下语义适用:
If comm is an intercommunicator, MPI_BARRIER
involves two groups. The call returns at processes in one group (group A) of the intercommunicator only after all members of the other group (group B) have entered the call (and vice versa). A process may return from the call before all processes in its own group have entered the call.
(MPI 3.1 Standard, 5.3)
我有一段代码使用 mpi4py 生成多个 mpi 可执行实例。我希望代码在这些进程完成时停止,然后调用第二组相同的可执行文件。
问题是所有对 mpi 可执行文件的调用都会立即产生。
似乎没有办法使用屏障来防止这种情况发生。有谁知道这是否正确,如果正确,有没有人知道我需要的结果。
#!/usr/bin/env python
from mpi4py import MPI
import numpy
import sys
import os
rank = MPI.COMM_WORLD.Get_rank()
new_comm = MPI.COMM_WORLD.Split(color=rank, key=rank)
print(new_comm.Get_rank())
cwd=os.getcwd()
directory=os.path.join(cwd,str(rank))
print(rank,directory)
os.chdir(directory)
new_comm.Spawn("SOME_F90_MPI_EXECUTABLE",
args=None,
maxprocs=4)
'''I want to pause here until the spawned processes finish running...'''
new_comm.Barrier()
MPI.COMM_WORLD.Barrier()
print(new_comm.Get_rank())
cwd=os.getcwd()
directory=os.path.join(cwd,str(rank))
print(rank,directory)
os.chdir(directory+"_2")
new_comm.Spawn("SOME_F90_MPI_EXECUTABLE",
args=["> output"],
maxprocs=4)
new_comm.Disconnect()
print("All finished here.....")
谢谢!
您必须使用 内部通讯器 由 Spawn
:
child_comm = MPI.COMM_WORLD.Spawn("./spawnchild.py", args=None, maxprocs=2)
child_comm.Barrier()
对于 child,获取 parent intercommunicator(在 Fortran 中类似):
parent = MPI.COMM_WORLD.Get_parent()
assert(parent != MPI.COMM_NULL)
parent.Barrier();
请注意,由两组进程组成的 intercommunicator 的行为不同于传统的 intercommunicator。例如。对于屏障,以下语义适用:
If comm is an intercommunicator,
MPI_BARRIER
involves two groups. The call returns at processes in one group (group A) of the intercommunicator only after all members of the other group (group B) have entered the call (and vice versa). A process may return from the call before all processes in its own group have entered the call.
(MPI 3.1 Standard, 5.3)