[CMake] Using MPI and non-MPI compiler in the same cmake project?
Tim Gallagher
tim.gallagher at gatech.edu
Tue Jun 26 09:20:12 EDT 2012
Don't change the compiler.
Do:
find_package(MPI REQUIRED)
add_definitions(${MPI_Fortran_COMPILE_FLAGS})
include_directories(${MPI_Fortran_INCLUDE_DIRS})
link_directories(${MPI_Fortran_LIBRARY_DIRS})
target_link_libraries(<parallel code> ${MPI_Fortran_LIBRARIES})
if(MPI_EXTRA_LIBRARY)
target_link_libraries(<parallel code> ${MPI_EXTRA_LIBRARY})
endif()
get_target_property(CURRENT_LINK_FLAGS <parallel code> LINK_FLAGS)
if(CURRENT_LINK_FLAGS)
set(MY_MPI_LINK_FLAGS "${CURRENT_LINK_FLAGS};${MPI_Fortran_LINK_FLAGS}")
else()
set(MY_MPI_LINK_FLAGS "${MPI_Fortran_LINK_FLAGS}")
endif()
if(MY_MPI_LINK_FLAGS)
set_target_properties(<parallel code> PROPERTIES LINK_FLAGS ${MY_MPI_LINK_FLAGS})
endif()
This way, you still use ifort to do the compilation but you add all the MPI required flags and libraries to the parallel code only. Any other targets that aren't parallel don't get the MPI libraries.
The only reason FindMPI locates the executable is to get the flags for you, you don't actually want to use that as the compiler. If you wanted it as the compiler, you should do FC=f90mpi ccmake .... instead and not even call find_package(MPI). You don't want to change the compiler variable once it's been set by CMake.
Tim
----- Original Message -----
From: "Eli Ateljevich" <eli at water.ca.gov>
To: cmake at cmake.org
Sent: Monday, June 25, 2012 10:43:03 PM
Subject: [CMake] Using MPI and non-MPI compiler in the same cmake project?
Hi all,
My project is mostly built with Fortran that uses mpif90 as a wrapper. I use find_package(MPI REQUIRED) to locate f90mpi and then change set the CMAKE_Fortran_COMPILER to ${MPI_Fortran_COMPILER}.
This seemed to work fine until started wrapping up some utilities that do not need to be parallelized. The MPI compiler seems to take quite a bit longer to compile than the serial compiler (ifort). The utilities that would be appropriate for serial compilation have a slighlty different extension (f90 instead of F90).
I realize it is unusual to maintain two compilers for the same language , but in this case the two are related as "mpi wrapper" and "wrapee". There seem to be a few possibilities:
1. Maintain a variable that refers to the compiler and flags for serial and switch to them for just the utilities. Is this even legal? Can I change CMAKE_Fortran_COMPILER at the file or library scope? Could I create a custom rule that somehow inherits from the Fortran rule or is this a can of worms?
2. Never switch to mpiwrapper, but instead make us of the libraries it finds. I have seen this technique referenced more than I have seen the use of mpif90, but I don't know what aspects of mpif90 might get left out by doing this. How would I maintain two sets of flags ... is there an easy way to override flags on a per-target or per-file basis?
Or is there a better way entirely?
Thanks so much,
Eli
--
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
More information about the CMake
mailing list