1
1
/*
2
- * Copyright (c) 2016-2020 IBM Corporation. All rights reserved.
2
+ * Copyright (c) 2016-2022 IBM Corporation. All rights reserved.
3
3
* $COPYRIGHT$
4
4
*
5
5
* Additional copyrights may follow
22
22
#include "ompi/mca/bml/base/base.h"
23
23
#include "ompi/mca/mtl/base/base.h"
24
24
25
- static void
26
- mystrncpy (char * to , const char * from , int n ) {
27
- snprintf (to , n , "%s" , from );
28
- }
29
-
30
25
// For converting comm_method strings to comm_method id# and back.
31
26
// This starts as our local set of strings, but gets Allreduced into
32
27
// a global mapping so all the strings at all the ranks are represented.
@@ -44,6 +39,9 @@ static comm_method_string_conversion_t comm_method_string_conversion;
44
39
#define MODE_IS_MTL 2
45
40
#define MODE_IS_BTL 3
46
41
42
+ #define CALLED_FROM_MPI_INIT 1
43
+ #define CALLED_FROM_MPI_FINALIZE 2
44
+
47
45
// ----------------------------------------------------------------------------
48
46
49
47
// return the pml's module:component:name function pointer in fp
@@ -64,6 +62,10 @@ static char*
64
62
lookup_btl_name_for_send (ompi_communicator_t * comm , int rank ) {
65
63
ompi_proc_t * dst_proc = ompi_group_peer_lookup_existing (comm -> c_remote_group , rank );
66
64
65
+ if (NULL == dst_proc ) {
66
+ return NULL ;
67
+ }
68
+
67
69
mca_bml_base_endpoint_t * endpoint = mca_bml_base_get_endpoint (dst_proc );
68
70
if (endpoint &&
69
71
endpoint -> btl_send .bml_btls &&
@@ -84,22 +86,27 @@ lookup_btl_name_for_send(ompi_communicator_t* comm, int rank) {
84
86
// that the caller has to free.
85
87
static char *
86
88
comm_method_string (MPI_Comm comm , int rank , int * comm_mode ) {
87
- char * p ;
89
+ char * p , * btl ;
88
90
char * string = malloc (COMM_METHOD_STRING_SIZE );
89
91
90
92
if (!string ) { return NULL ; }
91
93
92
94
p = lookup_pml_name ();
93
95
if (p && 0 == strncmp ("ob1" , p , 4 )) { // BTL
94
96
if (comm_mode ) { * comm_mode = MODE_IS_BTL ; }
95
- mystrncpy (string , lookup_btl_name_for_send (comm , rank ), COMM_METHOD_STRING_SIZE );
97
+ btl = lookup_btl_name_for_send (comm , rank );
98
+ if (NULL == btl ) {
99
+ strncpy (string , "n/a" , COMM_METHOD_STRING_SIZE );
100
+ } else {
101
+ strncpy (string , btl , COMM_METHOD_STRING_SIZE );
102
+ }
96
103
}
97
104
else if (p && 0 == strncmp ("cm" , p , 3 )) { // MTL
98
105
if (comm_mode ) { * comm_mode = MODE_IS_MTL ; }
99
- mystrncpy (string , lookup_mtl_name (), COMM_METHOD_STRING_SIZE );
106
+ strncpy (string , lookup_mtl_name (), COMM_METHOD_STRING_SIZE );
100
107
} else { // PML
101
108
if (comm_mode ) { * comm_mode = MODE_IS_PML ; }
102
- mystrncpy (string , p , COMM_METHOD_STRING_SIZE );
109
+ strncpy (string , p , COMM_METHOD_STRING_SIZE );
103
110
}
104
111
return string ;
105
112
}
@@ -144,12 +151,12 @@ static void
144
151
add_string_to_conversion_struct (comm_method_string_conversion_t * data , char * string )
145
152
{
146
153
int i ;
147
- if (0 == strcmp (string , "n/a" )) { return ; }
154
+ if (NULL == string || 0 == strcmp (string , "n/a" )) { return ; }
148
155
149
156
i = lookup_string_in_conversion_struct (data , string );
150
157
if (i == 0 ) { // didn't find string in list, so add it
151
158
if (data -> n < MAX_COMM_METHODS ) {
152
- mystrncpy (data -> str [data -> n ], string , COMM_METHOD_STRING_SIZE );
159
+ strncpy (data -> str [data -> n ], string , COMM_METHOD_STRING_SIZE );
153
160
++ (data -> n );
154
161
}
155
162
}
@@ -214,14 +221,14 @@ static void ompi_report_comm_methods(int called_from_location);
214
221
void ompi_hook_comm_method_mpi_init_bottom (int argc , char * * argv , int requested , int * provided )
215
222
{
216
223
if ( mca_hook_comm_method_enable_mpi_init ) {
217
- ompi_report_comm_methods ( 1 );
224
+ ompi_report_comm_methods ( CALLED_FROM_MPI_INIT );
218
225
}
219
226
}
220
227
221
228
void ompi_hook_comm_method_mpi_finalize_top (void )
222
229
{
223
230
if ( mca_hook_comm_method_enable_mpi_finalize ) {
224
- ompi_report_comm_methods ( 2 );
231
+ ompi_report_comm_methods ( CALLED_FROM_MPI_FINALIZE );
225
232
}
226
233
}
227
234
@@ -312,7 +319,7 @@ abbreviate_list_into_string(char *str, int max, int *list, int nlist)
312
319
// When activated from init: we establish connections before printing.
313
320
// When activated from finalize: we just print whatever info is available.
314
321
static void
315
- ompi_report_comm_methods (int called_from_location ) // 1 = from init, 2 = from finalize
322
+ ompi_report_comm_methods (int called_from_location )
316
323
{
317
324
int numhosts , i , j , k ;
318
325
int max2Dprottable = 12 ;
@@ -416,7 +423,7 @@ ompi_report_comm_methods(int called_from_location) // 1 = from init, 2 = from fi
416
423
417
424
// If we're running during init, establish connections between all peers
418
425
// (in leader_comm, which is all the ranks that are here at this point)
419
- if (called_from_location == 1 ) {
426
+ if (CALLED_FROM_MPI_INIT == called_from_location ) {
420
427
for (i = 0 ; i <=nleaderranks /2 ; ++ i ) {
421
428
// (Examples to show why the loop is i<=nleaderranks/2)
422
429
// np4 : 0 1 2 3 i=0 0c0 i=1 0c0&1&3 i=2 0c0&1&3&2
0 commit comments