-
Notifications
You must be signed in to change notification settings - Fork 0
/
impl-type-functions.c
694 lines (631 loc) · 27.6 KB
/
impl-type-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
// 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>
#include <mpi.h>
//#include "muk-dl.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-status.h"
#include "impl-constant-conversions.h"
#include "impl-handle-conversions.h"
//#include "impl-predefined-handle.h"
#include "impl-keyval-map.h"
// used by WRAP_Type_create_keyval
int type_copy_attr_trampoline(MPI_Datatype impl_type, int type_keyval, void *extra_state, void *attribute_val_in, void *attribute_val_out, int *flag)
{
WRAP_Type_copy_attr_function * type_copy_attr_fn;
int rc = find_type_keyval_callbacks(type_keyval, &type_copy_attr_fn, NULL);
if (rc==0) {
printf("%s: find_type_keyval_callbacks failed for type_keyval=%d\n",__func__,type_keyval);
return MPI_ERR_INTERN;
}
if ((intptr_t)type_copy_attr_fn == (intptr_t)MPI_TYPE_NULL_COPY_FN) {
#ifdef DEBUG
printf("%s: find_type_keyval_callbacks found MPI_TYPE_NULL_COPY_FN for type_keyval=%d\n",__func__,type_keyval);
#endif
*flag = 0;
return MPI_SUCCESS;
}
else if ((intptr_t)type_copy_attr_fn == (intptr_t)MPI_TYPE_DUP_FN) {
#ifdef DEBUG
printf("%s: find_type_keyval_callbacks found MPI_TYPE_DUP_FN for type_keyval=%d\n",__func__,type_keyval);
#endif
*(void**)attribute_val_out = attribute_val_in;
*flag = 1;
return MPI_SUCCESS;
}
else {
#ifdef DEBUG
printf("%s: find_type_keyval_callbacks found type_copy_attr_fn=%p for type_keyval=%d\n",
__func__,type_copy_attr_fn,type_keyval);
#endif
WRAP_Datatype wrap_type = OUTPUT_MPI_Datatype(impl_type);
rc = (*type_copy_attr_fn)(wrap_type, type_keyval, extra_state, attribute_val_in, attribute_val_out, flag);
return RETURN_CODE_MUK_TO_IMPL(rc);
}
}
int type_delete_attr_trampoline(MPI_Datatype impl_type, int type_keyval, void *attribute_val, void *extra_state)
{
WRAP_Type_delete_attr_function * type_delete_attr_fn;
int rc = find_type_keyval_callbacks(type_keyval, NULL, &type_delete_attr_fn);
if (rc==0) {
printf("%s: find_type_keyval_callbacks failed for type_keyval=%d\n",__func__,type_keyval);
return MPI_ERR_INTERN;
}
if ((intptr_t)type_delete_attr_fn == (intptr_t)MPI_TYPE_NULL_DELETE_FN) {
#ifdef DEBUG
printf("%s: find_type_keyval_callbacks found MPI_TYPE_NULL_DELETE_FN for type_keyval=%d\n",__func__,type_keyval);
#endif
return MPI_SUCCESS;
}
else {
#ifdef DEBUG
printf("%s: find_type_keyval_callbacks found type_copy_attr_fn=%p for type_keyval=%d\n",
__func__,type_copy_attr_fn,type_keyval);
#endif
WRAP_Datatype wrap_type = OUTPUT_MPI_Datatype(impl_type);
rc = (*type_delete_attr_fn)(wrap_type, type_keyval, attribute_val, extra_state);
return RETURN_CODE_MUK_TO_IMPL(rc);
}
}
int WRAP_Type_create_keyval(WRAP_Type_copy_attr_function *type_copy_attr_fn, WRAP_Type_delete_attr_function *type_delete_attr_fn, int *type_keyval, void *extra_state)
{
bool needs_trampoline = false;
MPI_Type_copy_attr_function * impl_type_copy_attr_fn;
if ((intptr_t)type_copy_attr_fn == (intptr_t)MUK_TYPE_NULL_COPY_FN) {
impl_type_copy_attr_fn = MPI_TYPE_NULL_COPY_FN;
}
else if ((intptr_t)type_copy_attr_fn == (intptr_t)MUK_TYPE_DUP_FN) {
impl_type_copy_attr_fn = MPI_TYPE_DUP_FN;
}
else {
needs_trampoline = true;
impl_type_copy_attr_fn = type_copy_attr_trampoline;
}
MPI_Type_delete_attr_function * impl_type_delete_attr_fn;
if ((intptr_t)type_delete_attr_fn == (intptr_t)MUK_TYPE_NULL_DELETE_FN) {
impl_type_delete_attr_fn = MPI_TYPE_NULL_DELETE_FN;
}
else {
needs_trampoline = true;
impl_type_delete_attr_fn = type_delete_attr_trampoline;
}
int rc = IMPL_Type_create_keyval(impl_type_copy_attr_fn, impl_type_delete_attr_fn, type_keyval, extra_state);
if (rc) goto end;
if (needs_trampoline) {
int rc = add_type_keyval_callbacks(*type_keyval, type_copy_attr_fn, type_delete_attr_fn);
if (rc==0) rc = MPI_ERR_INTERN;
}
end:
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_free_keyval(int *type_keyval)
{
int rc = IMPL_Type_free_keyval(type_keyval);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_commit(WRAP_Datatype *datatype)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(*datatype);
int rc = IMPL_Type_commit(&impl_datatype);
*datatype = OUTPUT_MPI_Datatype(impl_datatype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_contiguous(int count, WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_contiguous(count, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_contiguous_c(WRAP_Count count, WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_contiguous_c(count, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Type_create_darray(int size, int rank, int ndims, const int array_of_gsizes[], const int array_of_distribs[], const int array_of_dargs[], const int array_of_psizes[], int order, WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
int rc;
int * impl_array_of_distribs = calloc(ndims,sizeof(int));
if (impl_array_of_distribs == NULL) {
rc = MPI_ERR_INTERN;
goto end;
}
int * impl_array_of_dargs = calloc(ndims,sizeof(int));
if (impl_array_of_dargs == NULL) {
rc = MPI_ERR_INTERN;
goto end;
}
for (int d=0; d<ndims; d++)
{
int dist = array_of_distribs[d];
if (dist == MUK_DISTRIBUTE_BLOCK) {
impl_array_of_distribs[d] = MPI_DISTRIBUTE_BLOCK;
}
else if (dist == MUK_DISTRIBUTE_CYCLIC) {
impl_array_of_distribs[d] = MPI_DISTRIBUTE_CYCLIC;
}
else if (dist == MUK_DISTRIBUTE_NONE) {
impl_array_of_distribs[d] = MPI_DISTRIBUTE_NONE;
}
else {
impl_array_of_distribs[d] = MPI_UNDEFINED;
}
int darg = array_of_dargs[d];
if (darg == MUK_DISTRIBUTE_DFLT_DARG) {
impl_array_of_dargs[d] = MPI_DISTRIBUTE_DFLT_DARG;
} else {
impl_array_of_dargs[d] = darg;
}
}
int impl_order = MPI_UNDEFINED;
if (order == MUK_ORDER_C) {
impl_order = MPI_ORDER_C;
}
else if (order == MUK_ORDER_FORTRAN) {
impl_order = MPI_ORDER_FORTRAN;
}
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
rc = IMPL_Type_create_darray(size, rank, ndims, array_of_gsizes, impl_array_of_distribs, impl_array_of_dargs, array_of_psizes, impl_order, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
free(impl_array_of_distribs);
free(impl_array_of_dargs);
end:
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_create_darray_c(int size, int rank, int ndims, const WRAP_Count array_of_gsizes[], const int array_of_distribs[], const int array_of_dargs[], const int array_of_psizes[], int order, WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
int impl_order = MPI_UNDEFINED;
if (order == MUK_ORDER_C) {
impl_order = MPI_ORDER_C;
}
else if (order == MUK_ORDER_FORTRAN) {
impl_order = MPI_ORDER_FORTRAN;
}
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_darray_c(size, rank, ndims, array_of_gsizes, array_of_distribs, array_of_dargs, array_of_psizes, impl_order, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_create_f90_complex(int p, int r, WRAP_Datatype *newtype)
{
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_f90_complex(p, r, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_create_f90_integer(int r, WRAP_Datatype *newtype)
{
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_f90_integer(r, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_create_f90_real(int p, int r, WRAP_Datatype *newtype)
{
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_f90_real(p, r, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_create_hindexed(int count, const int array_of_blocklengths[], const WRAP_Aint array_of_displacements[], WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_hindexed(count, array_of_blocklengths, array_of_displacements, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_create_hindexed_block(int count, int blocklength, const WRAP_Aint array_of_displacements[], WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_hindexed_block(count, blocklength, array_of_displacements, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_create_hindexed_block_c(WRAP_Count count, WRAP_Count blocklength, const WRAP_Count array_of_displacements[], WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_hindexed_block_c(count, blocklength, array_of_displacements, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
#if MPI_VERSION >= 4
int WRAP_Type_create_hindexed_c(WRAP_Count count, const WRAP_Count array_of_blocklengths[], const WRAP_Count array_of_displacements[], WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_hindexed_c(count, array_of_blocklengths, array_of_displacements, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Type_create_hvector(int count, int blocklength, WRAP_Aint stride, WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_hvector(count, blocklength, stride, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_create_hvector_c(WRAP_Count count, WRAP_Count blocklength, WRAP_Count stride, WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_hvector_c(count, blocklength, stride, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Type_create_indexed_block(int count, int blocklength, const int array_of_displacements[], WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_indexed_block(count, blocklength, array_of_displacements, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_create_indexed_block_c(WRAP_Count count, WRAP_Count blocklength, const WRAP_Count array_of_displacements[], WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_indexed_block_c(count, blocklength, array_of_displacements, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Type_create_resized(WRAP_Datatype oldtype, WRAP_Aint lb, WRAP_Aint extent, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_resized(impl_oldtype, lb, extent, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_create_resized_c(WRAP_Datatype oldtype, WRAP_Count lb, WRAP_Count extent, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_resized_c(impl_oldtype, lb, extent, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Type_create_struct(int count, const int array_of_blocklengths[], const WRAP_Aint array_of_displacements[], const WRAP_Datatype array_of_types[], WRAP_Datatype *newtype)
{
MPI_Datatype * impl_array_of_types = calloc(count,sizeof(MPI_Datatype));
for (int i=0; i<count; i++) {
impl_array_of_types[i] = CONVERT_MPI_Datatype(array_of_types[i]);
}
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_struct(count, array_of_blocklengths, array_of_displacements, impl_array_of_types, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
free(impl_array_of_types);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_create_struct_c(WRAP_Count count, const WRAP_Count array_of_blocklengths[], const WRAP_Count array_of_displacements[], const WRAP_Datatype array_of_types[], WRAP_Datatype *newtype)
{
MPI_Datatype * impl_array_of_types = calloc(count,sizeof(MPI_Datatype));
for (MPI_Count i=0; i<count; i++) {
impl_array_of_types[i] = CONVERT_MPI_Datatype(array_of_types[i]);
}
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_struct_c(count, array_of_blocklengths, array_of_displacements, impl_array_of_types, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
free(impl_array_of_types);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Type_create_subarray(int ndims, const int array_of_sizes[], const int array_of_subsizes[], const int array_of_starts[], int order, WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
int impl_order = MPI_UNDEFINED;
if (order == MUK_ORDER_C) {
impl_order = MPI_ORDER_C;
}
else if (order == MUK_ORDER_FORTRAN) {
impl_order = MPI_ORDER_FORTRAN;
}
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_subarray(ndims, array_of_sizes, array_of_subsizes, array_of_starts, impl_order, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_create_subarray_c(int ndims, const WRAP_Count array_of_sizes[], const WRAP_Count array_of_subsizes[], const WRAP_Count array_of_starts[], int order, WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
int impl_order = MPI_UNDEFINED;
if (order == MUK_ORDER_C) {
impl_order = MPI_ORDER_C;
}
else if (order == MUK_ORDER_FORTRAN) {
impl_order = MPI_ORDER_FORTRAN;
}
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_create_subarray_c(ndims, array_of_sizes, array_of_subsizes, array_of_starts, impl_order, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_delete_attr(WRAP_Datatype datatype, int type_keyval)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_delete_attr(impl_datatype, type_keyval);
if (rc) goto end;
rc = remove_type_keyval_callbacks(type_keyval);
if (rc==0) rc = MPI_ERR_INTERN;
end:
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_dup(WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_dup(impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_extent(WRAP_Datatype datatype, WRAP_Aint *extent)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_extent(impl_datatype, extent);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_free(WRAP_Datatype *datatype)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(*datatype);
int rc = IMPL_Type_free(&impl_datatype);
*datatype = OUTPUT_MPI_Datatype(impl_datatype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_get_attr(WRAP_Datatype datatype, int type_keyval, void *attribute_val, int *flag)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_get_attr(impl_datatype, KEY_MUK_TO_IMPL(type_keyval), attribute_val, flag);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_get_contents(WRAP_Datatype datatype, int max_integers, int max_addresses, int max_datatypes, int array_of_integers[], WRAP_Aint array_of_addresses[], WRAP_Datatype array_of_datatypes[])
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
MPI_Datatype * impl_array_of_datatypes = calloc(max_datatypes,sizeof(MPI_Datatype));
int rc = IMPL_Type_get_contents(impl_datatype, max_integers, max_addresses, max_datatypes, array_of_integers, array_of_addresses, impl_array_of_datatypes);
for (int i=0; i<max_datatypes; i++) {
array_of_datatypes[i] = OUTPUT_MPI_Datatype(impl_array_of_datatypes[i]);
}
free(impl_array_of_datatypes);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_get_contents_c(WRAP_Datatype datatype, WRAP_Count max_integers, WRAP_Count max_addresses, WRAP_Count max_large_counts, WRAP_Count max_datatypes, int array_of_integers[], WRAP_Aint array_of_addresses[], WRAP_Count array_of_large_counts[], WRAP_Datatype array_of_datatypes[])
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
MPI_Datatype * impl_array_of_datatypes = calloc(max_datatypes,sizeof(MPI_Datatype));
int rc = IMPL_Type_get_contents_c(impl_datatype, max_integers, max_addresses, max_large_counts, max_datatypes, array_of_integers, array_of_addresses, array_of_large_counts, impl_array_of_datatypes);
for (int i=0; i<max_datatypes; i++) {
array_of_datatypes[i] = OUTPUT_MPI_Datatype(impl_array_of_datatypes[i]);
}
free(impl_array_of_datatypes);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Type_get_envelope(WRAP_Datatype datatype, int *num_integers, int *num_addresses, int *num_datatypes, int *combiner)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_get_envelope(impl_datatype, num_integers, num_addresses, num_datatypes, combiner);
*combiner = COMBINER_CODE_IMPL_TO_MUK(*combiner);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_get_envelope_c(WRAP_Datatype datatype, WRAP_Count *num_integers, WRAP_Count *num_addresses, WRAP_Count *num_large_counts, WRAP_Count *num_datatypes, int *combiner)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_get_envelope_c(impl_datatype, num_integers, num_addresses, num_large_counts, num_datatypes, combiner);
*combiner = COMBINER_CODE_IMPL_TO_MUK(*combiner);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Type_get_extent(WRAP_Datatype datatype, WRAP_Aint *lb, WRAP_Aint *extent)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_get_extent(impl_datatype, lb, extent);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_get_extent_c(WRAP_Datatype datatype, WRAP_Count *lb, WRAP_Count *extent)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_get_extent_c(impl_datatype, lb, extent);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Type_get_extent_x(WRAP_Datatype datatype, WRAP_Count *lb, WRAP_Count *extent)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_get_extent_x(impl_datatype, lb, extent);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_get_name(WRAP_Datatype datatype, char *type_name, int *resultlen)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
// MUK defines all the possible datatypes, without knowing if the implementation
// supports them, so we prevent crashes by doing this.
if (impl_datatype == MPI_DATATYPE_NULL) {
strcpy(type_name,"MPI_DATATYPE_NULL");
*resultlen = strlen("MPI_DATATYPE_NULL");
return MPI_ERR_TYPE;
}
int rc = IMPL_Type_get_name(impl_datatype, type_name, resultlen);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_get_true_extent(WRAP_Datatype datatype, WRAP_Aint *true_lb, WRAP_Aint *true_extent)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_get_true_extent(impl_datatype, true_lb, true_extent);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_get_true_extent_c(WRAP_Datatype datatype, WRAP_Count *true_lb, WRAP_Count *true_extent)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_get_true_extent_c(impl_datatype, true_lb, true_extent);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Type_get_true_extent_x(WRAP_Datatype datatype, WRAP_Count *true_lb, WRAP_Count *true_extent)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_get_true_extent_x(impl_datatype, true_lb, true_extent);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_hindexed(int count, int array_of_blocklengths[], WRAP_Aint array_of_displacements[], WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_hindexed(count, array_of_blocklengths, array_of_displacements, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_hvector(int count, int blocklength, WRAP_Aint stride, WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_hvector(count, blocklength, stride, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_indexed(int count, const int array_of_blocklengths[], const int array_of_displacements[], WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_indexed(count, array_of_blocklengths, array_of_displacements, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_indexed_c(WRAP_Count count, const WRAP_Count array_of_blocklengths[], const WRAP_Count array_of_displacements[], WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_indexed_c(count, array_of_blocklengths, array_of_displacements, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Type_lb(WRAP_Datatype datatype, WRAP_Aint *displacement)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_lb(impl_datatype, displacement);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_match_size(int typeclass, int size, WRAP_Datatype *datatype)
{
MPI_Datatype impl_datatype;
int impl_typeclass;
if (typeclass == MUK_TYPECLASS_INTEGER) {
impl_typeclass = MPI_TYPECLASS_INTEGER;
}
else if (typeclass == MUK_TYPECLASS_REAL) {
impl_typeclass = MPI_TYPECLASS_REAL;
}
else if (typeclass == MUK_TYPECLASS_COMPLEX) {
impl_typeclass = MPI_TYPECLASS_COMPLEX;
}
else {
printf("Unknown typeclass: %d\n", typeclass);
impl_typeclass = MPI_UNDEFINED;
}
int rc = IMPL_Type_match_size(impl_typeclass, size, &impl_datatype);
*datatype = OUTPUT_MPI_Datatype(impl_datatype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_set_attr(WRAP_Datatype datatype, int type_keyval, void *attribute_val)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_set_attr(impl_datatype, type_keyval, attribute_val);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_set_name(WRAP_Datatype datatype, const char *type_name)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_set_name(impl_datatype, type_name);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_size(WRAP_Datatype datatype, int *size)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_size(impl_datatype, size);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_size_c(WRAP_Datatype datatype, WRAP_Count *size)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_size_c(impl_datatype, size);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Type_size_x(WRAP_Datatype datatype, WRAP_Count *size)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_size_x(impl_datatype, size);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_struct(int count, int array_of_blocklengths[], WRAP_Aint array_of_displacements[], WRAP_Datatype array_of_types[], WRAP_Datatype *newtype)
{
MPI_Datatype * impl_array_of_types = calloc(count,sizeof(MPI_Datatype));
for (int i=0; i<count; i++) {
impl_array_of_types[i] = CONVERT_MPI_Datatype(array_of_types[i]);
}
MPI_Datatype impl_newtype;
int rc = IMPL_Type_struct(count, array_of_blocklengths, array_of_displacements, impl_array_of_types, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
free(impl_array_of_types);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_ub(WRAP_Datatype datatype, WRAP_Aint *displacement)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Type_ub(impl_datatype, displacement);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Type_vector(int count, int blocklength, int stride, WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_vector(count, blocklength, stride, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#if MPI_VERSION >= 4
int WRAP_Type_vector_c(WRAP_Count count, WRAP_Count blocklength, WRAP_Count stride, WRAP_Datatype oldtype, WRAP_Datatype *newtype)
{
MPI_Datatype impl_oldtype = CONVERT_MPI_Datatype(oldtype);
MPI_Datatype impl_newtype;
int rc = IMPL_Type_vector_c(count, blocklength, stride, impl_oldtype, &impl_newtype);
*newtype = OUTPUT_MPI_Datatype(impl_newtype);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif