10
10
* University of Stuttgart. All rights reserved.
11
11
* Copyright (c) 2004-2005 The Regents of the University of California.
12
12
* 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.
14
14
* Copyright (c) 2011-2015 Cisco Systems, Inc. All rights reserved.
15
15
* Copyright (c) 2012-2013 Inria. All rights reserved.
16
16
* 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,
192
192
return ret ;
193
193
}
194
194
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 )
196
198
{
197
199
int k = 0 ;
198
- int j = 0 ;
199
- int n = 0 ;
200
+ int g = 0 ;
200
201
int ret = OMPI_SUCCESS , tmp_rank = 0 ;
201
- int coords_tmp [ 2 ] = { 0 } ;
202
+ int * coords_tmp = NULL ;
202
203
203
204
mca_io_ompio_cart_topo_components cart_topo ;
204
205
memset (& cart_topo , 0 , sizeof (mca_io_ompio_cart_topo_components ));
205
206
206
207
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 ;
208
215
goto exit ;
209
216
}
210
217
@@ -227,6 +234,13 @@ int mca_io_ompio_cart_based_grouping(mca_io_ompio_file_t *ompio_fh)
227
234
goto exit ;
228
235
}
229
236
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
+
230
244
ret = ompio_fh -> f_comm -> c_topo -> topo .cart .cart_get (ompio_fh -> f_comm ,
231
245
cart_topo .ndims ,
232
246
cart_topo .dims ,
@@ -237,55 +251,50 @@ int mca_io_ompio_cart_based_grouping(mca_io_ompio_file_t *ompio_fh)
237
251
goto exit ;
238
252
}
239
253
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
250
255
251
256
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 ]);
252
262
coords_tmp [0 ] = k ;
253
- coords_tmp [ 1 ] = k * cart_topo . dims [ 1 ];
263
+
254
264
ret = ompio_fh -> f_comm -> c_topo -> topo .cart .cart_rank (ompio_fh -> f_comm ,coords_tmp ,& tmp_rank );
255
265
if ( OMPI_SUCCESS != ret ) {
256
266
opal_output (1 , "mca_io_ompio_cart_based_grouping: Error in cart_rank\n" );
257
267
goto exit ;
258
268
}
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
+ }
271
288
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 ;
280
295
}
281
296
}
282
297
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");*/
289
298
290
299
exit :
291
300
if (NULL != cart_topo .dims ) {
@@ -300,6 +309,10 @@ int mca_io_ompio_cart_based_grouping(mca_io_ompio_file_t *ompio_fh)
300
309
free (cart_topo .coords );
301
310
cart_topo .coords = NULL ;
302
311
}
312
+ if (NULL != coords_tmp ) {
313
+ free (coords_tmp );
314
+ coords_tmp = NULL ;
315
+ }
303
316
304
317
return ret ;
305
318
}
0 commit comments