1# -----------------------------------------------------------------------------
2
3#  Datatype
4
5cdef api object PyMPIDatatype_New(MPI_Datatype arg):
6    cdef Datatype obj = <Datatype>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>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>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#  Op
45
46cdef api object PyMPIOp_New(MPI_Op arg):
47    cdef Op obj = <Op>Op.__new__(Op)
48    obj.ob_mpi = arg
49    return obj
50
51cdef api MPI_Op* PyMPIOp_Get(object arg) except NULL:
52    return &(<Op?>arg).ob_mpi
53
54# -----------------------------------------------------------------------------
55
56#  Info
57
58cdef api object PyMPIInfo_New(MPI_Info arg):
59    cdef Info obj = <Info>Info.__new__(Info)
60    obj.ob_mpi = arg
61    return obj
62
63cdef api MPI_Info* PyMPIInfo_Get(object arg) except NULL:
64    return &(<Info?>arg).ob_mpi
65
66# -----------------------------------------------------------------------------
67
68#  Group
69
70cdef api object PyMPIGroup_New(MPI_Group arg):
71    cdef Group obj = <Group>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# Comm
81
82cdef api object PyMPIComm_New(MPI_Comm arg):
83    cdef type cls   = Comm
84    cdef int  inter = 0
85    cdef int  topo  = MPI_UNDEFINED
86    if arg != MPI_COMM_NULL:
87        CHKERR( MPI_Comm_test_inter(arg, &inter) )
88        if inter:
89            cls = Intercomm
90        else:
91            CHKERR( MPI_Topo_test(arg, &topo) )
92            if topo == <int>MPI_UNDEFINED:
93                cls = Intracomm
94            elif topo == <int>MPI_CART:
95                cls = Cartcomm
96            elif topo == <int>MPI_GRAPH:
97                cls = Graphcomm
98            elif topo == <int>MPI_DIST_GRAPH:
99                cls = Distgraphcomm
100            else:
101                cls = Intracomm
102    cdef Comm obj = <Comm>cls()
103    obj.ob_mpi = arg
104    return obj
105
106cdef api MPI_Comm* PyMPIComm_Get(object arg) except NULL:
107    return &(<Comm?>arg).ob_mpi
108
109# -----------------------------------------------------------------------------
110
111# Win
112
113cdef api object PyMPIWin_New(MPI_Win arg):
114    cdef Win obj = <Win>Win.__new__(Win)
115    obj.ob_mpi = arg
116    return obj
117
118cdef api MPI_Win* PyMPIWin_Get(object arg) except NULL:
119    return &(<Win?>arg).ob_mpi
120
121# -----------------------------------------------------------------------------
122
123# File
124
125cdef api object PyMPIFile_New(MPI_File arg):
126    cdef File obj = <File>File.__new__(File)
127    obj.ob_mpi = arg
128    return obj
129
130cdef api MPI_File* PyMPIFile_Get(object arg) except NULL:
131    return &(<File?>arg).ob_mpi
132
133# -----------------------------------------------------------------------------
134
135# Errhandler
136
137cdef api object PyMPIErrhandler_New(MPI_Errhandler arg):
138    cdef Errhandler obj = <Errhandler>Errhandler.__new__(Errhandler)
139    obj.ob_mpi = arg
140    return obj
141
142cdef api MPI_Errhandler* PyMPIErrhandler_Get(object arg) except NULL:
143    return &(<Errhandler?>arg).ob_mpi
144
145# -----------------------------------------------------------------------------
146