roll back changes switching from MPI::MPI_CXX to MPI::MPI_C

This commit is contained in:
Axel Kohlmeyer
2025-06-02 15:48:40 -04:00
parent 1fae7e3f98
commit 1fc8e05642
8 changed files with 26 additions and 30 deletions

View File

@ -203,6 +203,10 @@ if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif() endif()
# do not include the (obsolete) MPI C++ bindings which makes for leaner object files
# and avoids namespace conflicts. Put this early to increase its visbility.
set(MPI_CXX_SKIP_MPICXX TRUE)
######################################################################## ########################################################################
# User input options # # User input options #
######################################################################## ########################################################################
@ -400,28 +404,24 @@ if(PKG_ADIOS)
endif() endif()
if(NOT CMAKE_CROSSCOMPILING) if(NOT CMAKE_CROSSCOMPILING)
find_package(MPI QUIET COMPONENTS C) find_package(MPI QUIET COMPONENTS CXX)
option(BUILD_MPI "Build MPI version" ${MPI_FOUND}) option(BUILD_MPI "Build MPI version" ${MPI_FOUND})
else() else()
option(BUILD_MPI "Build MPI version" OFF) option(BUILD_MPI "Build MPI version" OFF)
endif() endif()
if(BUILD_MPI) if(BUILD_MPI)
# do not include the (obsolete) MPI C++ bindings which makes
# for leaner object files and avoids namespace conflicts
set(MPI_CXX_SKIP_MPICXX TRUE)
# We use a non-standard procedure to cross-compile with MPI on Windows # We use a non-standard procedure to cross-compile with MPI on Windows
if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING) if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING)
include(MPI4WIN) include(MPI4WIN)
else() else()
find_package(MPI REQUIRED COMPONENTS C) find_package(MPI REQUIRED COMPONENTS CXX)
option(LAMMPS_LONGLONG_TO_LONG "Workaround if your system or MPI version does not recognize 'long long' data types" OFF) option(LAMMPS_LONGLONG_TO_LONG "Workaround if your system or MPI version does not recognize 'long long' data types" OFF)
if(LAMMPS_LONGLONG_TO_LONG) if(LAMMPS_LONGLONG_TO_LONG)
target_compile_definitions(lammps PRIVATE -DLAMMPS_LONGLONG_TO_LONG) target_compile_definitions(lammps PRIVATE -DLAMMPS_LONGLONG_TO_LONG)
endif() endif()
endif() endif()
target_link_libraries(lammps PUBLIC MPI::MPI_C) target_link_libraries(lammps PUBLIC MPI::MPI_CXX)
target_compile_definitions(lammps PUBLIC -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX=1)
else() else()
target_sources(lammps PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS/mpi.cpp) target_sources(lammps PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS/mpi.cpp)
add_library(mpi_stubs INTERFACE) add_library(mpi_stubs INTERFACE)
@ -717,7 +717,6 @@ foreach(PKG_LIB POEMS ATC AWPMD H5MD)
file(GLOB_RECURSE ${PKG_LIB}_SOURCES CONFIGURE_DEPENDS file(GLOB_RECURSE ${PKG_LIB}_SOURCES CONFIGURE_DEPENDS
${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/[^.]*.c ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/[^.]*.cpp) ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/[^.]*.c ${LAMMPS_LIB_SOURCE_DIR}/${PKG_LIB}/[^.]*.cpp)
add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES}) add_library(${PKG_LIB} STATIC ${${PKG_LIB}_SOURCES})
target_compile_definitions(${PKG_LIB} PUBLIC -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX=1)
set_target_properties(${PKG_LIB} PROPERTIES OUTPUT_NAME lammps_${PKG_LIB}${LAMMPS_MACHINE}) set_target_properties(${PKG_LIB} PROPERTIES OUTPUT_NAME lammps_${PKG_LIB}${LAMMPS_MACHINE})
target_link_libraries(lammps PRIVATE ${PKG_LIB}) target_link_libraries(lammps PRIVATE ${PKG_LIB})
if(PKG_LIB STREQUAL "awpmd") if(PKG_LIB STREQUAL "awpmd")
@ -743,7 +742,7 @@ if(PKG_ATC)
message(FATAL_ERROR "The ATC Package is not compatible with -DLAMMPS_BIGBIG") message(FATAL_ERROR "The ATC Package is not compatible with -DLAMMPS_BIGBIG")
endif() endif()
if(BUILD_MPI) if(BUILD_MPI)
target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} MPI::MPI_C) target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} MPI::MPI_CXX)
else() else()
target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} mpi_stubs) target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} mpi_stubs)
endif() endif()
@ -1057,9 +1056,9 @@ else()
endif() endif()
if(BUILD_MPI) if(BUILD_MPI)
message(STATUS "<<< MPI flags >>> message(STATUS "<<< MPI flags >>>
-- MPI_defines: ${MPI_C_COMPILE_DEFINITIONS} -- MPI_defines: ${MPI_CXX_COMPILE_DEFINITIONS}
-- MPI includes: ${MPI_C_INCLUDE_PATH} -- MPI includes: ${MPI_CXX_INCLUDE_PATH}
-- MPI libraries: ${MPI_C_LIBRARIES};${MPI_Fortran_LIBRARIES}") -- MPI libraries: ${MPI_CXX_LIBRARIES};${MPI_Fortran_LIBRARIES}")
endif() endif()
if(PKG_GPU) if(PKG_GPU)
message(STATUS "<<< GPU package settings >>> message(STATUS "<<< GPU package settings >>>

View File

@ -62,6 +62,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
endif() endif()
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
# skip over obsolete MPI-2 C++ bindings
set(MPI_CXX_SKIP_MPICXX TRUE)
####### #######
# helper functions from LAMMPSUtils.cmake # helper functions from LAMMPSUtils.cmake
function(validate_option name values) function(validate_option name values)
@ -128,9 +131,7 @@ endif()
################################################################################ ################################################################################
# MPI configuration # MPI configuration
if(NOT CMAKE_CROSSCOMPILING) if(NOT CMAKE_CROSSCOMPILING)
set(MPI_CXX_SKIP_MPICXX TRUE) find_package(MPI QUIET COMPONENTS CXX)
enable_language(C)
find_package(MPI QUIET COMPONENTS C)
option(BUILD_MPI "Build MPI version" ${MPI_FOUND}) option(BUILD_MPI "Build MPI version" ${MPI_FOUND})
else() else()
option(BUILD_MPI "Build MPI version" OFF) option(BUILD_MPI "Build MPI version" OFF)

View File

@ -27,8 +27,7 @@ if(BUILD_OMP)
endif() endif()
if(BUILD_MPI) if(BUILD_MPI)
target_compile_definitions(colvars PUBLIC -DCOLVARS_MPI -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX=1) target_link_libraries(colvars PUBLIC MPI::MPI_CXX)
target_link_libraries(colvars PUBLIC MPI::MPI_C)
endif() endif()
if(COLVARS_DEBUG) if(COLVARS_DEBUG)

View File

@ -484,12 +484,11 @@ RegisterFixStyle(${GPU_SOURCES_DIR}/fix_gpu.h)
get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES) get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES)
if(BUILD_MPI) if(BUILD_MPI)
target_link_libraries(gpu PRIVATE MPI::MPI_C) target_link_libraries(gpu PRIVATE MPI::MPI_CXX)
else() else()
target_link_libraries(gpu PRIVATE mpi_stubs) target_link_libraries(gpu PRIVATE mpi_stubs)
endif() endif()
target_compile_definitions(gpu PRIVATE -DLAMMPS_${LAMMPS_SIZES} -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX=1)
set_target_properties(gpu PROPERTIES OUTPUT_NAME lammps_gpu${LAMMPS_MACHINE}) set_target_properties(gpu PROPERTIES OUTPUT_NAME lammps_gpu${LAMMPS_MACHINE})
target_sources(lammps PRIVATE ${GPU_SOURCES}) target_sources(lammps PRIVATE ${GPU_SOURCES})
target_include_directories(lammps PRIVATE ${GPU_SOURCES_DIR}) target_include_directories(lammps PRIVATE ${GPU_SOURCES_DIR})

