gethostname() function missing in openMPI
Asked Answered
S

1

1

I had to replace mpich2 with OpenMPI due to dependency of OpenFOAM on OpenMPI.

Earlier (when using mpich2) in my code I was using gethostname() function to get the name of the machine for debugging purpose. However this function does not seem to be a standard MPI function, and is not working anymore with OpenMPI libraries. Is there any other function for getting the host name in OpenMPI, or MPI standard? I am using mpicc for compiling and mpirun for running the code.

Thanks,

Sourabh

Squinteyed answered 4/3, 2014 at 14:37 Comment(4)
gethostname is not a standard MPI function. Are you confusing it with MPI_Get_processor_name which is ?Rosiarosicrucian
Actually gethostname() used to work earlier, after installing OpenMPI it stopped working. I just checked MPI_Get_processor_name() is working, Thanks.Squinteyed
The prototype of gethostname() is in unistd.h. How exactly is it not working with Open MPI?Proximity
I am not sure how! I had not included unistd.h but gethostname() was working when I was including only mpi.h and stdio.h The only explanation I have is that gethostname() might be defined inside some library in mpich2's mpi.h.Squinteyed
T
5

gethostname() is defined in unistd.h that was included by mpi.h, in the previous version. That's not a feature you should rely on, since you should always explicitly include the files which define the symbols you use. Clearly you were relying on it without realizing.

However if your MPI code is supposed to run on POSIX systems only, its safe to add

#include <unistd.h>

gethostname() is POSIX2001.1 standard.

However the MPI portable solution is MPI_Get_processor_name() as shown in the comment by High Performance Mark

Toggle answered 5/3, 2014 at 19:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.