-
Notifications
You must be signed in to change notification settings - Fork 14
/
win.go
277 lines (201 loc) · 6.02 KB
/
win.go
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// Copyright (c) 2013 Alexander Beifuß <7beifuss@informatik.uni-hamburg.de>
// Johann Weging <johann@weging.net>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package MPI
/*
#include <stdlib.h>
#include <mpi.h>
*/
import "C"
import (
"unsafe"
)
//MPI_Win_call_errhandler
//Passes the supplied error code to the error handler assigned to a window.
func Win_call_errhandler(win Win, errorcode int) int {
err := C.MPI_Win_call_errhandler(C.MPI_Win(win), C.int(errorcode))
return int(err)
}
//MPI_Win_complete
//Completes an RMA access epoch on win started by a call to MPI_Win_start
func Win_complete(win Win) int {
err := C.MPI_Win_complete(C.MPI_Win(win))
return int(err)
}
//Win_create
//One-sided MPI call that returns a window object for RMA operations.
func Win_create(base interface{}, size Aint, displacementUnit int, info Info, comm Comm) (Win, int) {
baseVoidPtr := Get_void_ptr(base)
var cWin C.MPI_Win
err := C.MPI_Win_create(baseVoidPtr,
C.MPI_Aint(size),
C.int(displacementUnit),
C.MPI_Info(info),
C.MPI_Comm(comm),
&cWin)
return Win(cWin), int(err)
}
//MPI_Win_delete_attr
//Deletes an attribute from a window.
func Win_delete_attr(win Win, winKeyval int) (Win, int) {
cWin := C.MPI_Win(win)
err := C.MPI_Win_delete_attr(cWin, C.int(winKeyval))
return Win(cWin), int(err)
}
//Win_fence
//Synchronizes RMA calls on a window.
func Win_fence(assert bool, win Win) int {
cAssert := C.int(0)
if assert {
cAssert = 1
}
err := C.MPI_Win_fence(cAssert, C.MPI_Win(win))
return int(err)
}
//Win_free
//Frees the window object and returns a null handle.
func Win_free(win Win) (Win, int) {
cWin := C.MPI_Win(win)
err := C.MPI_Win_free(&cWin)
return Win(cWin), int(err)
}
//Win_free_keyval
//Frees a window keyval.
func Win_free_keyval(keyval int) (int, int) {
cKeyval := C.int(keyval)
err := C.MPI_Win_free_keyval(&cKeyval)
return int(cKeyval), int(err)
}
//Win_get_attr
//Obtains the value of a window attribute.
func Win_get_attr(win Win, winKeyval int) (uintptr, bool, int) {
var attributeVal uintptr
var cFlag C.int
flag := false
err := C.MPI_Win_get_attr(C.MPI_Win(win),
C.int(winKeyval),
unsafe.Pointer(attributeVal),
&cFlag)
if int(cFlag) != 0 {
flag = true
}
return attributeVal, flag, int(err)
}
//Win_get_errhandler
//Retrieves the error handler currently associated with a window.
func Win_get_errhandler(win Win) (Errhandler, int) {
var cErrhandler C.MPI_Errhandler
err := C.MPI_Win_get_errhandler(C.MPI_Win(win), &cErrhandler)
return Errhandler(cErrhandler), int(err)
}
//Win_get_group
//Returns a duplicate of the group of the communicator used to create the window.
func Win_get_group(win Win) (Group, int) {
var cGroup C.MPI_Group
err := C.MPI_Win_get_group(C.MPI_Win(win), &cGroup)
return Group(cGroup), int(err)
}
//MPI_Win_get_name
//Obtains the name of a window.
func Win_get_name(win Win) (string, int) {
cstrWinName := (*C.char)(C.malloc(C.size_t(MAX_OBJECT_NAME)))
cResultLength := C.int(0)
err := C.MPI_Win_get_name(C.MPI_Win(win),
cstrWinName,
&cResultLength)
winName := C.GoStringN(cstrWinName, cResultLength)
C.free(unsafe.Pointer(cstrWinName))
return winName, int(err)
}
//Win_lock
//Starts an RMA access epoch locking access to a particular rank.
func Win_lock(lockTpe int, rank int, assert bool, win Win) int {
cAssert := C.int(0)
if assert {
cAssert = C.int(1)
}
err := C.MPI_Win_lock(C.int(lockTpe),
C.int(rank),
cAssert,
C.MPI_Win(win))
return int(err)
}
//Win_post
//Starts an RMA exposure epoch for the local window associated with win.
func Win_post(group Group, assert bool, win Win) int {
cAssert := C.int(0)
if assert {
cAssert = C.int(1)
}
err := C.MPI_Win_post(C.MPI_Group(group),
cAssert,
C.MPI_Win(win))
return int(err)
}
//Win_set_attr
//Sets the value of a window attribute.
func Win_set_attr(win Win, winKeyval int, attributeVal interface{}) int {
attributeValVoidPtr := Get_void_ptr(attributeVal)
err := C.MPI_Win_set_attr(C.MPI_Win(win),
C.int(winKeyval),
attributeValVoidPtr)
return int(err)
}
//Win_set_errhandler
//Attaches a new error handler to a window.
func Win_set_errhandler(win Win, errhandler Errhandler) int {
err := C.MPI_Win_set_errhandler(C.MPI_Win(win), C.MPI_Errhandler(errhandler))
return int(err)
}
//Win_set_name
//Sets the name of a window.
func Win_set_name(win Win, winName string) int {
cstrWinName := C.CString(winName)
err := C.MPI_Win_set_name(C.MPI_Win(win), cstrWinName)
C.free(unsafe.Pointer(cstrWinName))
return int(err)
}
//Win_start
//Starts an RMA access epoch for win.
func Win_start(group Group, assert bool, win Win) int {
cAssert := C.int(0)
if assert {
cAssert = C.int(1)
}
err := C.MPI_Win_start(C.MPI_Group(group), cAssert, C.MPI_Win(win))
return int(err)
}
//MPI_Win_test
//Attempts to complete an RMA exposure epoch; a nonblocking version of MPI_Win_wait.
func Win_test(win Win) (bool, int) {
var cFlag C.int
flag := false
err := C.MPI_Win_test(C.MPI_Win(win), &cFlag)
if int(cFlag) != 0 {
flag = true
}
return flag, int(err)
}
//Win_unlock
//Completes an RMA access epoch started by a call to MPI_Win_lock.
func Win_unlock(rank int, win Win) int {
err := C.MPI_Win_unlock(C.int(rank), C.MPI_Win(win))
return int(err)
}
//Win_wait
//Completes an RMA exposure epoch started by a call to MPI_Win_post on win.
func Win_wait(win Win) int {
err := C.MPI_Win_wait(C.MPI_Win(win))
return int(err)
}