@@ -795,7 +795,7 @@ static int prepare_device_for_use_nolock (mca_btl_openib_device_t *device)
795795}
796796
797797static int init_ib_proc_nolock (mca_btl_openib_module_t * openib_btl , mca_btl_openib_proc_t * ib_proc ,
798- mca_btl_base_endpoint_t * * endpoint_ptr ,
798+ volatile mca_btl_base_endpoint_t * * endpoint_ptr ,
799799 int local_port_cnt , int btl_rank )
800800{
801801 int rem_port_cnt , matching_port = -1 , j , rc ;
@@ -944,6 +944,22 @@ static int init_ib_proc_nolock(mca_btl_openib_module_t* openib_btl, mca_btl_open
944944 return OPAL_SUCCESS ;
945945}
946946
947+ static int get_openib_btl_params (mca_btl_openib_module_t * openib_btl , int * port_cnt_ptr )
948+ {
949+ int port_cnt = 0 , rank = -1 , j ;
950+ for (j = 0 ; j < mca_btl_openib_component .ib_num_btls ; j ++ ){
951+ if (mca_btl_openib_component .openib_btls [j ]-> port_info .subnet_id
952+ == openib_btl -> port_info .subnet_id ) {
953+ if (openib_btl == mca_btl_openib_component .openib_btls [j ]) {
954+ rank = port_cnt ;
955+ }
956+ port_cnt ++ ;
957+ }
958+ }
959+ * port_cnt_ptr = port_cnt ;
960+ return rank ;
961+ }
962+
947963/*
948964 * add a proc to this btl module
949965 * creates an endpoint that is setup on the
@@ -960,16 +976,11 @@ int mca_btl_openib_add_procs(
960976 int i ,j , rc , local_procs ;
961977 int lcl_subnet_id_port_cnt = 0 ;
962978 int btl_rank = 0 ;
963- mca_btl_base_endpoint_t * endpoint ;
979+ volatile mca_btl_base_endpoint_t * endpoint ;
964980
965- for (j = 0 ; j < mca_btl_openib_component .ib_num_btls ; j ++ ){
966- if (mca_btl_openib_component .openib_btls [j ]-> port_info .subnet_id
967- == openib_btl -> port_info .subnet_id ) {
968- if (openib_btl == mca_btl_openib_component .openib_btls [j ]) {
969- btl_rank = lcl_subnet_id_port_cnt ;
970- }
971- lcl_subnet_id_port_cnt ++ ;
972- }
981+ btl_rank = get_openib_btl_params (openib_btl , & lcl_subnet_id_port_cnt );
982+ if ( 0 > btl_rank ){
983+ return OPAL_ERR_NOT_FOUND ;
973984 }
974985
975986#if HAVE_XRC
@@ -1056,7 +1067,7 @@ int mca_btl_openib_add_procs(
10561067 if (reachable ) {
10571068 opal_bitmap_set_bit (reachable , i );
10581069 }
1059- peers [i ] = endpoint ;
1070+ peers [i ] = ( mca_btl_base_endpoint_t * ) endpoint ;
10601071 }
10611072
10621073 }
@@ -1072,9 +1083,9 @@ int mca_btl_openib_add_procs(
10721083struct mca_btl_base_endpoint_t * mca_btl_openib_get_ep (struct mca_btl_base_module_t * btl , struct opal_proc_t * proc )
10731084{
10741085 mca_btl_openib_module_t * openib_btl = (mca_btl_openib_module_t * ) btl ;
1075- mca_btl_base_endpoint_t * endpoint = NULL ;
1086+ volatile mca_btl_base_endpoint_t * endpoint = NULL ;
10761087 mca_btl_openib_proc_t * ib_proc ;
1077- int j , rc ;
1088+ int rc ;
10781089 int local_port_cnt = 0 , btl_rank ;
10791090 bool is_new ;
10801091
@@ -1114,14 +1125,10 @@ struct mca_btl_base_endpoint_t *mca_btl_openib_get_ep (struct mca_btl_base_modul
11141125 }
11151126
11161127 endpoint = NULL ;
1117- for (j = 0 ; j < mca_btl_openib_component .ib_num_btls ; j ++ ){
1118- if (mca_btl_openib_component .openib_btls [j ]-> port_info .subnet_id
1119- == openib_btl -> port_info .subnet_id ) {
1120- if (openib_btl == mca_btl_openib_component .openib_btls [j ]) {
1121- btl_rank = local_port_cnt ;
1122- }
1123- local_port_cnt ++ ;
1124- }
1128+
1129+ btl_rank = get_openib_btl_params (openib_btl , & local_port_cnt );
1130+ if ( 0 > btl_rank ){
1131+ goto exit ;
11251132 }
11261133
11271134 (void )init_ib_proc_nolock (openib_btl , ib_proc , & endpoint ,
@@ -1130,14 +1137,15 @@ struct mca_btl_base_endpoint_t *mca_btl_openib_get_ep (struct mca_btl_base_modul
11301137exit :
11311138 opal_mutex_unlock (& ib_proc -> proc_lock );
11321139
1133- if (is_new && OPAL_PROC_ON_LOCAL_NODE (proc -> proc_flags )) {
1140+ if ( (NULL != endpoint ) && is_new &&
1141+ OPAL_PROC_ON_LOCAL_NODE (proc -> proc_flags )) {
11341142 opal_mutex_lock (& openib_btl -> ib_lock );
11351143 openib_btl -> local_procs += 1 ;
11361144 openib_btl -> device -> mem_reg_max = openib_btl -> device -> mem_reg_max_total / openib_btl -> local_procs ;
11371145 opal_mutex_unlock (& openib_btl -> ib_lock );
11381146 }
11391147
1140- return endpoint ;
1148+ return ( struct mca_btl_base_endpoint_t * ) endpoint ;
11411149}
11421150
11431151/*
0 commit comments