1from mpi4py import MPI
2import cffi
3import os
4
5_libdir = os.path.dirname(__file__)
6
7ffi = cffi.FFI()
8if MPI._sizeof(MPI.Comm) == ffi.sizeof('int'):
9    _mpi_comm_t = 'int'
10else:
11    _mpi_comm_t = 'void*'
12ffi.cdef("""
13typedef %(_mpi_comm_t)s MPI_Comm;
14void sayhello(MPI_Comm);
15""" % vars())
16lib = ffi.dlopen(os.path.join(_libdir, "libhelloworld.so"))
17
18def sayhello(comm):
19    comm_ptr = MPI._addressof(comm)
20    comm_val = ffi.cast('MPI_Comm*', comm_ptr)[0]
21    lib.sayhello(comm_val)
22