为什么如果每个进程的根本都是它本身, Gather() 就会失败?

2024-04-28 20:08:41 发布

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

代码:

#mpiexec  -n 2 python3  gather.py
from mpi4py import MPI

comm = MPI.COMM_WORLD
rank = comm.Get_rank()

a = 1
comm.barrier()
b = comm.gather(a, root=rank)
print("b:", b, rank )
comm.barrier()

输出应为:

b:[1, 1], 0

b:[1, 1], 1

但是,程序不会打印任何内容,也不会终止。原因是什么?我怎样才能达到期望的输出?你知道吗


Tags: 代码frompyimportworldgetmpi4pypython3
1条回答
网友
1楼 · 发布于 2024-04-28 20:08:41

MPI中的所有集合操作必须由相应通信器中的所有进程调用。所有进程上的许多参数必须相同。参数的语义在MPI standard中有很好的记录:

The argumentsroot and comm must have identical values on all processes.

但是同样,还有MPI_Allgather,在这之后所有进程上的所有数据都是可用的,即没有根。你知道吗

相关问题 更多 >