1# -----------------------------------------------------------------------------
2
3#  Datatype
4
5cdef api object PyMPIDatatype_New(MPI_Datatype arg):
6    cdef Datatype obj = Datatype.__new__(Datatype)
7    obj.ob_mpi = arg
8    return obj
9
10cdef api MPI_Datatype* PyMPIDatatype_Get(object arg) except NULL:
11    return &(<Datatype?>arg).ob_mpi
12
13# -----------------------------------------------------------------------------
14
15#  Status
16
17cdef api object PyMPIStatus_New(MPI_Status *arg):
18    cdef Status obj = Status.__new__(Status)
19    if (arg != NULL and
20        arg != MPI_STATUS_IGNORE and
21        arg != MPI_STATUSES_IGNORE):
22        obj.ob_mpi = arg[0]
23    else: pass  # XXX should fail ?
24    return obj
25
26cdef api MPI_Status* PyMPIStatus_Get(object arg) except? NULL:
27    if arg is None: return MPI_STATUS_IGNORE
28    return &(<Status?>arg).ob_mpi
29
30# -----------------------------------------------------------------------------
31
32#  Request
33
34cdef api object PyMPIRequest_New(MPI_Request arg):
35    cdef Request obj = Request.__new__(Request)
36    obj.ob_mpi = arg
37    return obj
38
39cdef api MPI_Request* PyMPIRequest_Get(object arg) except NULL:
40    return &(<Request?>arg).ob_mpi
41
42# -----------------------------------------------------------------------------
43
44#  Message
45
46cdef api object PyMPIMessage_New(MPI_Message arg):
47    cdef Message obj = Message.__new__(Message)
48    obj.ob_mpi = arg
49    return obj
50
51cdef api MPI_Message* PyMPIMessage_Get(object arg) except NULL:
52    return &(<Message?>arg).ob_mpi
53
54# -----------------------------------------------------------------------------
55
56#  Op
57
58cdef api object PyMPIOp_New(MPI_Op arg):
59    cdef Op obj = Op.__new__(Op)
60    obj.ob_mpi = arg
61    return obj
62
63cdef api MPI_Op* PyMPIOp_Get(object arg) except NULL:
64    return &(<Op?>arg).ob_mpi
65
66# -----------------------------------------------------------------------------
67
68#  Group
69
70cdef api object PyMPIGroup_New(MPI_Group arg):
71    cdef Group obj = Group.__new__(Group)
72    obj.ob_mpi = arg
73    return obj
74
75cdef api MPI_Group* PyMPIGroup_Get(object arg) except NULL:
76    return &(<Group?>arg).ob_mpi
77
78# -----------------------------------------------------------------------------
79
80#  Info
81
82cdef api object PyMPIInfo_New(MPI_Info arg):
83    cdef Info obj = Info.__new__(Info)
84    obj.ob_mpi = arg
85    return obj
86
87cdef api MPI_Info* PyMPIInfo_Get(object arg) except NULL:
88    return &(<Info?>arg).ob_mpi
89
90# -----------------------------------------------------------------------------
91
92# Errhandler
93
94cdef api object PyMPIErrhandler_New(MPI_Errhandler arg):
95    cdef Errhandler obj = Errhandler.__new__(Errhandler)
96    obj.ob_mpi = arg
97    return obj
98
99cdef api MPI_Errhandler* PyMPIErrhandler_Get(object arg) except NULL:
100    return &(<Errhandler?>arg).ob_mpi
101
102# -----------------------------------------------------------------------------
103
104# Comm
105
106cdef api object PyMPIComm_New(MPI_Comm arg):
107    cdef type cls   = Comm
108    cdef int  inter = 0
109    cdef int  topo  = MPI_UNDEFINED
110    if arg != MPI_COMM_NULL:
111        CHKERR( MPI_Comm_test_inter(arg, &inter) )
112        if inter:
113            cls = Intercomm
114        else:
115            CHKERR( MPI_Topo_test(arg, &topo) )
116            if topo == MPI_UNDEFINED:
117                cls = Intracomm
118            elif topo == MPI_CART:
119                cls = Cartcomm
120            elif topo == MPI_GRAPH:
121                cls = Graphcomm
122            elif topo == MPI_DIST_GRAPH:
123                cls = Distgraphcomm
124            else:
125                cls = Intracomm
126    cdef Comm obj = <Comm>cls.__new__(cls)
127    obj.ob_mpi = arg
128    return obj
129
130cdef api MPI_Comm* PyMPIComm_Get(object arg) except NULL:
131    return &(<Comm?>arg).ob_mpi
132
133# -----------------------------------------------------------------------------
134
135# Win
136
137cdef api object PyMPIWin_New(MPI_Win arg):
138    cdef Win obj = Win.__new__(Win)
139    obj.ob_mpi = arg
140    return obj
141
142cdef api MPI_Win* PyMPIWin_Get(object arg) except NULL:
143    return &(<Win?>arg).ob_mpi
144
145# -----------------------------------------------------------------------------
146
147# File
148
149cdef api object PyMPIFile_New(MPI_File arg):
150    cdef File obj = File.__new__(File)
151    obj.ob_mpi = arg
152    return obj
153
154cdef api MPI_File* PyMPIFile_Get(object arg) except NULL:
155    return &(<File?>arg).ob_mpi
156
157# -----------------------------------------------------------------------------
158