如何使用find_path在特定目录中找到mpicc和mpicxx?

时间:2016-05-03 11:18:07

标签: cmake mpi

我想找到mpiccmpicxx的路径,并将CMAKE_CXX_COMPILERCMAKE_C_COMPILER设置为mpiccmpicxxmpiccmpicxx存储在两个目录中(mpi的两个实现),我在find_path()中使用cmake来查找路径,但返回的目录是不是正确的目录。这是我的代码:

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)

返回(错误)目录:

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

$ENV{PATH}是:

/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

mpicc和mpicxx的正确目录是:

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

我试过这种方式:

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

但仍然有错误的目录。那么如何在特定目录中找到mpicc和mpicxx?

1 个答案:

答案 0 :(得分:0)

使用CMake提供的FindMPI.cmake。如果失败,请相应地设置CMAKE_PREFIX_PATH

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

你不应该将CMAKE_CXX_COMPILER设置为MPI包装器,而是让CMake找出正确的标志。