我的项目主要是 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/