@@ -287,23 +287,16 @@ int mca_topo_base_dist_graph_create(mca_topo_base_module_t* module,
287287 ompi_communicator_t * * newcomm )
288288{
289289 int err ;
290-
291290 ompi_proc_t * * topo_procs = NULL ;
292291 int num_procs , ret , rank , i ;
293292 ompi_communicator_t * new_comm ;
294293 mca_topo_base_comm_dist_graph_2_2_0_t * topo ;
295- num_procs = ompi_comm_size (comm_old );
296- rank = ompi_comm_rank (comm_old );
294+
297295 topo_procs = (ompi_proc_t * * )malloc (num_procs * sizeof (ompi_proc_t * ));
298- if (OMPI_GROUP_IS_DENSE (comm_old -> c_local_group )) {
299- memcpy (topo_procs ,
300- comm_old -> c_local_group -> grp_proc_pointers ,
301- num_procs * sizeof (ompi_proc_t * ));
302- } else {
303- for (i = 0 ; i < num_procs ; i ++ ) {
304- topo_procs [i ] = ompi_group_peer_lookup (comm_old -> c_local_group ,i );
305- }
296+ if (NULL == topo_procs ) {
297+ return OMPI_ERR_OUT_OF_RESOURCE ;
306298 }
299+ num_procs = ompi_comm_size (comm_old );
307300 new_comm = ompi_comm_allocate (num_procs , 0 );
308301 if (NULL == new_comm ) {
309302 free (topo_procs );
@@ -317,10 +310,22 @@ int mca_topo_base_dist_graph_create(mca_topo_base_module_t* module,
317310 & topo );
318311 if ( OMPI_SUCCESS != err ) {
319312 free (topo_procs );
320- ompi_comm_free (newcomm );
313+ ompi_comm_free (& new_comm );
321314 return err ;
322315 }
323316
317+ /* we cannot simply call ompi_comm_create because c_topo
318+ must be set before invoking ompi_comm_enable */
319+ rank = ompi_comm_rank (comm_old );
320+ if (OMPI_GROUP_IS_DENSE (comm_old -> c_local_group )) {
321+ memcpy (topo_procs ,
322+ comm_old -> c_local_group -> grp_proc_pointers ,
323+ num_procs * sizeof (ompi_proc_t * ));
324+ } else {
325+ for (i = 0 ; i < num_procs ; i ++ ) {
326+ topo_procs [i ] = ompi_group_peer_lookup (comm_old -> c_local_group ,i );
327+ }
328+ }
324329 assert (NULL == new_comm -> c_topo );
325330 new_comm -> c_topo = module ;
326331 new_comm -> c_topo -> reorder = reorder ;
0 commit comments