This source file includes following definitions.
- custom_match_prq_cancel
- custom_match_prq_find_verify
- custom_match_prq_find_dequeue_verify
- custom_match_prq_append
- custom_match_prq_size
- custom_match_prq_init
- custom_match_prq_destroy
- custom_match_print
- custom_match_prq_dump
- custom_match_umq_find_verify_hold
- custom_match_umq_remove_hold
- custom_match_umq_append
- custom_match_umq_init
- custom_match_umq_destroy
- custom_match_umq_size
- custom_match_umq_dump
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #ifndef PML_OB1_CUSTOM_MATCH_LINKEDLIST_H
15 #define PML_OB1_CUSTOM_MATCH_LINKEDLIST_H
16
17 #include "../pml_ob1_recvreq.h"
18 #include "../pml_ob1_recvfrag.h"
19
20 typedef struct custom_match_prq_node
21 {
22 int tag;
23 int tmask;
24 int src;
25 int smask;
26 struct custom_match_prq_node* next;
27 void* value;
28 } custom_match_prq_node;
29
30 typedef struct custom_match_prq
31 {
32 custom_match_prq_node* head;
33 custom_match_prq_node* tail;
34 custom_match_prq_node* pool;
35 int size;
36 } custom_match_prq;
37
38 static inline int custom_match_prq_cancel(custom_match_prq* list, void* req)
39 {
40 #if CUSTOM_MATCH_DEBUG_VERBOSE
41 printf("custom_match_prq_cancel - list: %x req: %x\n", list, req);
42 #endif
43 custom_match_prq_node* prev = 0;
44 custom_match_prq_node* elem = list->head;
45 int i;
46 while(elem)
47 {
48 if(elem->value == req)
49 {
50
51 elem->tag = ~0;
52 elem->tmask = ~0;
53 elem->src = ~0;
54 elem->smask = ~0;
55 elem->value = 0;
56 if(prev)
57 {
58 prev->next = elem->next;
59 }
60 else
61 {
62 list->head = elem->next;
63 }
64 if(!elem->next)
65 {
66 list->tail = prev;
67 }
68 elem->next = list->pool;
69 list->pool = elem;
70 list->size--;
71 return 1;
72 }
73 prev = elem;
74 elem = elem->next;
75 }
76 return 0;
77 }
78
79 static inline void* custom_match_prq_find_verify(custom_match_prq* list, int tag, int peer)
80 {
81 #if CUSTOM_MATCH_DEBUG_VERBOSE
82 printf("custom_match_prq_find_verify list: %x tag: %x peer: %x\n", list, tag, peer);
83 #endif
84 custom_match_prq_node* elem = list->head;
85 int result;
86
87 while(elem)
88 {
89 result = ((elem->tag & elem->tmask) == (tag & elem->tmask)) &&
90 ((elem->src & elem->smask) == (peer & elem->smask));
91 if(result)
92 {
93 return elem->value;
94 }
95 elem = elem->next;
96 }
97 return 0;
98 }
99
100 static inline void* custom_match_prq_find_dequeue_verify(custom_match_prq* list, int tag, int peer)
101 {
102 #if CUSTOM_MATCH_DEBUG_VERBOSE
103 printf("custom_match_prq_find_dequeue_verify list: %x:%d tag: %x peer: %x\n", list, list->size, tag, peer);
104 #endif
105 custom_match_prq_node* prev = 0;
106 custom_match_prq_node* elem = list->head;
107 int result;
108
109 while(elem)
110 {
111 result = ((elem->tag & elem->tmask) == (tag & elem->tmask)) &&
112 ((elem->src & elem->smask) == (peer & elem->smask));
113 if(result)
114 {
115 void* payload = elem->value;
116 elem->tag = ~0;
117 elem->tmask = ~0;
118 elem->src = ~0;
119 elem->smask = ~0;
120 elem->value = 0;
121 if(prev)
122 {
123 prev->next = elem->next;
124 }
125 else
126 {
127 list->head = elem->next;
128 }
129 if(!elem->next)
130 {
131 list->tail = prev;
132 }
133 elem->next = list->pool;
134 list->pool = elem;
135 #if CUSTOM_MATCH_DEBUG_VERBOSE
136 printf("%x == %x added to the pool\n", elem, list->pool);
137 #endif
138 list->size--;
139 mca_pml_base_request_t *req = (mca_pml_base_request_t *)payload;
140 #if CUSTOM_MATCH_DEBUG_VERBOSE
141 printf("Found list: %x tag: %x peer: %x\n", list, req->req_tag, req->req_peer);
142 #endif
143 return payload;
144 }
145 prev = elem;
146 elem = elem->next;
147 }
148 return 0;
149 }
150
151
152 static inline void custom_match_prq_append(custom_match_prq* list, void* payload, int tag, int source)
153 {
154 int32_t mask_tag, mask_src;
155 if(source == OMPI_ANY_SOURCE)
156 {
157 mask_src = 0;
158 }
159 else
160 {
161 mask_src = ~0;
162 }
163 if(tag == OMPI_ANY_TAG)
164 {
165 mask_tag = 0;
166 }
167 else
168 {
169 mask_tag = ~0;
170 }
171 mca_pml_base_request_t *req = (mca_pml_base_request_t *)payload;
172 #if CUSTOM_MATCH_DEBUG_VERBOSE
173 printf("custom_match_prq_append list: %x tag: %x soruce: %x tag: %x peer: %x\n", list, tag, source, req->req_tag, req->req_peer);
174 #endif
175 int i;
176 custom_match_prq_node* elem;
177 #if CUSTOM_MATCH_DEBUG_VERBOSE
178 printf("%x next elem in the pool\n", list->pool);
179 #endif
180 if(list->pool)
181 {
182 elem = list->pool;
183 list->pool = list->pool->next;
184 }
185 else
186 {
187 elem = malloc(sizeof(custom_match_prq_node));
188 }
189 elem->next = 0;
190 if(list->tail)
191 {
192 list->tail->next = elem;
193 list->tail = elem;
194 }
195 else
196 {
197 list->head = elem;
198 list->tail = elem;
199 }
200
201 elem = list->tail;
202 elem->tag = tag;
203 elem->tmask = mask_tag;
204 elem->src = source;
205 elem->smask = mask_src;
206 elem->value = payload;
207 list->size++;
208 #if CUSTOM_MATCH_DEBUG_VERBOSE
209 printf("Exiting custom_match_prq_append\n");
210 #endif
211 }
212
213 static inline int custom_match_prq_size(custom_match_prq* list)
214 {
215 return list->size;
216 }
217
218 static inline custom_match_prq* custom_match_prq_init()
219 {
220 #if CUSTOM_MATCH_DEBUG_VERBOSE
221 printf("custom_match_prq_init\n");
222 #endif
223 custom_match_prq* list = malloc(sizeof(custom_match_prq));
224 list->head = 0;
225 list->tail = 0;
226 list->pool = 0;
227 list->size = 0;
228 return list;
229 }
230
231 static inline void custom_match_prq_destroy(custom_match_prq* list)
232 {
233 #if CUSTOM_MATCH_DEBUG_VERBOSE
234 printf("custom_match_prq_destroy\n");
235 #endif
236 custom_match_prq_node* elem;
237 int i = 0;
238 int j = 0;
239 while(list->head)
240 {
241 elem = list->head;
242 list->head = list->head->next;
243 free(elem);
244 i++;
245 }
246 while(list->pool)
247 {
248 elem = list->pool;
249 list->pool = list->pool->next;
250 free(elem);
251 j++;
252 }
253 free(list);
254 #if CUSTOM_MATCH_DEBUG_VERBOSE
255 printf("Number of prq elements destroyed = %d %d\n", i, j);
256 #endif
257 }
258
259 static inline void custom_match_print(custom_match_prq* list)
260 {
261 custom_match_prq_node* elem;
262 int i = 0;
263 int j = 0;
264 printf("Elements in the list (this is currenly only partialy implemented):\n");
265 for(elem = list->head; elem; elem = elem->next)
266 {
267 printf("This is the %d linked list element\n", ++i);
268 printf("%d The key is %d, the mask is %d, the value is %ld\n", i, elem->tag, elem->tmask, elem->value);
269 i++;
270 }
271 }
272
273 static inline void custom_match_prq_dump(custom_match_prq* list)
274 {
275 opal_list_item_t* item;
276 char cpeer[64], ctag[64];
277
278 custom_match_prq_node* elem;
279 int i = 0;
280 int j = 0;
281 printf("Elements in the list:\n");
282 for(elem = list->head; elem; elem = elem->next)
283 {
284 printf("This is the %d linked list element\n", ++i);
285 if(elem->value)
286 {
287 mca_pml_base_request_t *req = (mca_pml_base_request_t *)elem->value;
288 if( OMPI_ANY_SOURCE == req->req_peer ) snprintf(cpeer, 64, "%s", "ANY_SOURCE");
289 else snprintf(cpeer, 64, "%d", req->req_peer);
290 if( OMPI_ANY_TAG == req->req_tag ) snprintf(ctag, 64, "%s", "ANY_TAG");
291 else snprintf(ctag, 64, "%d", req->req_tag);
292 opal_output(0, "req %p peer %s tag %s addr %p count %lu datatype %s [%p] [%s %s] req_seq %" PRIu64,
293 (void*) req, cpeer, ctag,
294 (void*) req->req_addr, req->req_count,
295 (0 != req->req_count ? req->req_datatype->name : "N/A"),
296 (void*) req->req_datatype,
297 (req->req_pml_complete ? "pml_complete" : ""),
298 (req->req_free_called ? "freed" : ""),
299 req->req_sequence);
300
301 }
302 }
303 }
304
305
306
307
308 typedef struct custom_match_umq_node
309 {
310 int tag;
311 int src;
312 struct custom_match_umq_node* next;
313 void* value;
314 } custom_match_umq_node;
315
316 typedef struct custom_match_umq
317 {
318 custom_match_umq_node* head;
319 custom_match_umq_node* tail;
320 custom_match_umq_node* pool;
321 int size;
322 } custom_match_umq;
323
324 static inline void custom_match_umq_dump(custom_match_umq* list);
325
326 static inline void* custom_match_umq_find_verify_hold(custom_match_umq* list, int tag, int peer, custom_match_umq_node** hold_prev, custom_match_umq_node** hold_elem, int* hold_index)
327 {
328 #if CUSTOM_MATCH_DEBUG_VERBOSE
329 printf("custom_match_umq_find_verify_hold list: %x:%d tag: %x peer: %x\n", list, list->size, tag, peer);
330 custom_match_umq_dump(list);
331 #endif
332 custom_match_umq_node* prev = 0;
333 custom_match_umq_node* elem = list->head;
334 int result;
335
336 int tmask = ~0;
337 int smask = ~0;
338 if(peer == OMPI_ANY_SOURCE)
339 {
340 smask = 0;
341 }
342
343 if(tag == OMPI_ANY_TAG)
344 {
345 tmask = 0;
346 }
347
348 tag = tag & tmask;
349 peer = peer & smask;
350
351 while(elem)
352 {
353 result = ((elem->tag & tmask) == tag) &&
354 ((elem->src & smask) == peer);
355 if(result)
356 {
357 #if CUSTOM_MATCH_DEBUG_VERBOSE
358 printf("Found list: %x tag: %x peer: %x\n", list, tag, peer);
359 #endif
360 *hold_prev = prev;
361 *hold_elem = elem;
362 *hold_index = 0;
363 return elem->value;
364 }
365 prev = elem;
366 elem = elem->next;
367 }
368 return 0;
369 }
370
371
372 static inline void custom_match_umq_remove_hold(custom_match_umq* list, custom_match_umq_node* prev, custom_match_umq_node* elem, int i)
373 {
374 #if CUSTOM_MATCH_DEBUG_VERBOSE
375 printf("custom_match_umq_find_remove_hold %x %x %x\n", prev, elem, i);
376 #endif
377 elem->tag = ~0;
378 elem->src = ~0;
379 elem->value = 0;
380 if(prev)
381 {
382 prev->next = elem->next;
383 }
384 else
385 {
386 list->head = elem->next;
387 }
388 if(!elem->next)
389 {
390 list->tail = prev;
391 }
392 elem->next = list->pool;
393 list->pool = elem;
394 list->size--;
395 }
396
397 static inline void custom_match_umq_append(custom_match_umq* list, int tag, int source, void* payload)
398 {
399 #if CUSTOM_MATCH_DEBUG_VERBOSE
400 printf("custom_match_umq_append list: %x payload: %x tag: %d src: %d\n", list, payload, tag, source);
401 #endif
402 int i;
403 custom_match_umq_node* elem;
404 list->size++;
405 if(list->pool)
406 {
407 #if CUSTOM_MATCH_DEBUG_VERBOSE
408 printf("Grab an element from the pool\n");
409 #endif
410 elem = list->pool;
411 list->pool = list->pool->next;
412 }
413 else
414 {
415 #if CUSTOM_MATCH_DEBUG_VERBOSE
416 printf("Make a new element\n");
417 #endif
418 elem = malloc(sizeof(custom_match_umq_node));
419 }
420 elem->next = 0;
421 if(list->tail)
422 {
423 #if CUSTOM_MATCH_DEBUG_VERBOSE
424 printf("Append to list of elems\n");
425 #endif
426 list->tail->next = elem;
427 list->tail = elem;
428 }
429 else
430 {
431 #if CUSTOM_MATCH_DEBUG_VERBOSE
432 printf("New Elem is only Elem\n");
433 #endif
434 list->head = elem;
435 list->tail = elem;
436 }
437
438 elem = list->tail;
439 elem->tag = tag;
440 elem->src = source;
441 elem->value = payload;
442 #if CUSTOM_MATCH_DEBUG_VERBOSE
443 custom_match_umq_dump(list);
444 #endif
445 }
446
447 static inline custom_match_umq* custom_match_umq_init()
448 {
449 #if CUSTOM_MATCH_DEBUG_VERBOSE
450 printf("custom_match_umq_init\n");
451 #endif
452 custom_match_umq* list = malloc(sizeof(custom_match_umq));
453 list->head = 0;
454 list->tail = 0;
455 list->pool = 0;
456 list->size = 0;
457 return list;
458 }
459
460 static inline void custom_match_umq_destroy(custom_match_umq* list)
461 {
462 #if CUSTOM_MATCH_DEBUG_VERBOSE
463 printf("custom_match_umq_destroy\n");
464 #endif
465 custom_match_umq_node* elem;
466 int i = 0;
467 int j = 0;
468 while(list->head)
469 {
470 elem = list->head;
471 list->head = list->head->next;
472 free(elem);
473 i++;
474 }
475 while(list->pool)
476 {
477 elem = list->pool;
478 list->pool = list->pool->next;
479 free(elem);
480 j++;
481 }
482 free(list);
483 #if CUSTOM_MATCH_DEBUG_VERBOSE
484 printf("Number of umq elements destroyed = %d %d\n", i, j);
485 #endif
486 }
487
488 static inline int custom_match_umq_size(custom_match_umq* list)
489 {
490 return list->size;
491 }
492
493 static inline void custom_match_umq_dump(custom_match_umq* list)
494 {
495 char cpeer[64], ctag[64];
496
497 custom_match_umq_node* elem;
498 int i = 0;
499 int j = 0;
500 printf("Elements in the list:\n");
501 for(elem = list->head; elem; elem = elem->next)
502 {
503 printf("This is the %d linked list element\n", ++i);
504 if(elem->value)
505 {
506 mca_pml_ob1_recv_frag_t *req = (mca_pml_ob1_recv_frag_t *)elem->value;
507 printf("%x %x %x\n", elem->value, req->hdr.hdr_match.hdr_tag, req->hdr.hdr_match.hdr_src);
508 if( OMPI_ANY_SOURCE == req->hdr.hdr_match.hdr_src ) snprintf(cpeer, 64, "%s", "ANY_SOURCE");
509 else snprintf(cpeer, 64, "%d", req->hdr.hdr_match.hdr_src);
510 if( OMPI_ANY_TAG == req->hdr.hdr_match.hdr_tag ) snprintf(ctag, 64, "%s", "ANY_TAG");
511 else snprintf(ctag, 64, "%d", req->hdr.hdr_match.hdr_tag);
512
513
514
515
516
517
518
519
520
521
522 }
523 }
524 }
525
526 #endif