[CMake] CMake + MPI

Chuck Atkins chuck.atkins at kitware.com
Wed Sep 9 11:11:27 EDT 2015


>
> The only exception to that (which I am aware of) is if you are on a CRAY
> system where the MPI (and BLAS and LAPACK) are baked into the compiler
> wrappers (cc, ftn, etc). In those situations, you actually do not want to
> run find_package(MPI) or it will throw errors.
>

Not true.  The FindMPI.cmake module performs the appropriate introspection
to check if your primary compiler wraps accordingly.  For example, on a
Cray XC30, with the PrgEnv-pgi and cray-mpich modules loaded:

p02064 at swan:~/Code/tmp/build> cat ../source/CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(TestMPI C CXX)

find_package(MPI REQUIRED)

add_executable(test-mpi-c test-mpi.c)
target_include_directories(test-mpi-c PRIVATE ${MPI_C_INCLUDE_PATH})
target_link_libraries(test-mpi-c ${MPI_C_LIBRARIES})

add_executable(test-mpi-cxx test-mpi.cxx)
target_include_directories(test-mpi-cxx PRIVATE ${MPI_CXX_INCLUDE_PATH})
target_link_libraries(test-mpi-cxx ${MPI_CXX_LIBRARIES})
p02064 at swan:~/Code/tmp/build>

p02064 at swan:~/Code/tmp/build> cmake ../source
-- The C compiler identification is PGI 15.7.0
-- The CXX compiler identification is PGI 15.7.0
-- Check for working C compiler: /opt/cray/craype/2.4.1/bin/cc
-- Check for working C compiler: /opt/cray/craype/2.4.1/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /opt/cray/craype/2.4.1/bin/CC
-- Check for working CXX compiler: /opt/cray/craype/2.4.1/bin/CC -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found MPI_C: /opt/cray/craype/2.4.1/bin/cc
-- Found MPI_CXX: /opt/cray/craype/2.4.1/bin/CC
-- Configuring done
-- Generating done
-- Build files have been written to: /home/users/p02064/Code/tmp/build
p02064 at swan:~/Code/tmp/build>

p02064 at swan:~/Code/tmp/build> grep '^MPI_.*' CMakeCache.txt | grep -v
INTERNAL
MPI_CXX_COMPILER:STRING=/opt/cray/craype/2.4.1/bin/CC
MPI_CXX_COMPILE_FLAGS:STRING=
MPI_CXX_INCLUDE_PATH:STRING=
MPI_CXX_LIBRARIES:STRING=
MPI_CXX_LINK_FLAGS:STRING=
MPI_CXX_NO_INTERROGATE:STRING=/opt/cray/craype/2.4.1/bin/CC
MPI_C_COMPILER:STRING=/opt/cray/craype/2.4.1/bin/cc
MPI_C_COMPILE_FLAGS:STRING=
MPI_C_INCLUDE_PATH:STRING=
MPI_C_LIBRARIES:STRING=
MPI_C_LINK_FLAGS:STRING=
MPI_C_NO_INTERROGATE:STRING=/opt/cray/craype/2.4.1/bin/cc
MPI_EXTRA_LIBRARY:STRING=MPI_EXTRA_LIBRARY-NOTFOUND
MPI_LIBRARY:FILEPATH=MPI_LIBRARY-NOTFOUND
p02064 at swan:~/Code/tmp/build>

p02064 at swan:~/Code/tmp/build> make
[ 25%] Building C object CMakeFiles/test-mpi-c.dir/test-mpi.c.o
[ 50%] Linking C executable test-mpi-c
[ 50%] Built target test-mpi-c
[ 75%] Building CXX object CMakeFiles/test-mpi-cxx.dir/test-mpi.cxx.o
[100%] Linking CXX executable test-mpi-cxx
[100%] Built target test-mpi-cxx
p02064 at swan:~/Code/tmp/build>

As you can see from the resulting cache, the FindMPI module knows how to
act accordingly even when mpi libraries are folded into the regular
compiler.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150909/c8182ebe/attachment.html>


More information about the CMake mailing list