1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2016 Los Alamos National Security, LLC. All rights
4 * reserved.
5 * Copyright (c) 2016-2017 Research Organization for Information Science
6 * and Technology (RIST). All rights reserved.
7 * $COPYRIGHT$
8 *
9 * Additional copyrights may follow
10 *
11 * $HEADER$
12 */
13
14 #include "ompi_config.h"
15
16 #include "ompi/communicator/communicator.h"
17 #include "ompi/attribute/attribute.h"
18 #include "ompi/errhandler/errhandler.h"
19 #include "ompi/file/file.h"
20 #include "opal/class/opal_list.h"
21 #include "cxx_glue.h"
22
23 typedef struct ompi_cxx_intercept_file_extra_state_item_t {
24 opal_list_item_t super;
25 ompi_cxx_intercept_file_extra_state_t state;
26 } ompi_cxx_intercept_file_extra_state_item_t;
27
28 OBJ_CLASS_DECLARATION(ompi_cxx_intercept_file_extra_state_item_t);
29 OBJ_CLASS_INSTANCE(ompi_cxx_intercept_file_extra_state_item_t, opal_list_item_t,
30 NULL, NULL);
31
ompi_cxx_comm_get_type(MPI_Comm comm)32 ompi_cxx_communicator_type_t ompi_cxx_comm_get_type (MPI_Comm comm)
33 {
34 if (OMPI_COMM_IS_GRAPH(comm)) {
35 return OMPI_CXX_COMM_TYPE_GRAPH;
36 } else if (OMPI_COMM_IS_CART(comm)) {
37 return OMPI_CXX_COMM_TYPE_CART;
38 } else if (OMPI_COMM_IS_INTRA(comm)) {
39 return OMPI_CXX_COMM_TYPE_INTRACOMM;
40 } else if (OMPI_COMM_IS_INTER(comm)) {
41 return OMPI_CXX_COMM_TYPE_INTERCOMM;
42 }
43
44 return OMPI_CXX_COMM_TYPE_UNKNOWN;
45 }
46
ompi_cxx_errhandler_invoke_comm(MPI_Comm comm,int ret,const char * message)47 int ompi_cxx_errhandler_invoke_comm (MPI_Comm comm, int ret, const char *message)
48 {
49 return OMPI_ERRHANDLER_INVOKE (comm, ret, message);
50 }
51
ompi_cxx_errhandler_invoke_file(MPI_File file,int ret,const char * message)52 int ompi_cxx_errhandler_invoke_file (MPI_File file, int ret, const char *message)
53 {
54 return OMPI_ERRHANDLER_INVOKE (file, ret, message);
55 }
56
ompi_cxx_attr_create_keyval_comm(MPI_Comm_copy_attr_function * copy_fn,MPI_Comm_delete_attr_function * delete_fn,int * keyval,void * extra_state,int flags,void * bindings_extra_state)57 int ompi_cxx_attr_create_keyval_comm (MPI_Comm_copy_attr_function *copy_fn,
58 MPI_Comm_delete_attr_function* delete_fn, int *keyval, void *extra_state,
59 int flags, void *bindings_extra_state)
60 {
61 ompi_attribute_fn_ptr_union_t copy_fn_u = {.attr_communicator_copy_fn =
62 (MPI_Comm_internal_copy_attr_function *) copy_fn};
63 ompi_attribute_fn_ptr_union_t delete_fn_u = {.attr_communicator_delete_fn =
64 (MPI_Comm_delete_attr_function *) delete_fn};
65
66 return ompi_attr_create_keyval (COMM_ATTR, copy_fn_u, delete_fn_u, keyval, extra_state, 0, bindings_extra_state);
67 }
68
ompi_cxx_attr_create_keyval_win(MPI_Win_copy_attr_function * copy_fn,MPI_Win_delete_attr_function * delete_fn,int * keyval,void * extra_state,int flags,void * bindings_extra_state)69 int ompi_cxx_attr_create_keyval_win (MPI_Win_copy_attr_function *copy_fn,
70 MPI_Win_delete_attr_function* delete_fn, int *keyval, void *extra_state,
71 int flags, void *bindings_extra_state)
72 {
73 ompi_attribute_fn_ptr_union_t copy_fn_u = {.attr_win_copy_fn =
74 (MPI_Win_internal_copy_attr_function *) copy_fn};
75 ompi_attribute_fn_ptr_union_t delete_fn_u = {.attr_win_delete_fn =
76 (MPI_Win_delete_attr_function *) delete_fn};
77
78 return ompi_attr_create_keyval (WIN_ATTR, copy_fn_u, delete_fn_u, keyval, extra_state, 0, NULL);
79 }
80
ompi_cxx_attr_create_keyval_type(MPI_Type_copy_attr_function * copy_fn,MPI_Type_delete_attr_function * delete_fn,int * keyval,void * extra_state,int flags,void * bindings_extra_state)81 int ompi_cxx_attr_create_keyval_type (MPI_Type_copy_attr_function *copy_fn,
82 MPI_Type_delete_attr_function* delete_fn, int *keyval, void *extra_state,
83 int flags, void *bindings_extra_state)
84 {
85 ompi_attribute_fn_ptr_union_t copy_fn_u = {.attr_datatype_copy_fn =
86 (MPI_Type_internal_copy_attr_function *) copy_fn};
87 ompi_attribute_fn_ptr_union_t delete_fn_u = {.attr_datatype_delete_fn =
88 (MPI_Type_delete_attr_function *) delete_fn};
89
90 return ompi_attr_create_keyval (TYPE_ATTR, copy_fn_u, delete_fn_u, keyval, extra_state, 0, NULL);
91 }
92
ompi_cxx_errhandler_create_comm(ompi_cxx_dummy_fn_t * fn)93 MPI_Errhandler ompi_cxx_errhandler_create_comm (ompi_cxx_dummy_fn_t *fn)
94 {
95 ompi_errhandler_t *errhandler;
96 errhandler = ompi_errhandler_create(OMPI_ERRHANDLER_TYPE_COMM,
97 (ompi_errhandler_generic_handler_fn_t *) fn,
98 OMPI_ERRHANDLER_LANG_CXX);
99 errhandler->eh_cxx_dispatch_fn =
100 (ompi_errhandler_cxx_dispatch_fn_t *) ompi_mpi_cxx_comm_errhandler_invoke;
101 return errhandler;
102 }
103
ompi_cxx_errhandler_create_win(ompi_cxx_dummy_fn_t * fn)104 MPI_Errhandler ompi_cxx_errhandler_create_win (ompi_cxx_dummy_fn_t *fn)
105 {
106 ompi_errhandler_t *errhandler;
107 errhandler = ompi_errhandler_create(OMPI_ERRHANDLER_TYPE_WIN,
108 (ompi_errhandler_generic_handler_fn_t *) fn,
109 OMPI_ERRHANDLER_LANG_CXX);
110 errhandler->eh_cxx_dispatch_fn =
111 (ompi_errhandler_cxx_dispatch_fn_t *) ompi_mpi_cxx_win_errhandler_invoke;
112 return errhandler;
113 }
114
ompi_cxx_errhandler_create_file(ompi_cxx_dummy_fn_t * fn)115 MPI_Errhandler ompi_cxx_errhandler_create_file (ompi_cxx_dummy_fn_t *fn)
116 {
117 ompi_errhandler_t *errhandler;
118 errhandler = ompi_errhandler_create(OMPI_ERRHANDLER_TYPE_FILE,
119 (ompi_errhandler_generic_handler_fn_t *) fn,
120 OMPI_ERRHANDLER_LANG_CXX);
121 errhandler->eh_cxx_dispatch_fn =
122 (ompi_errhandler_cxx_dispatch_fn_t *) ompi_mpi_cxx_file_errhandler_invoke;
123 return errhandler;
124 }
125
126 ompi_cxx_intercept_file_extra_state_t
ompi_cxx_new_intercept_state(void * read_fn_cxx,void * write_fn_cxx,void * extent_fn_cxx,void * extra_state_cxx)127 *ompi_cxx_new_intercept_state (void *read_fn_cxx, void *write_fn_cxx, void *extent_fn_cxx,
128 void *extra_state_cxx)
129 {
130 ompi_cxx_intercept_file_extra_state_item_t *intercept;
131
132 intercept = OBJ_NEW(ompi_cxx_intercept_file_extra_state_item_t);
133 if (NULL == intercept) {
134 return NULL;
135 }
136
137 opal_list_append(&ompi_registered_datareps, &intercept->super);
138 intercept->state.read_fn_cxx = read_fn_cxx;
139 intercept->state.write_fn_cxx = write_fn_cxx;
140 intercept->state.extent_fn_cxx = extent_fn_cxx;
141 intercept->state.extra_state_cxx = extra_state_cxx;
142
143 return &intercept->state;
144 }
145
ompi_cxx_errhandler_set_callbacks(struct ompi_errhandler_t * errhandler,MPI_Comm_errhandler_function * eh_comm_fn,ompi_file_errhandler_fn * eh_file_fn,MPI_Win_errhandler_function * eh_win_fn)146 void ompi_cxx_errhandler_set_callbacks (struct ompi_errhandler_t *errhandler, MPI_Comm_errhandler_function *eh_comm_fn,
147 ompi_file_errhandler_fn *eh_file_fn, MPI_Win_errhandler_function *eh_win_fn)
148 {
149 errhandler->eh_comm_fn = eh_comm_fn;
150 errhandler->eh_file_fn = eh_file_fn;
151 errhandler->eh_win_fn = eh_win_fn;
152 }
153