1from mpi4py import MPI 2import ctypes 3import os 4 5_libdir = os.path.dirname(__file__) 6 7if MPI._sizeof(MPI.Comm) == ctypes.sizeof(ctypes.c_int): 8 MPI_Comm = ctypes.c_int 9else: 10 MPI_Comm = ctypes.c_void_p 11_lib = ctypes.CDLL(os.path.join(_libdir, "libhelloworld.so")) 12_lib.sayhello.restype = None 13_lib.sayhello.argtypes = [MPI_Comm] 14 15def sayhello(comm): 16 comm_ptr = MPI._addressof(comm) 17 comm_val = MPI_Comm.from_address(comm_ptr) 18 _lib.sayhello(comm_val) 19