From d086cc5a0ee604652e4681fe3bca6d4929b2666f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 11 Dec 2023 09:54:49 +0100 Subject: [PATCH] COMP: stricter handling of openmp vs no-openmp - give precedence to ~openmp (-no-openmp) over +openmp (-openmp) in the general rules and in the Makefile. This makes it robuster when specifying +openmp in general, but ~openmp for specific build components. - disable openmp for OSspecific and Pstream components. Neither should contain any openmp code anyhow. Additionally, since OSspecific is generally built as a static object, it can become problematic (eg, with AMD ROCm) if the compiler generates information that openmp is required but then uses static linkage. --- src/OSspecific/MSwindows/Allwmake | 3 ++- src/OSspecific/POSIX/Allwmake | 3 ++- src/Pstream/Allwmake | 5 ++-- src/Pstream/Allwmake-mpi | 3 ++- src/parallel/decompose/Allwmake-mpi | 3 ++- wmake/makefiles/general | 8 +++++-- wmake/rules/General/general | 8 +++++-- wmake/scripts/AllwmakeParseArguments | 10 ++++++-- wmake/scripts/wmakeFunctions | 36 +++++++++++++++++++++++----- 9 files changed, 61 insertions(+), 18 deletions(-) diff --git a/src/OSspecific/MSwindows/Allwmake b/src/OSspecific/MSwindows/Allwmake index b294db8920..54fd2ae995 100755 --- a/src/OSspecific/MSwindows/Allwmake +++ b/src/OSspecific/MSwindows/Allwmake @@ -19,6 +19,7 @@ fi unset COMP_FLAGS LINK_FLAGS # Make object (non-shared by default) -wmake $targetType +# Never want/need openmp, especially for static objects +wmake -no-openmp $targetType #------------------------------------------------------------------------------ diff --git a/src/OSspecific/POSIX/Allwmake b/src/OSspecific/POSIX/Allwmake index f5913a9a4e..0da34ed520 100755 --- a/src/OSspecific/POSIX/Allwmake +++ b/src/OSspecific/POSIX/Allwmake @@ -14,6 +14,7 @@ then fi # Make object (non-shared by default) -wmake $targetType +# Never want/need openmp, especially for static objects +wmake -no-openmp $targetType #------------------------------------------------------------------------------ diff --git a/src/Pstream/Allwmake b/src/Pstream/Allwmake index dd2ad10d8a..109fef62ea 100755 --- a/src/Pstream/Allwmake +++ b/src/Pstream/Allwmake @@ -3,9 +3,10 @@ cd "${0%/*}" || exit # Run from this directory . ${WM_PROJECT_DIR:?}/wmake/scripts/AllwmakeParseArguments #------------------------------------------------------------------------------ +# Never need/want openmp for MPI interfaces, or for static linkage -echo "wmake $targetType dummy (mpi=$WM_MPLIB)" -wmake $targetType dummy +echo "wmake -no-openmp $targetType${targetType:+ }dummy (mpi=$WM_MPLIB)" +wmake -no-openmp $targetType dummy ./Allwmake-mpi $targetType $* diff --git a/src/Pstream/Allwmake-mpi b/src/Pstream/Allwmake-mpi index 9b72d0f821..4f2ae200e0 100755 --- a/src/Pstream/Allwmake-mpi +++ b/src/Pstream/Allwmake-mpi @@ -7,6 +7,7 @@ cd "${0%/*}" || exit # Run from this directory # Environment # - FOAM_MPI_LIBBIN (optional: defaults to FOAM_LIBBIN/FOAM_MPI) -wmakeLibMpi mpi +# Never need/want openmp for MPI interfaces +wmakeLibMpi -no-openmp mpi #------------------------------------------------------------------------------ diff --git a/src/parallel/decompose/Allwmake-mpi b/src/parallel/decompose/Allwmake-mpi index 1a3bf2ab17..ceb23ce3f1 100755 --- a/src/parallel/decompose/Allwmake-mpi +++ b/src/parallel/decompose/Allwmake-mpi @@ -15,7 +15,8 @@ if have_scotch then if have_ptscotch then - wmakeLibMpi ptscotchDecomp "scotch=$SCOTCH_VERSION" + # Never need/want openmp for MPI interfaces + wmakeLibMpi -no-openmp ptscotchDecomp "scotch=$SCOTCH_VERSION" fi fi diff --git a/wmake/makefiles/general b/wmake/makefiles/general index 9b50f7886c..cea6c58690 100644 --- a/wmake/makefiles/general +++ b/wmake/makefiles/general @@ -6,7 +6,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2011-2016 OpenFOAM Foundation -# Copyright (C) 2019-2022 OpenCFD Ltd. +# Copyright (C) 2019-2023 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -19,7 +19,7 @@ # # Embedded Control Parameters # -# WM_COMPILE_CONTROL (+openmp) +# WM_COMPILE_CONTROL (+openmp | ~openmp) # WM_COMPILE_CONTROL (~openfoam) # WM_OSTYPE (windows) # @@ -62,9 +62,13 @@ SYS_INC = SYS_LIBS = # Add linkage for openmp into the system libraries +# - if enabled (+openmp) and not disabled (~openmp). +# - disable has higher precedence +ifeq (,$(findstring ~openmp,$(WM_COMPILE_CONTROL))) ifneq (,$(findstring +openmp,$(WM_COMPILE_CONTROL))) SYS_LIBS = $(LINK_OPENMP) endif +endif # These are set by Make/options EXE_INC = diff --git a/wmake/rules/General/general b/wmake/rules/General/general index 8715cd0239..7e3ce1caa4 100644 --- a/wmake/rules/General/general +++ b/wmake/rules/General/general @@ -52,9 +52,13 @@ sinclude $(RULES)/general sinclude $(RULES)/c++ endif -# Add compile flags for openmp +# Compile flags for openmp +# - if enabled (+openmp) and not disabled (~openmp). +# - disable has higher precedence +ifeq (,$(findstring ~openmp,$(WM_COMPILE_CONTROL))) ifneq (,$(findstring +openmp,$(WM_COMPILE_CONTROL))) -c++FLAGS += $(COMP_OPENMP) + c++FLAGS += $(COMP_OPENMP) +endif endif include $(GENERAL_RULES)/transform diff --git a/wmake/scripts/AllwmakeParseArguments b/wmake/scripts/AllwmakeParseArguments index 0f5ddeea8e..63a7501a30 100644 --- a/wmake/scripts/AllwmakeParseArguments +++ b/wmake/scripts/AllwmakeParseArguments @@ -27,6 +27,7 @@ # # Parsed options (wmake) # -debug | -debug-O[g0123] +# -openmp | -no-openmp # -strict # -q | -queue # -build-root=... @@ -88,7 +89,7 @@ USAGE #------------------------------------------------------------------------------ unset wmakeOpt_frontend wmakeOpt_nonRecursive -unset wmakeOpt_debug wmakeOpt_log wmakeOpt_strict wmakeOpt_queue +unset wmakeOpt_debug wmakeOpt_log wmakeOpt_openmp wmakeOpt_strict wmakeOpt_queue for arg in "$@" do @@ -184,6 +185,11 @@ do continue # Argument handled, remove it ;; + -openmp | -no-openmp) + wmakeOpt_openmp="$arg" + continue # Argument handled, remove it + ;; + -q | -queue) wmakeOpt_queue="-queue" continue # Argument handled, remove it @@ -240,7 +246,7 @@ fi #------------------------------------------------------------------------------ unset wmakeOpt_frontend wmakeOpt_nonRecursive -unset wmakeOpt_debug wmakeOpt_log wmakeOpt_strict wmakeOpt_queue +unset wmakeOpt_debug wmakeOpt_log wmakeOpt_openmp wmakeOpt_strict wmakeOpt_queue unset -f usage diff --git a/wmake/scripts/wmakeFunctions b/wmake/scripts/wmakeFunctions index 5225e90109..2e6ad10f7f 100644 --- a/wmake/scripts/wmakeFunctions +++ b/wmake/scripts/wmakeFunctions @@ -6,7 +6,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2015-2016 OpenFOAM Foundation -# Copyright (C) 2018-2021 OpenCFD Ltd. +# Copyright (C) 2018-2023 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -348,19 +348,43 @@ sameDependency() # Build a mpi-versioned library (targetType) -# - use sentinel file(s) to handle paraview version changes -# compile into qualified directory +# compile into MPI-qualified directory # use sentinel file(s) to handle version changes # 1 - libName # 2... build/configure information # # Global variables used: # - WM_OPTIONS, WM_MPLIB, FOAM_MPI +# - targetType # # Requires that WM_MPLIB contain an "MPI" string +# +# Has very simple option handling (bool options only!) that allow +# things like "wmakeLibMpi -debug -no-openmp" etc. +# wmakeLibMpi() { - local libName="$1" + local libName + local wmakeCmd="wmake" + + # Very simple option handling (bool options only!) + while [ "$#" -gt 0 ] + do + case "$1" in + (- | --) # Stop option parsing + shift + break + ;; + (-*) # Any bool option + wmakeCmd="$wmakeCmd $1" + ;; + (*) + break # Done + ;; + esac + shift + done + libName="$1" shift case "$WM_MPLIB" in (*MPI* | *mpi*) @@ -374,8 +398,8 @@ wmakeLibMpi() sentinel=$(sameDependency "$libName" "MPLIB=$WM_MPLIB" "MPI=$FOAM_MPI" $@) || \ wclean "$libName" - echo "wmake $targetType $libName (mpi=$WM_MPLIB:$FOAM_MPI)" - wmake $targetType "$libName" && \ + echo "$wmakeCmd $targetType${targetType:+ }(mpi=$WM_MPLIB:$FOAM_MPI)" + $wmakeCmd $targetType "$libName" && \ storeDependency "$sentinel" "MPLIB=$WM_MPLIB" "MPI=$FOAM_MPI" $@ ) ;;