Matrix 矩阵的mpi4py-Allgatherv
我有一个矩阵Matrix 矩阵的mpi4py-Allgatherv,matrix,mpi4py,Matrix,Mpi4py,我有一个矩阵x,大小分别为(n0,N)和(n1,N),分别用于两个不同的MPI进程。我试图将它们收集到一个矩阵中,定义在两个过程中 以下是我的尝试: """ 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
x
,大小分别为(n0,N)
和(n1,N)
,分别用于两个不同的MPI进程。我试图将它们收集到一个矩阵中,定义在两个过程中
以下是我的尝试:
"""
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,N),dtype=np.float64)
x_gathered = np.zeros((n0+n1,N), x.dtype )
comm.Allgatherv([x, MPI.DOUBLE], [x_gathered, MPI.DOUBLE], )
print(x_gathered)
我得到一个错误:
MPIR_Localcopy(46)..........................: Message truncated; 64 bytes received but buffer size is 56
我注意到,当我设置两个大小时,代码运行正常。有人能解释一下为什么我不能在不同的
n0
和n1
情况下使用allgatrov
,以及如何使用mpi4py
最终实现此Allgatherv
操作?我想我已经弄明白了:Allgatherv
需要额外的参数来执行sendcounts
和置换
,请参阅
"""
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,N,),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, MPI.DOUBLE], )
print(x_gathered)