[CMake] MPI Compilers

Todd Gamblin tgamblin at llnl.gov
Wed Jul 6 16:46:13 EDT 2011


Hi Tim,

> How do we tell the project to use the compilers found by FindMPI?

Compiler detection in CMake currently happens before FindMPI and I'm not sure whether it makes sense to force that to happen after FindMPI runs.  The expectation is that the user will supply the matching compiler in a toolchain file or during configuration by setting CMAKE_<lang>_COMPILER to one that matches MPI_<lang>_COMPILER.

> On the master branch, FindMPI has been modified to create MPI_<LANG>_COMPILER, etc.., but how does one then specify that it should be used rather than the CMAKE_<LANG>_COMPILER?


There are three methods outlined in the FAQ:

	http://www.cmake.org/Wiki/CMake_FAQ#How_do_I_use_a_different_compiler.3F

I've seen projects that use method 3 if they want to use the MPI compilers, and I suspect that this is what you're looking for.  But I'm not sure if that is the best option.

CMake's FindMPI is designed to make MPI look like any other library by extracting args from the various compilers, so you've got these variables:

	MPI_<lang>_INCLUDE_PATH
	MPI_<lang>_LIBRARIES
	MPI_<lang>_COMPILE_FLAGS
	MPI_<lang>_LINK_FLAGS

You can use the first two with include_directories and target_link_libraries to get things building with MPI, and if you need the specific compile and link flags (which is generally a good practice) you can add those to your project with set_target_properties and these properties:

	http://www.cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:COMPILE_FLAGS
	http://www.cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:LINK_FLAGS

If whoever builds your project supplies matching sequential and MPI compilers, things should build fine and you won't need to use the MPI compiler directly.  On BlueGene I have two toolchain files that know where to look for the xl or gcc compilers and the matching MPI compilers.

Regarding this:

> Along similar lines, we have it currently working with:
> 
>  find_package(MPI REQUIRED)
>    include(CMakeForceCompiler)
>    CMAKE_FORCE_C_COMPILER(mpicc ${CMAKE_C_COMPILER_ID})
>    CMAKE_FORCE_CXX_COMPILER(mpicxx ${CMAKE_CXX_COMPILER_ID})
>    CMAKE_FORCE_Fortran_COMPILER(mpif90 ${CMAKE_Fortran_COMPILER_ID})
> 
> Which works, but I can't find where the compile flags are coming from. It's not using CMAKE_Fortran_FLAGS_*, but it does change it's flags based on the build type. Anybody have any idea how to set the flags?


I'm not sure what you're seeing that changes with the build type, and I don't have a lot of experience with CMakeForceCompiler, so I'll defer to others on that.

-Todd


On Jul 6, 2011, at 9:41 AM, Tim Gallagher wrote:

> Along similar lines, we have it currently working with:
> 
>  find_package(MPI REQUIRED)
>    include(CMakeForceCompiler)
>    CMAKE_FORCE_C_COMPILER(mpicc ${CMAKE_C_COMPILER_ID})
>    CMAKE_FORCE_CXX_COMPILER(mpicxx ${CMAKE_CXX_COMPILER_ID})
>    CMAKE_FORCE_Fortran_COMPILER(mpif90 ${CMAKE_Fortran_COMPILER_ID})
> 
> Which works, but I can't find where the compile flags are coming from. It's not using CMAKE_Fortran_FLAGS_*, but it does change it's flags based on the build type. Anybody have any idea how to set the flags?
> 
> Tim
> 
> ----- Original Message -----
> From: "Tim Gallagher" <tim.gallagher at gatech.edu>
> To: cmake at cmake.org
> Sent: Wednesday, July 6, 2011 12:31:49 PM
> Subject: [CMake] MPI Compilers
> 
> Hi,
> 
> How do we tell the project to use the compilers found by FindMPI? On the master branch, FindMPI has been modified to create MPI_<LANG>_COMPILER, etc.., but how does one then specify that it should be used rather than the CMAKE_<LANG>_COMPILER?
> 
> Tim
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

______________________________________________________________________
Todd Gamblin, tgamblin at llnl.gov, http://people.llnl.gov/gamblin2
CASC @ Lawrence Livermore National Laboratory, Livermore, CA, USA



More information about the CMake mailing list