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