2

有人能告诉我为什么这个最小的工作示例(MWE)抱怨TypeError: expected a writeable buffer object吗?

MWE:

#!/usr/bin/env python
from mpi4py import MPI

# MPI Initialization
rank = MPI.COMM_WORLD.Get_rank()
comm = MPI.COMM_WORLD

if __name__ == '__main__':
   a = True
   if rank == 0:
      a = False
      comm.Send ( [ a, MPI.BOOL ], 1, 111 )
   if rank == 1:
      comm.Recv ([ a, MPI.BOOL], 0, 111 )

错误:

Traceback (most recent call last):
  File "test.py", line 14, in <module>
    comm.Recv ([ a, MPI.BOOL], 0, 111 )
  File "Comm.pyx", line 143, in mpi4py.MPI.Comm.Recv (src/mpi4py.MPI.c:62980)
  File "message.pxi", line 323, in mpi4py.MPI.message_p2p_recv (src/mpi4py.MPI.c:22814)
  File "message.pxi", line 309, in mpi4py.MPI._p_msg_p2p.for_recv (src/mpi4py.MPI.c:22665)
  File "message.pxi", line 111, in mpi4py.MPI.message_simple (src/mpi4py.MPI.c:20516)
  File "message.pxi", line 51, in mpi4py.MPI.message_basic (src/mpi4py.MPI.c:19644)
  File "asbuffer.pxi", line 108, in mpi4py.MPI.getbuffer (src/mpi4py.MPI.c:6757)
  File "asbuffer.pxi", line 48, in mpi4py.MPI.PyObject_GetBufferEx (src/mpi4py.MPI.c:6081)
TypeError: expected a writeable buffer object
Traceback (most recent call last):
  File "test.py", line 12, in <module>
    comm.Send ( [ a, MPI.BOOL ], 1, 111 )
  File "Comm.pyx", line 132, in mpi4py.MPI.Comm.Send (src/mpi4py.MPI.c:62796)
  File "message.pxi", line 318, in mpi4py.MPI.message_p2p_send (src/mpi4py.MPI.c:22744)
  File "message.pxi", line 301, in mpi4py.MPI._p_msg_p2p.for_send (src/mpi4py.MPI.c:22604)
  File "message.pxi", line 111, in mpi4py.MPI.message_simple (src/mpi4py.MPI.c:20516)
  File "message.pxi", line 51, in mpi4py.MPI.message_basic (src/mpi4py.MPI.c:19644)
  File "asbuffer.pxi", line 108, in mpi4py.MPI.getbuffer (src/mpi4py.MPI.c:6757)
  File "asbuffer.pxi", line 50, in mpi4py.MPI.PyObject_GetBufferEx (src/mpi4py.MPI.c:6093)

===================================================================================
=   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
=   EXIT CODE: 1
=   CLEANING UP REMAINING PROCESSES
=   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
===================================================================================
[proxy:0:0@raspi1] HYD_pmcd_pmip_control_cmd_cb (./pm/pmiserv/pmip_cb.c:886): assert (!closed) failed
[proxy:0:0@raspi1] HYDT_dmxu_poll_wait_for_event (./tools/demux/demux_poll.c:77): callback returned error status
[proxy:0:0@raspi1] main (./pm/pmiserv/pmip.c:206): demux engine error waiting for event
[mpiexec@raspi1] HYDT_bscu_wait_for_completion (./tools/bootstrap/utils/bscu_wait.c:76): one of the processes terminated badly; aborting
[mpiexec@raspi1] HYDT_bsci_wait_for_completion (./tools/bootstrap/src/bsci_wait.c:23): launcher returned error waiting for completion
[mpiexec@raspi1] HYD_pmci_wait_for_completion (./pm/pmiserv/pmiserv_pmci.c:217): launcher returned error waiting for completion
[mpiexec@raspi1] main (./ui/mpich/mpiexec.c:331): process manager error waiting for completion
4

3 回答 3

2

我不是 MPI 专家,但我想知道 numpy 中的布尔数据类型是否与 C 中的布尔数据类型不兼容?也许这就是导致错误的原因。(不是证据,而是一些证据:http ://docs.scipy.org/doc/numpy/reference/arrays.scalars.html#arrays-scalars-built-in和https://cython.readthedocs.org/en/最新/src/tutorial/numpy.html )

puk,正如您所指出的,一种解决方案是使用sendsend 和recv(带有小写 s 和 r)函数(http://mpi4py.scipy.org/docs/usrman/tutorial.html)将数据作为 python 对象传输。“在幕后”,mpi4pypickle用于此,因此可以发送任何通用 python 对象。

我回答的主要原因是使用整数数组发布替代解决方案,0 对应于 True,1 对应于 False:

#!/usr/bin/env python
import numpy as np
from mpi4py import MPI

# MPI Initialization
rank = MPI.COMM_WORLD.Get_rank()
comm = MPI.COMM_WORLD

if __name__ == '__main__':
    a=np.array([0,])
    if rank == 0:
        a[0]=1
        comm.Send( [ a, MPI.INT ], 1, tag=111 )
        print rank,a
    if rank == 1:
        comm.Recv([ a, MPI.INT], 0, tag=111 )
        print rank,a

如果有人想利用更快(根据mpi4py文档)的 numpy 数组。

于 2014-04-02T03:16:22.883 回答
1

我不知道为什么我会收到上述错误,所以如果有人知道,请回答,我会接受。话虽如此,如果我改用这种风格,我可以让代码工作(旧代码注释掉):

MWE:

#!/usr/bin/env python
from mpi4py import MPI

# MPI Initialization
rank = MPI.COMM_WORLD.Get_rank()
comm = MPI.COMM_WORLD

if __name__ == '__main__':
   a = True
   if rank == 0:
      a = False
      # comm.Send ( [ a, MPI.BOOL ], dest=1, tag=111 )
      comm.send ( a, dest=1, tag=111 )
   if rank == 1:
      # comm.Recv ([ a, MPI.BOOL], dest=0, tag=111 )
      a = comm.recv (source=0, tag=111 )
于 2013-10-15T03:02:33.177 回答
0

MPI 的大写函数接受类似黄油的对象,例如 python 中的 NumPy 数组。小写函数使用 pickle 以便能够发送对象。

http://mpi4py.readthedocs.org/en/latest/tutorial.html

于 2015-11-10T14:10:33.647 回答