openMPI中缺少gethostname()函数 [英] gethostname() function missing in openMPI

查看:179
本文介绍了openMPI中缺少gethostname()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于OpenFOAM对OpenMPI的依赖性,我不得不用OpenMPI替换mpich2.

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

在我的代码中(使用mpich2时)较早时,我正在使用gethostname()函数来获取用于调试目的的计算机名称.但是,此功能似乎不是标准的MPI功能,并且不能再与OpenMPI库一起使用.还有其他功能可用于获取OpenMPI或MPI标准中的主机名吗?我正在使用mpicc进行编译,并使用mpirun来运行代码.

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.

谢谢

苏拉布

推荐答案

gethostname()在先前版本的mpi.h所包含的unistd.h中定义.这不是您应该依赖的功能,因为您应该始终明确包含定义您使用的符号的文件.显然,您是依靠它而没有意识到.

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.

但是,如果您的MPI代码仅应在POSIX系统上运行,则可以安全添加

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

#include <unistd.h>

gethostname()是POSIX2001.1标准.

gethostname() is POSIX2001.1 standard.

然而,MPI便携式解决方案是MPI_Get_processor_name(),如高性能标记

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

这篇关于openMPI中缺少gethostname()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