[CMake] Use of mpi compiler / FINDMPI.cmake
James C. Sutherland
James.Sutherland at utah.edu
Tue Dec 8 10:17:46 EST 2009
On Dec 8, 2009, at 4:09 AM, Olivier Pierard wrote:
> Dear all,
>
> I'm a little bit confused with the use of findmpi.cmake. Does anyone
> has an example of its usage (for compilation, not yet for running) ?
>
> Since we have two mpi implementations (mpich and openmpi-ib), I set the
> compiler as indicated in the preamble of the module and the library to
> not found:
> set(MPI_COMPILER ${MPI_ROOT}/bin/mpicxx)
> set(MPI_LIBRARY MPI_LIBRARY-NOTFOUND)
> find_package(MPI)
>
This is what I do, but I don't set MPI_LIBRARY to "not-found".
>
> Cache variables are well set for MPI but not for MPIEXEC (but I don't
> care for the moment, it's in a non-standard location):
> MPIEXEC MPIEXEC-NOTFOUND
> MPIEXEC_MAX_NUMPROCS 2
> MPIEXEC_NUMPROC_FLAG -np
> MPIEXEC_POSTFLAGS
> MPIEXEC_PREFLAGS
> MPI_COMPILE_FLAGS
> MPI_EXTRA_LIBRARY
> /softs/openmpi-ib/1.2.8-1/64/gcc/4.1.2/lib64/libmpi.so;/softs/openmpi
> MPI_INCLUDE_PATH
> /softs/openmpi-ib/1.2.8-1/64/gcc/4.1.2/include
> MPI_LIBRARY
> /softs/openmpi-ib/1.2.8-1/64/gcc/4.1.2/lib64/libmpi_cxx.so
> MPI_LINK_FLAGS -Wl,-rpath
> -Wl,/softs/openmpi-ib/1.2.8-1/64/gcc/4.1.2/lib64 -Wl,--exp
>
> Now, what do I have to do with these variables ?
I just compile as usual, and put the MPI_LIBRARY in the link line via target_link_libraries(...)
Then also put MPI_INCLUDE_PATH in the include path via include_directories(...)
The MPIEXEC, MPIEXEC_MAX_NUMPROCS, MPIEXEC_NUMPROC_FLAG are useful if you need to run tests through CTest. They allow you a generic, cross-platform way of doing this.
>
> More precisely, how can I force the use of the MPI_COMPILER ? Do I have
> to set the CMAKE_CXX_COMPILER to MPI_COMPILER value ? If yes, how can I
> force it because it is initially set to /usr/bin/c++ (I've a cache
> option to switch on/off sequential/parallel mode) and it seems
> impossible to modify CMAKE_CXX_COMPILER once the variable is set (by the
> way, when is it exectly initialized, with enable_language ?). If that's
> the way, I imagine I've to append MPI_LIBRARY, MPI_COMPILE_FLAGS,
> MPI_LINK_FLAGS,... to default flags, include dirs,...
>
I don't touch any of the compiler flags. This seems to work for me.
More information about the CMake
mailing list