1
- /* -*- Mode: C; c-basic-offset:4 ; -*- */
1
+ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2
2
/*
3
3
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
4
4
* University Research and Technology
13
13
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
14
14
* Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
15
15
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
16
+ * Copyright (c) 2016 Los Alamos National Security, LLC. All rights
17
+ * reserved.
16
18
* $COPYRIGHT$
17
19
*
18
20
* Additional copyrights may follow
@@ -169,6 +171,7 @@ int32_t ompi_datatype_create_darray(int size,
169
171
ptrdiff_t orig_extent , * st_offsets = NULL ;
170
172
int i , start_loop , end_loop , step ;
171
173
int * coords = NULL , rc = OMPI_SUCCESS ;
174
+ ptrdiff_t displs [2 ], tmp_size = 1 ;
172
175
173
176
/* speedy corner case */
174
177
if (ndims < 1 ) {
@@ -187,10 +190,13 @@ int32_t ompi_datatype_create_darray(int size,
187
190
int tmp_rank = rank , procs = size ;
188
191
189
192
coords = (int * ) malloc (ndims * sizeof (int ));
193
+ displs [1 ] = orig_extent ;
190
194
for (i = 0 ; i < ndims ; i ++ ) {
191
195
procs = procs / psize_array [i ];
192
196
coords [i ] = tmp_rank / procs ;
193
197
tmp_rank = tmp_rank % procs ;
198
+ /* compute the upper bound of the datatype, including all dimensions */
199
+ displs [1 ] *= gsize_array [i ];
194
200
}
195
201
}
196
202
@@ -246,7 +252,6 @@ int32_t ompi_datatype_create_darray(int size,
246
252
lastType = * newtype ;
247
253
}
248
254
249
-
250
255
/**
251
256
* We need to shift the content (useful data) of the datatype, so
252
257
* we need to force the displacement to be moved. Therefore, we
@@ -255,29 +260,26 @@ int32_t ompi_datatype_create_darray(int size,
255
260
* new data, and insert the last_Type with the correct
256
261
* displacement.
257
262
*/
258
- {
259
- ptrdiff_t displs [2 ], tmp_size = 1 ;
260
-
261
- displs [0 ] = st_offsets [start_loop ];
262
- displs [1 ] = orig_extent ;
263
- for (i = start_loop + step ; i != end_loop ; i += step ) {
264
- tmp_size *= gsize_array [i - step ];
265
- displs [0 ] += tmp_size * st_offsets [i ];
266
- displs [1 ] *= gsize_array [i ];
267
- }
268
- displs [0 ] *= orig_extent ;
269
-
270
- * newtype = ompi_datatype_create (lastType -> super .desc .used );
271
- rc = ompi_datatype_add (* newtype , lastType , 1 , displs [0 ], displs [1 ]);
272
- ompi_datatype_destroy (& lastType );
273
- opal_datatype_resize ( & (* newtype )-> super , 0 , displs [1 ] );
274
- /* need to destroy the old type even in error condition, so
275
- don't check return code from above until after cleanup. */
276
- if (MPI_SUCCESS != rc ) newtype = NULL ;
263
+ displs [0 ] = st_offsets [start_loop ];
264
+ for (i = start_loop + step ; i != end_loop ; i += step ) {
265
+ tmp_size *= gsize_array [i - step ];
266
+ displs [0 ] += tmp_size * st_offsets [i ];
267
+ }
268
+ displs [0 ] *= orig_extent ;
269
+
270
+ * newtype = ompi_datatype_create (lastType -> super .desc .used );
271
+ rc = ompi_datatype_add (* newtype , lastType , 1 , displs [0 ], displs [1 ]);
272
+ ompi_datatype_destroy (& lastType );
273
+ /* need to destroy the old type even in error condition, so
274
+ don't check return code from above until after cleanup. */
275
+ if (MPI_SUCCESS != rc ) {
276
+ ompi_datatype_destroy (newtype );
277
+ } else {
278
+ (void ) opal_datatype_resize ( & (* newtype )-> super , 0 , displs [1 ]);
277
279
}
278
280
279
281
cleanup :
280
- if ( NULL != st_offsets ) free (st_offsets );
281
- if ( NULL != coords ) free (coords );
282
- return OMPI_SUCCESS ;
282
+ free (st_offsets );
283
+ free (coords );
284
+ return rc ;
283
285
}
0 commit comments