How to pass an MPI communicator from python to C via cython?

大憨熊 提交于 2019-12-06 03:11:13

The conversion is rather simple, as a mpi4py.MPI.Comm-object internally stores an MPI_Comm handle as member ob_mpi1. Therefore, if one changes the last line of helloworld_wrap.pyx to pass comm.ob_mpi instead of comm, the module compiles and works as intended:

helloworld_wrap.pyx:

cimport mpi4py.MPI as MPI
cimport mpi4py.libmpi as libmpi

cdef extern from "helloworld.h":
   void sayhello(libmpi.MPI_Comm comm)

def py_sayhello(MPI.Comm comm):
    sayhello(comm.ob_mpi)

Surprisingly, I did not find any documentation for this but only realized this when studying the sources of mpi4py.MPI.Comm. I am not sure, if this is the intended way to handle this, but I could not get it to work otherwise.


1 In fact, most, if not all objects in mpi4py.MPI that model a corresponding MPI handle in C, hold a corresponding handle as member ob_mpi.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!