File: MPI.pyx

package info (click to toggle)
paraview 3.14.1-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 234,468 kB
  • sloc: cpp: 2,166,013; ansic: 801,575; xml: 58,068; tcl: 49,247; python: 43,091; java: 16,625; fortran: 12,224; sh: 11,722; yacc: 5,688; perl: 3,128; makefile: 2,228; lex: 1,311; lisp: 486; asm: 471; pascal: 228
file content (259 lines) | stat: -rw-r--r-- 5,817 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
__doc__ = u"""
Message Passing Interface.
"""

include "stdlib.pxi"

include "mpi.pxi"

include "atimport.pxi"

initialize()
startup()

include "allocate.pxi"
include "asmpistr.pxi"
include "asbuffer.pxi"
include "asmemory.pxi"
include "asarray.pxi"
include "helpers.pxi"
include "message.pxi"
include "pickled.pxi"

include "CAPI.pxi"

include "Exception.pyx"     # DONE
include "Errhandler.pyx"    # DONE
include "Datatype.pyx"      # DONE
include "Status.pyx"        # DONE
include "Request.pyx"       # DONE
include "Info.pyx"          # DONE
include "Op.pyx"            # DONE (except user-defined operations)
include "Group.pyx"         # DONE
include "Comm.pyx"          # DONE
include "Win.pyx"           # DONE
include "File.pyx"          # DONE

# Assorted constants
# ------------------

UNDEFINED = MPI_UNDEFINED
#"""Undefined integer value"""

ANY_SOURCE = MPI_ANY_SOURCE
#"""Wildcard source value for receives"""

ANY_TAG = MPI_ANY_TAG
#"""Wildcard tag value for receives"""

PROC_NULL = MPI_PROC_NULL
#"""Special process rank for send/receive"""

ROOT = MPI_ROOT
#"""Root process for collective inter-communications"""

BOTTOM = __BOTTOM__
#"""Special address for buffers"""

IN_PLACE = __IN_PLACE__
#"""*In-place* option for collective communications"""



# Predefined Attribute Keyvals
# ----------------------------

KEYVAL_INVALID  = MPI_KEYVAL_INVALID

TAG_UB          = MPI_TAG_UB
HOST            = MPI_HOST
IO              = MPI_IO
WTIME_IS_GLOBAL = MPI_WTIME_IS_GLOBAL

UNIVERSE_SIZE   = MPI_UNIVERSE_SIZE
APPNUM          = MPI_APPNUM

LASTUSEDCODE    = MPI_LASTUSEDCODE

WIN_BASE        = MPI_WIN_BASE
WIN_SIZE        = MPI_WIN_SIZE
WIN_DISP_UNIT   = MPI_WIN_DISP_UNIT


# Memory Allocation
# -----------------

def Alloc_mem(Aint size, Info info=INFO_NULL):
    """
    Allocate memory for message passing and RMA
    """
    cdef void *base = NULL
    cdef MPI_Info cinfo = _arg_Info(info)
    CHKERR( MPI_Alloc_mem(size, cinfo, &base) )
    return tomemory(base, size)

def Free_mem(memory):
    """
    Free memory allocated with `Alloc_mem()`
    """
    cdef void *base = NULL
    asmemory(memory, &base, NULL)
    CHKERR( MPI_Free_mem(base) )


# Initialization and Exit
# -----------------------

def Init():
    """
    Initialize the MPI execution environment
    """
    CHKERR( MPI_Init(NULL, NULL) )
    startup()

def Finalize():
    """
    Terminate the MPI execution environment
    """
    cleanup()
    CHKERR( MPI_Finalize() )

# Levels of MPI threading support
# -------------------------------

THREAD_SINGLE     = MPI_THREAD_SINGLE
# """Only one thread will execute"""

THREAD_FUNNELED   = MPI_THREAD_FUNNELED
# """MPI calls are *funneled* to the main thread"""

THREAD_SERIALIZED = MPI_THREAD_SERIALIZED
# """MPI calls are *serialized*"""

THREAD_MULTIPLE   = MPI_THREAD_MULTIPLE
# """Multiple threads may call MPI"""

def Init_thread(int required=THREAD_MULTIPLE):
    """
    Initialize the MPI execution environment
    """
    cdef int provided = MPI_THREAD_SINGLE
    CHKERR( MPI_Init_thread(NULL, NULL, required, &provided) )
    startup()
    return provided

def Query_thread():
    """
    Return the level of thread support
    provided by the MPI library
    """
    cdef int provided = MPI_THREAD_SINGLE
    CHKERR( MPI_Query_thread(&provided) )
    return provided

def Is_thread_main():
    """
    Indicate whether this thread called
    ``Init`` or ``Init_thread``
    """
    cdef bint flag = 1
    CHKERR( MPI_Is_thread_main(&flag) )
    return flag

def Is_initialized():
    """
    Indicates whether ``Init`` has been called
    """
    cdef bint flag = 0
    CHKERR( MPI_Initialized(&flag) )
    return flag

def Is_finalized():
    """
    Indicates whether ``Finalize`` has completed
    """
    cdef bint flag = 0
    CHKERR( MPI_Finalized(&flag) )
    return flag

# Implementation Information
# --------------------------

# MPI Version Number
# -----------------

def Get_version():
    """
    Obtain the version number of the MPI standard supported
    by the implementation as a tuple ``(version, subversion)``
    """
    cdef int version = 1
    cdef int subversion = 0
    CHKERR( MPI_Get_version(&version, &subversion) )
    return (version, subversion)

VERSION    = MPI_VERSION
SUBVERSION = MPI_SUBVERSION

# Environmental Inquires
# ----------------------

def Get_processor_name():
    """
    Obtain the name of the calling processor
    """
    cdef char name[MPI_MAX_PROCESSOR_NAME+1]
    cdef int nlen = 0
    CHKERR( MPI_Get_processor_name(name, &nlen) )
    return tompistr(name, nlen)

# Timers and Synchronization
# --------------------------

def Wtime():
    """
    Return an elapsed time on the calling processor
    """
    return MPI_Wtime()

def Wtick():
    """
    Return the resolution of ``Wtime``
    """
    return MPI_Wtick()


# Maximum string sizes
# --------------------

# MPI-1
MAX_PROCESSOR_NAME = MPI_MAX_PROCESSOR_NAME
MAX_ERROR_STRING   = MPI_MAX_ERROR_STRING
# MPI-2
MAX_PORT_NAME      = MPI_MAX_PORT_NAME
MAX_INFO_KEY       = MPI_MAX_INFO_KEY
MAX_INFO_VAL       = MPI_MAX_INFO_VAL
MAX_OBJECT_NAME    = MPI_MAX_OBJECT_NAME
MAX_DATAREP_STRING = MPI_MAX_DATAREP_STRING



# --------------------------------------------------------------------

cdef extern from "vendor.h":
    int MPI_Get_vendor(const_char**,int*,int*,int*)

def get_vendor():
    """
    Infomation about the underlying MPI implementation

    :Returns:
      - a string with the name of the MPI implementation
      - an integer 3-tuple version ``(major, minor, micro)``
    """
    cdef const_char *name=NULL
    cdef int major=0, minor=0, micro=0
    CHKERR( MPI_Get_vendor(&name, &major, &minor, &micro) )
    return (mpistr(name), (major, minor, micro))

# --------------------------------------------------------------------