ENH: Improvements in finding MPI on windows. ENH: reorganized searching mpi for mpi components (include,lib,bin) using a single set of search paths instead of seperately mainted lists of paths for each.

This commit is contained in:
Dave Partyka 2009-10-27 12:43:50 -04:00
parent ae1e9900fa
commit 4915e92998

View File

@ -65,21 +65,58 @@
# (To distributed this file outside of CMake, substitute the full
# License text for the above reference.)
# Try to find the MPI driver program
find_program(MPI_COMPILER
NAMES mpic++ mpicxx mpiCC mpicc
DOC "MPI compiler. Used only to detect MPI compilation flags.")
mark_as_advanced(MPI_COMPILER)
# This module is maintained by David Partyka <dave.partyka@kitware.com>.
file(TO_CMAKE_PATH "$ENV{ProgramFiles}" ProgramFiles)
# A set of directories to search through in addition to the standard system paths
# that find_program will search through.
# Microsoft HPC SDK is automatically added to the system path
# Argonne National Labs MPICH2 sets a registry key that we can use.
set(MPI_PACKAGE_DIR
mpi
mpich
openmpi
lib/mpi
lib/mpich
lib/openmpi
"MPICH/SDK"
"Microsoft Compute Cluster Pack"
)
set(MPI_PREFIX_PATH)
if(WIN32)
list(APPEND MPI_PREFIX_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MPICH\\SMPD;binary]/..")
endif()
foreach(SystemPrefixDir ${CMAKE_SYSTEM_PREFIX_PATH})
foreach(MpiPackageDir ${MPI_PREFIX_PATH})
if(EXISTS ${SystemPrefixDir}/${MpiPackageDir})
list(APPEND MPI_PREFIX_PATH "${SystemPrefixDir}/${MpiPackageDir}")
endif()
endforeach(MpiPackageDir)
endforeach(SystemPrefixDir)
# Most mpi distros have some form of mpiexec which gives us something we can reliably look for.
find_program(MPIEXEC
NAMES mpiexec mpirun lamexec
PATHS /usr/bin /usr/local/bin /usr/local/mpi/bin
"$ENV{SystemDrive}/Program Files/MPICH/SDK/Bin"
"${ProgramFiles}/MPICH2/Bin"
"$ENV{SystemDrive}/Program Files/Microsoft Compute Cluster Pack/Bin"
"$ENV{SystemDrive}/Program Files/Microsoft HPC Pack 2008 SDK/Bin"
DOC "Executable for running MPI programs.")
PATHS ${MPI_PREFIX_PATH}
PATH_SUFFIXES bin
DOC "Executable for running MPI programs."
)
# call get_filename_component twice to remove mpiexec and the directory it exists in (typically bin).
# This gives us a fairly reliable base directory to search for /bin /lib and /include from.
get_filename_component(MPI_BASE_DIR ${MPIEXEC} PATH)
get_filename_component(MPI_BASE_DIR ${MPI_BASE_DIR} PATH)
# If there is an mpi compiler find it and interogate (farther below) it for the include
# and lib dirs otherwise we will continue to search from ${MPI_BASE_DIR}.
find_program(MPI_COMPILER
NAMES mpic++ mpicxx mpiCC mpicc
HINTS "${MPI_BASE_DIR}"
PATH_SUFFIXES bin
DOC "MPI compiler. Used only to detect MPI compilation flags.")
mark_as_advanced(MPI_COMPILER)
set(MPIEXEC_NUMPROC_FLAG "-np" CACHE STRING "Flag used by MPI to specify the number of processes for MPIEXEC; the next option will be the number of processes.")
set(MPIEXEC_PREFLAGS "" CACHE STRING "These flags will be directly before the executable that is being run by MPIEXEC.")
@ -95,6 +132,7 @@ elseif (MPI_COMPILER)
# Check whether the -showme:compile option works. This indicates
# that we have either Open MPI or a newer version of LAM-MPI, and
# implies that -showme:link will also work.
# Note that Windows distros do not have an mpi compiler to interogate.
exec_program(${MPI_COMPILER}
ARGS -showme:compile
OUTPUT_VARIABLE MPI_COMPILE_CMDLINE
@ -183,7 +221,10 @@ elseif (MPI_COMPILE_CMDLINE)
if (NOT MPI_INCLUDE_PATH_WORK)
# If all else fails, just search for mpi.h in the normal include
# paths.
find_path(MPI_INCLUDE_PATH mpi.h)
find_path(MPI_INCLUDE_PATH mpi.h
HINTS ${MPI_BASE_DIR} ${MPI_PREFIX_PATH}
PATH_SUFFIXES include
)
set(MPI_INCLUDE_PATH_WORK ${MPI_INCLUDE_PATH})
endif (NOT MPI_INCLUDE_PATH_WORK)
@ -261,41 +302,29 @@ elseif (MPI_COMPILE_CMDLINE)
set(MPI_INCLUDE_PATH ${MPI_INCLUDE_PATH_WORK} CACHE STRING "MPI include path" FORCE)
set(MPI_LINK_FLAGS ${MPI_LINK_FLAGS_WORK} CACHE STRING "MPI linking flags" FORCE)
else (MPI_COMPILE_CMDLINE)
# No MPI compiler to interogate so attempt to find everything with find functions.
find_path(MPI_INCLUDE_PATH mpi.h
/usr/local/include
/usr/include
/usr/include/mpi
/usr/local/mpi/include
"$ENV{SystemDrive}/Program Files/MPICH/SDK/Include"
"${ProgramFiles}/MPICH2/include"
"$ENV{SystemDrive}/Program Files/Microsoft Compute Cluster Pack/Include"
"$ENV{SystemDrive}/Program Files/Microsoft HPC Pack 2008 SDK/Include"
HINTS ${MPI_BASE_DIR} ${MPI_PREFIX_PATH}
PATH_SUFFIXES include
)
# Decide between 32-bit and 64-bit libraries for Microsoft's MPI
if (CMAKE_CL_64)
if(CMAKE_SIZEOF_VOID_P EQUALS 8)
set(MS_MPI_ARCH_DIR amd64)
else (CMAKE_CL_64)
else()
set(MS_MPI_ARCH_DIR i386)
endif (CMAKE_CL_64)
endif()
find_library(MPI_LIBRARY
NAMES mpi mpich msmpi
PATHS /usr/lib /usr/local/lib /usr/local/mpi/lib
"$ENV{SystemDrive}/Program Files/MPICH/SDK/Lib"
"${ProgramFiles}/MPICH2/Lib"
"$ENV{SystemDrive}/Program Files/Microsoft Compute Cluster Pack/Lib/${MS_MPI_ARCH_DIR}"
"$ENV{SystemDrive}/Program Files/Microsoft HPC Pack 2008 SDK/Lib/${MS_MPI_ARCH_DIR}"
HINTS ${MPI_BASE_DIR} ${MPI_PREFIX_PATH}
PATH_SUFFIXES lib lib/${MS_MPI_ARCH_DIR} Lib Lib/${MS_MPI_ARCH_DIR}
)
find_library(MPI_LIBRARY
NAMES mpich2
PATHS
"${ProgramFiles}/MPICH2/Lib")
find_library(MPI_EXTRA_LIBRARY
NAMES mpi++
PATHS /usr/lib /usr/local/lib /usr/local/mpi/lib
"$ENV{SystemDrive}/Program Files/MPICH/SDK/Lib"
HINTS ${MPI_BASE_DIR} ${MPI_PREFIX_PATH}
PATH_SUFFIXES lib
DOC "Extra MPI libraries to link against.")
set(MPI_COMPILE_FLAGS "" CACHE STRING "MPI compilation flags")
@ -327,3 +356,8 @@ find_package_handle_standard_args(MPI DEFAULT_MSG MPI_LIBRARY MPI_INCLUDE_PATH)
mark_as_advanced(MPI_INCLUDE_PATH MPI_COMPILE_FLAGS MPI_LINK_FLAGS MPI_LIBRARY
MPI_EXTRA_LIBRARY)
# unset to cleanup namespace
unset(MPI_PACKAGE_DIR)
unset(MPI_PREFIX_PATH)
unset(MPI_BASE_DIR)