我正在尝试使用mpi4py在两个沟通者之间进行沟通。这两个沟通者是通过拆分父沟通者而产生的。
我使用mpi.comm.split拆分了一个现有的通信器,将通信器分为节点数相等的组。
例如我取了12个节点,将其分成3组,每组4个节点
每个节点都有一些初始化的数据。接下来,我需要将一些数据从一组转移到另一组(这是我毫无头绪的地方)。
我还研究了代码here
我尝试的代码如下:
import mpi4py
from mpi4py import MPI
MPI.Init()
comm=MPI.COMM_WORLD
size = comm.Get_size() # Should be 12
rank = comm.Get_rank() # Rank of the process
# Total 12 processors
# Create 3 groups
groupSize = 3
group = comm.Get_group()
subGroup = rank // groupSize
# Split the communicator
subComm = MPI.Comm.Split(comm, subGroup, rank)
subSize, subRank = subComm.Get_size(), subComm.Get_rank()
# Initialize the data at every process
data = {}
data = {0: rank, 1: 'rank', 2: 'size', 3: size}
# Need to exchange the data - at rank 0 of every group
# - between groups
# - take from previous group, send to next group
# - group 0 rank 0 takes from group 2 rank 0
# - group 1 rank 0 takes from group 0 rank 0
# - group 2 rank 0 takes from group 1 rank 0
# - and sends respectively
当我尝试以下代码时,它会花费时间并且不会导致任何后果
comm01= comm.Create_intercomm(0, subComm, 1, tag=rank)