From ae5b2326c047f80c577877af0811b17923869071 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 29 Apr 2019 18:41:26 +0200 Subject: [PATCH] ENH: provide separate makeSCOTCH script for independent use - improve handling of scotch build toolchain - relax the test for existence of libscotcherrexit, which can also be incorporated into libscotch itself --- Allwmake | 207 +------------ .../Makefile.inc.OpenFOAM-Linux-Mingw.shlib | 11 +- etc/patches/scotch_6.0.6 | 44 ++- etc/tools/ThirdPartyFunctions | 18 ++ makeHYPRE | 2 +- makeMETIS | 2 +- makeMGridGen | 2 +- makePETSC | 2 +- makeSCOTCH | 290 ++++++++++++++++++ 9 files changed, 355 insertions(+), 223 deletions(-) create mode 100755 makeSCOTCH diff --git a/Allwmake b/Allwmake index 1340393..fc11e87 100755 --- a/Allwmake +++ b/Allwmake @@ -38,21 +38,6 @@ exportCompiler true # Compiler info + flags for CMake/configure exportLinker # Linker flags for CMake/configure useGccFlag $@ # Scan arguments for a '-gcc' option -warnBuildIssues() -{ - echo - echo " ---------------------------------------------------" - echo " Optional component ($1) had build issues" - echo " OpenFOAM will nonetheless remain largely functional" - echo " ---------------------------------------------------" - echo -} - -warnNotFound() -{ - echo "Optional component ($1) was not found" -} - #------------------------------------------------------------------------------ echo @@ -73,191 +58,10 @@ esac #------------------------------------------------------------------------------ -# Building scotch on different platforms is still a bit of a pain - -# Get SCOTCH_VERSION, SCOTCH_ARCH_PATH -if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/scotch) -then - . $settings -else - echo - echo "Error: no config.sh/scotch settings" - echo -fi - -echo -echo ======================================== -echo "Scotch decomposition ($SCOTCH_VERSION)" -echo " $SCOTCH_ARCH_PATH" - -SCOTCH_SOURCE_DIR=$sourceBASE/$SCOTCH_VERSION - -# Needs generalizing, but works fairly well -for scotchMakefile in \ - "OpenFOAM-$(uname -s)-${WM_COMPILER}.shlib" \ - "OpenFOAM-$(uname -s).shlib" \ - OpenFOAM-Linux.shlib \ -; -do - scotchMakefile="etc/makeFiles/scotch/Makefile.inc.$scotchMakefile" - [ -f "$scotchMakefile" ] && break -done - - -if [ -f "$SCOTCH_ARCH_PATH/include/scotch.h" ] \ -&& [ -r "$FOAM_EXT_LIBBIN/libscotch$EXT_SO" ] \ -&& [ -r "$FOAM_EXT_LIBBIN/libscotcherrexit$EXT_SO" ] -then - echo " scotch include: $SCOTCH_ARCH_PATH/include" - echo " scotch library: $FOAM_EXT_LIBBIN" -elif [ -d "$SCOTCH_SOURCE_DIR" ] -then -( - # Older versions ok, but scotch-6.0.5a cannot build in parallel. - # Force serial build - export WM_NCOMPPROCS=1 - echo "*** building scotch in serial ***" - echo - - [ -f "$scotchMakefile" ] || { - echo " Error: no such makefile: $scotchMakefile" - exit 1 - } - - cd $SCOTCH_SOURCE_DIR/src || exit 1 - export GIT_DIR=$SCOTCH_SOURCE_DIR/.git # Mask seeing our own git-repo - rm -rf $SCOTCH_ARCH_PATH - - applyPatch $SCOTCH_VERSION .. # patch at parent-level - - prefixDIR=$SCOTCH_ARCH_PATH - incDIR=$SCOTCH_ARCH_PATH/include - libDIR=$FOAM_EXT_LIBBIN - - mkdir -p $prefixDIR 2>/dev/null - mkdir -p $incDIR 2>/dev/null - mkdir -p $libDIR 2>/dev/null - - # Makefile relative to this directory - scotchMakefile=../../$scotchMakefile - - if [ -f $scotchMakefile ] - then - rm -f Makefile.inc - ln -s $scotchMakefile Makefile.inc - fi - [ -f Makefile.inc ] || { - echo " Error: scotch needs an appropriate Makefile.inc" - exit 1 - } - - export CCS="$(whichCC)" # CCS (serial compiler) - export CCP="$(whichMpicc)" # CCP (parallel compiler) default=mpicc - - # Consistency for Intel-MPI and non-icc compilers - [ -n "$I_MPI_CC" ] || export I_MPI_CC="$(whichCC)" - - make realclean 2>/dev/null # Extra safety - make -j $WM_NCOMPPROCS libscotch \ - && make \ - prefix=$prefixDIR \ - includedir=$incDIR \ - libdir=$libDIR \ - install - - make realclean 2>/dev/null || true # Failed cleanup is uncritical -) || warnBuildIssues SCOTCH -else - warnNotFound SCOTCH -fi - -# Build ptscotch if MPI (ThirdParty or system) is available -# and normal scotch was built (has include and library) -if [ "${FOAM_MPI:-dummy}" != dummy ] && \ - [ -f $SCOTCH_ARCH_PATH/include/scotch.h \ - -a -r $FOAM_EXT_LIBBIN/libscotch$EXT_SO ] || \ -{ - # Report that the above tests failed and pass-through the failure - echo - echo " WARNING: skipping pt-scotch - no mpi or not found" - false -} -then - echo - echo ======================================== - echo "pt-scotch decomposition ($SCOTCH_VERSION with $FOAM_MPI)" - echo " $SCOTCH_ARCH_PATH" - - if [ -f $SCOTCH_ARCH_PATH/include/$FOAM_MPI/ptscotch.h \ - -a -r $FOAM_EXT_LIBBIN/$FOAM_MPI/libptscotch$EXT_SO \ - -a -r $FOAM_EXT_LIBBIN/$FOAM_MPI/libptscotcherrexit$EXT_SO ] - then - echo " ptscotch include: $SCOTCH_ARCH_PATH/include/$FOAM_MPI" - echo " ptscotch library: $FOAM_EXT_LIBBIN/$FOAM_MPI" - else - ( - # Older versions ok, but scotch-6.0.5a cannot build in parallel. - # Force serial build - export WM_NCOMPPROCS=1 - echo "*** building pt-scotch in serial ***" - - [ -f "$scotchMakefile" ] || { - echo " Error: no such makefile: $scotchMakefile" - exit 1 - } - - cd $SCOTCH_SOURCE_DIR/src || exit 1 - export GIT_DIR=$SCOTCH_SOURCE_DIR/.git # Mask seeing our own git-repo - echo - - prefixDIR=$SCOTCH_ARCH_PATH - incDIR=$SCOTCH_ARCH_PATH/include/$FOAM_MPI - libDIR=$FOAM_EXT_LIBBIN/$FOAM_MPI - - mkdir -p $prefixDIR 2>/dev/null - mkdir -p $incDIR 2>/dev/null - mkdir -p $libDIR 2>/dev/null - - if [ -f $scotchMakefile ] - then - rm -f Makefile.inc - ln -s $scotchMakefile Makefile.inc - fi - [ -f Makefile.inc ] || { - echo " Error: ptscotch needs an appropriate Makefile.inc" - exit 1 - } - - export CCS="$(whichCC)" # CCS (serial compiler) - export CCP=$(whichMpicc) # CCP (parallel compiler) default=mpicc - - # Consistency for Intel-MPI and non-icc compilers - [ -n "$I_MPI_CC" ] || export I_MPI_CC="$(whichCC)" - - make realclean 2>/dev/null # Extra safety - make -j $WM_NCOMPPROCS libptscotch \ - && make \ - prefix=$prefixDIR \ - includedir=$incDIR \ - libdir=$libDIR \ - install - - make realclean 2>/dev/null || true # Failed cleanup is uncritical - ) || warnBuildIssues PTSCOTCH - fi - - # Verify existence of ptscotch include - [ -f $SCOTCH_ARCH_PATH/include/$FOAM_MPI/ptscotch.h ] || { - echo - echo " WARNING: required include file 'ptscotch.h' not found!" - } -fi - -# Could now remove $SCOTCH_SOURCE_DIR/src/Makefile.inc +./makeSCOTCH #------------------------------------------------------------------------------ - echo echo ======================================== # Get KAHIP_ARCH_PATH @@ -271,13 +75,12 @@ then ./makeKAHIP -test "$KAHIP_ARCH_PATH" || \ ./makeKAHIP || warnBuildIssues KAHIP else - warnNotFound KAHIP # METIS is optional + warnNotFound KAHIP # is optional fi #------------------------------------------------------------------------------ echo echo ======================================== - # Get METIS_ARCH_PATH if settings=$($WM_PROJECT_DIR/bin/foamEtcFile config.sh/metis) then @@ -289,7 +92,7 @@ then ./makeMETIS -test "$METIS_ARCH_PATH" || \ ./makeMETIS || warnBuildIssues METIS else - warnNotFound METIS # METIS is optional + warnNotFound METIS # is optional fi #------------------------------------------------------------------------------ @@ -301,7 +104,7 @@ then ./makeCGAL -test "$CGAL_ARCH_PATH" "$BOOST_ARCH_PATH" || \ ./makeCGAL || warnBuildIssues CGAL else - warnNotFound CGAL # CGAL is optional + warnNotFound CGAL # is optional fi echo @@ -312,7 +115,7 @@ then ./makeFFTW -test "$FFTW_ARCH_PATH" || \ ./makeFFTW || warnBuildIssues FFTW else - warnNotFound FFTW # FFTW is optional + warnNotFound FFTW # is optional fi echo diff --git a/etc/makeFiles/scotch/Makefile.inc.OpenFOAM-Linux-Mingw.shlib b/etc/makeFiles/scotch/Makefile.inc.OpenFOAM-Linux-Mingw.shlib index 05ece01..0b769f1 100644 --- a/etc/makeFiles/scotch/Makefile.inc.OpenFOAM-Linux-Mingw.shlib +++ b/etc/makeFiles/scotch/Makefile.inc.OpenFOAM-Linux-Mingw.shlib @@ -23,14 +23,19 @@ EXE = LIB = .dll OBJ = .o -AR = $(CC) +# Separate the cross-compilation flags from regular CFLAGS to ensure that +# system gcc does not use them for the scotch build toolchain + +CFLAGS_CROSS = -DCOMMON_WINDOWS -DCOMMON_STUB_FORK + +AR = x86_64-w64-mingw32-gcc ARFLAGS = $(CFLAGS) -shared -Wl,--output-def,libscotch.def,--out-implib,libscotch.a,--enable-auto-import,--strip-all -o -CC = x86_64-w64-mingw32-gcc +CC = x86_64-w64-mingw32-gcc $(CFLAGS_CROSS) CCS = x86_64-w64-mingw32-gcc CCP = x86_64-w64-mingw32-gcc CCD = gcc CFLAGS = $(WM_CFLAGS) -fPIC -O3 \ - -DCOMMON_WINDOWS -DCOMMON_STUB_FORK -DCOMMON_PTHREAD_FILE \ + -DCOMMON_PTHREAD_FILE \ -UCOMMON_FILE_COMPRESS \ -DCOMMON_RANDOM_FIXED_SEED \ -DSCOTCH_DETERMINISTIC \ diff --git a/etc/patches/scotch_6.0.6 b/etc/patches/scotch_6.0.6 index 2c42f70..4ff5aa2 100644 --- a/etc/patches/scotch_6.0.6 +++ b/etc/patches/scotch_6.0.6 @@ -1,32 +1,48 @@ ---- scotch_6.0.6/src/libscotch/Makefile.orig 2019-04-14 19:54:54.819485613 +0200 -+++ scotch_6.0.6/src/libscotch/Makefile 2019-04-14 19:52:10.623889351 +0200 -@@ -51,6 +51,8 @@ +--- scotch_6.0.6/src/libscotch/Makefile.orig 2019-04-29 14:59:53.957103493 +0200 ++++ scotch_6.0.6/src/libscotch/Makefile 2019-04-29 18:50:42.560080675 +0200 +@@ -51,6 +51,12 @@ .PHONY : ptscotch scotch ptinstall install clean realclean -+libscotch : libscotch$(LIB) scotch.h ++ifeq ($(WM_OSTYPE),MSwindows) ++ ++libscotch : libscotch$(LIB) scotch.h ++ ++endif + scotch : $(MAKE) CC="$(CCS)" CCD="$(CCS)" \ scotch.h \ -@@ -436,7 +438,8 @@ - wgraph_part_rb$(OBJ) \ - wgraph_part_st$(OBJ) \ +@@ -438,6 +444,11 @@ wgraph_part_zr$(OBJ) \ -- wgraph_store$(OBJ) -+ wgraph_store$(OBJ) \ -+ library_error_exit$(OBJ) + wgraph_store$(OBJ) ++ifeq ($(WM_OSTYPE),MSwindows) ++## Add into libscotch instead of having a separate library ++LIBSCOTCHDEPS += library_error_exit$(OBJ) ++endif ++ ## ## Todo list. + ## --- scotch_6.0.6/src/Makefile.orig 2018-07-14 17:24:49.000000000 +0200 -+++ scotch_6.0.6/src/Makefile 2019-04-14 19:56:43.207219102 +0200 -@@ -90,7 +90,7 @@ ++++ scotch_6.0.6/src/Makefile 2019-04-29 18:39:16.365132864 +0200 +@@ -89,9 +89,18 @@ + $(mandir)/man1 : $(mandir) -$(MKDIR) $(mandir)/man1 - libscotch : required -- (cd libscotch ; $(MAKE) VERSION=$(VERSION) RELEASE=$(RELEASE) PATCHLEVEL=$(PATCHLEVEL) scotch && $(MAKE) install) ++ifeq ($(WM_OSTYPE),MSwindows) ++ ++libscotch : required + (cd libscotch ; $(MAKE) VERSION=$(VERSION) RELEASE=$(RELEASE) PATCHLEVEL=$(PATCHLEVEL) libscotch && $(MAKE) install) ++ ++else ++ + libscotch : required + (cd libscotch ; $(MAKE) VERSION=$(VERSION) RELEASE=$(RELEASE) PATCHLEVEL=$(PATCHLEVEL) scotch && $(MAKE) install) ++endif ++ scotch : libscotch (cd scotch ; $(MAKE) VERSION=$(VERSION) RELEASE=$(RELEASE) PATCHLEVEL=$(PATCHLEVEL) scotch && $(MAKE) install) + (cd libscotchmetis ; $(MAKE) scotch && $(MAKE) install) diff --git a/etc/tools/ThirdPartyFunctions b/etc/tools/ThirdPartyFunctions index e947731..bc61473 100644 --- a/etc/tools/ThirdPartyFunctions +++ b/etc/tools/ThirdPartyFunctions @@ -302,6 +302,24 @@ die() exit 1 } +# Warn +warnBuildIssues() +{ + echo + echo " ---------------------------------------------------" + echo " Optional component ($1) had build issues" + echo " OpenFOAM will nonetheless remain largely functional" + echo " ---------------------------------------------------" + echo +} + +# Warn +warnNotFound() +{ + echo "Optional component ($1) was not found" +} + + # Test if it matches "*-none" _foamIsNone() { diff --git a/makeHYPRE b/makeHYPRE index 28f2917..6906e6d 100755 --- a/makeHYPRE +++ b/makeHYPRE @@ -130,7 +130,7 @@ fi # HYPRE_SOURCE_DIR : location of the original sources HYPRE_SOURCE_DIR=$sourceBASE/$hyprePACKAGE -: ${HYPRE_ARCH_PATH:=$installBASE$WM_SIZE_OPTIONS/$hyprePACKAGE} +: "${HYPRE_ARCH_PATH:=$installBASE$WM_SIZE_OPTIONS/$hyprePACKAGE}" [ -d "$HYPRE_SOURCE_DIR" ] || { echo "Missing sources: '$hyprePACKAGE'" diff --git a/makeMETIS b/makeMETIS index b755d9a..e5a7525 100755 --- a/makeMETIS +++ b/makeMETIS @@ -130,7 +130,7 @@ fi # METIS_SOURCE_DIR : location of the original sources METIS_SOURCE_DIR=$sourceBASE/$metisPACKAGE -: ${METIS_ARCH_PATH:=$installBASE$WM_SIZE_OPTIONS/$metisPACKAGE} +: "${METIS_ARCH_PATH:=$installBASE$WM_SIZE_OPTIONS/$metisPACKAGE}" [ -d "$METIS_SOURCE_DIR" ] || { echo "Missing sources: '$metisPACKAGE'" diff --git a/makeMGridGen b/makeMGridGen index 1638e95..af226e9 100755 --- a/makeMGridGen +++ b/makeMGridGen @@ -94,7 +94,7 @@ fi # MGRIDGEN_ARCH_PATH : installation directory MGRIDGEN_SOURCE_DIR=$WM_THIRD_PARTY_DIR/$mgridgenPACKAGE -MGRIDGEN_ARCH_PATH=$installBASE$WM_SIZE_OPTIONS/$mgridgenPACKAGE +MGRIDGEN_ARCH_PATH="$installBASE$WM_SIZE_OPTIONS/$mgridgenPACKAGE" : ${FOAM_MPI:=dummy} diff --git a/makePETSC b/makePETSC index 06661b2..0aa130a 100755 --- a/makePETSC +++ b/makePETSC @@ -130,7 +130,7 @@ fi # PETSC_SOURCE_DIR : location of the original sources PETSC_SOURCE_DIR=$sourceBASE/$petscPACKAGE -: ${PETSC_ARCH_PATH:=$installBASE$WM_SIZE_OPTIONS/$petscPACKAGE} +: "${PETSC_ARCH_PATH:=$installBASE$WM_SIZE_OPTIONS/$petscPACKAGE}" [ -d "$PETSC_SOURCE_DIR" ] || { echo "Missing sources: '$petscPACKAGE'" diff --git a/makeSCOTCH b/makeSCOTCH new file mode 100755 index 0000000..9443c67 --- /dev/null +++ b/makeSCOTCH @@ -0,0 +1,290 @@ +#!/bin/sh +#------------------------------------------------------------------------------ +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. +# \\/ M anipulation | +#------------------------------------------------------------------------------ +# License +# This file is part of OpenFOAM, licensed under GNU General Public License +# . +# +# Script +# makeSCOTCH +# +# Description +# Build the SCOTCH and PTSCOTCH libraries +# +# ---------------------------------------------- +# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# Run from third-party directory only +cd ${0%/*} && wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || { + echo "Error (${0##*/}) : not located in \$WM_THIRD_PARTY_DIR" + echo " Check your OpenFOAM environment and installation" + exit 1 +} +[ -n "$FOAM_EXT_LIBBIN" ] || { + echo "Error (${0##*/}) : \$FOAM_EXT_LIBBIN not set" + echo " Check your OpenFOAM environment and installation" + exit 1 +} +. etc/tools/ThirdPartyFunctions +#------------------------------------------------------------------------------ +_foamConfig scotch # Get SCOTCH_ARCH_PATH, SCOTCH_VERSION + +scotchPACKAGE=${SCOTCH_VERSION:-scotch-system} + +unset withMPI +case "$WM_MPLIB" in (*MPI*) [ "$FOAM_MPI" = dummy ] || withMPI=true ;; esac + +#------------------------------------------------------------------------------ +usage() +{ + exec 1>&2 + while [ "$#" -ge 1 ]; do echo "$1"; shift; done + /bin/cat</dev/null + mkdir -p $incDIR 2>/dev/null + mkdir -p $libDIR 2>/dev/null + + if [ -f "$makefileInc" ] + then + rm -f Makefile.inc + ln -s $makefileInc Makefile.inc + fi + [ -f Makefile.inc ] || { + echo " Error: scotch needs an appropriate Makefile.inc" + exit 1 + } + + export CCS="$(whichCC)" # CCS (serial compiler) + export CCP="$(whichMpicc)" # CCP (parallel compiler) default=mpicc + + # Consistency for Intel-MPI and non-icc compilers + [ -n "$I_MPI_CC" ] || export I_MPI_CC="$(whichCC)" + + make realclean 2>/dev/null # Extra safety + make -j $WM_NCOMPPROCS libscotch \ + && make \ + prefix=$prefixDIR \ + includedir=$incDIR \ + libdir=$libDIR \ + install + + rmdir "$SCOTCH_ARCH_PATH/bin" 2> /dev/null || true # Superfluous bin? + make realclean 2>/dev/null || true # Failed cleanup is uncritical +) || warnBuildIssues SCOTCH +else + warnNotFound SCOTCH +fi + + +# Build ptscotch when MPI (ThirdParty or system) is available + +[ "${withMPI}" = true ] || { + # Report that the above tests failed and pass-through the failure + echo "Skipping pt-scotch (no mpi)" + exit 0 +} + +echo +echo ======================================== +echo "pt-scotch decomposition ($scotchPACKAGE with $FOAM_MPI)" + +# Build ptscotch if normal scotch was built (has include and library) +[ -f "$SCOTCH_ARCH_PATH/include/scotch.h" ] && \ +[ -r "$FOAM_EXT_LIBBIN/libscotch$EXT_SO" ] || \ +{ + # Report that the above tests failed and pass-through the failure + echo + echo " skipping - no found" + exit 1 +} + +if [ -f "$SCOTCH_ARCH_PATH/include/$FOAM_MPI/ptscotch.h" ] && \ + [ -r "$FOAM_EXT_LIBBIN/$FOAM_MPI/libptscotch$EXT_SO" ] +then + echo " ptscotch include: $SCOTCH_ARCH_PATH/include/$FOAM_MPI" + echo " ptscotch library: $FOAM_EXT_LIBBIN/$FOAM_MPI" +else +( + # Older versions ok, but scotch-6.0.5a cannot build in parallel. + # Force serial build + export WM_NCOMPPROCS=1 + echo "*** building pt-scotch in serial ***" + + [ -f "$scotchMakefile" ] || { + echo " Error: no such makefile: $scotchMakefile" + exit 1 + } + + cd $SCOTCH_SOURCE_DIR/src || exit 1 + export GIT_DIR=$SCOTCH_SOURCE_DIR/.git # Mask seeing our own git-repo + echo + + prefixDIR=$SCOTCH_ARCH_PATH + incDIR=$SCOTCH_ARCH_PATH/include/$FOAM_MPI + libDIR=$FOAM_EXT_LIBBIN/$FOAM_MPI + + mkdir -p $prefixDIR 2>/dev/null + mkdir -p $incDIR 2>/dev/null + mkdir -p $libDIR 2>/dev/null + + if [ -f "$makefileInc" ] + then + rm -f Makefile.inc + ln -s $makefileInc Makefile.inc + fi + [ -f Makefile.inc ] || { + echo " Error: ptscotch needs an appropriate Makefile.inc" + exit 1 + } + + export CCS="$(whichCC)" # CCS (serial compiler) + export CCP="$(whichMpicc)" # CCP (parallel compiler) default=mpicc + + # Consistency for Intel-MPI and non-icc compilers + [ -n "$I_MPI_CC" ] || export I_MPI_CC="$(whichCC)" + + make realclean 2>/dev/null # Extra safety + make -j $WM_NCOMPPROCS libptscotch \ + && make \ + prefix=$prefixDIR \ + includedir=$incDIR \ + libdir=$libDIR \ + install + + rmdir "$SCOTCH_ARCH_PATH/bin" 2> /dev/null || true # Superfluous bin? + make realclean 2>/dev/null || true # Failed cleanup is uncritical +) || warnBuildIssues PTSCOTCH +fi + +# Verify existence of ptscotch include +[ -f "$SCOTCH_ARCH_PATH/include/$FOAM_MPI/ptscotch.h" ] || { + echo + echo " WARNING: required include file 'ptscotch.h' not found!" +} + +# Could now remove $SCOTCH_SOURCE_DIR/src/Makefile.inc + +#------------------------------------------------------------------------------