3636
3737#include "opal/mca/pmix/pmix.h"
3838
39- /*#define __DEBUG__ 1 */
39+ /* #define __DEBUG__ 1 */
4040
4141/**
4242 * This function is a allreduce between all processes to detect for oversubscription.
@@ -190,7 +190,6 @@ int mca_topo_treematch_dist_graph_create(mca_topo_base_module_t* topo_module,
190190 memcpy (vpids , colors , size * sizeof (int ));
191191
192192#ifdef __DEBUG__
193- fprintf (stdout ,"Process rank (2) is : %i \n" ,rank );
194193 if ( 0 == rank ) {
195194 dump_int_array ("lindex_to_grank : " , "" , lindex_to_grank , num_procs_in_node );
196195 dump_int_array ("Vpids : " , "" , colors , size );
@@ -657,6 +656,8 @@ int mca_topo_treematch_dist_graph_create(mca_topo_base_module_t* topo_module,
657656 comm_tree = tm_build_tree_from_topology (tm_topology ,aff_mat , NULL , NULL );
658657 sol = tm_compute_mapping (tm_topology , comm_tree );
659658
659+ assert (sol -> k_length == size );
660+
660661 k = (int * )calloc (sol -> k_length , sizeof (int ));
661662 for (idx = 0 ; idx < (int )sol -> k_length ; idx ++ )
662663 k [idx ] = sol -> k [idx ][0 ];
@@ -703,8 +704,13 @@ int mca_topo_treematch_dist_graph_create(mca_topo_base_module_t* topo_module,
703704
704705 } else { /* partially distributed reordering */
705706 ompi_communicator_t * localcomm = NULL ;
706- int * matching , * grank_to_lrank , * lrank_to_grank ;
707-
707+ int * grank_to_lrank , * lrank_to_grank ;
708+ int * marked = (int * )malloc ((num_nodes - 1 )* sizeof (int ));
709+ int node_position = 0 ;
710+ int offset = 0 ;
711+ int done = 0 ;
712+ int pos = 0 ;
713+
708714 if (OMPI_SUCCESS != (err = ompi_comm_split (comm_old , colors [rank ], rank ,
709715 & localcomm , false))) {
710716 goto release_and_return ;
@@ -719,7 +725,6 @@ int mca_topo_treematch_dist_graph_create(mca_topo_base_module_t* topo_module,
719725 goto release_and_return ;
720726 }
721727
722- matching = (int * )calloc (num_procs_in_node , sizeof (int ));
723728 grank_to_lrank = (int * )malloc (size * sizeof (int ));
724729 for (i = 0 ; i < size ; grank_to_lrank [i ++ ] = -1 );
725730 for (i = 0 ; i < num_procs_in_node ; i ++ )
@@ -832,6 +837,8 @@ int mca_topo_treematch_dist_graph_create(mca_topo_base_module_t* topo_module,
832837 aff_mat = tm_build_affinity_mat (comm_pattern ,num_procs_in_node );
833838 comm_tree = tm_build_tree_from_topology (tm_topology ,aff_mat , NULL , NULL );
834839 sol = tm_compute_mapping (tm_topology , comm_tree );
840+
841+ assert (sol -> k_length == num_procs_in_node );
835842
836843 k = (int * )calloc (sol -> k_length , sizeof (int ));
837844 for (idx = 0 ; idx < (int )sol -> k_length ; idx ++ )
@@ -854,25 +861,44 @@ int mca_topo_treematch_dist_graph_create(mca_topo_base_module_t* topo_module,
854861
855862 /* Todo : Bcast + group creation */
856863 /* scatter the ranks */
857- if (OMPI_SUCCESS != (err = localcomm -> c_coll -> coll_bcast (matching , num_procs_in_node ,
858- MPI_INT , 0 , localcomm ,
859- localcomm -> c_coll -> coll_bcast_module ))) {
860- free (lrank_to_grank );
864+ if (OMPI_SUCCESS != (err = localcomm -> c_coll -> coll_scatter (k , 1 , MPI_INT ,
865+ & newrank , 1 , MPI_INT ,
866+ 0 , localcomm ,
867+ localcomm -> c_coll -> coll_scatter_module ))) {
868+ if (NULL != k ) free (k );
861869 ompi_comm_free (& localcomm );
870+ free (lrank_to_grank );
862871 free (grank_to_lrank );
863- free (matching );
864872 goto release_and_return ;
865873 }
866874
867- if (0 == rank )
875+ /* compute the offset of newrank before the split */
876+ /* use the colors array, not the vpids */
877+ for (int idx = 0 ; idx < num_nodes - 1 ; idx ++ )
878+ marked [idx ] = -1 ;
879+
880+ while ( (node_position != rank ) && (colors [node_position ] != colors [rank ])){
881+ for (int idx = 0 ; idx < num_nodes - 1 ; idx ++ )
882+ if ( marked [idx ] == colors [node_position ] )
883+ done = 1 ;
884+ if (!done ) {
885+ for (int idx = 0 ; idx < size ; idx ++ )
886+ if (colors [idx ] == colors [node_position ])
887+ offset ++ ;
888+ marked [pos ++ ] = colors [node_position ];
889+ }
890+ node_position ++ ;
891+ }
892+ newrank += offset ;
893+
894+ if (rank == lindex_to_grank [0 ])
868895 free (k );
869896
870897 /* this needs to be optimized but will do for now */
871- if (OMPI_SUCCESS != (err = ompi_comm_split (localcomm , 0 , newrank , newcomm , false))) {
872- free (lrank_to_grank );
898+ if (OMPI_SUCCESS != (err = ompi_comm_split (comm_old , 0 , newrank , newcomm , false))) {
873899 ompi_comm_free (& localcomm );
900+ free (lrank_to_grank );
874901 free (grank_to_lrank );
875- free (matching );
876902 goto release_and_return ;
877903 }
878904 /* end of TODO */
@@ -882,7 +908,6 @@ int mca_topo_treematch_dist_graph_create(mca_topo_base_module_t* topo_module,
882908 (* newcomm )-> c_topo = topo_module ;
883909 (* newcomm )-> c_topo -> reorder = reorder ;
884910
885- free (matching );
886911 free (grank_to_lrank );
887912 free (lrank_to_grank );
888913 } /* distributed reordering end */
0 commit comments