Skip to content

Commit

Permalink
Merge pull request #403 from dash-project/sup-check-openmpi-version
Browse files Browse the repository at this point in the history
Reliably check MPI implementation and version
  • Loading branch information
devreal authored Mar 5, 2018
2 parents eacfc2f + ee6e92b commit 2e59fa1
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 54 deletions.
17 changes: 17 additions & 0 deletions CMakeExt/Code/test_compatible_ompi.c
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
}

12 changes: 12 additions & 0 deletions CMakeExt/Code/test_mpi_support.c
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
}

2 changes: 1 addition & 1 deletion CMakeExt/HDF5.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ if(HDF5_FOUND)
check_symbol_exists(H5_HAVE_PARALLEL "H5pubconf.h" HAVE_H5_PARALLEL)
cmake_pop_check_state()

if(NOT HAVE_H5_PARALLEL)
if(NOT HAVE_H5_PARALLEL OR "${MPI_IMPL_ID}" STREQUAL "")
message(STATUS "HDF5 provides only serial version")
set(HDF5_FOUND OFF CACHE BOOL "HDF5_FOUND" FORCE)
unset(HDF5_LIBRARIES)
Expand Down
195 changes: 147 additions & 48 deletions CMakeExt/MPI.cmake
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)
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ message(INFO "Enabled DART backends: (DART_IMPLEMENTATIONS) "
${DART_IMPLEMENTATIONS})
message(INFO "C compiler id: ${CMAKE_C_COMPILER_ID}")
message(INFO "C++ compiler id: ${CMAKE_CXX_COMPILER_ID}")
if (MPI_FOUND)
if (DEFINED MPI_IMPL_ID)
message(INFO "MPI implementation: " ${MPI_IMPL_ID})
endif()

Expand Down
4 changes: 4 additions & 0 deletions dart-impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(DART_IMPLEMENTATIONS_LIST ${DART_IMPLEMENTATIONS_LIST}
set(ENABLE_THREADSUPPORT ${ENABLE_THREADSUPPORT}
PARENT_SCOPE)


if (ENABLE_THREADSUPPORT)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -DDART_ENABLE_THREADSUPPORT")
Expand All @@ -28,6 +29,9 @@ add_subdirectory(base)

# DART implementation of every enabled DART variant:
if (";${DART_IMPLEMENTATIONS_LIST};" MATCHES ";mpi;")
if(NOT MPI_IS_DART_COMPATIBLE)
message(FATAL_ERROR "Detected MPI library does not support MPI-3.")
endif()
set(DART_IMPLEMENTATION_MPI_ENABLED ON
CACHE BOOL INTERNAL FORCE)
add_subdirectory(mpi)
Expand Down
8 changes: 4 additions & 4 deletions dash/include/dash/io/hdf5/StorageDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#ifdef DASH_ENABLE_HDF5

#ifndef MPI_IMPL_ID
#pragma error "HDF5 module requires dart-mpi"
#endif

#include <dash/Exception.h>
#include <dash/Init.h>
#include <dash/Array.h>
Expand All @@ -28,10 +32,6 @@
#include <functional>
#include <utility>

#ifndef MPI_IMPL_ID
#pragma error "HDF5 module requires dart-mpi"
#endif

#include <dash/dart/if/dart_io.h>

namespace dash {
Expand Down

0 comments on commit 2e59fa1

Please sign in to comment.