File: helloworld.pyx

package info (click to toggle)
mpi4py 3.0.3-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 12,428 kB
  • sloc: python: 18,672; javascript: 9,118; ansic: 7,092; makefile: 567; sh: 183; f90: 158; cpp: 103
file content (67 lines) | stat: -rw-r--r-- 1,382 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
cdef extern from "mpi-compat.h": pass

# ---------


# Python-level module import
# (file: mpi4py/MPI.so)

from mpi4py import MPI

# Python-level objects and code

size  = MPI.COMM_WORLD.Get_size()
rank  = MPI.COMM_WORLD.Get_rank()
pname = MPI.Get_processor_name()

hwmess = "Hello, World! I am process %d of %d on %s."
print (hwmess % (rank, size, pname))



# ---------


# Cython-level cimport
# this make available mpi4py's Python extension types
# (file:  mpi4py/include/mpi4py/MPI.pxd)

from mpi4py cimport MPI
from mpi4py.MPI cimport Intracomm as IntracommType

# C-level cdef, typed, Python objects

cdef MPI.Comm WORLD = MPI.COMM_WORLD
cdef IntracommType SELF = MPI.COMM_SELF


# ---------


# Cython-level cimport with PXD file
# this make available the native MPI C API
# with namespace-protection (stuff accessed as mpi.XXX)
# (file: mpi4py/include/mpi4py/libmpi.pxd)

from mpi4py cimport libmpi as mpi

cdef mpi.MPI_Comm world1 = WORLD.ob_mpi

cdef int ierr1=0

cdef int size1 = 0
ierr1 = mpi.MPI_Comm_size(mpi.MPI_COMM_WORLD, &size1)

cdef int rank1 = 0
ierr1 = mpi.MPI_Comm_rank(mpi.MPI_COMM_WORLD, &rank1)

cdef int rlen1=0
cdef char pname1[mpi.MPI_MAX_PROCESSOR_NAME]
ierr1 = mpi.MPI_Get_processor_name(pname1, &rlen1)
pname1[rlen1] = 0 # just in case ;-)

hwmess = "Hello, World! I am process %d of %d on %s."
print (hwmess % (rank1, size1, pname1))


# ---------