Skip to content

Commit 3b0b8fa

Browse files
committed
io/ompio: update cartesian based grouping strategy
update the cartesian communicator based grouping strategy to match the other algorithms used in the aggregator selection process. Signed-off-by: Edgar Gabriel <[email protected]>
1 parent bd6b430 commit 3b0b8fa

File tree

3 files changed

+127
-72
lines changed

3 files changed

+127
-72
lines changed

ompi/mca/common/ompio/common_ompio_file_view.c

Lines changed: 69 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* University of Stuttgart. All rights reserved.
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
12-
* Copyright (c) 2008-2016 University of Houston. All rights reserved.
12+
* Copyright (c) 2008-2017 University of Houston. All rights reserved.
1313
* Copyright (c) 2017 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
1515
* Copyright (c) 2017 IBM Corporation. All rights reserved.
@@ -28,6 +28,7 @@
2828

2929
#include "common_ompio.h"
3030
#include "ompi/mca/fcoll/base/base.h"
31+
#include "ompi/mca/topo/topo.h"
3132

3233
static OMPI_MPI_OFFSET_TYPE get_contiguous_chunk_size (mca_io_ompio_file_t *);
3334
static int datatype_duplicate (ompi_datatype_t *oldtype, ompi_datatype_t **newtype );
@@ -59,11 +60,11 @@ int mca_common_ompio_set_view (mca_io_ompio_file_t *fh,
5960
const char *datarep,
6061
opal_info_t *info)
6162
{
62-
63+
int ret=OMPI_SUCCESS;
6364
size_t max_data = 0;
6465
int i;
6566
int num_groups = 0;
66-
mca_io_ompio_contg *contg_groups;
67+
mca_io_ompio_contg *contg_groups=NULL;
6768

6869
size_t ftype_size;
6970
ptrdiff_t ftype_extent, lb, ub;
@@ -166,36 +167,69 @@ int mca_common_ompio_set_view (mca_io_ompio_file_t *fh,
166167
}
167168

168169
if ( SIMPLE != mca_io_ompio_grouping_option ) {
169-
if( OMPI_SUCCESS != mca_io_ompio_fview_based_grouping(fh,
170-
&num_groups,
171-
contg_groups)){
170+
171+
ret = mca_io_ompio_fview_based_grouping(fh,
172+
&num_groups,
173+
contg_groups);
174+
if ( OMPI_SUCCESS != ret ) {
172175
opal_output(1, "mca_common_ompio_set_view: mca_io_ompio_fview_based_grouping failed\n");
173-
free(contg_groups);
174-
return OMPI_ERROR;
176+
goto exit;
175177
}
176178
}
177179
else {
178-
if( OMPI_SUCCESS != mca_io_ompio_simple_grouping(fh,
179-
&num_groups,
180-
contg_groups)){
181-
opal_output(1, "mca_common_ompio_set_view: mca_io_ompio_simple_grouping failed\n");
182-
free(contg_groups);
183-
return OMPI_ERROR;
180+
int done=0;
181+
int ndims;
182+
if ( fh->f_comm->c_flags & OMPI_COMM_CART ){
183+
ret = fh->f_comm->c_topo->topo.cart.cartdim_get( fh->f_comm, &ndims);
184+
if ( OMPI_SUCCESS != ret ){
185+
goto exit;
186+
}
187+
if ( ndims > 1 ) {
188+
ret = mca_io_ompio_cart_based_grouping( fh,
189+
&num_groups,
190+
contg_groups);
191+
if (OMPI_SUCCESS != ret ) {
192+
opal_output(1, "mca_common_ompio_set_view: mca_io_ompio_cart_based_grouping failed\n");
193+
goto exit;
194+
}
195+
done=1;
196+
}
197+
}
198+
199+
if ( !done ) {
200+
ret = mca_io_ompio_simple_grouping(fh,
201+
&num_groups,
202+
contg_groups);
203+
if ( OMPI_SUCCESS != ret ){
204+
opal_output(1, "mca_common_ompio_set_view: mca_io_ompio_simple_grouping failed\n");
205+
goto exit;
206+
}
184207
}
185208
}
186-
187-
188-
if ( OMPI_SUCCESS != mca_io_ompio_finalize_initial_grouping(fh,
189-
num_groups,
190-
contg_groups) ){
191-
opal_output(1, "mca_common_ompio_set_view: mca_io_ompio_finalize_initial_grouping failed\n");
192-
free(contg_groups);
193-
return OMPI_ERROR;
209+
210+
#ifdef DEBUG_OMPIO
211+
if ( fh->f_rank == 0) {
212+
int ii, jj;
213+
printf("BEFORE finalize_init: comm size = %d num_groups = %d\n", fh->f_size, num_groups);
214+
for ( ii=0; ii< num_groups; ii++ ) {
215+
printf("contg_groups[%d].procs_per_contg_group=%d\n", ii, contg_groups[ii].procs_per_contg_group);
216+
printf("contg_groups[%d].procs_in_contg_group.[", ii);
217+
218+
for ( jj=0; jj< contg_groups[ii].procs_per_contg_group; jj++ ) {
219+
printf("%d,", contg_groups[ii].procs_in_contg_group[jj]);
220+
}
221+
printf("]\n");
222+
}
194223
}
195-
for( i = 0; i < fh->f_size; i++){
196-
free(contg_groups[i].procs_in_contg_group);
224+
#endif
225+
226+
ret = mca_io_ompio_finalize_initial_grouping(fh,
227+
num_groups,
228+
contg_groups);
229+
if ( OMPI_SUCCESS != ret ) {
230+
opal_output(1, "mca_common_ompio_set_view: mca_io_ompio_finalize_initial_grouping failed\n");
231+
goto exit;
197232
}
198-
free(contg_groups);
199233

200234
if ( etype == filetype &&
201235
ompi_datatype_is_predefined (filetype ) &&
@@ -204,12 +238,19 @@ int mca_common_ompio_set_view (mca_io_ompio_file_t *fh,
204238
}
205239

206240

207-
if (OMPI_SUCCESS != mca_fcoll_base_file_select (fh, NULL)) {
241+
ret = mca_fcoll_base_file_select (fh, NULL);
242+
if ( OMPI_SUCCESS != ret ) {
208243
opal_output(1, "mca_common_ompio_set_view: mca_fcoll_base_file_select() failed\n");
209-
return OMPI_ERROR;
244+
goto exit;
210245
}
211246

212-
return OMPI_SUCCESS;
247+
exit:
248+
for( i = 0; i < fh->f_size; i++){
249+
free(contg_groups[i].procs_in_contg_group);
250+
}
251+
free(contg_groups);
252+
253+
return ret;
213254
}
214255

215256
OMPI_MPI_OFFSET_TYPE get_contiguous_chunk_size (mca_io_ompio_file_t *fh)

ompi/mca/io/ompio/io_ompio_aggregators.c

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* University of Stuttgart. All rights reserved.
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
13-
* Copyright (c) 2008-2016 University of Houston. All rights reserved.
13+
* Copyright (c) 2008-2017 University of Houston. All rights reserved.
1414
* Copyright (c) 2011-2015 Cisco Systems, Inc. All rights reserved.
1515
* Copyright (c) 2012-2013 Inria. All rights reserved.
1616
* Copyright (c) 2015-2017 Research Organization for Information Science
@@ -192,19 +192,26 @@ int mca_io_ompio_fview_based_grouping(mca_io_ompio_file_t *fh,
192192
return ret;
193193
}
194194

195-
int mca_io_ompio_cart_based_grouping(mca_io_ompio_file_t *ompio_fh)
195+
int mca_io_ompio_cart_based_grouping(mca_io_ompio_file_t *ompio_fh,
196+
int *num_groups,
197+
mca_io_ompio_contg *contg_groups)
196198
{
197199
int k = 0;
198-
int j = 0;
199-
int n = 0;
200+
int g=0;
200201
int ret = OMPI_SUCCESS, tmp_rank = 0;
201-
int coords_tmp[2] = { 0 };
202+
int *coords_tmp = NULL;
202203

203204
mca_io_ompio_cart_topo_components cart_topo;
204205
memset (&cart_topo, 0, sizeof(mca_io_ompio_cart_topo_components));
205206

206207
ret = ompio_fh->f_comm->c_topo->topo.cart.cartdim_get(ompio_fh->f_comm, &cart_topo.ndims);
207-
if (OMPI_SUCCESS != ret ) {
208+
if (OMPI_SUCCESS != ret ) {
209+
goto exit;
210+
}
211+
212+
if (cart_topo.ndims < 2 ) {
213+
/* We shouldn't be here, this routine only works for more than 1 dimension */
214+
ret = MPI_ERR_INTERN;
208215
goto exit;
209216
}
210217

@@ -227,6 +234,13 @@ int mca_io_ompio_cart_based_grouping(mca_io_ompio_file_t *ompio_fh)
227234
goto exit;
228235
}
229236

237+
coords_tmp = (int*)malloc (cart_topo.ndims * sizeof(int));
238+
if (NULL == coords_tmp) {
239+
opal_output (1, "OUT OF MEMORY\n");
240+
ret = OMPI_ERR_OUT_OF_RESOURCE;
241+
goto exit;
242+
}
243+
230244
ret = ompio_fh->f_comm->c_topo->topo.cart.cart_get(ompio_fh->f_comm,
231245
cart_topo.ndims,
232246
cart_topo.dims,
@@ -237,55 +251,50 @@ int mca_io_ompio_cart_based_grouping(mca_io_ompio_file_t *ompio_fh)
237251
goto exit;
238252
}
239253

240-
ompio_fh->f_init_procs_per_group = cart_topo.dims[1]; //number of elements per row
241-
ompio_fh->f_init_num_aggrs = cart_topo.dims[0]; //number of rows
242-
243-
//Make an initial list of potential aggregators
244-
ompio_fh->f_init_aggr_list = (int *) malloc (ompio_fh->f_init_num_aggrs * sizeof(int));
245-
if (NULL == ompio_fh->f_init_aggr_list) {
246-
opal_output (1, "OUT OF MEMORY\n");
247-
ret = OMPI_ERR_OUT_OF_RESOURCE;
248-
goto exit;
249-
}
254+
*num_groups = cart_topo.dims[0]; //number of rows
250255

251256
for(k = 0; k < cart_topo.dims[0]; k++){
257+
int done = 0;
258+
int index = cart_topo.ndims-1;
259+
260+
memset ( coords_tmp, 0, cart_topo.ndims * sizeof(int));
261+
contg_groups[k].procs_per_contg_group = (ompio_fh->f_size / cart_topo.dims[0]);
252262
coords_tmp[0] = k;
253-
coords_tmp[1] = k * cart_topo.dims[1];
263+
254264
ret = ompio_fh->f_comm->c_topo->topo.cart.cart_rank (ompio_fh->f_comm,coords_tmp,&tmp_rank);
255265
if ( OMPI_SUCCESS != ret ) {
256266
opal_output (1, "mca_io_ompio_cart_based_grouping: Error in cart_rank\n");
257267
goto exit;
258268
}
259-
ompio_fh->f_init_aggr_list[k] = tmp_rank;
260-
}
261-
262-
//Initial Grouping
263-
ompio_fh->f_init_procs_in_group = (int*)malloc (ompio_fh->f_init_procs_per_group * sizeof(int));
264-
if (NULL == ompio_fh->f_init_procs_in_group) {
265-
opal_output (1, "OUT OF MEMORY\n");
266-
free (ompio_fh->f_init_aggr_list );
267-
ompio_fh->f_init_aggr_list=NULL;
268-
ret = OMPI_ERR_OUT_OF_RESOURCE;
269-
goto exit;
270-
}
269+
contg_groups[k].procs_in_contg_group[0] = tmp_rank;
270+
271+
for ( g=1; g< contg_groups[k].procs_per_contg_group; g++ ) {
272+
done = 0;
273+
index = cart_topo.ndims-1;
274+
275+
while ( ! done ) {
276+
coords_tmp[index]++;
277+
if ( coords_tmp[index] ==cart_topo.dims[index] ) {
278+
coords_tmp[index]=0;
279+
index--;
280+
}
281+
else {
282+
done = 1;
283+
}
284+
if ( index == 0 ) {
285+
done = 1;
286+
}
287+
}
271288

272-
for (j=0 ; j< ompio_fh->f_size ; j++) {
273-
ompio_fh->f_comm->c_topo->topo.cart.cart_coords (ompio_fh->f_comm, j, cart_topo.ndims, coords_tmp);
274-
if (coords_tmp[0] == cart_topo.coords[0]) {
275-
if ((coords_tmp[1]/ompio_fh->f_init_procs_per_group) ==
276-
(cart_topo.coords[1]/ompio_fh->f_init_procs_per_group)) {
277-
ompio_fh->f_init_procs_in_group[n] = j;
278-
n++;
279-
}
289+
ret = ompio_fh->f_comm->c_topo->topo.cart.cart_rank (ompio_fh->f_comm,coords_tmp,&tmp_rank);
290+
if ( OMPI_SUCCESS != ret ) {
291+
opal_output (1, "mca_io_ompio_cart_based_grouping: Error in cart_rank\n");
292+
goto exit;
293+
}
294+
contg_groups[k].procs_in_contg_group[g] = tmp_rank;
280295
}
281296
}
282297

283-
/*print original group */
284-
/*printf("RANK%d Initial distribution \n",ompio_fh->f_rank);
285-
for(k = 0; k < ompio_fh->f_init_procs_per_group; k++){
286-
printf("%d,", ompio_fh->f_init_procs_in_group[k]);
287-
}
288-
printf("\n");*/
289298

290299
exit:
291300
if (NULL != cart_topo.dims) {
@@ -300,6 +309,10 @@ int mca_io_ompio_cart_based_grouping(mca_io_ompio_file_t *ompio_fh)
300309
free (cart_topo.coords);
301310
cart_topo.coords = NULL;
302311
}
312+
if (NULL != coords_tmp) {
313+
free (coords_tmp);
314+
coords_tmp = NULL;
315+
}
303316

304317
return ret;
305318
}

ompi/mca/io/ompio/io_ompio_aggregators.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ OMPI_DECLSPEC int mca_io_ompio_set_aggregator_props (struct mca_io_ompio_file_t
5151
int num_aggregators,
5252
size_t bytes_per_proc);
5353

54-
int mca_io_ompio_cart_based_grouping(mca_io_ompio_file_t *ompio_fh);
54+
int mca_io_ompio_cart_based_grouping(mca_io_ompio_file_t *ompio_fh, int *num_groups,
55+
mca_io_ompio_contg *contg_groups);
5556

5657
int mca_io_ompio_fview_based_grouping(mca_io_ompio_file_t *fh, int *num_groups,
5758
mca_io_ompio_contg *contg_groups);

0 commit comments

Comments
 (0)