Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
316 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...