14
14
#define FLATTEN_DEBUG 1
15
15
#endif
16
16
17
+ struct adio_short_int {
18
+ short elem_s ;
19
+ int elem_i ;
20
+ };
21
+
22
+ struct adio_double_int {
23
+ double elem_d ;
24
+ int elem_i ;
25
+ };
26
+
27
+ struct adio_long_int {
28
+ long elem_l ;
29
+ int elem_i ;
30
+ };
31
+
32
+ struct adio_long_double_int {
33
+ long double elem_ld ;
34
+ int elem_i ;
35
+ };
36
+
37
+ int ADIOI_Type_get_envelope (MPI_Datatype datatype , int * num_integers ,
38
+ int * num_addresses , int * num_datatypes , int * combiner )
39
+ {
40
+ int rc , is_contig ;
41
+
42
+ ADIOI_Datatype_iscontig (datatype , & is_contig );
43
+
44
+ rc = MPI_Type_get_envelope (datatype , num_integers , num_addresses , num_datatypes , combiner );
45
+ if (MPI_SUCCESS != rc || MPI_COMBINER_NAMED != * combiner || is_contig ) {
46
+ return rc ;
47
+ }
48
+
49
+ if (MPI_SHORT_INT == datatype || MPI_DOUBLE_INT == datatype || MPI_LONG_DOUBLE_INT == datatype ||
50
+ MPI_LONG_INT == datatype ) {
51
+ * num_integers = 2 ;
52
+ * num_addresses = 2 ;
53
+ * num_datatypes = 2 ;
54
+ * combiner = MPI_COMBINER_STRUCT ;
55
+ }
56
+
57
+ return rc ;
58
+ }
59
+
60
+ int ADIOI_Type_get_contents (MPI_Datatype datatype , int max_integers ,
61
+ int max_addresses , int max_datatypes , int array_of_integers [],
62
+ MPI_Aint array_of_addresses [], MPI_Datatype array_of_datatypes [])
63
+ {
64
+ int dontcare , combiner ;
65
+ int rc ;
66
+
67
+ rc = MPI_Type_get_envelope (datatype , & dontcare , & dontcare , & dontcare , & combiner );
68
+ if (MPI_SUCCESS != rc ) {
69
+ return rc ;
70
+ }
71
+
72
+ if (MPI_COMBINER_NAMED != combiner ) {
73
+ return MPI_Type_get_contents (datatype , max_integers , max_addresses , max_datatypes ,
74
+ array_of_integers , array_of_addresses , array_of_datatypes );
75
+ }
76
+
77
+ array_of_integers [0 ] = 1 ;
78
+ array_of_integers [1 ] = 1 ;
79
+ array_of_addresses [0 ] = 0 ;
80
+ array_of_datatypes [1 ] = MPI_INT ;
81
+
82
+ if (MPI_SHORT_INT == datatype ) {
83
+ array_of_datatypes [0 ] = MPI_SHORT ;
84
+ array_of_addresses [1 ] = offsetof (struct adio_short_int , elem_i );
85
+ } else if (MPI_DOUBLE_INT == datatype ) {
86
+ array_of_datatypes [0 ] = MPI_DOUBLE ;
87
+ array_of_addresses [1 ] = offsetof (struct adio_double_int , elem_i );
88
+ } else if (MPI_LONG_DOUBLE_INT == datatype ) {
89
+ array_of_datatypes [0 ] = MPI_LONG_DOUBLE ;
90
+ array_of_addresses [1 ] = offsetof (struct adio_long_double_int , elem_i );
91
+ } else if (MPI_LONG_INT == datatype ) {
92
+ array_of_datatypes [0 ] = MPI_LONG ;
93
+ array_of_addresses [1 ] = offsetof (struct adio_long_int , elem_i );
94
+ } else {
95
+ rc = MPI_ERR_TYPE ;
96
+ }
97
+
98
+ return rc ;
99
+ }
100
+
17
101
void ADIOI_Optimize_flattened (ADIOI_Flatlist_node * flat_type );
18
102
/* flatten datatype and add it to Flatlist */
19
103
void ADIOI_Flatten_datatype (MPI_Datatype datatype )
@@ -118,11 +202,15 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
118
202
int * ints ;
119
203
MPI_Aint * adds ; /* Make no assumptions about +/- sign on these */
120
204
MPI_Datatype * types ;
121
- MPI_Type_get_envelope (datatype , & nints , & nadds , & ntypes , & combiner );
205
+ ADIOI_Type_get_envelope (datatype , & nints , & nadds , & ntypes , & combiner );
206
+ if (combiner == MPI_COMBINER_NAMED ) {
207
+ return ; /* can't do anything else: calling get_contents on a builtin
208
+ type is an error */
209
+ }
122
210
ints = (int * ) ADIOI_Malloc ((nints + 1 )* sizeof (int ));
123
211
adds = (MPI_Aint * ) ADIOI_Malloc ((nadds + 1 )* sizeof (MPI_Aint ));
124
212
types = (MPI_Datatype * ) ADIOI_Malloc ((ntypes + 1 )* sizeof (MPI_Datatype ));
125
- MPI_Type_get_contents (datatype , nints , nadds , ntypes , ints , adds , types );
213
+ ADIOI_Type_get_contents (datatype , nints , nadds , ntypes , ints , adds , types );
126
214
127
215
#ifdef FLATTEN_DEBUG
128
216
DBG_FPRINTF (stderr ,"ADIOI_Flatten:: st_offset %#llX, curr_index %#llX\n" ,st_offset ,* curr_index );
@@ -153,7 +241,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
153
241
#ifdef FLATTEN_DEBUG
154
242
DBG_FPRINTF (stderr ,"ADIOI_Flatten:: MPI_COMBINER_DUP\n" );
155
243
#endif
156
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
244
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
157
245
& old_ntypes , & old_combiner );
158
246
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
159
247
if ((old_combiner != MPI_COMBINER_NAMED ) && (!old_is_contig ))
@@ -218,7 +306,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
218
306
DBG_FPRINTF (stderr ,"ADIOI_Flatten:: MPI_COMBINER_CONTIGUOUS\n" );
219
307
#endif
220
308
top_count = ints [0 ];
221
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
309
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
222
310
& old_ntypes , & old_combiner );
223
311
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
224
312
@@ -263,7 +351,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
263
351
DBG_FPRINTF (stderr ,"ADIOI_Flatten:: MPI_COMBINER_VECTOR\n" );
264
352
#endif
265
353
top_count = ints [0 ];
266
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
354
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
267
355
& old_ntypes , & old_combiner );
268
356
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
269
357
@@ -326,7 +414,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
326
414
DBG_FPRINTF (stderr ,"ADIOI_Flatten:: MPI_COMBINER_HVECTOR_INTEGER\n" );
327
415
#endif
328
416
top_count = ints [0 ];
329
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
417
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
330
418
& old_ntypes , & old_combiner );
331
419
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
332
420
@@ -388,7 +476,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
388
476
DBG_FPRINTF (stderr ,"ADIOI_Flatten:: MPI_COMBINER_INDEXED\n" );
389
477
#endif
390
478
top_count = ints [0 ];
391
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
479
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
392
480
& old_ntypes , & old_combiner );
393
481
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
394
482
MPI_Type_extent (types [0 ], & old_extent );
@@ -494,7 +582,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
494
582
DBG_FPRINTF (stderr ,"ADIOI_Flatten:: MPI_COMBINER_INDEXED_BLOCK\n" );
495
583
#endif
496
584
top_count = ints [0 ];
497
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
585
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
498
586
& old_ntypes , & old_combiner );
499
587
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
500
588
MPI_Type_extent (types [0 ], & old_extent );
@@ -583,7 +671,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
583
671
DBG_FPRINTF (stderr ,"ADIOI_Flatten:: MPI_COMBINER_HINDEXED_INTEGER\n" );
584
672
#endif
585
673
top_count = ints [0 ];
586
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
674
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
587
675
& old_ntypes , & old_combiner );
588
676
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
589
677
@@ -675,7 +763,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
675
763
#endif
676
764
top_count = ints [0 ];
677
765
for (n = 0 ; n < top_count ; n ++ ) {
678
- MPI_Type_get_envelope (types [n ], & old_nints , & old_nadds ,
766
+ ADIOI_Type_get_envelope (types [n ], & old_nints , & old_nadds ,
679
767
& old_ntypes , & old_combiner );
680
768
ADIOI_Datatype_iscontig (types [n ], & old_is_contig );
681
769
@@ -746,7 +834,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
746
834
747
835
/* handle the datatype */
748
836
749
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
837
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
750
838
& old_ntypes , & old_combiner );
751
839
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
752
840
@@ -827,16 +915,20 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
827
915
MPI_Aint * adds ; /* Make no assumptions about +/- sign on these */
828
916
MPI_Datatype * types ;
829
917
830
- MPI_Type_get_envelope (datatype , & nints , & nadds , & ntypes , & combiner );
918
+ ADIOI_Type_get_envelope (datatype , & nints , & nadds , & ntypes , & combiner );
919
+ if (combiner == MPI_COMBINER_NAMED ) {
920
+ return 1 ; /* builtin types not supposed to be passed to this routine
921
+ */
922
+ }
831
923
ints = (int * ) ADIOI_Malloc ((nints + 1 )* sizeof (int ));
832
924
adds = (MPI_Aint * ) ADIOI_Malloc ((nadds + 1 )* sizeof (MPI_Aint ));
833
925
types = (MPI_Datatype * ) ADIOI_Malloc ((ntypes + 1 )* sizeof (MPI_Datatype ));
834
- MPI_Type_get_contents (datatype , nints , nadds , ntypes , ints , adds , types );
926
+ ADIOI_Type_get_contents (datatype , nints , nadds , ntypes , ints , adds , types );
835
927
836
928
switch (combiner ) {
837
929
#ifdef MPIIMPL_HAVE_MPI_COMBINER_DUP
838
930
case MPI_COMBINER_DUP :
839
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
931
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
840
932
& old_ntypes , & old_combiner );
841
933
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
842
934
if ((old_combiner != MPI_COMBINER_NAMED ) && (!old_is_contig ))
@@ -895,7 +987,7 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
895
987
#endif
896
988
case MPI_COMBINER_CONTIGUOUS :
897
989
top_count = ints [0 ];
898
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
990
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
899
991
& old_ntypes , & old_combiner );
900
992
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
901
993
@@ -919,7 +1011,7 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
919
1011
case MPI_COMBINER_HVECTOR :
920
1012
case MPI_COMBINER_HVECTOR_INTEGER :
921
1013
top_count = ints [0 ];
922
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
1014
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
923
1015
& old_ntypes , & old_combiner );
924
1016
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
925
1017
@@ -954,7 +1046,7 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
954
1046
case MPI_COMBINER_HINDEXED :
955
1047
case MPI_COMBINER_HINDEXED_INTEGER :
956
1048
top_count = ints [0 ];
957
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
1049
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
958
1050
& old_ntypes , & old_combiner );
959
1051
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
960
1052
@@ -990,7 +1082,7 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
990
1082
#endif
991
1083
case MPI_COMBINER_INDEXED_BLOCK :
992
1084
top_count = ints [0 ];
993
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
1085
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
994
1086
& old_ntypes , & old_combiner );
995
1087
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
996
1088
@@ -1024,7 +1116,7 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
1024
1116
top_count = ints [0 ];
1025
1117
count = 0 ;
1026
1118
for (n = 0 ; n < top_count ; n ++ ) {
1027
- MPI_Type_get_envelope (types [n ], & old_nints , & old_nadds ,
1119
+ ADIOI_Type_get_envelope (types [n ], & old_nints , & old_nadds ,
1028
1120
& old_ntypes , & old_combiner );
1029
1121
ADIOI_Datatype_iscontig (types [n ], & old_is_contig );
1030
1122
@@ -1056,7 +1148,7 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
1056
1148
count += 2 ;
1057
1149
1058
1150
/* add for datatype */
1059
- MPI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
1151
+ ADIOI_Type_get_envelope (types [0 ], & old_nints , & old_nadds ,
1060
1152
& old_ntypes , & old_combiner );
1061
1153
ADIOI_Datatype_iscontig (types [0 ], & old_is_contig );
1062
1154
0 commit comments