-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #403 from dash-project/sup-check-openmpi-version
Reliably check MPI implementation and version
- Loading branch information
Showing
7 changed files
with
186 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <mpi.h> | ||
|
||
int main() | ||
{ | ||
|
||
#if defined(OMPI_MAJOR_VERSION) \ | ||
&& OMPI_MAJOR_VERSION > 2 \ | ||
|| ( OMPI_MAJOR_VERSION == 2 \ | ||
&& OMPI_MINOR_VERSION >= 1 \ | ||
&& OMPI_RELEASE_VERSION >= 1) | ||
// Open MPI >=2.1.1 is fine | ||
return 0; | ||
#else | ||
#error "Open MPI version with broken alignment of shared memory windows detected!" | ||
#endif | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <mpi.h> | ||
|
||
int main() | ||
{ | ||
|
||
#if MPI_VERSION >= 3 | ||
return 0; | ||
#else | ||
#error "Support for at least MPI 3.0 required!" | ||
#endif | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,156 @@ | ||
INCLUDE (CheckSymbolExists) | ||
INCLUDE (CMakePushCheckState) | ||
|
||
if (NOT $ENV{MPI_C_COMPILER} STREQUAL "") | ||
set(MPI_C_COMPILER $ENV{MPI_C_COMPILER} | ||
CACHE STRING "MPI C compiler") | ||
endif() | ||
if (NOT $ENV{MPI_CXX_COMPILER} STREQUAL "") | ||
set(MPI_CXX_COMPILER $ENV{MPI_CXX_COMPILER} | ||
CACHE STRING "MPI C++ compiler") | ||
endif() | ||
|
||
find_package(MPI) | ||
|
||
if (MPI_INCLUDE_PATH AND MPI_LIBRARY) | ||
set(MPI_FOUND TRUE CACHE BOOL "Found the MPI library") | ||
if ("${MPI_INCLUDE_PATH}" MATCHES "mpich") | ||
set(MPI_IMPL_IS_MPICH TRUE CACHE BOOL "MPICH detected") | ||
set(MPI_IMPL_ID "mpich" CACHE STRING "MPI implementation identifier") | ||
elseif ("${MPI_INCLUDE_PATH}" MATCHES "cray") | ||
set(MPI_IMPL_IS_CRAY TRUE CACHE BOOL "CrayMPI detected") | ||
set(MPI_IMPL_ID "craympi" CACHE STRING "MPI implementation identifier") | ||
elseif ("${MPI_INCLUDE_PATH}" MATCHES "mvapich") | ||
set(MPI_IMPL_IS_MVAPICH TRUE CACHE BOOL "MVAPICH detected") | ||
set(MPI_IMPL_ID "mvapich" CACHE STRING "MPI implementation identifier") | ||
elseif ("${MPI_INCLUDE_PATH}" MATCHES "impi" | ||
OR "${MPI_INCLUDE_PATH}" MATCHES "intel") | ||
set(MPI_IMPL_IS_INTEL TRUE CACHE BOOL "IntelMPI detected") | ||
set(MPI_IMPL_ID "intelmpi" CACHE STRING "MPI implementation identifier") | ||
elseif ("${MPI_INCLUDE_PATH}" MATCHES "openmpi") | ||
set(MPI_IMPL_IS_OPENMPI TRUE CACHE BOOL "OpenMPI detected") | ||
set(MPI_IMPL_ID "openmpi" CACHE STRING "MPI implementation identifier") | ||
# temporarily disable shared memory windows due to alignment problems | ||
set(ENABLE_SHARED_WINDOWS OFF) | ||
message(WARNING "MPI shared windows disabled due to defective allocation in OpenMPI") | ||
if (NOT DEFINED MPI_IMPL_ID) | ||
|
||
if (NOT $ENV{MPI_C_COMPILER} STREQUAL "") | ||
set(MPI_C_COMPILER $ENV{MPI_C_COMPILER} | ||
CACHE STRING "MPI C compiler") | ||
endif() | ||
if (NOT $ENV{MPI_CXX_COMPILER} STREQUAL "") | ||
set(MPI_CXX_COMPILER $ENV{MPI_CXX_COMPILER} | ||
CACHE STRING "MPI C++ compiler") | ||
endif() | ||
|
||
# find MPI environment | ||
find_package(MPI) | ||
|
||
# helper function that executes the MPI compiler | ||
# on the given source file and sets | ||
# resvar to true if the compile step succeeded | ||
function (check_mpi_compile sourcefile resvar) | ||
|
||
# check for MPI-3 | ||
get_filename_component(filename ${sourcefile} NAME) | ||
execute_process( | ||
COMMAND "${MPI_C_COMPILER}" -c "${sourcefile}" -o "${CMAKE_BINARY_DIR}/${filename}.o" | ||
RESULT_VARIABLE RETURN_VAL | ||
OUTPUT_VARIABLE OUTPUT | ||
ERROR_VARIABLE OUTPUT | ||
) | ||
|
||
if (RETURN_VAL EQUAL 0) | ||
set (${resvar} TRUE PARENT_SCOPE) | ||
else () | ||
set (${resvar} FALSE PARENT_SCOPE) | ||
message (STATUS "Failed to execute MPI compiler: \n${OUTPUT}") | ||
endif () | ||
|
||
endfunction () | ||
|
||
|
||
# Determine MPI implementation | ||
|
||
# save current state | ||
cmake_push_check_state() | ||
set (CMAKE_REQUIRED_INCLUDES ${MPI_INCLUDE_PATH}) | ||
|
||
# check for Open MPI | ||
check_symbol_exists( | ||
OMPI_MAJOR_VERSION | ||
mpi.h | ||
HAVE_OPEN_MPI | ||
) | ||
if (HAVE_OPEN_MPI) | ||
set (MPI_IMPL_IS_OPENMPI TRUE CACHE BOOL "OpenMPI detected") | ||
set (MPI_IMPL_ID "openmpi" CACHE STRING "MPI implementation identifier") | ||
check_mpi_compile(${CMAKE_SOURCE_DIR}/CMakeExt/Code/test_compatible_ompi.c OMPI_OK) | ||
if (NOT OMPI_OK) | ||
message(WARNING | ||
"Disabling shared memory window support due to defective allocation " | ||
"in OpenMPI <2.1.1") | ||
set (ENABLE_SHARED_WINDOWS OFF) | ||
endif() | ||
endif() | ||
|
||
# order matters: all of the following | ||
# implementations also define MPICH | ||
if (NOT DEFINED MPI_IMPL_ID) | ||
# check for Intel MPI | ||
check_symbol_exists( | ||
I_MPI_VERSION | ||
mpi.h | ||
HAVE_I_MPI | ||
) | ||
if (HAVE_I_MPI) | ||
set (MPI_IMPL_IS_INTEL TRUE CACHE BOOL "IntelMPI detected") | ||
set (MPI_IMPL_ID "intelmpi" CACHE STRING "MPI implementation identifier") | ||
endif () | ||
endif () | ||
|
||
if (NOT DEFINED MPI_IMPL_ID) | ||
# check for MVAPICH | ||
check_symbol_exists( | ||
MVAPICH2_VERSION | ||
mpi.h | ||
HAVE_MVAPICH | ||
) | ||
if (HAVE_MVAPICH) | ||
set (MPI_IMPL_IS_MVAPICH TRUE CACHE BOOL "MVAPICH detected") | ||
set (MPI_IMPL_ID "mvapich" CACHE STRING "MPI implementation identifier") | ||
endif () | ||
endif () | ||
|
||
if (NOT DEFINED MPI_IMPL_ID) | ||
# check for Cray MPI | ||
check_symbol_exists( | ||
CRAY_MPICH_VERSION | ||
mpi.h | ||
HAVE_CRAY_MPI | ||
) | ||
if (NOT HAVE_CRAY_MPI) | ||
# fall-back for versions prior to MPT 7.6.0 | ||
# MPIX_PortName_Backlog is a Cray extension | ||
check_symbol_exists( | ||
MPIX_PortName_Backlog | ||
mpi.h | ||
HAVE_CRAY_MPI | ||
) | ||
endif() | ||
if (HAVE_CRAY_MPI) | ||
set(MPI_IMPL_IS_CRAY TRUE CACHE BOOL "CrayMPI detected") | ||
set(MPI_IMPL_ID "craympi" CACHE STRING "MPI implementation identifier") | ||
endif () | ||
endif () | ||
|
||
if (NOT DEFINED MPI_IMPL_ID) | ||
# check for MVAPICH | ||
check_symbol_exists( | ||
MPICH | ||
mpi.h | ||
HAVE_MPICH | ||
) | ||
if (HAVE_MPICH) | ||
set (MPI_IMPL_IS_MPICH TRUE CACHE BOOL "MPICH detected") | ||
set (MPI_IMPL_ID "mpich" CACHE STRING "MPI implementation identifier") | ||
endif () | ||
endif () | ||
|
||
# restore state | ||
cmake_pop_check_state() | ||
|
||
if (NOT DEFINED MPI_IMPL_ID) | ||
set (MPI_IMPL_ID "UNKNOWN" CACHE STRING "MPI implementation identifier") | ||
endif() | ||
else (MPI_INCLUDE_PATH AND MPI_LIBRARY) | ||
set(MPI_FOUND FALSE CACHE BOOL "Did not find the MPI library") | ||
endif (MPI_INCLUDE_PATH AND MPI_LIBRARY) | ||
|
||
message(STATUS "Detected MPI implementation: ${MPI_IMPL_ID}") | ||
message(STATUS "Detected MPI C compiler: ${MPI_C_COMPILER}") | ||
|
||
# check for MPI-3 | ||
check_mpi_compile(${CMAKE_SOURCE_DIR}/CMakeExt/Code/test_mpi_support.c HAVE_MPI3) | ||
|
||
# save current state | ||
cmake_push_check_state() | ||
set(CMAKE_REQUIRED_INCLUDES ${MPI_INCLUDE_PATH}) | ||
check_symbol_exists( | ||
MPI_NO_OP | ||
mpi.h | ||
HAVE_MPI_NO_OP | ||
) | ||
cmake_pop_check_state() | ||
if (NOT HAVE_MPI3) | ||
message(${OUTPUT}) | ||
set(MPI_IS_DART_COMPATIBLE FALSE CACHE BOOL | ||
"MPI LIB has support for MPI-3") | ||
message (WARNING | ||
"Detected MPI implementation (${MPI_IMPL_ID}) does not support MPI-3") | ||
message (STATUS "${OUTPUT}") | ||
unset (MPI_IMPL_ID CACHE) | ||
else() | ||
set(MPI_IS_DART_COMPATIBLE TRUE CACHE BOOL | ||
"MPI LIB has support for MPI-3") | ||
endif() | ||
|
||
if (NOT HAVE_MPI_NO_OP) | ||
message(FATAL_ERROR "Detected MPI library does not support MPI-3.") | ||
endif() | ||
set (CMAKE_C_COMPILER ${CMAKE_C_COMPILER_SAFE}) | ||
|
||
endif(NOT DEFINED MPI_IMPL_ID) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters