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

Categories

0 votes
162 views
in Technique[技术] by (71.8m points)

How to compile an MPI included c program using cmake

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?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

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

For MPI, you have to find mpi first

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})

and finally link your program(s) (which is my_mpi_target in my case)

 target_link_libraries(my_mpi_target ${MPI_C_LIBRARIES})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...