File: helloworld.py

package info (click to toggle)
mpi4py 4.0.3-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,196 kB
  • sloc: python: 32,170; ansic: 13,449; makefile: 602; sh: 314; f90: 178; cpp: 148
file content (20 lines) | stat: -rw-r--r-- 423 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from mpi4py import MPI
import cffi
import os

_libdir = os.path.dirname(__file__)

ffi = cffi.FFI()
if MPI._sizeof(MPI.Comm) == ffi.sizeof('int'):
    MPI_Comm = 'int'
else:
    MPI_Comm = 'void*'
ffi.cdef(f"""
typedef {MPI_Comm} MPI_Comm;
void sayhello(MPI_Comm);
""")
lib = ffi.dlopen(os.path.join(_libdir, "libhelloworld.so"))

def sayhello(comm):
    comm_c = ffi.cast('MPI_Comm', comm.handle)
    lib.sayhello(comm_c)