gpt4 book ai didi

python - 如果每个进程的根都是其自身,为什么 Gather() 会失败?

转载 作者:太空宇宙 更新时间:2023-11-03 16:36:14 26 4
gpt4 key购买 nike

代码:

#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

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

最佳答案

MPI 中的所有集体操作必须由相应通信器中的所有进程调用。所有进程中的许多参数必须相同。 MPI standard 中详细记录了参数的语义。 :

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

但话又说回来,还有MPI_Allgather,之后整个数据在所有进程上都可用 - 即没有根。

关于python - 如果每个进程的根都是其自身,为什么 Gather() 会失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37174356/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com