@@ -74,7 +74,7 @@ int main(int argc, char **argv)
7474 MPI_Comm comm = MPI_COMM_WORLD ;
7575 int rank , commsize ;
7676 double offs = 0 , rtt = 0 ;
77- char hname [1024 ];
77+ char hname [OPAL_MAXHOSTNAMELEN ];
7878
7979 MPI_Comm_rank (comm , & rank );
8080 MPI_Comm_size (comm , & commsize );
@@ -98,7 +98,7 @@ int main(int argc, char **argv)
9898 exit (1 );
9999 }
100100
101- if ( gethostname (hname , 1024 ) ){
101+ if ( gethostname (hname , sizeof ( hname ) ) ){
102102 perror ("Cannot get hostname. Abort" );
103103 MPI_Abort (MPI_COMM_WORLD , 1 );
104104 }
@@ -129,13 +129,13 @@ int main(int argc, char **argv)
129129 fprintf (stderr , "Fail to allocate memory. Abort\n" );
130130 MPI_Abort (MPI_COMM_WORLD , 1 );
131131 }
132- char * hnames = malloc (1024 * commsize );
132+ char * hnames = malloc (OPAL_MAXHOSTNAMELEN * commsize );
133133 if ( hnames == NULL ){
134134 fprintf (stderr , "Fail to allocate memory. Abort\n" );
135135 MPI_Abort (MPI_COMM_WORLD , 1 );
136136 }
137137
138- MPI_Gather (hname ,1024 ,MPI_CHAR ,hnames ,1024 ,MPI_CHAR , 0 , MPI_COMM_WORLD );
138+ MPI_Gather (hname ,sizeof ( hname ) ,MPI_CHAR ,hnames ,sizeof ( hname ) ,MPI_CHAR , 0 , MPI_COMM_WORLD );
139139 MPI_Gather (send ,2 ,MPI_DOUBLE ,measure ,2 , MPI_DOUBLE , 0 , MPI_COMM_WORLD );
140140 char tmpname [128 ];
141141 FILE * fp = fopen (filename ,"w" );
@@ -144,15 +144,15 @@ int main(int argc, char **argv)
144144 MPI_Abort (MPI_COMM_WORLD , 1 );
145145 }
146146 double (* m )[2 ] = (void * )measure ;
147- char (* h )[1024 ] = (void * )hnames ;
147+ char (* h )[OPAL_MAXHOSTNAMELEN ] = (void * )hnames ;
148148 int i ;
149149 fprintf (fp , "# Used algorithm: %s\n" , (alg ? "binary tree" : "linear" ));
150150 for (i = 0 ; i < commsize ;i ++ ){
151151 fprintf (fp , "%s %lf %lf\n" , h [i ], m [i ][0 ], m [i ][1 ]);
152152 }
153153 fclose (fp );
154154 } else {
155- MPI_Gather (hname ,1024 , MPI_CHAR , NULL , 1024 , MPI_CHAR , 0 , MPI_COMM_WORLD );
155+ MPI_Gather (hname , sizeof ( hname ) , MPI_CHAR , NULL , sizeof ( hname ) , MPI_CHAR , 0 , MPI_COMM_WORLD );
156156 MPI_Gather (send ,2 , MPI_DOUBLE , NULL , 2 , MPI_DOUBLE , 0 , MPI_COMM_WORLD );
157157 }
158158
0 commit comments