From 500f1d086d1b3c8824704a59046308aa1c20338a Mon Sep 17 00:00:00 2001 From: Caitlin Ross Date: Tue, 26 May 2026 15:57:15 -0500 Subject: [PATCH] use MPI::MPI_C imported target for MPI discovery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the hand-rolled SetupMPI.cmake and the soft-warn IF(MPI_C_FOUND) fallback with a single find_package(MPI REQUIRED COMPONENTS C), and attach MPI to the ROSS target via target_link_libraries(ROSS PUBLIC MPI::MPI_C). MPI is PUBLIC because core/ross.h does #include , so the include path must propagate to consumers. Adds target_link_libraries(ROSS PRIVATE m) for libm and replaces the now-empty ROSS_EXTERNAL_LIBS plumbing. After this, ROSS configures cleanly with the system C compiler — no CC=mpicc or -DCMAKE_C_COMPILER=mpicc required. For non-standard MPI installs, hint with -DMPI_HOME=... or `module load ` before configuring. CLAUDE.md updated accordingly. --- CLAUDE.md | 4 +- CMakeLists.txt | 13 ++----- core/CMakeLists.txt | 6 ++- core/cmake/SetupMPI.cmake | 77 --------------------------------------- 4 files changed, 10 insertions(+), 90 deletions(-) delete mode 100644 core/cmake/SetupMPI.cmake diff --git a/CLAUDE.md b/CLAUDE.md index 58d65f7ab..700e8e262 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -7,14 +7,14 @@ Rensselaer's Optimistic Simulation System — a parallel discrete-event simulato Typical manual configure: ``` -cmake -S . -B build -DROSS_BUILD_MODELS=ON -DCMAKE_C_COMPILER=mpicc -DCMAKE_BUILD_TYPE=Debug +cmake -S . -B build -DROSS_BUILD_MODELS=ON -DCMAKE_BUILD_TYPE=Debug cmake --build build -j cmake --install build ``` Models are **not** built by default — pass `-DROSS_BUILD_MODELS=ON` to include `phold` and any symlinked-in models. `BUILD_TESTING=ON` enables the ctest suite. -MPI is required. The top-level `CMakeLists.txt` does per-arch detection via `CMAKE_SYSTEM_PROCESSOR` and falls back to a `gtod` clock if unrecognized. Set `-DROSS_CLOCK_OVERRIDE=YES` to force the gtod clock. +MPI is required and auto-discovered via `find_package(MPI)` — do not set `CC=mpicc` or `-DCMAKE_C_COMPILER=mpicc`. For non-standard installs, hint with `-DMPI_HOME=...` or `module load ` before configuring. The top-level `CMakeLists.txt` does per-arch detection via `CMAKE_SYSTEM_PROCESSOR` and falls back to a `gtod` clock if unrecognized. Set `-DROSS_CLOCK_OVERRIDE=YES` to force the gtod clock. ## Running a model diff --git a/CMakeLists.txt b/CMakeLists.txt index ef98e484d..4c996f64b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,15 +183,10 @@ ENDIF(VALID_ARCH AND NOT ${ROSS_CLOCK_OVERRIDE}) ## MPI -INCLUDE(SetupMPI) -IF(MPI_C_FOUND) - INCLUDE_DIRECTORIES(${MPI_C_INCLUDE_PATH}) - LIST(APPEND ROSS_EXTERNAL_LIBS ${MPI_C_LIBRARIES}) -ELSE(MPI_C_FOUND) - MESSAGE("WARNING: Could not find MPI!") - MESSAGE(" Either add an MPI compiler to your path (using modules)") - MESSAGE(" Or force CMake to build using the correct compiler (`export CC=mpicc`)") -ENDIF(MPI_C_FOUND) +# MPI is required; build the system C compiler against MPI::MPI_C rather than +# forcing CC=mpicc. For non-standard installs, hint with -DMPI_HOME=... or +# `module load ` before configuring. +find_package(MPI REQUIRED COMPONENTS C) # Code coverage instrumentation (GCC/Clang only). Applied at directory scope # so flags propagate to core/ and models/. Collect with lcov/gcovr after ctest. diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index dbcec0f26..5c74bc96d 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -121,8 +121,10 @@ OPTION(ROSS_BUILD_SHARED_LIBS "Build shared libraries instead of static" OFF) SET(BUILD_SHARED_LIBS ${ROSS_BUILD_SHARED_LIBS}) ADD_LIBRARY(ROSS ${ross_srcs}) SET_TARGET_PROPERTIES(ROSS PROPERTIES OUTPUT_NAME ROSS) -TARGET_LINK_LIBRARIES(ROSS ${ROSS_EXTERNAL_LIBS}) -TARGET_INCLUDE_DIRECTORIES(ROSS INTERFACE ${MPI_C_INCLUDE_PATH}) +# MPI is PUBLIC because core/ross.h does `#include ` — consumers must +# inherit the MPI include path and link against MPI when they link ROSS. +target_link_libraries(ROSS PUBLIC MPI::MPI_C) +target_link_libraries(ROSS PRIVATE m) # Build Specific Config Header CONFIGURE_FILE(config.h.in config.h) diff --git a/core/cmake/SetupMPI.cmake b/core/cmake/SetupMPI.cmake deleted file mode 100644 index c257cefae..000000000 --- a/core/cmake/SetupMPI.cmake +++ /dev/null @@ -1,77 +0,0 @@ -############################################################################### -# Copyright (c) 2017, Lawrence Livermore National Security, LLC. -# -# Produced at the Lawrence Livermore National Laboratory -# -# LLNL-CODE-725085 -# -# All rights reserved. -# -# This file is part of BLT. -# -# For additional details, please also read BLT/LICENSE. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, -# this list of conditions and the disclaimer below. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the disclaimer (as noted below) in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of the LLNS/LLNL nor the names of its contributors may -# be used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, -# LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################### - -################################ -# MPI -################################ - -find_package(MPI) -message(STATUS "MPI C Compile Flags: ${MPI_C_COMPILE_FLAGS}") -message(STATUS "MPI C Include Path: ${MPI_C_INCLUDE_PATH}") -message(STATUS "MPI C Link Flags: ${MPI_C_LINK_FLAGS}") -message(STATUS "MPI C Libraries: ${MPI_C_LIBRARIES}") - -message(STATUS "MPI CXX Compile Flags: ${MPI_CXX_COMPILE_FLAGS}") -message(STATUS "MPI CXX Include Path: ${MPI_CXX_INCLUDE_PATH}") -message(STATUS "MPI CXX Link Flags: ${MPI_CXX_LINK_FLAGS}") -message(STATUS "MPI CXX Libraries: ${MPI_CXX_LIBRARIES}") - -message(STATUS "MPI Executable: ${MPIEXEC}") -message(STATUS "MPI Num Proc Flag: ${MPIEXEC_NUMPROC_FLAG}") - - -if (ENABLE_FORTRAN) - # Determine if we should use fortran mpif.h header or fortran mpi module - find_path(mpif_path - NAMES "mpif.h" - PATHS ${MPI_Fortran_INCLUDE_PATH} - NO_DEFAULT_PATH - ) - - if(mpif_path) - set(MPI_Fortran_USE_MPIF ON CACHE PATH "") - message(STATUS "Using MPI Fortran header: mpif.h") - else() - set(MPI_Fortran_USE_MPIF OFF CACHE PATH "") - message(STATUS "Using MPI Fortran module: mpi.mod") - endif() -endif()