Skip to content

Commit 0a57cca

Browse files
committed
Fix the subarray and darray type creation. Include a
small patch provided by Gilles.
1 parent 62f161e commit 0a57cca

File tree

3 files changed

+31
-49
lines changed

3 files changed

+31
-49
lines changed

ompi/datatype/ompi_datatype_create_darray.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2014 The University of Tennessee and The University
6+
* Copyright (c) 2004-2015 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
@@ -247,32 +247,28 @@ int32_t ompi_datatype_create_darray(int size,
247247
}
248248

249249

250-
/* set displacement and UB correctly. Please read the comment in subarray */
250+
/**
251+
* We need to shift the content (useful data) of the datatype, so
252+
* we need to force the displacement to be moved. Therefore, we
253+
* cannot use resize as it will only set the soft lb and ub
254+
* markers without moving the data. Instead, we have to create a
255+
* new data, and insert the last_Type with the correct
256+
* displacement.
257+
*/
251258
{
252-
ptrdiff_t displs[3], tmp_size;
253-
ompi_datatype_t *types[3];
254-
int blength[3] = { 1, 1, 1};
259+
ptrdiff_t displs[2], tmp_size = 1;
255260

256-
displs[1] = st_offsets[start_loop];
257-
tmp_size = 1;
258-
for (i = start_loop + step ; i != end_loop ; i += step) {
261+
displs[0] = st_offsets[start_loop];
262+
displs[1] = orig_extent;
263+
for (i = start_loop + step; i != end_loop; i += step) {
259264
tmp_size *= gsize_array[i - step];
260-
displs[1] += tmp_size * st_offsets[i];
265+
displs[0] += tmp_size * st_offsets[i];
266+
displs[1] *= gsize_array[i];
261267
}
268+
displs[0] *= orig_extent;
262269

263-
displs[0] = 0;
264-
displs[1] *= orig_extent;
265-
displs[2] = orig_extent;
266-
for (i = 0 ; i < ndims ; i++) {
267-
displs[2] *= gsize_array[i];
268-
}
269-
if(oldtype->super.flags & (OPAL_DATATYPE_FLAG_USER_LB | OPAL_DATATYPE_FLAG_USER_UB) ) {
270-
types[0] = MPI_LB; types[1] = lastType; types[2] = MPI_UB;
271-
272-
rc = ompi_datatype_create_struct(3, blength, displs, types, newtype);
273-
} else {
274-
ompi_datatype_create_resized(lastType, displs[1], displs[2], newtype);
275-
}
270+
*newtype = ompi_datatype_create(lastType->super.desc.used);
271+
ompi_datatype_add(*newtype, lastType, 1, displs[0], displs[1]);
276272
ompi_datatype_destroy(&lastType);
277273
/* need to destroy the old type even in error condition, so
278274
don't check return code from above until after cleanup. */

ompi/datatype/ompi_datatype_create_subarray.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2014 The University of Tennessee and The University
6+
* Copyright (c) 2004-2015 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
@@ -91,29 +91,16 @@ int32_t ompi_datatype_create_subarray(int ndims,
9191
}
9292

9393
replace_subarray_type:
94-
/*
95-
* Resized will only set the soft lb and ub markers without moving the real
96-
* data inside. Thus, in case the original data contains the hard markers
97-
* (MPI_LB or MPI_UB) we must force the displacement of the data upward to
98-
* the right position AND set the hard markers LB and UB.
99-
*
100-
* NTH: ompi_datatype_create_resized() does not do enough for the general
101-
* pack/unpack functions to work correctly. Until this is fixed always use
102-
* ompi_datatype_create_struct(). Once this is fixed remove 1 || below. To
103-
* verify that the regression is fixed run the subarray test in the Open MPI
104-
* ibm testsuite.
105-
*/
106-
if(1 || oldtype->super.flags & (OPAL_DATATYPE_FLAG_USER_LB | OPAL_DATATYPE_FLAG_USER_UB) ) {
107-
MPI_Aint displs[3];
108-
MPI_Datatype types[3];
109-
int blength[3] = { 1, 1, 1 };
110-
111-
displs[0] = 0; displs[1] = displ * extent; displs[2] = size * extent;
112-
types[0] = MPI_LB; types[1] = last_type; types[2] = MPI_UB;
113-
ompi_datatype_create_struct( 3, blength, displs, types, newtype );
114-
} else {
115-
ompi_datatype_create_resized(last_type, displ * extent, size * extent, newtype);
116-
}
94+
/**
95+
* We need to shift the content (useful data) of the datatype, so
96+
* we need to force the displacement to be moved. Therefore, we
97+
* cannot use resize as it will only set the soft lb and ub
98+
* markers without moving the data. Instead, we have to create a
99+
* new data, and insert the last_Type with the correct
100+
* displacement.
101+
*/
102+
*newtype = ompi_datatype_create( last_type->super.desc.used );
103+
ompi_datatype_add( *newtype, last_type, 1, displ * extent, size * extent);
117104
ompi_datatype_destroy( &last_type );
118105

119106
return OMPI_SUCCESS;

opal/datatype/opal_datatype_resize.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* of Tennessee Research Foundation. All rights
55
* reserved.
66
* Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
7+
* Copyright (c) 2015 Research Organization for Information Science
8+
* and Technology (RIST). All rights reserved.
79
* $COPYRIGHT$
810
*
911
* Additional copyrights may follow
@@ -21,9 +23,6 @@ int32_t opal_datatype_resize( opal_datatype_t* type, OPAL_PTRDIFF_TYPE lb, OPAL_
2123
type->lb = lb;
2224
type->ub = lb + extent;
2325

24-
type->true_lb += lb;
25-
type->true_ub += lb;
26-
2726
type->flags &= ~OPAL_DATATYPE_FLAG_NO_GAPS;
2827
if( (extent == (OPAL_PTRDIFF_TYPE)type->size) &&
2928
(type->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) ) {

0 commit comments

Comments
 (0)