View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0004137 | OpenFOAM | Contribution | public | 2024-08-13 11:46 | 2024-08-13 11:48 |
Reporter | wyldckat | Assigned To | |||
Priority | low | Severity | tweak | Reproducibility | always |
Status | new | Resolution | open | ||
Platform | GNU/Linux | OS | Other | OS Version | (please specify) |
Product Version | dev | ||||
Summary | 0004137: Proposal for improving the build workflow for parallel libraries | ||||
Description | This is a proposal to replace 'wmake/scripts/AllwmakeMpiLib', namely the way of building OpenFOAM's decomposition libraries for ptscotch, parmetis and zoltan, as well revising the build workflow for 'Pstream/mpi'. Attached are the following files: - replaceAllwmakeMpiLib_v1.patch - this shows the changes made to the files - replaceAllwmakeMpiLib_v1.tar.gz - has all modified files, but does not remove the ones that are no longer needed. Commands for removing the outdated files: git rm src/Pstream/Allwclean git rm src/parallel/decompose/parMetis/Allwclean git rm src/parallel/decompose/ptscotch/Allwclean git rm src/parallel/decompose/zoltan/Allwclean git rm wmake/scripts/AllwmakeMpiLib The changes are as follows: 1. 'Make/files' for the relevant libraries, receive a new variable definition MPILIB, which defines the version of the library it depends on. - For Pstream/mpi, this has been set to be OpenFOAM's own version name and number, for consistency. 2. 'wmakeMpiLib' and 'wcleanMpiLib' functions are removed, along with the script 'wmake/scripts/AllwmakeMpiLib'. 3. The 'Allwclean' scripts are no longer needed. 4. 'ptscotch/Allwmake' no longer checks if MPI is being used, given that parmetis' and zoltan's 'Allwmake' scripts didn't do that. 5. 'wmake' and 'wclean' now check if 'MPILIB' is defined in 'Make/files' and if so, change the 'WM_OPTIONS' variable, the same it used be done in the existing workflow. - 'wmake' also checks if 'WM_MPLIB' has MPI in the name. 6. 'wmake/makefiles/general' now adds conditional targets in function of 'MPILIB' being defined: a) Defines the tag file, similar to what is currently being done, but replaces the 2 files for a single one for the decomposition libraries, since it gives the same exact effect. b) Appends to 'lib', 'libo' and 'libso' targets the dependency on the new target 'tagmpi'. c) Target 'tagmpi' depends on the tag file existing. d) Object files now also depend on the tag file existing. e) And finally the target for creating said tag file. There is still room for improvement, but this is the next major step for simplifying the build process for these libraries. Examples of further improvement: A. Remove 'Allwmake' from 'Pstream', given that the current workflow no longer requires it. | ||||
Additional Information | I've recently been improving my skills with hacking into OpenFOAM's Make files, then adding to my several-years nagging feeling that the existing handling of 'Pstream/mpi' and 'ptscotch' is very hackish, along with the recent issue 4125, I've finally delved into this topic, hence this proposal. | ||||
Tags | No tags attached. | ||||
|
replaceAllwmakeMpiLib_v1.patch (12,054 bytes)
diff --git a/src/Pstream/Allwclean b/src/Pstream/Allwclean deleted file mode 100755 index 2650e4e38a..0000000000 --- a/src/Pstream/Allwclean +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -cd ${0%/*} || exit 1 # Run from this directory - -# Define how an mpi-versioned library is created -# clean the qualified directory -wcleanMpiLib() -{ - for libName - do - ( - WM_OPTIONS="$WM_OPTIONS$WM_MPLIB" - wclean $libName - ) - done -} - -wclean dummy - -case "$WM_MPLIB" in -*MPI*) - wcleanMpiLib mpi - ;; -esac - - -#------------------------------------------------------------------------------ diff --git a/src/Pstream/Allwmake b/src/Pstream/Allwmake index 9fdd37bae3..c517d487c7 100755 --- a/src/Pstream/Allwmake +++ b/src/Pstream/Allwmake @@ -5,28 +5,11 @@ cd ${0%/*} || exit 1 # Run from this directory . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments -# Define how to create an mpi-versioned library of $targetType -# compile into qualified directory -# use sentinel file to handle version changes -wmakeMpiLib() -{ - for libName - do - ( - WM_OPTIONS="$WM_OPTIONS$WM_MPLIB" - whichmpi="$WM_PROJECT_DIR/platforms/$WM_OPTIONS/src/Pstream/$libName/using:$FOAM_MPI" - [ -e "$whichmpi" ] || wclean $libName - wmake $targetType $libName - touch "$whichmpi" - ) - done -} - wmake $targetType dummy case "$WM_MPLIB" in *MPI*) - wmakeMpiLib mpi + wmake $targetType mpi ;; esac diff --git a/src/Pstream/mpi/Make/files b/src/Pstream/mpi/Make/files index c01382d678..cffb5f68fc 100644 --- a/src/Pstream/mpi/Make/files +++ b/src/Pstream/mpi/Make/files @@ -3,4 +3,5 @@ UIPread.C UPstream.C PstreamGlobals.C +MPILIB = $(WM_PROJECT)-$(WM_PROJECT_VERSION) LIB = $(FOAM_LIBBIN)/$(FOAM_MPI)/libPstream diff --git a/src/parallel/decompose/parMetis/Allwclean b/src/parallel/decompose/parMetis/Allwclean deleted file mode 100755 index 12ac95e286..0000000000 --- a/src/parallel/decompose/parMetis/Allwclean +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -cd ${0%/*} || exit 1 # Run from this directory - -. $WM_PROJECT_DIR/wmake/scripts/AllwmakeMpiLib - -wcleanMpiLib - -#------------------------------------------------------------------------------ diff --git a/src/parallel/decompose/parMetis/Allwmake b/src/parallel/decompose/parMetis/Allwmake index 5be6f60fa9..d0470f255c 100755 --- a/src/parallel/decompose/parMetis/Allwmake +++ b/src/parallel/decompose/parMetis/Allwmake @@ -9,10 +9,9 @@ case $PARMETIS_TYPE in none) ;; *) - . $WM_PROJECT_DIR/wmake/scripts/AllwmakeMpiLib . $($WM_PROJECT_DIR/bin/foamEtcFile config.sh/parMetis) echo " using PARMETIS_ARCH_PATH=$PARMETIS_ARCH_PATH" - wmakeMpiLib parmetis-$PARMETIS_VERSION parMetis + wmake $targetType ;; esac diff --git a/src/parallel/decompose/parMetis/Make/files b/src/parallel/decompose/parMetis/Make/files index 3d70ac1174..8b901ca1fc 100644 --- a/src/parallel/decompose/parMetis/Make/files +++ b/src/parallel/decompose/parMetis/Make/files @@ -1,3 +1,4 @@ parMetis.C +MPILIB = parmetis-$(PARMETIS_VERSION) LIB = $(FOAM_LIBBIN)/$(FOAM_MPI)/libparMetisDecomp diff --git a/src/parallel/decompose/ptscotch/Allwclean b/src/parallel/decompose/ptscotch/Allwclean deleted file mode 100755 index 12ac95e286..0000000000 --- a/src/parallel/decompose/ptscotch/Allwclean +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -cd ${0%/*} || exit 1 # Run from this directory - -. $WM_PROJECT_DIR/wmake/scripts/AllwmakeMpiLib - -wcleanMpiLib - -#------------------------------------------------------------------------------ diff --git a/src/parallel/decompose/ptscotch/Allwmake b/src/parallel/decompose/ptscotch/Allwmake index 8fbf4ae38c..1b7e2e5c10 100755 --- a/src/parallel/decompose/ptscotch/Allwmake +++ b/src/parallel/decompose/ptscotch/Allwmake @@ -4,21 +4,15 @@ cd ${0%/*} || exit 1 # Run from this directory # Parse arguments for library compilation . $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments -# Build if Scotch is enabled and MPI is available -if [ -n "$WM_MPLIB" ] && [ -d "$FOAM_LIBBIN/$FOAM_MPI" ] -then - case $SCOTCH_TYPE in - none) - ;; - *) - . $WM_PROJECT_DIR/wmake/scripts/AllwmakeMpiLib - . $($WM_PROJECT_DIR/bin/foamEtcFile config.sh/scotch) - echo " using SCOTCH_ARCH_PATH=$SCOTCH_ARCH_PATH" - wmakeMpiLib scotch_$SCOTCH_VERSION ptscotch - ;; - esac -else - echo " skipping ptscotch" -fi +# Build if Scotch is enabled +case $SCOTCH_TYPE in +none) + ;; +*) + . $($WM_PROJECT_DIR/bin/foamEtcFile config.sh/scotch) + echo " using SCOTCH_ARCH_PATH=$SCOTCH_ARCH_PATH" + wmake $targetType + ;; +esac #------------------------------------------------------------------------------ diff --git a/src/parallel/decompose/ptscotch/Make/files b/src/parallel/decompose/ptscotch/Make/files index a889925dfc..2cfc347807 100644 --- a/src/parallel/decompose/ptscotch/Make/files +++ b/src/parallel/decompose/ptscotch/Make/files @@ -1,3 +1,4 @@ ptscotch.C +MPILIB = scotch_$(SCOTCH_VERSION) LIB = $(FOAM_LIBBIN)/$(FOAM_MPI)/libptscotchDecomp diff --git a/src/parallel/decompose/zoltan/Allwclean b/src/parallel/decompose/zoltan/Allwclean deleted file mode 100755 index 12ac95e286..0000000000 --- a/src/parallel/decompose/zoltan/Allwclean +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -cd ${0%/*} || exit 1 # Run from this directory - -. $WM_PROJECT_DIR/wmake/scripts/AllwmakeMpiLib - -wcleanMpiLib - -#------------------------------------------------------------------------------ diff --git a/src/parallel/decompose/zoltan/Allwmake b/src/parallel/decompose/zoltan/Allwmake index 6b2e4dac8e..9134b7b0f5 100755 --- a/src/parallel/decompose/zoltan/Allwmake +++ b/src/parallel/decompose/zoltan/Allwmake @@ -9,10 +9,9 @@ case $ZOLTAN_TYPE in none) ;; *) - . $WM_PROJECT_DIR/wmake/scripts/AllwmakeMpiLib . $($WM_PROJECT_DIR/bin/foamEtcFile config.sh/zoltan) echo " using ZOLTAN_ARCH_PATH=$ZOLTAN_ARCH_PATH" - wmakeMpiLib Zoltan-$ZOLTAN_VERSION zoltan + wmake $targetType ;; esac diff --git a/src/parallel/decompose/zoltan/Make/files b/src/parallel/decompose/zoltan/Make/files index a139f3c266..162e3fc3db 100644 --- a/src/parallel/decompose/zoltan/Make/files +++ b/src/parallel/decompose/zoltan/Make/files @@ -1,3 +1,4 @@ zoltan.C +MPILIB = Zoltan-$(ZOLTAN_VERSION) LIB = $(FOAM_LIBBIN)/$(FOAM_MPI)/libzoltanDecomp diff --git a/wmake/makefiles/general b/wmake/makefiles/general index e549260f3b..fd300728c0 100644 --- a/wmake/makefiles/general +++ b/wmake/makefiles/general @@ -2,7 +2,7 @@ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | Website: https://openfoam.org -# \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation +# \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation # \\/ M anipulation | #------------------------------------------------------------------------------ # License @@ -202,6 +202,32 @@ $(LIB).o: $(OBJECTS) $E $(LD) -r -o $(LIB).o $(OBJECTS) +#------------------------------------------------------------------------------ +# Add dependencies for MPI-based libraries +#------------------------------------------------------------------------------ + +# MPILIB should define the name and version of library that it depends on +ifdef MPILIB + +TAGMPI_FILE=$(OBJECTS_DIR)/using\:$(FOAM_MPI)_$(MPILIB) + +.PHONY: tagmpi +libso: tagmpi +lib: tagmpi +libo: tagmpi + +tagmpi: $(TAGMPI_FILE) + +# Objects must depend on this tag file, otherwise they should all rebuild due to +# new version +$(OBJECTS): $(TAGMPI_FILE) + +$(TAGMPI_FILE): + @touch $(TAGMPI_FILE) + +endif + + #------------------------------------------------------------------------------ # Set rule to create the include directory for libraries #------------------------------------------------------------------------------ diff --git a/wmake/scripts/AllwmakeMpiLib b/wmake/scripts/AllwmakeMpiLib deleted file mode 100644 index 30eea78ba6..0000000000 --- a/wmake/scripts/AllwmakeMpiLib +++ /dev/null @@ -1,65 +0,0 @@ -#----------------------------------*-sh-*-------------------------------------- -# ========= | -# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox -# \\ / O peration | Website: https://openfoam.org -# \\ / A nd | Copyright (C) 2024 OpenFOAM Foundation -# \\/ M anipulation | -#------------------------------------------------------------------------------ -# License -# This file is part of OpenFOAM. -# -# OpenFOAM is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# for more details. -# -# You should have received a copy of the GNU General Public License -# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. -# -# File -# wmake/scripts/AllwmakeMpiLib -# -# Description -# Bash functions to compile and clean MPI dependent libraries -# -# Usage -# . $WM_PROJECT_DIR/wmake/scripts/AllwmakeMpiLib -# -#------------------------------------------------------------------------------ - -# Define how to create an mpi-versioned library of $targetType -# compile into qualified directory -# use sentinel file to handle version changes -wmakeMpiLib() -{ - ( - version="$1" - libName="$2" - - WM_OPTIONS="$WM_OPTIONS$WM_MPLIB" - whichmpi="$WM_PROJECT_DIR/platforms/$WM_OPTIONS/src/parallel/decompose/$libName/using:$FOAM_MPI" - whichtarget="$WM_PROJECT_DIR/platforms/$WM_OPTIONS/src/parallel/decompose/$libName/using:$version" - [ -e "$whichmpi" -a -e "$whichtarget" ] || wclean -noLnInclude - echo "wmake $targetType" - wmake $targetType - touch "$whichmpi" "$whichtarget" - ) -} - - -# Define how to clean an mpi-versioned library -wcleanMpiLib() -{ - ( - WM_OPTIONS="$WM_OPTIONS$WM_MPLIB" - wclean - ) -} - - -#------------------------------------------------------------------------------ diff --git a/wmake/wclean b/wmake/wclean index 8a3150de7f..2e92c91516 100755 --- a/wmake/wclean +++ b/wmake/wclean @@ -265,6 +265,16 @@ unset targetType if [ -d "$MakeDir" ] then + + # Detect if MPILIB is defined + if grep -q -e '^ *MPILIB *=' "$MakeDir/files" + then + if [ "${WM_MPLIB}" != "${WM_MPLIB/MPI/}" ] + then + export WM_OPTIONS="$WM_OPTIONS$WM_MPLIB" + fi + fi + objectsDir=$MakeDir/$WM_OPTIONS expandPath "$PWD" if [[ "$exPath" = *"$WM_PROJECT_DIR"* ]] diff --git a/wmake/wmake b/wmake/wmake index 307114655d..f7939d2dae 100755 --- a/wmake/wmake +++ b/wmake/wmake @@ -3,7 +3,7 @@ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | Website: https://openfoam.org -# \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation +# \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation # \\/ M anipulation | #------------------------------------------------------------------------------ # License @@ -388,6 +388,18 @@ then esac fi +# Detect if MPILIB is defined +if grep -q -e '^ *MPILIB *=' "$MakeDir/files" +then + if [ "${WM_MPLIB}" = "${WM_MPLIB/MPI/}" ] + then + echo "$Script warning: skipping this library since WM_MPLIB is not MPI" + exit 0 + else + export WM_OPTIONS="$WM_OPTIONS$WM_MPLIB" + fi +fi + #------------------------------------------------------------------------------ # Created the objectsDir directory |