This source file includes following definitions.
- PERUSE_Init
- PERUSE_Query_supported_events
- PERUSE_Query_event
- PERUSE_Query_event_name
- PERUSE_Query_environment
- PERUSE_Query_queue_event_scope
- PERUSE_Event_comm_register
- PERUSE_Event_activate
- PERUSE_Event_deactivate
- PERUSE_Event_release
- PERUSE_Event_comm_callback_set
- PERUSE_Event_comm_callback_get
- PERUSE_Event_get
- PERUSE_Event_object_get
- PERUSE_Event_propagate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #include "ompi_config.h"
16 # include <string.h>
17 #include "mpi.h"
18 #include "ompi/peruse/peruse.h"
19 #include "ompi/peruse/peruse-internal.h"
20 #include "ompi/communicator/communicator.h"
21 #include "ompi/runtime/params.h"
22
23
24
25
26
27 typedef struct {
28 const char* name;
29 const int id;
30 } peruse_event_associations_t;
31
32
33
34
35
36 static const peruse_event_associations_t PERUSE_events[] = {
37
38 { "PERUSE_COMM_REQ_ACTIVATE", PERUSE_COMM_REQ_ACTIVATE },
39 { "PERUSE_COMM_REQ_MATCH_UNEX", PERUSE_COMM_REQ_MATCH_UNEX },
40 { "PERUSE_COMM_REQ_INSERT_IN_POSTED_Q", PERUSE_COMM_REQ_INSERT_IN_POSTED_Q },
41 { "PERUSE_COMM_REQ_REMOVE_FROM_POSTED_Q", PERUSE_COMM_REQ_REMOVE_FROM_POSTED_Q },
42 { "PERUSE_COMM_REQ_XFER_BEGIN", PERUSE_COMM_REQ_XFER_BEGIN },
43 { "PERUSE_COMM_REQ_XFER_CONTINUE", PERUSE_COMM_REQ_XFER_CONTINUE },
44 { "PERUSE_COMM_REQ_XFER_END", PERUSE_COMM_REQ_XFER_END },
45 { "PERUSE_COMM_REQ_COMPLETE", PERUSE_COMM_REQ_COMPLETE },
46 { "PERUSE_COMM_REQ_NOTIFY", PERUSE_COMM_REQ_NOTIFY },
47 { "PERUSE_COMM_MSG_ARRIVED", PERUSE_COMM_MSG_ARRIVED },
48 { "PERUSE_COMM_MSG_INSERT_IN_UNEX_Q", PERUSE_COMM_MSG_INSERT_IN_UNEX_Q },
49 { "PERUSE_COMM_MSG_REMOVE_FROM_UNEX_Q", PERUSE_COMM_MSG_REMOVE_FROM_UNEX_Q },
50 { "PERUSE_COMM_MSG_MATCH_POSTED_REQ", PERUSE_COMM_MSG_MATCH_POSTED_REQ },
51
52
53 { "PERUSE_COMM_SEARCH_POSTED_Q_BEGIN", PERUSE_COMM_SEARCH_POSTED_Q_BEGIN },
54 { "PERUSE_COMM_SEARCH_POSTED_Q_END", PERUSE_COMM_SEARCH_POSTED_Q_END },
55 { "PERUSE_COMM_SEARCH_UNEX_Q_BEGIN", PERUSE_COMM_SEARCH_UNEX_Q_BEGIN },
56 { "PERUSE_COMM_SEARCH_UNEX_Q_END", PERUSE_COMM_SEARCH_UNEX_Q_END },
57 { "PERUSE_CUSTOM_EVENT", PERUSE_CUSTOM_EVENT }
58 };
59
60 const int PERUSE_num_events = (sizeof(PERUSE_events) / sizeof(peruse_event_associations_t));
61
62
63
64
65 int PERUSE_Init (void)
66 {
67 if (MPI_PARAM_CHECK) {
68 int32_t state = ompi_mpi_state;
69 if (state < OMPI_MPI_STATE_INIT_COMPLETED ||
70 state >= OMPI_MPI_STATE_FINALIZE_STARTED) {
71 return PERUSE_ERR_INIT;
72 }
73 }
74 ompi_peruse_init ();
75 return PERUSE_SUCCESS;
76 }
77
78
79
80 int PERUSE_Query_supported_events (int* num_supported,
81 char*** event_names,
82 int** events)
83 {
84 int i;
85 *num_supported = PERUSE_num_events;
86
87 *event_names = (char**) malloc (PERUSE_num_events * sizeof (char *));
88 *events = (int*) malloc (PERUSE_num_events * sizeof (int));
89
90 for (i = 0; i < PERUSE_num_events; i++) {
91 (*event_names)[i] = strdup (PERUSE_events[i].name);
92 (*events)[i] = PERUSE_events[i].id;
93 }
94
95 return PERUSE_SUCCESS;
96 }
97
98
99
100 int PERUSE_Query_event (const char* event_name, int* event)
101 {
102 int i;
103
104 for( i = 0; i < PERUSE_num_events; i++ ) {
105 if( !strcmp (event_name, PERUSE_events[i].name) ) {
106 *event = PERUSE_events[i].id;
107 return PERUSE_SUCCESS;
108 }
109 }
110 return PERUSE_ERR_EVENT;
111 }
112
113
114
115 int PERUSE_Query_event_name (int event, char** event_name)
116 {
117 if (event < 0 || event > PERUSE_num_events ||
118 NULL == PERUSE_events[event].name)
119 return PERUSE_EVENT_INVALID;
120
121 *event_name = strdup(PERUSE_events[event].name);
122 return PERUSE_SUCCESS;
123 }
124
125
126
127 int PERUSE_Query_environment (int * env_size, char *** env)
128 {
129
130 return PERUSE_SUCCESS;
131 }
132
133
134 int PERUSE_Query_queue_event_scope (int * scope)
135 {
136 *scope = PERUSE_PER_COMM;
137
138 return PERUSE_SUCCESS;
139 }
140
141
142
143
144
145
146 int PERUSE_Event_comm_register (int event,
147 MPI_Comm comm,
148 peruse_comm_callback_f * callback_fn,
149 void * param,
150 peruse_event_h * event_h)
151 {
152 ompi_peruse_handle_t * handle;
153 if (MPI_PARAM_CHECK) {
154 OMPI_ERR_PERUSE_INIT_FINALIZE;
155
156 if( (event < 0) || (event > PERUSE_num_events) ||
157 (NULL == PERUSE_events[event].name) )
158 return PERUSE_ERR_EVENT;
159
160 if( (MPI_COMM_NULL == comm) || ompi_comm_invalid (comm) )
161 return PERUSE_ERR_COMM;
162
163 if (NULL == callback_fn)
164 return PERUSE_ERR_GENERIC;
165
166 if (NULL == event_h)
167 return PERUSE_ERR_EVENT_HANDLE;
168 }
169
170 handle = OBJ_NEW (ompi_peruse_handle_t);
171
172
173
174
175 handle->active = 0;
176 handle->event = event;
177 handle->type = PERUSE_TYPE_COMM;
178 handle->comm = comm;
179 handle->fn = (ompi_peruse_callback_f*) callback_fn;
180 handle->param = param;
181
182
183
184
185 OPAL_THREAD_LOCK (&comm->c_lock);
186 if( NULL == comm->c_peruse_handles ) {
187 comm->c_peruse_handles = (ompi_peruse_handle_t**)calloc( PERUSE_num_events, sizeof(ompi_peruse_handle_t*) );
188 }
189 OPAL_THREAD_UNLOCK (&comm->c_lock);
190 comm->c_peruse_handles[event] = handle;
191
192 *event_h = handle;
193 return PERUSE_SUCCESS;
194 }
195
196
197
198 int PERUSE_Event_activate (peruse_event_h event_h)
199 {
200 ompi_peruse_handle_t* handle = (ompi_peruse_handle_t*)event_h;
201
202 if (MPI_PARAM_CHECK) {
203 OMPI_ERR_PERUSE_INIT_FINALIZE;
204
205 if (PERUSE_EVENT_HANDLE_NULL == event_h)
206 return PERUSE_ERR_EVENT_HANDLE;
207 }
208
209 OPAL_THREAD_LOCK (&handle->lock);
210 handle->active = 1;
211 OPAL_THREAD_UNLOCK (&handle->lock);
212 return PERUSE_SUCCESS;
213 }
214
215
216
217 int PERUSE_Event_deactivate (peruse_event_h event_h)
218 {
219 ompi_peruse_handle_t* handle = (ompi_peruse_handle_t*)event_h;
220
221 if (MPI_PARAM_CHECK) {
222 OMPI_ERR_PERUSE_INIT_FINALIZE;
223
224 if (PERUSE_EVENT_HANDLE_NULL == event_h)
225 return PERUSE_ERR_EVENT_HANDLE;
226 }
227
228 OPAL_THREAD_LOCK (&handle->lock);
229 handle->active = 0;
230 OPAL_THREAD_UNLOCK (&handle->lock);
231 return PERUSE_SUCCESS;
232 }
233
234
235
236 int PERUSE_Event_release (peruse_event_h * event_h)
237 {
238 if (MPI_PARAM_CHECK) {
239 OMPI_ERR_PERUSE_INIT_FINALIZE;
240
241 if (PERUSE_EVENT_HANDLE_NULL == event_h)
242 return PERUSE_ERR_EVENT_HANDLE;
243 }
244
245
246
247 *event_h = PERUSE_EVENT_HANDLE_NULL;
248 return PERUSE_SUCCESS;
249 }
250
251 #define PERUSE_MPI_PARAM_CHECK(obj_upper,obj_lower ) \
252 if (MPI_PARAM_CHECK) { \
253 OMPI_ERR_PERUSE_INIT_FINALIZE; \
254 \
255 if (PERUSE_EVENT_HANDLE_NULL == event_h || \
256 ((ompi_peruse_handle_t*)event_h)->active || \
257 ((ompi_peruse_handle_t*)event_h)->type != \
258 PERUSE_TYPE_ ## obj_upper) \
259 return PERUSE_ERR_EVENT_HANDLE; \
260 \
261 if (NULL == callback_fn) \
262 return PERUSE_ERR_PARAMETER; \
263
264
265
266
267
268 \
269 } \
270
271
272 int PERUSE_Event_comm_callback_set (peruse_event_h event_h,
273 peruse_comm_callback_f* callback_fn,
274 void* param)
275 {
276 ompi_peruse_handle_t* handle = (ompi_peruse_handle_t*)event_h;
277
278 PERUSE_MPI_PARAM_CHECK (COMM, comm);
279
280 OPAL_THREAD_LOCK (&handle->lock);
281 handle->fn = (ompi_peruse_callback_f*) callback_fn;
282 handle->param = param;
283 OPAL_THREAD_UNLOCK (&handle->lock);
284
285 return PERUSE_SUCCESS;
286 }
287
288
289 int PERUSE_Event_comm_callback_get (peruse_event_h event_h,
290 peruse_comm_callback_f** callback_fn,
291 void** param)
292 {
293 ompi_peruse_handle_t* handle = (ompi_peruse_handle_t*)event_h;
294
295 PERUSE_MPI_PARAM_CHECK (COMM, comm);
296
297 OPAL_THREAD_LOCK (&handle->lock);
298 *callback_fn = (peruse_comm_callback_f*) handle->fn;
299 *param = handle->param;
300 OPAL_THREAD_UNLOCK (&handle->lock);
301
302 return PERUSE_SUCCESS;
303 }
304
305
306 int PERUSE_Event_get (peruse_event_h event_h, int* event)
307 {
308 if (MPI_PARAM_CHECK) {
309 OMPI_ERR_PERUSE_INIT_FINALIZE;
310
311 if (NULL == event_h)
312 return PERUSE_ERR_EVENT_HANDLE;
313
314 if (NULL == event)
315 return PERUSE_ERR_PARAMETER;
316 }
317
318 *event = ((ompi_peruse_handle_t*)event_h)->event;
319 return PERUSE_SUCCESS;
320 }
321
322
323
324 int PERUSE_Event_object_get (peruse_event_h event_h, void** mpi_object)
325 {
326 ompi_peruse_handle_t* p = (ompi_peruse_handle_t*)event_h;
327
328 if (MPI_PARAM_CHECK) {
329 OMPI_ERR_PERUSE_INIT_FINALIZE;
330
331 if (NULL == event_h)
332 return PERUSE_ERR_EVENT_HANDLE;
333
334 if (NULL == mpi_object)
335 return PERUSE_ERR_PARAMETER;
336 }
337
338 switch (p->type) {
339 case PERUSE_TYPE_COMM:
340 *mpi_object = p->comm;
341 return PERUSE_SUCCESS;
342 }
343 return PERUSE_ERR_GENERIC;
344 }
345
346
347
348 int PERUSE_Event_propagate (peruse_event_h event_h, int mode)
349 {
350 return PERUSE_SUCCESS;
351 }