0
我正在製作一個簡單的程序,我試圖使用mpi4py從8x8矩陣發送4 x 4矩陣子矩陣。我的方法是使用子數組數據類型,但我不斷收到分段錯誤。使用mpi4py創建子數組數據類型
我的代碼如下:
import numpy as np
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
sizes = (8,8) # Matrix dimensions
subsizes = (4,4) # Sub-matrix dimensions
displs = (0, 4, 32, 36)
counts = (1, 1, 1, 1)
starts = (0,0)
mynum = counts[rank]
glob = np.empty((8,8), dtype = 'f')
local = np.empty((4,4), dtype = 'f')
if rank == 0: # Fill each quadrant with 0-3
for row in range(0,4):
for col in range(0,4):
glob[row, col] = 0
for row in range(0,4):
for col in range(4,8):
glob[row, col] = 1
for row in range(4,8):
for col in range(0,4):
glob[row, col] = 2
for row in range(4,8):
for col in range(4,8):
glob[row, col] = 3
print glob
submatrixType = MPI.DOUBLE.Create_subarray(sizes, subsizes, starts, order = MPI.ORDER_C)
submatrixType.Commit()
sendbuf = [glob, counts, displs, submatrixType]
recvbuf = [local, 16, MPI.DOUBLE]
comm.Scatterv(sendbuf, recvbuf, root = 0)
# or use
#comm.Scatterv(sendbuf, recvbuf, MPI.DOUBLE)
print rank, " " ,local
我的結果與4個進程運行時,如下:
Proc 0: [[0. 0. 0. 0.]
[1. 1. 1. 1.]
[0. 0. 0. 0.]
[1. 1. 1. 1.]]
Traceback (most recent call last):
Traceback (most recent call last):
File "main.py", line 41, in <module>
File "main.py", line 41, in <module>
comm.Scatterv(sendbuf, local, root = 0)
comm.Scatterv(sendbuf, local, root = 0)
File "Comm.pyx", line 454, in mpi4py.MPI.Comm.Scatterv (src/mpi4py.MPI.c:67458)
File "Comm.pyx", line 454, in mpi4py.MPI.Comm.Scatterv (src/mpi4py.MPI.c:67458)
mpi4py.MPImpi4py.MPI.Exception: .Exception: MPI_ERR_TRUNCATE: message truncated
MPI_ERR_TRUNCATE: message truncated
Traceback (most recent call last):
File "main.py", line 41, in <module>
comm.Scatterv(sendbuf, local, root = 0)
File "Comm.pyx", line 454, in mpi4py.MPI.Comm.Scatterv (src/mpi4py.MPI.c:67458)
mpi4py.MPI.Exception: MPI_ERR_TRUNCATE: message truncated
我有關於Create_subarray錯誤的想法或有什麼可以否則會出錯?
我用C++代替了我的應用程序。 mpi4py最終並沒有真正削減它,我在解決內存步進問題時遇到了問題。謝謝您的意見! – Hamps