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
290299exit :
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}
0 commit comments