如何使用 cmake 编译包含 MPI 的 c 程序 [英] How to compile an MPI included c program using cmake
问题描述
我正在尝试将 openmp 和 mpi 技术应用于需要构建cmake .&&make"的开源 C 程序.我已经在 How to set linkerCMake 的 try_compile 函数中的 OpenMP 标志 如何包含 -fopenmp 标志但仍然对 mpi 感到困惑.我该怎么办?
I am trying to apply openmp and mpi techniques to an open source C program which requires "cmake . && make" to be built. I already found at How to set linker flags for OpenMP in CMake's try_compile function how to include the -fopenmp flags but still confused about mpi. What can I do about that?
推荐答案
OpenMP
这是关于 OpenMP 的问题吗?然后你所要做的就是使用 -fopenmp
编译,你可以通过将它附加到 CMAKE_C_FLAGS
来完成,例如:
OpenMP
Is this a question about OpenMP? Then all you have to do is compile with -fopenmp
which you can do by appending it to CMAKE_C_FLAGS
, for example:
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp)
MPI
对于MPI,必须先找到mpi
find_package(MPI) #make it REQUIRED, if you want
然后将其头文件添加到您的搜索路径
then add it's header files to your search path
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
最后链接你的程序(在我的例子中是 my_mpi_target
)
and finally link your program(s) (which is my_mpi_target
in my case)
target_link_libraries(my_mpi_target ${MPI_C_LIBRARIES})
这篇关于如何使用 cmake 编译包含 MPI 的 c 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!