c++ - 如何禁用 MPI 的 C++ 包装器?

标签 c++ c openmpi

我的项目主要是 C 和 Fortran,但我必须在 C++ 文件中使用 MPI。我不想使用 C++ 包装器,也不想链接 libmpi_cxx.so,我只使用纯 C 接口(interface)。但是只要在我的 C++ 文件中包含 mpi.h 就足以让链接器提示缺少来自 libmpi_cxx.so 的引用:

h5pfc -g -lstdc++ *.o -o my_program
../bin/distance_to_wall.o: In function `MPI::Intracomm::Intracomm()':
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm.h:25: undefined reference to `MPI::Comm::Comm()'
../bin/distance_to_wall.o: In function `MPI::Intracomm::Intracomm(ompi_communicator_t*)':
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm_inln.h:23: undefined reference to `MPI::Comm::Comm()'
../bin/distance_to_wall.o: In function `MPI::Op::Init(void (*)(void const*, void*, int, MPI::Datatype const&), bool)':
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/op_inln.h:121: undefined reference to `ompi_mpi_cxx_op_intercept'
../bin/distance_to_wall.o:(.data.rel.ro._ZTVN3MPI3WinE[_ZTVN3MPI3WinE]+0x48): undefined reference to `MPI::Win::Free()'
../bin/distance_to_wall.o:(.data.rel.ro._ZTVN3MPI8DatatypeE[_ZTVN3MPI8DatatypeE]+0x78): undefined reference to `MPI::Datatype::Free()'
collect2: error: ld returned 1 exit status

添加 -lmpi_cxx 足以解决问题,但这似乎是为我没有得到的东西付费的情况(我不使用 MPI C++ 包装器),而且它似乎在不同的系统之间是可移植的MPI 实现,因为我必须明确列出 OpenMPI 依赖项,这违背了在第一种情况下使用编译器包装器的目的。

在 C++ 文件中包含 mpi.h 时,是否有 MPI 可移植的方法来禁用 C++ 接口(interface)?

最佳答案

它是特定于 Open MPI 的,但您应该能够通过定义宏 OMPI_SKIP_MPICXX 来禁用 C++ 接口(interface)。

参见:https://github.com/open-mpi/ompi/blob/master/ompi/include/mpi.h.in#L2716

关于c++ - 如何禁用 MPI 的 C++ 包装器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52899725/

相关文章:

C++重载<<运算符问题

c++ - printf 或任何输出函数实际上做了什么?

c - 对递归函数的多次调用的控制流程如何?

mpi - 玩具程序使用 OpenMPI 1.6 失败,但适用于 Mvapich2

java - OpenMPI Java 绑定(bind)行为差异(锁定、累积、获取)

c++ - vim 中意外的红色括号突出显示

c++ - 当我尝试输入值时程序崩溃

c - 警告 : assignment from incompatible pointer type [enabled by default]

c - 根据位置每 3 个元素从数组中删除元素

multithreading - InfiniBand:传输速率取决于MPI_Test *频率