Home > Back-end >  How to choose MPI vendor/distribution with CMake?
How to choose MPI vendor/distribution with CMake?

Time:12-28

I have a program that I would like to compile with CMake make but using two different MPI distributions, OpenMPI and MPICH.

In Ubuntu, I have both installed; these are all the compiler wrappers I have installed:

mpic             mpicxx           mpif77.mpich     mpijavac       
mpicc            mpicxx.mpich     mpif77.openmpi   mpijavac.pl    
mpiCC            mpicxx.openmpi   mpif90           mpirun         
mpicc.mpich      mpiexec          mpif90.mpich     mpirun.mpich   
mpicc.openmpi    mpiexec.hydra    mpif90.openmpi   mpirun.openmpi 
mpiCC.openmpi    mpiexec.mpich    mpifort          mpivars        
mpichversion     mpiexec.openmpi  mpifort.mpich                   
mpic  .openmpi   mpif77           mpifort.openmpi   

(OpenMPI is the default, i.e. when no distribution extension is specified. I am not using modules.)

How can I force CMake to choose MPICH over OpenMPI?

I tried setting -DMPI_ROOT=/usr/lib/x86_64-linux-gnu/mpich but I get this error:

-- Could NOT find MPI_CXX (missing: MPI_CXX_WORKS) 
CMake Error at /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
  Could NOT find MPI (missing: MPI_CXX_FOUND)

      Reason given by package: MPI component 'C' was requested, but language C is not enabled.  MPI component 'Fortran' was requested, but language Fortran is not enabled.  

Call Stack (most recent call first):
  /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.18/Modules/FindMPI.cmake:1721 (find_package_handle_standard_args)
  CMakeLists.txt:11 (find_package)
it still uses OpenMPI.

This is how my CMakeLists.txt looks like:

cmake_minimum_required(VERSION 3.12.0)
project(myproject VERSION 0.1 LANGUAGES CXX)

#enable_language(C)  #uncommenting these doesn't help
#enable_language(Fortran)

enable_testing()
include(CTest)

find_package(MPI REQUIRED)

CodePudding user response:

Setting -DMPI_ROOT= or -DMPI_HOME= didn't work for me. It still uses the default in my system (OpenMPI).

What worked was to set -DMPI_EXECUTABLE_SUFFIX=.mpich, option which I found near the end of the documentation: https://cmake.org/cmake/help/latest/module/FindMPI.html.

CodePudding user response:

Based on cmake documents, you should be able to select one by setting value of MPI_GUESS_LIBRARY_NAME.

  • Related