1
1

ompi: fixup hostname max length usage

Signed-off-by: Karol Mroz <mroz.karol@gmail.com>
Этот коммит содержится в:
Karol Mroz 2016-04-16 02:37:25 +02:00
родитель e1c64e6e59
Коммит 3322347da9
6 изменённых файлов: 13 добавлений и 13 удалений

Просмотреть файл

@ -95,7 +95,7 @@ opal_pointer_array_t ompi_info_f_to_c_table = {{0}};
*/ */
int ompi_info_init(void) int ompi_info_init(void)
{ {
char val[MPI_MAX_INFO_VAL]; char val[OPAL_MAXHOSTNAMELEN];
char *cptr; char *cptr;
/* initialize table */ /* initialize table */
@ -134,7 +134,7 @@ int ompi_info_init(void)
} }
/* local host name */ /* local host name */
gethostname(val, MPI_MAX_INFO_VAL); gethostname(val, sizeof(val));
ompi_info_set(&ompi_mpi_info_env.info, "host", val); ompi_info_set(&ompi_mpi_info_env.info, "host", val);
/* architecture name */ /* architecture name */

Просмотреть файл

@ -21,7 +21,7 @@
int pml_v_output_open(char *output, int verbosity) { int pml_v_output_open(char *output, int verbosity) {
opal_output_stream_t lds; opal_output_stream_t lds;
char hostname[32] = "NA"; char hostname[OPAL_MAXHOSTNAMELEN] = "NA";
OBJ_CONSTRUCT(&lds, opal_output_stream_t); OBJ_CONSTRUCT(&lds, opal_output_stream_t);
if(!output) { if(!output) {
@ -40,7 +40,7 @@ int pml_v_output_open(char *output, int verbosity) {
lds.lds_file_suffix = output; lds.lds_file_suffix = output;
} }
lds.lds_is_debugging = true; lds.lds_is_debugging = true;
gethostname(hostname, 32); gethostname(hostname, sizeof(hostname));
asprintf(&lds.lds_prefix, "[%s:%05d] pml_v: ", hostname, getpid()); asprintf(&lds.lds_prefix, "[%s:%05d] pml_v: ", hostname, getpid());
lds.lds_verbose_level = verbosity; lds.lds_verbose_level = verbosity;
mca_pml_v.output = opal_output_open(&lds); mca_pml_v.output = opal_output_open(&lds);

Просмотреть файл

@ -66,7 +66,7 @@ int MPI_Get_processor_name(char *name, int *resultlen)
Guard against gethostname() returning a *really long* hostname Guard against gethostname() returning a *really long* hostname
and not null-terminating the string. The Fortran API version and not null-terminating the string. The Fortran API version
will pad to the right if necessary. */ will pad to the right if necessary. */
gethostname(name, MPI_MAX_PROCESSOR_NAME - 1); gethostname(name, (MPI_MAX_PROCESSOR_NAME - 1));
name[MPI_MAX_PROCESSOR_NAME - 1] = '\0'; name[MPI_MAX_PROCESSOR_NAME - 1] = '\0';
*resultlen = (int) strlen(name); *resultlen = (int) strlen(name);

Просмотреть файл

@ -119,7 +119,7 @@ int
ompi_mpi_abort(struct ompi_communicator_t* comm, ompi_mpi_abort(struct ompi_communicator_t* comm,
int errcode) int errcode)
{ {
char *msg, *host, hostname[MAXHOSTNAMELEN]; char *msg, *host, hostname[OPAL_MAXHOSTNAMELEN];
pid_t pid = 0; pid_t pid = 0;
/* Protection for recursive invocation */ /* Protection for recursive invocation */

Просмотреть файл

@ -113,7 +113,7 @@ int ompi_mpi_finalize(void)
/* Note that if we're not initialized or already finalized, we /* Note that if we're not initialized or already finalized, we
cannot raise an MPI exception. The best that we can do is cannot raise an MPI exception. The best that we can do is
write something to stderr. */ write something to stderr. */
char hostname[MAXHOSTNAMELEN]; char hostname[OPAL_MAXHOSTNAMELEN];
pid_t pid = getpid(); pid_t pid = getpid();
gethostname(hostname, sizeof(hostname)); gethostname(hostname, sizeof(hostname));

Просмотреть файл

@ -74,7 +74,7 @@ int main(int argc, char **argv)
MPI_Comm comm = MPI_COMM_WORLD; MPI_Comm comm = MPI_COMM_WORLD;
int rank, commsize; int rank, commsize;
double offs = 0, rtt = 0; double offs = 0, rtt = 0;
char hname[1024]; char hname[OPAL_MAXHOSTNAMELEN];
MPI_Comm_rank(comm, &rank); MPI_Comm_rank(comm, &rank);
MPI_Comm_size(comm, &commsize); MPI_Comm_size(comm, &commsize);
@ -98,7 +98,7 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if( gethostname(hname, 1024) ){ if( gethostname(hname, sizeof(hname)) ){
perror("Cannot get hostname. Abort"); perror("Cannot get hostname. Abort");
MPI_Abort(MPI_COMM_WORLD, 1); MPI_Abort(MPI_COMM_WORLD, 1);
} }
@ -129,13 +129,13 @@ int main(int argc, char **argv)
fprintf(stderr, "Fail to allocate memory. Abort\n"); fprintf(stderr, "Fail to allocate memory. Abort\n");
MPI_Abort(MPI_COMM_WORLD, 1); MPI_Abort(MPI_COMM_WORLD, 1);
} }
char *hnames = malloc(1024*commsize); char *hnames = malloc(OPAL_MAXHOSTNAMELEN * commsize);
if( hnames == NULL ){ if( hnames == NULL ){
fprintf(stderr, "Fail to allocate memory. Abort\n"); fprintf(stderr, "Fail to allocate memory. Abort\n");
MPI_Abort(MPI_COMM_WORLD, 1); MPI_Abort(MPI_COMM_WORLD, 1);
} }
MPI_Gather(hname,1024,MPI_CHAR,hnames,1024,MPI_CHAR, 0, MPI_COMM_WORLD); MPI_Gather(hname,sizeof(hname),MPI_CHAR,hnames,sizeof(hname),MPI_CHAR, 0, MPI_COMM_WORLD);
MPI_Gather(send,2,MPI_DOUBLE,measure,2, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Gather(send,2,MPI_DOUBLE,measure,2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
char tmpname[128]; char tmpname[128];
FILE *fp = fopen(filename,"w"); FILE *fp = fopen(filename,"w");
@ -144,7 +144,7 @@ int main(int argc, char **argv)
MPI_Abort(MPI_COMM_WORLD, 1); MPI_Abort(MPI_COMM_WORLD, 1);
} }
double (*m)[2] = (void*)measure; double (*m)[2] = (void*)measure;
char (*h)[1024] = (void*)hnames; char (*h)[OPAL_MAXHOSTNAMELEN] = (void*)hnames;
int i; int i;
fprintf(fp, "# Used algorithm: %s\n", (alg ? "binary tree" : "linear")); fprintf(fp, "# Used algorithm: %s\n", (alg ? "binary tree" : "linear"));
for(i=0; i<commsize;i++){ for(i=0; i<commsize;i++){
@ -152,7 +152,7 @@ int main(int argc, char **argv)
} }
fclose(fp); fclose(fp);
} else { } else {
MPI_Gather(hname,1024, MPI_CHAR, NULL, 1024, MPI_CHAR, 0, MPI_COMM_WORLD); MPI_Gather(hname, sizeof(hname), MPI_CHAR, NULL, sizeof(hname), MPI_CHAR, 0, MPI_COMM_WORLD);
MPI_Gather(send,2, MPI_DOUBLE, NULL, 2, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Gather(send,2, MPI_DOUBLE, NULL, 2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
} }