如何解决矩阵的mpi4py Allgatherv
我分别具有两个不同的MPI流程的矩阵x
和大小(n0,N)
和(n1,N)
。我正在尝试将它们收集到在两个过程中都定义的单个矩阵中。
这是我的尝试:
"""
run with: mpiexec -n 2 python test.py
"""
from mpi4py import MPI
import numpy as np
comm=MPI.COMM_WORLD
n0=3
n1=4
N=2
if comm.Get_rank()==0:
x=np.ones((n0,N),dtype=np.float64)
else:
x=2.0*np.ones((n1,dtype=np.float64)
x_gathered = np.zeros((n0+n1,x.dtype )
comm.Allgatherv([x,MPI.DOUBLE],[x_gathered,)
print(x_gathered)
我遇到错误:
MPIR_Localcopy(46)..........................: Message truncated; 64 bytes received but buffer size is 56
我注意到,当我设置两个大小n0=n1
时,代码可以正常运行。有人可以向我解释为什么在Allgatherv
和n0
不同的情况下我不能使用n1
的原因,以及如何Allgatherv
的最终使用{{ 1}}?
解决方法
我想我已经弄清楚了:Allgatherv
需要sendcounts
和displacements
的附加参数,请参见here。
"""
mpiexec -n 2 python test.py
"""
from mpi4py import MPI
import numpy as np
from sys import getsizeof
comm=MPI.COMM_WORLD
n0=4
n1=3
N=2
if comm.Get_rank()==0:
x=np.ones((n0,N,),dtype=np.float64)
else:
x=2.0*np.ones((n1,dtype=np.float64)
x_gathered = np.zeros(((n0+n1)*N,dtype=np.float64 )
sendcountes=(n0*N,n1*N)
displacements=(0,n0*N)
comm.Allgatherv([x,MPI.DOUBLE],[x_gathered,sendcountes,displacements,)
print(x_gathered)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。