0

I would like to find the path of mpicc and mpicxx, and set CMAKE_CXX_COMPILER and CMAKE_C_COMPILER as mpicc and mpicxx. mpicc and mpicxx are store in two directories (two implementation of mpi), I used find_path() in cmake to find the paths, but the returned directories was not the right directories. Here is my code:

FIND_PATH(MPI_INTEL_C mpicc $ENV{PATH})
FIND_PATH(MPI_INTEL_CXX mpicxx $ENV{PATH})

MESSAGE(STATUS "MPI_INTEL_C: ${MPI_INTEL_C}")
MESSAGE(STATUS "MPI_INTEL_CXX: ${MPI_INTEL_CXX}")

IF(MPI_INTEL_C AND MPI_INTEL_CXX)
    MESSAGE(STATUS "Intel MPI compiler is used.")
    SET(CMAKE_CXX_COMPILER mpicxx)
    SET(CMAKE_C_COMPILER mpicc)
ELSE(MPI_INTEL_C AND MPI_INTEL_CXX)
    MESSAGE(FATAL_ERROR "mpicc and mpicxx not found.")
ENDIF(MPI_INTEL_C AND MPI_INTEL_CXX)

The returned (wrong) directoriesare:

-- MPI_INTEL_C: /export/ictce3.1/impi/3.1/bin64
-- MPI_INTEL_CXX: /export/ictce3.1/impi/3.1/bin64

And $ENV{PATH} is:

/export/mpi/mpich_intel/bin:/export/ictce3.1/impi/3.1/bin64:/export/ictce3.1/itac/7.1/bin:/export/ictce3.1//fce/10.1.015/bin:/export/ictce3.1//cce/10.1.015/bin:/export/ictce3.1//idbe/10.1.015/bin:/export/mpi/mpich_intel/bin:/export/ictce3.1/impi/3.1/bin64:/export/ictce3.1/itac/7.1/bin:/export/ictce3.1//fce/10.1.015/bin:/export/ictce3.1//cce/10.1.015/bin:/export/ictce3.1//idbe/10.1.015/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/java/jdk1.6.0_03/bin:/usr/java/jdk1.6.0_03/jre/bin:/usr/local/jakarta-tomcat-4.1.18/bin:/export/mpi/mpich_intel/include:/export/mpi/mpich_intel/lib:/export/ictce3.1/cce/10.1.015/lib:/export/ictce3.1/cce/10.1.015/bin:/export/ljrs/bin:/export/ljrs/sbin

And the right directories of mpicc and mpicxx are:

-- MPI_INTEL_C: /export/mpi/mpich_intel/bin
-- MPI_INTEL_CXX: /export/mpi/mpich_intel/bin

I tried this way:

FIND_PATH(MPI_INTEL_C mpicc PATHS /export/mpi/mpich_intel/bin)
FIND_PATH(MPI_INTEL_CXX mpicxx PATHS /export/mpi/mpich_intel/bin)

but still got the wrong directories. So how to find mpicc and mpicxx in the specific directory?

usr1234567
  • 21,601
  • 16
  • 108
  • 128
just_rookie
  • 873
  • 12
  • 33
  • 1
    Possible duplicate of [How to compile an MPI included c program using cmake](http://stackoverflow.com/questions/23163075/how-to-compile-an-mpi-included-c-program-using-cmake) – Zulan May 03 '16 at 16:51

1 Answers1

0

Use FindMPI.cmake provided by CMake. If this fails, set the CMAKE_PREFIX_PATH accordingly.

Documentation: https://cmake.org/cmake/help/v3.5/module/FindMPI.html

You should not set the CMAKE_CXX_COMPILER to the MPI wrapper, but let CMake figure the right flags out.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
  • So if we use `FindMPI.cmake`, we should use `mpiexec` to run `mpi` program? And how to set parameters about `mpiexec` in cmake? Thank you! – just_rookie May 03 '16 at 12:56
  • Just read the documentation! When using MPIEXEC to execute MPI applications, you should typically use all of the MPIEXEC flags as follows: ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} PROCS ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS – usr1234567 May 03 '16 at 12:58
  • I had read the documentation before, but when I used `mpiexec -n 8 mpiprogram` to run the program, only one process was used. – just_rookie May 03 '16 at 13:10
  • Well, the documentation is unfortunately not clear on how to *use* the variables set by the module. But in my experience I agree that it is better to use `MPI__INCLUDE_PATH` & linker friends. But I have not seen CMake just *figuring the right flags out*. – Zulan May 03 '16 at 16:54