Skip to content

Commit 4d876ec

Browse files
committed
io/romio314: fix minmax datatypes
romio assumes that all predefined datatypes are contiguous. Because of the (terribly named) composed datatypes MPI_SHORT_INT, MPI_DOUBLE_INT, MPI_LONG_INT, etc this is an incorrect assumption. The simplest way to fix this is to override the MPI_Type_get_envelope and MPI_Type_get_contents calls with calls that will work on these datatypes. Note that not all calls to these MPI functions are replaced, only the ones used when flattening a non-contiguous datatype. References #5009 Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
1 parent 55c6918 commit 4d876ec

File tree

3 files changed

+120
-22
lines changed

3 files changed

+120
-22
lines changed

ompi/mca/io/romio314/romio/adio/common/ad_set_view.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ void ADIO_Set_view(ADIO_File fd, ADIO_Offset disp, MPI_Datatype etype,
3535

3636
/* set new etypes and filetypes */
3737

38-
MPI_Type_get_envelope(etype, &i, &j, &k, &combiner);
38+
ADIOI_Type_get_envelope(etype, &i, &j, &k, &combiner);
3939
if (combiner == MPI_COMBINER_NAMED) fd->etype = etype;
4040
else {
4141
MPI_Type_contiguous(1, etype, &copy_etype);
4242
MPI_Type_commit(&copy_etype);
4343
fd->etype = copy_etype;
4444
}
45-
MPI_Type_get_envelope(filetype, &i, &j, &k, &combiner);
45+
ADIOI_Type_get_envelope(filetype, &i, &j, &k, &combiner);
4646
if (combiner == MPI_COMBINER_NAMED)
4747
fd->filetype = filetype;
4848
else {

ompi/mca/io/romio314/romio/adio/common/flatten.c

Lines changed: 112 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,90 @@
1414
#define FLATTEN_DEBUG 1
1515
#endif
1616

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+
17101
void ADIOI_Optimize_flattened(ADIOI_Flatlist_node *flat_type);
18102
/* flatten datatype and add it to Flatlist */
19103
void ADIOI_Flatten_datatype(MPI_Datatype datatype)
@@ -118,11 +202,15 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
118202
int *ints;
119203
MPI_Aint *adds; /* Make no assumptions about +/- sign on these */
120204
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+
}
122210
ints = (int *) ADIOI_Malloc((nints+1)*sizeof(int));
123211
adds = (MPI_Aint *) ADIOI_Malloc((nadds+1)*sizeof(MPI_Aint));
124212
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);
126214

127215
#ifdef FLATTEN_DEBUG
128216
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,
153241
#ifdef FLATTEN_DEBUG
154242
DBG_FPRINTF(stderr,"ADIOI_Flatten:: MPI_COMBINER_DUP\n");
155243
#endif
156-
MPI_Type_get_envelope(types[0], &old_nints, &old_nadds,
244+
ADIOI_Type_get_envelope(types[0], &old_nints, &old_nadds,
157245
&old_ntypes, &old_combiner);
158246
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
159247
if ((old_combiner != MPI_COMBINER_NAMED) && (!old_is_contig))
@@ -218,7 +306,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
218306
DBG_FPRINTF(stderr,"ADIOI_Flatten:: MPI_COMBINER_CONTIGUOUS\n");
219307
#endif
220308
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,
222310
&old_ntypes, &old_combiner);
223311
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
224312

@@ -263,7 +351,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
263351
DBG_FPRINTF(stderr,"ADIOI_Flatten:: MPI_COMBINER_VECTOR\n");
264352
#endif
265353
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,
267355
&old_ntypes, &old_combiner);
268356
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
269357

@@ -326,7 +414,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
326414
DBG_FPRINTF(stderr,"ADIOI_Flatten:: MPI_COMBINER_HVECTOR_INTEGER\n");
327415
#endif
328416
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,
330418
&old_ntypes, &old_combiner);
331419
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
332420

