@@ -69,7 +69,7 @@ int main(int argc, char **argv)
6969 MPI_Comm comm = MPI_COMM_WORLD ;
7070 int rank , commsize ;
7171 double offs = 0 , rtt = 0 ;
72- char hname [1024 ];
72+ char hname [OPAL_MAXHOSTNAMELEN ];
7373
7474 MPI_Comm_rank (comm , & rank );
7575 MPI_Comm_size (comm , & commsize );
@@ -93,7 +93,7 @@ int main(int argc, char **argv)
9393 exit (1 );
9494 }
9595
96- if ( gethostname (hname , 1024 ) ){
96+ if ( gethostname (hname , sizeof ( hname ) ) ){
9797 perror ("Cannot get hostname. Abort" );
9898 MPI_Abort (MPI_COMM_WORLD , 1 );
9999 }
@@ -114,13 +114,13 @@ int main(int argc, char **argv)
114114 fprintf (stderr , "Fail to allocate memory. Abort\n" );
115115 MPI_Abort (MPI_COMM_WORLD , 1 );
116116 }
117- char * hnames = malloc (1024 * commsize );
117+ char * hnames = malloc (OPAL_MAXHOSTNAMELEN * commsize );
118118 if ( hnames == NULL ){
119119 fprintf (stderr , "Fail to allocate memory. Abort\n" );
120120 MPI_Abort (MPI_COMM_WORLD , 1 );
121121 }
122122
123- MPI_Gather (hname ,1024 ,MPI_CHAR ,hnames ,1024 ,MPI_CHAR , 0 , MPI_COMM_WORLD );
123+ MPI_Gather (hname ,sizeof ( hname ) ,MPI_CHAR ,hnames ,sizeof ( hname ) ,MPI_CHAR , 0 , MPI_COMM_WORLD );
124124 MPI_Gather (send ,2 ,MPI_DOUBLE ,measure ,2 , MPI_DOUBLE , 0 , MPI_COMM_WORLD );
125125 char tmpname [128 ];
126126 FILE * fp = fopen (filename ,"w" );
@@ -129,14 +129,14 @@ int main(int argc, char **argv)
129129 MPI_Abort (MPI_COMM_WORLD , 1 );
130130 }
131131 double (* m )[2 ] = (void * )measure ;
132- char (* h )[1024 ] = (void * )hnames ;
132+ char (* h )[OPAL_MAXHOSTNAMELEN ] = (void * )hnames ;
133133 int i ;
134134 for (i = 0 ; i < commsize ;i ++ ){
135135 fprintf (fp , "%s %lf %lf\n" , h [i ], m [i ][0 ], m [i ][1 ]);
136136 }
137137 fclose (fp );
138138 } else {
139- MPI_Gather (hname ,1024 , MPI_CHAR , NULL , 1024 , MPI_CHAR , 0 , MPI_COMM_WORLD );
139+ MPI_Gather (hname , sizeof ( hname ) , MPI_CHAR , NULL , sizeof ( hname ) , MPI_CHAR , 0 , MPI_COMM_WORLD );
140140 MPI_Gather (send ,2 , MPI_DOUBLE , NULL , 2 , MPI_DOUBLE , 0 , MPI_COMM_WORLD );
141141 }
142142
0 commit comments