有人能告诉我为什么这个最小工作示例(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 )
错误:
^{pr2}$
我不知道为什么我会得到以上的错误,所以如果有人知道,请回答,我会接受。也就是说,如果我使用这种样式,我可以让代码工作(旧代码注释掉):
MWE:
我不是MPI专家,但是我想知道numpy中的boolean数据类型是否与C中的boolean数据类型不兼容?也许这就是导致错误的原因。(不是证据,而是一些证据:http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html#arrays-scalars-built-in和{a2})
puk,正如您所提到的,一个解决方案是使用
send
send和recv
(带小写的s和r)函数(http://mpi4py.scipy.org/docs/usrman/tutorial.html)将数据作为python对象传输。”在幕后,“mpi4py为此使用了pickle
,因此可以发送任何通用的python对象。在我回答的主要原因是发布一个使用整数数组的替代解决方案,0代表真,1代表假:
如果有人想利用更快的(根据
mpi4py
文档)numpy数组。在MPI的大写函数接受类似黄油的对象,比如python中的NumPy数组。小写函数使用pickle来发送对象。在
http://mpi4py.readthedocs.org/en/latest/tutorial.html
相关问题 更多 >
编程相关推荐