View File

@ -44,7 +44,7 @@ if(DOWNLOAD_N2P2)
set(N2P2_PROJECT_OPTIONS "-DN2P2_NO_MPI") set(N2P2_PROJECT_OPTIONS "-DN2P2_NO_MPI")
else() else()
# get path to MPI include directory # get path to MPI include directory
get_target_property(N2P2_MPI_INCLUDE MPI::MPI_C INTERFACE_INCLUDE_DIRECTORIES) get_target_property(N2P2_MPI_INCLUDE MPI::MPI_CXX INTERFACE_INCLUDE_DIRECTORIES)
foreach (_INCL ${N2P2_MPI_INCLUDE}) foreach (_INCL ${N2P2_MPI_INCLUDE})
set(N2P2_PROJECT_OPTIONS "${N2P2_PROJECT_OPTIONS} -I${_INCL}") set(N2P2_PROJECT_OPTIONS "${N2P2_PROJECT_OPTIONS} -I${_INCL}")
endforeach() endforeach()
@ -102,9 +102,9 @@ if(DOWNLOAD_N2P2)
# nnpif library has MPI calls if MPI is enabled, so we must link with MPI libs # nnpif library has MPI calls if MPI is enabled, so we must link with MPI libs
if(BUILD_MPI) if(BUILD_MPI)
set_target_properties(LAMMPS::N2P2::LIBNNPIF PROPERTIES set_target_properties(LAMMPS::N2P2::LIBNNPIF PROPERTIES
INTERFACE_LINK_LIBRARIES MPI::MPI_C) INTERFACE_LINK_LIBRARIES MPI::MPI_CXX)
if((CMAKE_SYSTEM_NAME STREQUAL Windows) AND CMAKE_CROSSCOMPILING) if((CMAKE_SYSTEM_NAME STREQUAL Windows) AND CMAKE_CROSSCOMPILING)
add_dependencies(LAMMPS::N2P2::LIBNNPIF MPI::MPI_C) add_dependencies(LAMMPS::N2P2::LIBNNPIF MPI::MPI_CXX)
endif() endif()
endif() endif()

