This source file includes following definitions.
- ompi_mpi_cxx_throw_exception
- ompi_mpi_cxx_comm_throw_excptn_fctn
- ompi_mpi_cxx_file_throw_excptn_fctn
- ompi_mpi_cxx_win_throw_excptn_fctn
- InitializeIntercepts
- ompi_mpi_cxx_comm_errhandler_invoke
- ompi_mpi_cxx_file_errhandler_invoke
- ompi_mpi_cxx_win_errhandler_invoke
- ompi_mpi_cxx_op_intercept
- ompi_mpi_cxx_comm_copy_attr_intercept
- ompi_mpi_cxx_comm_delete_attr_intercept
- ompi_mpi_cxx_type_copy_attr_intercept
- ompi_mpi_cxx_type_delete_attr_intercept
- ompi_mpi_cxx_win_copy_attr_intercept
- ompi_mpi_cxx_win_delete_attr_intercept
- ompi_mpi_cxx_grequest_query_fn_intercept
- ompi_mpi_cxx_grequest_free_fn_intercept
- ompi_mpi_cxx_grequest_cancel_fn_intercept
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 #include "mpicxx.h"
28 #include <cstdio>
29
30 #include "ompi_config.h"
31 #include "cxx_glue.h"
32
33 extern "C"
34 void ompi_mpi_cxx_throw_exception(int *errcode)
35 {
36 #if OMPI_HAVE_CXX_EXCEPTION_SUPPORT
37 throw(MPI::Exception(*errcode));
38 #else
39
40
41
42
43 fprintf(stderr, "MPI 2 C++ exception throwing is disabled, MPI::mpi_errno has the error code\n");
44 MPI::mpi_errno = *errcode;
45 #endif
46 }
47
48 extern "C"
49 void ompi_mpi_cxx_comm_throw_excptn_fctn(MPI_Comm *, int *errcode, ...)
50 {
51
52
53 va_list ap;
54 va_start(ap, errcode);
55 ompi_mpi_cxx_throw_exception(errcode);
56 va_end(ap);
57 }
58
59 extern "C"
60 void ompi_mpi_cxx_file_throw_excptn_fctn(MPI_File *, int *errcode, ...)
61 {
62 va_list ap;
63 va_start(ap, errcode);
64 ompi_mpi_cxx_throw_exception(errcode);
65 va_end(ap);
66 }
67
68 extern "C"
69 void ompi_mpi_cxx_win_throw_excptn_fctn(MPI_Win *, int *errcode, ...)
70 {
71 va_list ap;
72 va_start(ap, errcode);
73 ompi_mpi_cxx_throw_exception(errcode);
74 va_end(ap);
75 }
76
77
78 void
79 MPI::InitializeIntercepts()
80 {
81 ompi_cxx_errhandler_set_callbacks ((struct ompi_errhandler_t *) &ompi_mpi_errors_throw_exceptions,
82 ompi_mpi_cxx_comm_throw_excptn_fctn,
83 ompi_mpi_cxx_file_throw_excptn_fctn,
84 ompi_mpi_cxx_win_throw_excptn_fctn);
85 }
86
87
88
89
90
91 extern "C"
92 void ompi_mpi_cxx_comm_errhandler_invoke(MPI_Comm *c_comm, int *err,
93 const char *message, void *comm_fn)
94 {
95
96
97
98 MPI::Intracomm cxx_comm(*c_comm);
99 MPI::Comm::Errhandler_function *cxx_fn =
100 (MPI::Comm::Errhandler_function*) comm_fn;
101
102 cxx_fn((MPI::Comm&) cxx_comm, err, message);
103 }
104
105
106
107
108 extern "C"
109 void ompi_mpi_cxx_file_errhandler_invoke(MPI_File *c_file, int *err,
110 const char *message, void *file_fn)
111 {
112 MPI::File cxx_file(*c_file);
113 MPI::File::Errhandler_function *cxx_fn =
114 (MPI::File::Errhandler_function*) file_fn;
115
116 cxx_fn(cxx_file, err, message);
117 }
118
119
120
121
122 extern "C"
123 void ompi_mpi_cxx_win_errhandler_invoke(MPI_Win *c_win, int *err,
124 const char *message, void *win_fn)
125 {
126 MPI::Win cxx_win(*c_win);
127 MPI::Win::Errhandler_function *cxx_fn =
128 (MPI::Win::Errhandler_function*) win_fn;
129
130 cxx_fn(cxx_win, err, message);
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 extern "C" void
244 ompi_mpi_cxx_op_intercept(void *invec, void *outvec, int *len,
245 MPI_Datatype *datatype, MPI_User_function *c_fn)
246 {
247 MPI::Datatype cxx_datatype = *datatype;
248 MPI::User_function *cxx_callback = (MPI::User_function*) c_fn;
249 cxx_callback(invec, outvec, *len, cxx_datatype);
250 }
251
252
253
254
255 extern "C" int
256 ompi_mpi_cxx_comm_copy_attr_intercept(MPI_Comm comm, int keyval,
257 void *extra_state,
258 void *attribute_val_in,
259 void *attribute_val_out, int *flag,
260 MPI_Comm newcomm)
261 {
262 int ret = 0;
263 MPI::Comm::keyval_intercept_data_t *kid =
264 (MPI::Comm::keyval_intercept_data_t*) extra_state;
265
266
267
268
269 if (NULL != kid->c_copy_fn) {
270 return kid->c_copy_fn(comm, keyval, kid->extra_state, attribute_val_in,
271 attribute_val_out, flag);
272 }
273
274
275
276 MPI::Intracomm intracomm;
277 MPI::Intercomm intercomm;
278 MPI::Graphcomm graphcomm;
279 MPI::Cartcomm cartcomm;
280
281 bool bflag = OPAL_INT_TO_BOOL(*flag);
282
283 if (NULL != kid->cxx_copy_fn) {
284 ompi_cxx_communicator_type_t comm_type =
285 ompi_cxx_comm_get_type (comm);
286 switch (comm_type) {
287 case OMPI_CXX_COMM_TYPE_GRAPH:
288 graphcomm = MPI::Graphcomm(comm);
289 ret = kid->cxx_copy_fn(graphcomm, keyval, kid->extra_state,
290 attribute_val_in, attribute_val_out,
291 bflag);
292 break;
293 case OMPI_CXX_COMM_TYPE_CART:
294 cartcomm = MPI::Cartcomm(comm);
295 ret = kid->cxx_copy_fn(cartcomm, keyval, kid->extra_state,
296 attribute_val_in, attribute_val_out,
297 bflag);
298 break;
299 case OMPI_CXX_COMM_TYPE_INTRACOMM:
300 intracomm = MPI::Intracomm(comm);
301 ret = kid->cxx_copy_fn(intracomm, keyval, kid->extra_state,
302 attribute_val_in, attribute_val_out,
303 bflag);
304 break;
305 case OMPI_CXX_COMM_TYPE_INTERCOMM:
306 intercomm = MPI::Intercomm(comm);
307 ret = kid->cxx_copy_fn(intercomm, keyval, kid->extra_state,
308 attribute_val_in, attribute_val_out,
309 bflag);
310 break;
311 default:
312 ret = MPI::ERR_COMM;
313 }
314 } else {
315 ret = MPI::ERR_OTHER;
316 }
317
318 *flag = (int)bflag;
319 return ret;
320 }
321
322 extern "C" int
323 ompi_mpi_cxx_comm_delete_attr_intercept(MPI_Comm comm, int keyval,
324 void *attribute_val, void *extra_state)
325 {
326 int ret = 0;
327 MPI::Comm::keyval_intercept_data_t *kid =
328 (MPI::Comm::keyval_intercept_data_t*) extra_state;
329
330
331
332
333 if (NULL != kid->c_delete_fn) {
334 return kid->c_delete_fn(comm, keyval, attribute_val, kid->extra_state);
335 }
336
337
338
339 MPI::Intracomm intracomm;
340 MPI::Intercomm intercomm;
341 MPI::Graphcomm graphcomm;
342 MPI::Cartcomm cartcomm;
343
344 if (NULL != kid->cxx_delete_fn) {
345 ompi_cxx_communicator_type_t comm_type =
346 ompi_cxx_comm_get_type (comm);
347 switch (comm_type) {
348 case OMPI_CXX_COMM_TYPE_GRAPH:
349 graphcomm = MPI::Graphcomm(comm);
350 ret = kid->cxx_delete_fn(graphcomm, keyval, attribute_val,
351 kid->extra_state);
352 break;
353 case OMPI_CXX_COMM_TYPE_CART:
354 cartcomm = MPI::Cartcomm(comm);
355 ret = kid->cxx_delete_fn(cartcomm, keyval, attribute_val,
356 kid->extra_state);
357 break;
358 case OMPI_CXX_COMM_TYPE_INTRACOMM:
359 intracomm = MPI::Intracomm(comm);
360 ret = kid->cxx_delete_fn(intracomm, keyval, attribute_val,
361 kid->extra_state);
362 break;
363 case OMPI_CXX_COMM_TYPE_INTERCOMM:
364 intercomm = MPI::Intercomm(comm);
365 ret = kid->cxx_delete_fn(intercomm, keyval, attribute_val,
366 kid->extra_state);
367 break;
368 default:
369 ret = MPI::ERR_COMM;
370 }
371 } else {
372 ret = MPI::ERR_OTHER;
373 }
374
375 return ret;
376 }
377
378 extern "C" int
379 ompi_mpi_cxx_type_copy_attr_intercept(MPI_Datatype oldtype, int keyval,
380 void *extra_state, void *attribute_val_in,
381 void *attribute_val_out, int *flag)
382 {
383 int ret = 0;
384 MPI::Datatype::keyval_intercept_data_t *kid =
385 (MPI::Datatype::keyval_intercept_data_t*) extra_state;
386
387
388 if (NULL != kid->c_copy_fn) {
389
390
391 ret = kid->c_copy_fn(oldtype, keyval, kid->extra_state, attribute_val_in,
392 attribute_val_out, flag);
393 } else if (NULL != kid->cxx_copy_fn) {
394
395 bool bflag = OPAL_INT_TO_BOOL(*flag);
396 MPI::Datatype cxx_datatype(oldtype);
397 ret = kid->cxx_copy_fn(cxx_datatype, keyval, kid->extra_state,
398 attribute_val_in, attribute_val_out, bflag);
399 *flag = (int)bflag;
400 } else {
401 ret = MPI::ERR_TYPE;
402 }
403
404 return ret;
405 }
406
407 extern "C" int
408 ompi_mpi_cxx_type_delete_attr_intercept(MPI_Datatype type, int keyval,
409 void *attribute_val, void *extra_state)
410 {
411 int ret = 0;
412 MPI::Datatype::keyval_intercept_data_t *kid =
413 (MPI::Datatype::keyval_intercept_data_t*) extra_state;
414
415 if (NULL != kid->c_delete_fn) {
416 return kid->c_delete_fn(type, keyval, attribute_val, kid->extra_state);
417 } else if (NULL != kid->cxx_delete_fn) {
418 MPI::Datatype cxx_datatype(type);
419 return kid->cxx_delete_fn(cxx_datatype, keyval, attribute_val,
420 kid->extra_state);
421 } else {
422 ret = MPI::ERR_TYPE;
423 }
424
425 return ret;
426 }
427
428 extern "C" int
429 ompi_mpi_cxx_win_copy_attr_intercept(MPI_Win oldwin, int keyval,
430 void *extra_state, void *attribute_val_in,
431 void *attribute_val_out, int *flag)
432 {
433 int ret = 0;
434 MPI::Win::keyval_intercept_data_t *kid =
435 (MPI::Win::keyval_intercept_data_t*) extra_state;
436
437 if (NULL != kid->c_copy_fn) {
438
439
440 ret = kid->c_copy_fn(oldwin, keyval, kid->extra_state, attribute_val_in,
441 attribute_val_out, flag);
442 } else if (NULL != kid->cxx_copy_fn) {
443
444 bool bflag = OPAL_INT_TO_BOOL(*flag);
445 MPI::Win cxx_win(oldwin);
446 ret = kid->cxx_copy_fn(cxx_win, keyval, kid->extra_state,
447 attribute_val_in, attribute_val_out, bflag);
448 *flag = (int)bflag;
449 } else {
450 ret = MPI::ERR_WIN;
451 }
452
453 return ret;
454 }
455
456 extern "C" int
457 ompi_mpi_cxx_win_delete_attr_intercept(MPI_Win win, int keyval,
458 void *attribute_val, void *extra_state)
459 {
460 int ret = 0;
461 MPI::Win::keyval_intercept_data_t *kid =
462 (MPI::Win::keyval_intercept_data_t*) extra_state;
463
464 if (NULL != kid->c_delete_fn) {
465 return kid->c_delete_fn(win, keyval, attribute_val, kid->extra_state);
466 } else if (NULL != kid->cxx_delete_fn) {
467 MPI::Win cxx_win(win);
468 return kid->cxx_delete_fn(cxx_win, keyval, attribute_val,
469 kid->extra_state);
470 } else {
471 ret = MPI::ERR_WIN;
472 }
473
474 return ret;
475 }
476
477
478
479
480
481 extern "C" int
482 ompi_mpi_cxx_grequest_query_fn_intercept(void *state, MPI_Status *status)
483 {
484 MPI::Grequest::Intercept_data_t *data =
485 (MPI::Grequest::Intercept_data_t *) state;
486
487 MPI::Status s(*status);
488 int ret = data->id_cxx_query_fn(data->id_extra, s);
489 *status = s;
490 return ret;
491 }
492
493 extern "C" int
494 ompi_mpi_cxx_grequest_free_fn_intercept(void *state)
495 {
496 MPI::Grequest::Intercept_data_t *data =
497 (MPI::Grequest::Intercept_data_t *) state;
498 int ret = data->id_cxx_free_fn(data->id_extra);
499
500 delete data;
501 return ret;
502 }
503
504 extern "C" int
505 ompi_mpi_cxx_grequest_cancel_fn_intercept(void *state, int cancelled)
506 {
507 MPI::Grequest::Intercept_data_t *data =
508 (MPI::Grequest::Intercept_data_t *) state;
509 return data->id_cxx_cancel_fn(data->id_extra,
510 (0 != cancelled ? true : false));
511 }