Skip to content

Commit

Permalink
Merge pull request #136 from cwpearson/cmake/mpi-vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
cwpearson authored Jan 28, 2025
2 parents 5596896 + 9733a96 commit 1d5d090
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ project(
HOMEPAGE_URL "https://kokkos.org/kokkos-comm/"
)

include(cmake/mpi-vendor.cmake)

option(KokkosComm_ENABLE_PERFTESTS "Build KokkosComm perf tests" OFF)
option(KokkosComm_ENABLE_TESTS "Build KokkosComm tests" OFF)
option(KokkosComm_ENABLE_MPI "Build KokkosComm with MPI transport" ON)
Expand All @@ -42,6 +44,7 @@ find_package(Kokkos REQUIRED)
if(KOKKOSCOMM_ENABLE_MPI)
find_package(MPI REQUIRED)
endif()
kokkoscomm_set_mpi_vendor_variables()

add_subdirectory(src)
if(KOKKOSCOMM_ENABLE_TESTS)
Expand Down
2 changes: 2 additions & 0 deletions cmake/KokkosComm_config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
#define KOKKOSCOMM_VERSION_PATCH @KOKKOSCOMM_VERSION_PATCH@

#cmakedefine KOKKOSCOMM_ENABLE_MPI
#cmakedefine KOKKOSCOMM_IMPL_MPI_IS_MPICH
#cmakedefine KOKKOSCOMM_IMPL_MPI_IS_OPENMPI
29 changes: 29 additions & 0 deletions cmake/mpi-vendor.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function(kokkoscomm_set_mpi_vendor_variables)
# Initialize the variables to false
set(KOKKOSCOMM_IMPL_MPI_IS_MPICH FALSE CACHE BOOL "Is MPI MPICH")
set(KOKKOSCOMM_IMPL_MPI_IS_OPENMPI FALSE CACHE BOOL "Is MPI OpenMPI")

if(KOKKOSCOMM_ENABLE_MPI)
if(NOT MPIEXEC_EXECUTABLE)
message(WARNING "MPIEXEC_EXECUTABLE is not set - unable to determine MPI vendor")
return()
endif()

# Get the directory of the MPI executable
get_filename_component(MPIEXEC_DIR ${MPIEXEC_EXECUTABLE} DIRECTORY)

# Check for mpichversion
find_program(MPICHVERSION_EXECUTABLE mpichversion HINTS ${MPIEXEC_DIR})
find_program(OMPI_INFO_EXECUTABLE ompi_info HINTS ${MPIEXEC_DIR})

if (MPICHVERSION_EXECUTABLE AND OPENMPI_INFO_EXECUTABLE)
message(WARNING "Both MPICHVERSION_EXECUTABLE and OMPI_INFO_EXECUTABLE are set - unable to determine MPI vendor")
elseif(MPICHVERSION_EXECUTABLE)
message(STATUS "Detected MPI as MPICH")
set(KOKKOSCOMM_IMPL_MPI_IS_MPICH TRUE CACHE BOOL "Is MPI MPICH" FORCE)
elseif(OMPI_INFO_EXECUTABLE)
message(STATUS "Detected MPI as Open MPI")
set(KOKKOSCOMM_IMPL_MPI_IS_OPENMPI TRUE CACHE BOOL "Is MPI OpenMPI" FORCE)
endif()
endif()
endfunction()

0 comments on commit 1d5d090

Please sign in to comment.