View File

@ -28,9 +28,6 @@ if(MSVC)
endif() endif()
find_package(MPI REQUIRED COMPONENTS C) find_package(MPI REQUIRED COMPONENTS C)
# do not include the (obsolete) MPI C++ bindings which makes
# for leaner object files and avoids namespace conflicts
set(MPI_CXX_SKIP_MPICXX TRUE)
########################## ##########################

View File

@ -25,10 +25,10 @@ if(MSVC)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS) add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif() endif()
find_package(MPI QUIET COMPONENTS C)
# do not include the (obsolete) MPI C++ bindings which makes # do not include the (obsolete) MPI C++ bindings which makes
# for leaner object files and avoids namespace conflicts # for leaner object files and avoids namespace conflicts
set(MPI_CXX_SKIP_MPICXX TRUE) set(MPI_CXX_SKIP_MPICXX TRUE)
find_package(MPI QUIET COMPONENTS C CXX)
########################## ##########################
@ -38,7 +38,7 @@ if(NOT LAMMPS_SOURCE_DIR)
endif() endif()
add_executable(simpleCC simple.cpp) add_executable(simpleCC simple.cpp)
target_link_libraries(simpleCC PRIVATE LAMMPS::lammps MPI::MPI_C) target_link_libraries(simpleCC PRIVATE LAMMPS::lammps MPI::MPI_CXX)
add_executable(simpleC simple.c) add_executable(simpleC simple.c)
target_link_libraries(simpleC PRIVATE LAMMPS::lammps MPI::MPI_C) target_link_libraries(simpleC PRIVATE LAMMPS::lammps MPI::MPI_C)

View File

@ -33,10 +33,11 @@ endif()
################################################################################ ################################################################################
# MPI configuration # MPI configuration
if(NOT CMAKE_CROSSCOMPILING) # do not include the (obsolete) MPI C++ bindings which makes
enable_language(C) # for leaner object files and avoids namespace conflicts
set(MPI_CXX_SKIP_MPICXX TRUE) set(MPI_CXX_SKIP_MPICXX TRUE)
find_package(MPI QUIET COMPONENTS C) if(NOT CMAKE_CROSSCOMPILING)
find_package(MPI QUIET COMPONENTS CXX)
option(BUILD_MPI "Build MPI version" ${MPI_FOUND}) option(BUILD_MPI "Build MPI version" ${MPI_FOUND})
else() else()
option(BUILD_MPI "Build MPI version" OFF) option(BUILD_MPI "Build MPI version" OFF)