@@ -388,7 +476,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
388476
DBG_FPRINTF(stderr,"ADIOI_Flatten:: MPI_COMBINER_INDEXED\n");
389477
#endif
390478
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,
392480
&old_ntypes, &old_combiner);
393481
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
394482
MPI_Type_extent(types[0], &old_extent);
@@ -494,7 +582,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
494582
DBG_FPRINTF(stderr,"ADIOI_Flatten:: MPI_COMBINER_INDEXED_BLOCK\n");
495583
#endif
496584
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,
498586
&old_ntypes, &old_combiner);
499587
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
500588
MPI_Type_extent(types[0], &old_extent);
@@ -583,7 +671,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
583671
DBG_FPRINTF(stderr,"ADIOI_Flatten:: MPI_COMBINER_HINDEXED_INTEGER\n");
584672
#endif
585673
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,
587675
&old_ntypes, &old_combiner);
588676
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
589677

@@ -675,7 +763,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
675763
#endif
676764
top_count = ints[0];
677765
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,
679767
&old_ntypes, &old_combiner);
680768
ADIOI_Datatype_iscontig(types[n], &old_is_contig);
681769

@@ -746,7 +834,7 @@ void ADIOI_Flatten(MPI_Datatype datatype, ADIOI_Flatlist_node *flat,
746834

747835
/* handle the datatype */
748836

749-
MPI_Type_get_envelope(types[0], &old_nints, &old_nadds,
837+
ADIOI_Type_get_envelope(types[0], &old_nints, &old_nadds,
750838
&old_ntypes, &old_combiner);
751839
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
752840

@@ -827,16 +915,20 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
827915
MPI_Aint *adds; /* Make no assumptions about +/- sign on these */
828916
MPI_Datatype *types;
829917

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+
}
831923
ints = (int *) ADIOI_Malloc((nints+1)*sizeof(int));
832924
adds = (MPI_Aint *) ADIOI_Malloc((nadds+1)*sizeof(MPI_Aint));
833925
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);
835927

836928
switch (combiner) {
837929
#ifdef MPIIMPL_HAVE_MPI_COMBINER_DUP
838930
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,
840932
&old_ntypes, &old_combiner);
841933
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
842934
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
895987
#endif
896988
case MPI_COMBINER_CONTIGUOUS:
897989
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,
899991
&old_ntypes, &old_combiner);
900992
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
901993

@@ -919,7 +1011,7 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
9191011
case MPI_COMBINER_HVECTOR:
9201012
case MPI_COMBINER_HVECTOR_INTEGER:
9211013
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,
9231015
&old_ntypes, &old_combiner);
9241016
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
9251017

@@ -954,7 +1046,7 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
9541046
case MPI_COMBINER_HINDEXED:
9551047
case MPI_COMBINER_HINDEXED_INTEGER:
9561048
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,
9581050
&old_ntypes, &old_combiner);
9591051
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
9601052

@@ -990,7 +1082,7 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
9901082
#endif
9911083
case MPI_COMBINER_INDEXED_BLOCK:
9921084
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,
9941086
&old_ntypes, &old_combiner);
9951087
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
9961088

@@ -1024,7 +1116,7 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
10241116
top_count = ints[0];
10251117
count = 0;
10261118
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,
10281120
&old_ntypes, &old_combiner);
10291121
ADIOI_Datatype_iscontig(types[n], &old_is_contig);
10301122

@@ -1056,7 +1148,7 @@ MPI_Count ADIOI_Count_contiguous_blocks(MPI_Datatype datatype, MPI_Count *curr_i
10561148
count += 2;
10571149

10581150
/* 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,
10601152
&old_ntypes, &old_combiner);
10611153
ADIOI_Datatype_iscontig(types[0], &old_is_contig);
10621154

ompi/mca/io/romio314/romio/adio/include/adioi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ typedef struct {
324324

325325
/* prototypes for ADIO internal functions */
326326

327+
328+
int ADIOI_Type_get_envelope (MPI_Datatype datatype, int *num_integers,
329+
int *num_addresses, int *num_datatypes, int *combiner);
330+
int ADIOI_Type_get_contents (MPI_Datatype datatype, int max_integers,
331+
int max_addresses, int max_datatypes, int array_of_integers[],
332+
MPI_Aint array_of_addresses[], MPI_Datatype array_of_datatypes[]);
327333
void ADIOI_SetFunctions(ADIO_File fd);
328334
void ADIOI_Flatten_datatype(MPI_Datatype type);
329335
void ADIOI_Flatten(MPI_Datatype type, ADIOI_Flatlist_node *flat,

0 commit comments

Comments
 (0)