-
Notifications
You must be signed in to change notification settings - Fork 0
/
impl-commgroup-functions.c
990 lines (886 loc) · 35.7 KB
/
impl-commgroup-functions.c
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
// SPDX-License-Identifier: MIT
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#define OMPI_WANT_MPI_INTERFACE_WARNING 0
#include <mpi.h>
#include "muk-predefined.h"
#include "impl-scalar-types.h"
#include "wrap-handle-typedefs.h"
#define MUK_EXTERN extern
#include "impl-fpointers.h"
#include "impl-constant-conversions.h"
#include "impl-handle-conversions.h"
#include "impl-predefined-handle.h"
#include "impl-keyval-map.h"
extern int COMM_EH_HANDLE_KEY;
// WRAP->IMPL functions
// used by WRAP_Comm_create_errhandler
void comm_errhandler_trampoline(MPI_Comm *comm, int *errorcode, ...)
{
int rc;
int flag;
WRAP_Comm_errhandler_function * fp = NULL;
rc = IMPL_Comm_get_attr(*comm, COMM_EH_HANDLE_KEY, &fp, &flag);
if (rc != MPI_SUCCESS || !flag) {
printf("%s: IMPL_Comm_get_attr failed: flag=%d rc=%d\n", __func__, flag, rc);
}
WRAP_Comm wrap_comm = OUTPUT_MPI_Comm(*comm);
(*fp)(&wrap_comm,errorcode);
}
// used by WRAP_Comm_create_keyval
int copy_attr_trampoline(MPI_Comm impl_comm, int comm_keyval, void *extra_state, void *attribute_val_in, void *attribute_val_out, int *flag)
{
WRAP_Comm_copy_attr_function * comm_copy_attr_fn;
int rc = find_comm_keyval_callbacks(comm_keyval, &comm_copy_attr_fn, NULL);
if (rc==0) {
printf("%s: find_comm_keyval_callbacks failed for comm_keyval=%d\n",__func__,comm_keyval);
return MPI_ERR_INTERN;
}
if ((intptr_t)comm_copy_attr_fn == (intptr_t)MPI_COMM_NULL_COPY_FN) {
#ifdef DEBUG
printf("%s: find_comm_keyval_callbacks found MPI_COMM_NULL_COPY_FN for comm_keyval=%d\n",__func__,comm_keyval);
#endif
*flag = 0;
return MPI_SUCCESS;
}
else if ((intptr_t)comm_copy_attr_fn == (intptr_t)MPI_COMM_DUP_FN) {
#ifdef DEBUG
printf("%s: find_comm_keyval_callbacks found MPI_COMM_DUP_FN for comm_keyval=%d\n",__func__,comm_keyval);
#endif
*(void**)attribute_val_out = attribute_val_in;
*flag = 1;
return MPI_SUCCESS;
}
else {
#ifdef DEBUG
printf("%s: find_comm_keyval_callbacks found comm_copy_attr_fn=%p for comm_keyval=%d\n",
__func__,comm_copy_attr_fn,comm_keyval);
#endif
WRAP_Comm wrap_comm = OUTPUT_MPI_Comm(impl_comm);
rc = (*comm_copy_attr_fn)(wrap_comm, comm_keyval, extra_state, attribute_val_in, attribute_val_out, flag);
return RETURN_CODE_MUK_TO_IMPL(rc);
}
}
int delete_attr_trampoline(MPI_Comm impl_comm, int comm_keyval, void *attribute_val, void *extra_state)
{
WRAP_Comm_delete_attr_function * comm_delete_attr_fn;
int rc = find_comm_keyval_callbacks(comm_keyval, NULL, &comm_delete_attr_fn);
if (rc==0) {
printf("%s: find_comm_keyval_callbacks failed for comm_keyval=%d\n",__func__,comm_keyval);
return MPI_ERR_INTERN;
}
if ((intptr_t)comm_delete_attr_fn == (intptr_t)MPI_COMM_NULL_DELETE_FN) {
#ifdef DEBUG
printf("%s: find_comm_keyval_callbacks found MPI_COMM_NULL_DELETE_FN for comm_keyval=%d\n",__func__,comm_keyval);
#endif
return MPI_SUCCESS;
}
else {
#ifdef DEBUG
printf("%s: find_comm_keyval_callbacks found comm_copy_attr_fn=%p for comm_keyval=%d\n",
__func__,comm_copy_attr_fn,comm_keyval);
#endif
WRAP_Comm wrap_comm = OUTPUT_MPI_Comm(impl_comm);
rc = (*comm_delete_attr_fn)(wrap_comm, comm_keyval, attribute_val, extra_state);
return RETURN_CODE_MUK_TO_IMPL(rc);
}
}
int WRAP_Comm_create_errhandler(WRAP_Comm_errhandler_function *comm_errhandler_fn, WRAP_Errhandler *errhandler)
{
MPI_Errhandler impl_errhandler;
//int rc = IMPL_Comm_create_errhandler(comm_errhandler_fn, &impl_errhandler);
int rc = IMPL_Comm_create_errhandler(comm_errhandler_trampoline, &impl_errhandler);
*errhandler = OUTPUT_MPI_Errhandler(impl_errhandler);
add_comm_errhandler_callback(impl_errhandler, comm_errhandler_fn);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_set_errhandler(WRAP_Comm comm, WRAP_Errhandler errhandler)
{
int rc;
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Errhandler impl_errhandler = CONVERT_MPI_Errhandler(errhandler);
rc = IMPL_Comm_set_errhandler(impl_comm, impl_errhandler);
if (!IS_PREDEFINED_ERRHANDLER(impl_errhandler))
{
WRAP_Comm_errhandler_function * comm_errhandler_fn;
if (find_comm_errhandler_callback(impl_errhandler, &comm_errhandler_fn)) {
rc = IMPL_Comm_set_attr(impl_comm, COMM_EH_HANDLE_KEY, comm_errhandler_fn);
if (rc) {
printf("%s: Comm_set_attr failed\n",__func__);
goto end;
}
}
else {
printf("%s: lookup_comm_err_pair failed to find a callback for errhandler=%lx\n",
__func__, (intptr_t)impl_errhandler);
}
}
end:
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_get_errhandler(WRAP_Comm comm, WRAP_Errhandler *errhandler)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Errhandler impl_errhandler;
int rc = IMPL_Comm_get_errhandler(impl_comm, &impl_errhandler);
*errhandler = OUTPUT_MPI_Errhandler(impl_errhandler);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_call_errhandler(WRAP_Comm comm, int errorcode)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Comm_call_errhandler(impl_comm, errorcode);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if 0
// obsolete versions
// we just map the outer MPI symbols to the new API in libinit.c so we can ignore these.
int WRAP_Errhandler_create(WRAP_Comm_errhandler_function *comm_errhandler_fn, WRAP_Errhandler *errhandler)
{
MPI_Errhandler impl_errhandler;
//int rc = IMPL_Errhandler_create(comm_errhandler_fn, &impl_errhandler);
int rc = IMPL_Errhandler_create(comm_errhandler_trampoline, &impl_errhandler);
*errhandler = OUTPUT_MPI_Errhandler(impl_errhandler);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Errhandler_set(WRAP_Comm comm, WRAP_Errhandler errhandler)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Errhandler impl_errhandler = CONVERT_MPI_Errhandler(errhandler);
int rc = IMPL_Errhandler_set(impl_comm, impl_errhandler);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Errhandler_get(WRAP_Comm comm, WRAP_Errhandler *errhandler)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Errhandler impl_errhandler;
int rc = IMPL_Errhandler_get(impl_comm, &impl_errhandler);
*errhandler = OUTPUT_MPI_Errhandler(impl_errhandler);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
// regular functionality
int WRAP_Comm_create_from_group(WRAP_Group group, const char *stringtag, WRAP_Info info, WRAP_Errhandler errhandler, WRAP_Comm *newcomm)
{
MPI_Group impl_group = CONVERT_MPI_Group(group);
MPI_Info impl_info = CONVERT_MPI_Info(info);
MPI_Errhandler impl_errhandler = CONVERT_MPI_Errhandler(errhandler);
MPI_Comm impl_newcomm;
int rc = IMPL_Comm_create_from_group(impl_group, stringtag, impl_info, impl_errhandler, &impl_newcomm);
*newcomm = OUTPUT_MPI_Comm(impl_newcomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_create_group(WRAP_Comm comm, WRAP_Group group, int tag, WRAP_Comm *newcomm)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Group impl_group = CONVERT_MPI_Group(group);
MPI_Comm impl_newcomm;
int rc = IMPL_Comm_create_group(impl_comm, impl_group, tag, &impl_newcomm);
*newcomm = OUTPUT_MPI_Comm(impl_newcomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Cart_coords(WRAP_Comm comm, int rank, int maxdims, int coords[])
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Cart_coords(impl_comm, rank, maxdims, coords);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Cart_create(WRAP_Comm comm_old, int ndims, const int dims[], const int periods[], int reorder, WRAP_Comm *comm_cart)
{
MPI_Comm impl_comm_old = CONVERT_MPI_Comm(comm_old);
MPI_Comm impl_comm_cart;
int rc = IMPL_Cart_create(impl_comm_old, ndims, dims, periods, reorder, &impl_comm_cart);
*comm_cart = OUTPUT_MPI_Comm(impl_comm_cart);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Cart_get(WRAP_Comm comm, int maxdims, int dims[], int periods[], int coords[])
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Cart_get(impl_comm, maxdims, dims, periods, coords);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Cart_map(WRAP_Comm comm, int ndims, const int dims[], const int periods[], int *newrank)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Cart_map(impl_comm, ndims, dims, periods, newrank);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Cart_rank(WRAP_Comm comm, const int coords[], int *rank)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Cart_rank(impl_comm, coords, rank);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Cart_shift(WRAP_Comm comm, int direction, int disp, int *rank_source, int *rank_dest)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int impl_rank_source, impl_rank_dest;
int rc = IMPL_Cart_shift(impl_comm, direction, disp, &impl_rank_source, &impl_rank_dest);
*rank_source = RANK_MUK_TO_IMPL(impl_rank_source);
*rank_dest = RANK_MUK_TO_IMPL(impl_rank_dest);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Cart_sub(WRAP_Comm comm, const int remain_dims[], WRAP_Comm *newcomm)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Comm impl_newcomm;
int rc = IMPL_Cart_sub(impl_comm, remain_dims, &impl_newcomm);
*newcomm = OUTPUT_MPI_Comm(impl_newcomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Cartdim_get(WRAP_Comm comm, int *ndims)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Cartdim_get(impl_comm, ndims);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_accept(const char *port_name, WRAP_Info info, int root, WRAP_Comm comm, WRAP_Comm *newcomm)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Info impl_info = CONVERT_MPI_Info(info);
MPI_Comm impl_newcomm;
int rc = IMPL_Comm_accept(port_name, impl_info, RANK_MUK_TO_IMPL(root), impl_comm, &impl_newcomm);
*newcomm = OUTPUT_MPI_Comm(impl_newcomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_compare(WRAP_Comm comm1, WRAP_Comm comm2, int *result)
{
MPI_Comm impl_comm1 = CONVERT_MPI_Comm(comm1);
MPI_Comm impl_comm2 = CONVERT_MPI_Comm(comm2);
int rc = IMPL_Comm_compare(impl_comm1, impl_comm2, result);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_connect(const char *port_name, WRAP_Info info, int root, WRAP_Comm comm, WRAP_Comm *newcomm)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Info impl_info = CONVERT_MPI_Info(info);
MPI_Comm impl_newcomm;
int rc = IMPL_Comm_connect(port_name, impl_info, RANK_MUK_TO_IMPL(root), impl_comm, &impl_newcomm);
*newcomm = OUTPUT_MPI_Comm(impl_newcomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_create(WRAP_Comm comm, WRAP_Group group, WRAP_Comm *newcomm)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Group impl_group = CONVERT_MPI_Group(group);
MPI_Comm impl_newcomm;
int rc = IMPL_Comm_create(impl_comm, impl_group, &impl_newcomm);
*newcomm = OUTPUT_MPI_Comm(impl_newcomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_create_keyval(WRAP_Comm_copy_attr_function *comm_copy_attr_fn, WRAP_Comm_delete_attr_function *comm_delete_attr_fn, int *comm_keyval, void *extra_state)
{
bool needs_trampoline = false;
MPI_Comm_copy_attr_function * impl_comm_copy_attr_fn;
if ((intptr_t)comm_copy_attr_fn == (intptr_t)MUK_COMM_NULL_COPY_FN) {
impl_comm_copy_attr_fn = MPI_COMM_NULL_COPY_FN;
}
else if ((intptr_t)comm_copy_attr_fn == (intptr_t)MUK_COMM_DUP_FN) {
impl_comm_copy_attr_fn = MPI_COMM_DUP_FN;
}
else {
needs_trampoline = true;
impl_comm_copy_attr_fn = copy_attr_trampoline;
}
MPI_Comm_delete_attr_function * impl_comm_delete_attr_fn;
if ((intptr_t)comm_delete_attr_fn == (intptr_t)MUK_COMM_NULL_DELETE_FN) {
impl_comm_delete_attr_fn = MPI_COMM_NULL_DELETE_FN;
}
else {
needs_trampoline = true;
impl_comm_delete_attr_fn = delete_attr_trampoline;
}
int rc = IMPL_Comm_create_keyval(impl_comm_copy_attr_fn, impl_comm_delete_attr_fn, comm_keyval, extra_state);
if (rc) goto end;
if (needs_trampoline) {
int rc = add_comm_keyval_callbacks(*comm_keyval, comm_copy_attr_fn, comm_delete_attr_fn);
if (rc==0) rc = MPI_ERR_INTERN;
}
end:
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_delete_attr(WRAP_Comm comm, int comm_keyval)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Comm_delete_attr(impl_comm, comm_keyval);
if (rc) goto end;
rc = remove_comm_keyval_callbacks(comm_keyval);
if (rc==0) rc = MPI_ERR_INTERN;
end:
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_free_keyval(int *comm_keyval)
{
int rc = IMPL_Comm_free_keyval(comm_keyval);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_get_attr(WRAP_Comm comm, int comm_keyval, void *attribute_val, int *flag)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Comm_get_attr(impl_comm, KEY_MUK_TO_IMPL(comm_keyval), attribute_val, flag);
// MPI_TAG_UB and MPI_WTIME_IS_GLOBAL should not require conversion
if (comm_keyval == MUK_HOST) {
**(int**)attribute_val = RANK_IMPL_TO_MUK(**(int**)attribute_val);
}
if (comm_keyval == MUK_IO) {
**(int**)attribute_val = RANK_IMPL_TO_MUK(**(int**)attribute_val);
}
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_set_attr(WRAP_Comm comm, int comm_keyval, void *attribute_val)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Comm_set_attr(impl_comm, comm_keyval, attribute_val);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if 0
// deleted versions of the above
int WRAP_Keyval_create(WRAP_Copy_function *copy_fn, WRAP_Delete_function *delete_fn, int *keyval, void *extra_state)
{
MPI_Copy_function * impl_copy_fn = (MPI_Copy_function*)copy_fn;
if ((intptr_t)copy_fn == (intptr_t)MUK_NULL_COPY_FN) {
impl_copy_fn = MPI_NULL_COPY_FN;
} else {
printf("%s : %d FIXME\n",__func__,__LINE__);
}
MPI_Delete_function * impl_delete_fn = (MPI_Delete_function*)delete_fn;
if ((intptr_t)delete_fn == (intptr_t)MUK_NULL_DELETE_FN) {
impl_delete_fn = MPI_NULL_DELETE_FN;
} else {
printf("%s : %d FIXME\n",__func__,__LINE__);
}
int rc = IMPL_Keyval_create(impl_copy_fn, impl_delete_fn, keyval, extra_state);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Keyval_free(int *keyval)
{
int rc = IMPL_Keyval_free(keyval);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Attr_delete(WRAP_Comm comm, int keyval)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Attr_delete(impl_comm, keyval);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Attr_get(WRAP_Comm comm, int keyval, void *attribute_val, int *flag)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Attr_get(impl_comm, KEY_MUK_TO_IMPL(keyval), attribute_val, flag);
if (keyval == MUK_HOST) {
**(int**)attribute_val = RANK_IMPL_TO_MUK(**(int**)attribute_val);
}
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Attr_put(WRAP_Comm comm, int keyval, void *attribute_val)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Attr_put(impl_comm, keyval, attribute_val);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_free(WRAP_Comm *comm)
{
int rc;
MPI_Comm impl_comm = CONVERT_MPI_Comm(*comm);
rc = IMPL_Comm_free(&impl_comm);
*comm = OUTPUT_MPI_Comm(impl_comm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_disconnect(WRAP_Comm *comm)
{
int rc;
MPI_Comm impl_comm = CONVERT_MPI_Comm(*comm);
rc = IMPL_Comm_disconnect(&impl_comm);
*comm = OUTPUT_MPI_Comm(impl_comm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_dup(WRAP_Comm comm, WRAP_Comm *newcomm)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Comm impl_newcomm;
int rc = IMPL_Comm_dup(impl_comm, &impl_newcomm);
*newcomm = OUTPUT_MPI_Comm(impl_newcomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_dup_with_info(WRAP_Comm comm, WRAP_Info info, WRAP_Comm *newcomm)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Info impl_info = CONVERT_MPI_Info(info);
MPI_Comm impl_newcomm;
int rc = IMPL_Comm_dup_with_info(impl_comm, impl_info, &impl_newcomm);
*newcomm = OUTPUT_MPI_Comm(impl_newcomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_get_info(WRAP_Comm comm, WRAP_Info *info_used)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Info impl_info_used;
int rc = IMPL_Comm_get_info(impl_comm, &impl_info_used);
*info_used = OUTPUT_MPI_Info(impl_info_used);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_get_name(WRAP_Comm comm, char *comm_name, int *resultlen)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Comm_get_name(impl_comm, comm_name, resultlen);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_get_parent(WRAP_Comm *parent)
{
MPI_Comm impl_parent;
int rc = IMPL_Comm_get_parent(&impl_parent);
*parent = OUTPUT_MPI_Comm(impl_parent);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_group(WRAP_Comm comm, WRAP_Group *group)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Group impl_group;
int rc = IMPL_Comm_group(impl_comm, &impl_group);
*group = OUTPUT_MPI_Group(impl_group);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_idup(WRAP_Comm comm, WRAP_Comm *newcomm, WRAP_Request *request)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Comm impl_newcomm;
MPI_Request impl_request;
int rc = IMPL_Comm_idup(impl_comm, &impl_newcomm, &impl_request);
*request = OUTPUT_MPI_Request(impl_request);
*newcomm = OUTPUT_MPI_Comm(impl_newcomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_idup_with_info(WRAP_Comm comm, WRAP_Info info, WRAP_Comm *newcomm, WRAP_Request *request)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Info impl_info = CONVERT_MPI_Info(info);
MPI_Request impl_request;
MPI_Comm impl_newcomm;
int rc = IMPL_Comm_idup_with_info(impl_comm, impl_info, &impl_newcomm, &impl_request);
*request = OUTPUT_MPI_Request(impl_request);
*newcomm = OUTPUT_MPI_Comm(impl_newcomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_join(int fd, WRAP_Comm *intercomm)
{
MPI_Comm impl_intercomm;
int rc = IMPL_Comm_join(fd, &impl_intercomm);
*intercomm = OUTPUT_MPI_Comm(impl_intercomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_rank(WRAP_Comm comm, int *rank)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Comm_rank(impl_comm, rank);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_remote_group(WRAP_Comm comm, WRAP_Group *group)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Group impl_group;
int rc = IMPL_Comm_remote_group(impl_comm, &impl_group);
*group = OUTPUT_MPI_Group(impl_group);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_remote_size(WRAP_Comm comm, int *size)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Comm_remote_size(impl_comm, size);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_set_info(WRAP_Comm comm, WRAP_Info info)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Info impl_info = CONVERT_MPI_Info(info);
int rc = IMPL_Comm_set_info(impl_comm, impl_info);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_set_name(WRAP_Comm comm, const char *comm_name)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Comm_set_name(impl_comm, comm_name);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_size(WRAP_Comm comm, int *size)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Comm_size(impl_comm, size);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_split(WRAP_Comm comm, int color, int key, WRAP_Comm *newcomm)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Comm impl_newcomm;
int rc = IMPL_Comm_split(impl_comm, color, key, &impl_newcomm);
*newcomm = OUTPUT_MPI_Comm(impl_newcomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_split_type(WRAP_Comm comm, int split_type, int key, WRAP_Info info, WRAP_Comm *newcomm)
{
// this is the only place this conversion is required, so just inline it
int impl_type = MPI_UNDEFINED;
if (split_type == MUK_COMM_TYPE_SHARED) {
impl_type = MPI_COMM_TYPE_SHARED;
}
#if MPI_VERSION >= 4
else if (split_type == MUK_COMM_TYPE_HW_UNGUIDED) {
impl_type = MPI_COMM_TYPE_HW_UNGUIDED;
}
else if (split_type == MUK_COMM_TYPE_HW_GUIDED) {
impl_type = MPI_COMM_TYPE_HW_GUIDED;
}
#endif
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Info impl_info = CONVERT_MPI_Info(info);
MPI_Comm impl_newcomm;
int rc = IMPL_Comm_split_type(impl_comm, impl_type, key, impl_info, &impl_newcomm);
*newcomm = OUTPUT_MPI_Comm(impl_newcomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_test_inter(WRAP_Comm comm, int *flag)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Comm_test_inter(impl_comm, flag);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Dims_create(int nnodes, int ndims, int dims[])
{
int rc = IMPL_Dims_create(nnodes, ndims, dims);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Dist_graph_create(WRAP_Comm comm_old, int n, const int sources[], const int degrees[], const int destinations[], const int weights[], WRAP_Info info, int reorder, WRAP_Comm *comm_dist_graph, const int * mpich_unweighted, const int * mpich_weights_empty)
{
MPI_Comm impl_comm_old = CONVERT_MPI_Comm(comm_old);
MPI_Info impl_info = CONVERT_MPI_Info(info);
MPI_Comm impl_comm_dist_graph;
const int * impl_weights = WEIGHTS_MUK_TO_IMPL(weights, mpich_unweighted, mpich_weights_empty);
int rc = IMPL_Dist_graph_create(impl_comm_old, n, sources, degrees, destinations, impl_weights, impl_info, reorder, &impl_comm_dist_graph);
*comm_dist_graph = OUTPUT_MPI_Comm(impl_comm_dist_graph);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Dist_graph_create_adjacent(WRAP_Comm comm_old, int indegree, const int sources[], const int sourceweights[], int outdegree, const int destinations[], const int destweights[], WRAP_Info info, int reorder, WRAP_Comm *comm_dist_graph, const int * mpich_unweighted, const int * mpich_weights_empty)
{
MPI_Comm impl_comm_old = CONVERT_MPI_Comm(comm_old);
MPI_Info impl_info = CONVERT_MPI_Info(info);
MPI_Comm impl_comm_dist_graph;
const int * impl_sourceweights = WEIGHTS_MUK_TO_IMPL(sourceweights, mpich_unweighted, mpich_weights_empty);
const int * impl_destweights = WEIGHTS_MUK_TO_IMPL(destweights, mpich_unweighted, mpich_weights_empty);
int rc = IMPL_Dist_graph_create_adjacent(impl_comm_old, indegree, sources, impl_sourceweights, outdegree, destinations, impl_destweights, impl_info, reorder, &impl_comm_dist_graph);
*comm_dist_graph = OUTPUT_MPI_Comm(impl_comm_dist_graph);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Dist_graph_neighbors(WRAP_Comm comm, int maxindegree, int sources[], int sourceweights[], int maxoutdegree, int destinations[], int destweights[])
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Dist_graph_neighbors(impl_comm, maxindegree, sources, sourceweights, maxoutdegree, destinations, destweights);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Dist_graph_neighbors_count(WRAP_Comm comm, int *indegree, int *outdegree, int *weighted)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Dist_graph_neighbors_count(impl_comm, indegree, outdegree, weighted);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Graph_create(WRAP_Comm comm_old, int nnodes, const int indx[], const int edges[], int reorder, WRAP_Comm *comm_graph)
{
MPI_Comm impl_comm_old = CONVERT_MPI_Comm(comm_old);
MPI_Comm impl_comm_graph;
int rc = IMPL_Graph_create(impl_comm_old, nnodes, indx, edges, reorder, &impl_comm_graph);
*comm_graph = OUTPUT_MPI_Comm(impl_comm_graph);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Graph_get(WRAP_Comm comm, int maxindex, int maxedges, int indx[], int edges[])
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Graph_get(impl_comm, maxindex, maxedges, indx, edges);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Graph_map(WRAP_Comm comm, int nnodes, const int indx[], const int edges[], int *newrank)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int impl_newrank;
int rc = IMPL_Graph_map(impl_comm, nnodes, indx, edges, &impl_newrank);
if (impl_newrank == MPI_UNDEFINED) {
*newrank = MUK_UNDEFINED;
} else {
*newrank = impl_newrank;
}
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Graph_neighbors(WRAP_Comm comm, int rank, int maxneighbors, int neighbors[])
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Graph_neighbors(impl_comm, rank, maxneighbors, neighbors);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Graph_neighbors_count(WRAP_Comm comm, int rank, int *nneighbors)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Graph_neighbors_count(impl_comm, rank, nneighbors);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Graphdims_get(WRAP_Comm comm, int *nnodes, int *nedges)
{
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int rc = IMPL_Graphdims_get(impl_comm, nnodes, nedges);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Group_compare(WRAP_Group group1, WRAP_Group group2, int *result)
{
MPI_Group impl_group1 = CONVERT_MPI_Group(group1);
MPI_Group impl_group2 = CONVERT_MPI_Group(group2);
int rc = IMPL_Group_compare(impl_group1, impl_group2, result);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Group_difference(WRAP_Group group1, WRAP_Group group2, WRAP_Group *newgroup)
{
MPI_Group impl_group1 = CONVERT_MPI_Group(group1);
MPI_Group impl_group2 = CONVERT_MPI_Group(group2);
MPI_Group impl_newgroup;
int rc = IMPL_Group_difference(impl_group1, impl_group2, &impl_newgroup);
*newgroup = OUTPUT_MPI_Group(impl_newgroup);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Group_excl(WRAP_Group group, int n, const int ranks[], WRAP_Group *newgroup)
{
MPI_Group impl_group = CONVERT_MPI_Group(group);
MPI_Group impl_newgroup;
int rc = IMPL_Group_excl(impl_group, n, ranks, &impl_newgroup);
*newgroup = OUTPUT_MPI_Group(impl_newgroup);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Group_free(WRAP_Group *group)
{
MPI_Group impl_group = CONVERT_MPI_Group(*group);
int rc = IMPL_Group_free(&impl_group);
*group = OUTPUT_MPI_Group(impl_group);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Group_from_session_pset(WRAP_Session session, const char *pset_name, WRAP_Group *newgroup)
{
MPI_Session impl_session = CONVERT_MPI_Session(session);
MPI_Group impl_newgroup;
int rc = IMPL_Group_from_session_pset(impl_session, pset_name, &impl_newgroup);
*newgroup = OUTPUT_MPI_Group(impl_newgroup);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Group_incl(WRAP_Group group, int n, const int ranks[], WRAP_Group *newgroup)
{
MPI_Group impl_group = CONVERT_MPI_Group(group);
MPI_Group impl_newgroup;
int rc = IMPL_Group_incl(impl_group, n, ranks, &impl_newgroup);
*newgroup = OUTPUT_MPI_Group(impl_newgroup);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Group_intersection(WRAP_Group group1, WRAP_Group group2, WRAP_Group *newgroup)
{
MPI_Group impl_group1 = CONVERT_MPI_Group(group1);
MPI_Group impl_group2 = CONVERT_MPI_Group(group2);
MPI_Group impl_newgroup;
int rc = IMPL_Group_intersection(impl_group1, impl_group2, &impl_newgroup);
*newgroup = OUTPUT_MPI_Group(impl_newgroup);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Group_range_excl(WRAP_Group group, int n, int ranges[][3], WRAP_Group *newgroup)
{
MPI_Group impl_group = CONVERT_MPI_Group(group);
MPI_Group impl_newgroup;
int rc = IMPL_Group_range_excl(impl_group, n, ranges, &impl_newgroup);
*newgroup = OUTPUT_MPI_Group(impl_newgroup);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Group_range_incl(WRAP_Group group, int n, int ranges[][3], WRAP_Group *newgroup)
{
MPI_Group impl_group = CONVERT_MPI_Group(group);
MPI_Group impl_newgroup;
int rc = IMPL_Group_range_incl(impl_group, n, ranges, &impl_newgroup);
*newgroup = OUTPUT_MPI_Group(impl_newgroup);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Group_rank(WRAP_Group group, int *rank)
{
MPI_Group impl_group = CONVERT_MPI_Group(group);
int rc = IMPL_Group_rank(impl_group, rank);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Group_size(WRAP_Group group, int *size)
{
MPI_Group impl_group = CONVERT_MPI_Group(group);
int rc = IMPL_Group_size(impl_group, size);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Group_translate_ranks(WRAP_Group group1, int n, const int ranks1[], WRAP_Group group2, int ranks2[])
{
int rc;
// MPI_PROC_NULL is a valid rank for input to MPI_GROUP_TRANSLATE_RANKS,
// which returns MPI_PROC_NULL as the translated rank.
MPI_Group impl_group1 = CONVERT_MPI_Group(group1);
MPI_Group impl_group2 = CONVERT_MPI_Group(group2);
int * impl_ranks1 = calloc(n,sizeof(int));
if (impl_ranks1 == NULL) {
rc = MPI_ERR_INTERN;
goto end;
}
for (int i=0; i<n; i++) {
impl_ranks1[i] = RANK_MUK_TO_IMPL(ranks1[i]);
}
int * impl_ranks2 = calloc(n,sizeof(int));
if (impl_ranks2 == NULL) {
rc = MPI_ERR_INTERN;
goto end;
}
rc = IMPL_Group_translate_ranks(impl_group1, n, impl_ranks1, impl_group2, impl_ranks2);
for (int i=0; i<n; i++) {
ranks2[i] = RANK_IMPL_TO_MUK(impl_ranks2[i]);
}
free(impl_ranks1);
free(impl_ranks2);
end:
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Group_union(WRAP_Group group1, WRAP_Group group2, WRAP_Group *newgroup)
{
MPI_Group impl_group1 = CONVERT_MPI_Group(group1);
MPI_Group impl_group2 = CONVERT_MPI_Group(group2);
MPI_Group impl_newgroup;
int rc = IMPL_Group_union(impl_group1, impl_group2, &impl_newgroup);
*newgroup = OUTPUT_MPI_Group(impl_newgroup);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Intercomm_create(WRAP_Comm local_comm, int local_leader, WRAP_Comm peer_comm, int remote_leader, int tag, WRAP_Comm *newintercomm)
{
MPI_Comm impl_local_comm = CONVERT_MPI_Comm(local_comm);
MPI_Comm impl_peer_comm = CONVERT_MPI_Comm(peer_comm);
MPI_Comm impl_newintercomm;
int rc = IMPL_Intercomm_create(impl_local_comm, local_leader, impl_peer_comm, remote_leader, tag, &impl_newintercomm);
*newintercomm = OUTPUT_MPI_Comm(impl_newintercomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Intercomm_create_from_groups(WRAP_Group local_group, int local_leader, WRAP_Group remote_group, int remote_leader, const char *stringtag, WRAP_Info info, WRAP_Errhandler errhandler, WRAP_Comm *newintercomm)
{
MPI_Errhandler impl_errhandler = CONVERT_MPI_Errhandler(errhandler);
MPI_Group impl_local_group = CONVERT_MPI_Group(local_group);
MPI_Group impl_remote_group = CONVERT_MPI_Group(remote_group);
MPI_Info impl_info = CONVERT_MPI_Info(info);
MPI_Comm impl_newintercomm;
int rc = IMPL_Intercomm_create_from_groups(impl_local_group, local_leader, impl_remote_group, remote_leader, stringtag, impl_info, impl_errhandler, &impl_newintercomm);
*newintercomm = OUTPUT_MPI_Comm(impl_newintercomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Intercomm_merge(WRAP_Comm intercomm, int high, WRAP_Comm *newintracomm)
{
MPI_Comm impl_intercomm = CONVERT_MPI_Comm(intercomm);
MPI_Comm impl_newintracomm;
int rc = IMPL_Intercomm_merge(impl_intercomm, high, &impl_newintracomm);
*newintracomm = OUTPUT_MPI_Comm(impl_newintracomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Topo_test(WRAP_Comm comm, int *status)
{
// The output value status is one of the following:
// MPI_GRAPH MPI_CART MPI_DIST_GRAPH MPI_UNDEFINED
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
int impl_status;
int rc = IMPL_Topo_test(impl_comm, &impl_status);
// This is the only place we need this, so inline it.
if (impl_status == MPI_GRAPH) {
*status = MUK_GRAPH;
}
else if (impl_status == MPI_CART) {
*status = MUK_CART;
}
else if (impl_status == MPI_DIST_GRAPH) {
*status = MUK_DIST_GRAPH;
}
else if (impl_status == MPI_UNDEFINED) {
*status = MUK_UNDEFINED;
}
else {
printf("WRAP_Topo_test invalid status: %d\n", impl_status);
*status = MUK_UNDEFINED;
}
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Lookup_name(const char *service_name, WRAP_Info info, char *port_name)
{
MPI_Info impl_info = CONVERT_MPI_Info(info);
int rc = IMPL_Lookup_name(service_name, impl_info, port_name);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Publish_name(const char *service_name, WRAP_Info info, const char *port_name)
{
MPI_Info impl_info = CONVERT_MPI_Info(info);
int rc = IMPL_Publish_name(service_name, impl_info, port_name);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Unpublish_name(const char *service_name, WRAP_Info info, const char *port_name)
{
MPI_Info impl_info = CONVERT_MPI_Info(info);
int rc = IMPL_Unpublish_name(service_name, impl_info, port_name);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Open_port(WRAP_Info info, char *port_name)
{
MPI_Info impl_info = CONVERT_MPI_Info(info);
int rc = IMPL_Open_port(impl_info, port_name);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Close_port(const char *port_name)
{
int rc = IMPL_Close_port(port_name);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
// these are only used below so we leave them here
static inline bool IS_ARGV_NULL(char * argv[])
{
return ((intptr_t)argv == (intptr_t)MUK_ARGV_NULL);
}
static inline bool IS_ARGVS_NULL(char ** array_of_argv[])
{
return ((intptr_t)array_of_argv == (intptr_t)MUK_ARGVS_NULL);
}
static inline bool IS_ERRCODES_IGNORE(int * array_of_errcodes)
{
return ((intptr_t)array_of_errcodes == (intptr_t)MUK_ERRCODES_IGNORE);
}
int WRAP_Comm_spawn(const char *command, char *argv[], int maxprocs, WRAP_Info info, int root, WRAP_Comm comm, WRAP_Comm *intercomm, int * array_of_errcodes)
{
bool ignore_argv = IS_ARGV_NULL(argv);
bool ignore_errc = IS_ERRCODES_IGNORE(array_of_errcodes);
int rc;
MPI_Info impl_info = CONVERT_MPI_Info(info);
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Comm impl_intercomm;
rc = IMPL_Comm_spawn(command, ignore_argv ? MPI_ARGV_NULL : argv, maxprocs, impl_info, RANK_MUK_TO_IMPL(root), impl_comm, &impl_intercomm, ignore_errc ? MPI_ERRCODES_IGNORE : array_of_errcodes);
*intercomm = OUTPUT_MPI_Comm(impl_intercomm);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Comm_spawn_multiple(int count, char *array_of_commands[], char **array_of_argv[], const int array_of_maxprocs[], const WRAP_Info array_of_info[], int root, WRAP_Comm comm, WRAP_Comm *intercomm, int * array_of_errcodes)
{
bool ignore_argv = IS_ARGVS_NULL(array_of_argv);
bool ignore_errc = IS_ERRCODES_IGNORE(array_of_errcodes);
int rc;
MPI_Info * impl_array_of_info = calloc(count, sizeof(MPI_Info));
if (impl_array_of_info == NULL) {
rc = MPI_ERR_INTERN;
goto end;
}
for (int i=0; i<count; i++) {
impl_array_of_info[i] = CONVERT_MPI_Info(array_of_info[i]);
}
MPI_Comm impl_comm = CONVERT_MPI_Comm(comm);
MPI_Comm impl_intercomm;
rc = IMPL_Comm_spawn_multiple(count, array_of_commands, ignore_argv ? MPI_ARGVS_NULL : array_of_argv, array_of_maxprocs, impl_array_of_info, RANK_MUK_TO_IMPL(root), impl_comm, &impl_intercomm, ignore_errc ? MPI_ERRCODES_IGNORE : array_of_errcodes);
*intercomm = OUTPUT_MPI_Comm(impl_intercomm);
free(impl_array_of_info);
end:
return RETURN_CODE_IMPL_TO_MUK(rc);
}