【发布时间】:2020-10-24 12:03:28
【问题描述】:
我有一个 dtype = object 的 numpy 数组,我正在尝试使用 comm.Send() 和 comm.Recv 发送和接收,但我遇到了错误,似乎无法调试它。我尝试发送的数组包含 2 列:1 列字符串和 1 列整数。
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
data_array = np.empty(100,2), dtype=object)
data_array[:,0] = var_1
data_array[:,1] = var_2
(data_array_0, data_array_1) = np.array_split(data_array, 2)
data_array_0 = np.ascontiguousarray(data_array_0, dtype = object)
data_array_1 = np.ascontiguousarray(data_array_1, dtype = object)
if rank == 0:
comm.Send(data_array_1, dest=1)
elif rank == 1:
data_array_1 = np.empty([data_array_row_1, data_array_col], dtype = object)
comm.Recv(data_array_1, source=0) # <--- the line that's causing the error
我收到以下错误消息:
Traceback (most recent call last):
File "data_clean_parallel_1.py", line 156, in <module>
comm.Recv(data_array_1, source=0)
File "mpi4py/MPI/Comm.pyx", line 283, in mpi4py.MPI.Comm.Recv
File "mpi4py/MPI/msgbuffer.pxi", line 402, in mpi4py.MPI.message_p2p_recv
File "mpi4py/MPI/msgbuffer.pxi", line 388, in mpi4py.MPI._p_msg_p2p.for_recv
File "mpi4py/MPI/msgbuffer.pxi", line 155, in mpi4py.MPI.message_simple
File "mpi4py/MPI/msgbuffer.pxi", line 101, in mpi4py.MPI.message_basic
KeyError: 'O'
我真的不明白是什么导致了这个问题,如果有任何可能的替代方案,我可以使用 mpi4py 发送/接收字符串数据。
【问题讨论】:
-
有什么问题?你不明白为什么不能这样使用 object dtype 吗?或者你不明白为什么数组是object dtype?
-
所以object dtype不能和comm.Send和comm.Recv一起使用?如果是这样的话,有什么方法可以使用 Send 和 Recv 发送字符串数据?
标签: python numpy parallel-processing mpi mpi4py