From cd91a252ac54d54206d42b4b500fc3e80824a6cf Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Fri, 5 Apr 2019 13:10:53 +0200 Subject: [PATCH] ENH: improve handling of pt-scotch headers/libraries - provide dedicated detection 'have_ptscotch' function that can be used after the 'have_scotch' function. It sets the PTSCOTCH_ARCH_PATH, PTSCOTCH_INC_DIR, PTSCOTCH_LIB_DIR and helps when the serial and parallel versions are located with different logic. --- src/parallel/decompose/Allwmake | 3 +- .../decompose/ptscotchDecomp/Make/options | 10 +- wmake/scripts/have_scotch | 100 +++++++++++++++++- wmake/scripts/sysFunctions | 12 ++- 4 files changed, 114 insertions(+), 11 deletions(-) diff --git a/src/parallel/decompose/Allwmake b/src/parallel/decompose/Allwmake index b745c6a5032..ea5369a94cb 100755 --- a/src/parallel/decompose/Allwmake +++ b/src/parallel/decompose/Allwmake @@ -41,7 +41,8 @@ wmakeLnInclude -u decompositionMethods if have_scotch then wmake $targetType scotchDecomp - if [ -d "$FOAM_LIBBIN/$FOAM_MPI" ] + + if have_ptscotch then wmakeMpiLib "$SCOTCH_VERSION" ptscotchDecomp fi diff --git a/src/parallel/decompose/ptscotchDecomp/Make/options b/src/parallel/decompose/ptscotchDecomp/Make/options index 8cd4aa7b582..42e41f81462 100644 --- a/src/parallel/decompose/ptscotchDecomp/Make/options +++ b/src/parallel/decompose/ptscotchDecomp/Make/options @@ -1,13 +1,12 @@ /* - * NB: mplib PINC must appear after the SCOTCH_ARCH_PATH/include/FOAM_MPI - * to ensure we do not accidentally get a ptscotch header from the - * mpi distribution. + * NB: mplib PINC must appear after PTSCOTCH_INC_DIR to ensure we + * do not accidentally get a ptscotch header from the MPI distribution. */ sinclude $(GENERAL_RULES)/mplib$(WM_MPLIB) sinclude $(DEFAULT_RULES)/mplib$(WM_MPLIB) EXE_INC = \ - -I$(SCOTCH_ARCH_PATH)/include/$(FOAM_MPI) \ + -I$(PTSCOTCH_INC_DIR) \ -I$(SCOTCH_INC_DIR) \ $(PFLAGS) $(PINC) \ -I../decompositionMethods/lnInclude @@ -17,9 +16,8 @@ EXE_INC = \ * ptscotch 6 requires scotch linked in, but does not declare the dependency */ LIB_LIBS = \ + -L$(PTSCOTCH_LIB_DIR) \ -L$(SCOTCH_LIB_DIR) \ - -L$(FOAM_EXT_LIBBIN)/$(FOAM_MPI) \ - -L$(FOAM_EXT_LIBBIN) \ -lptscotch -lptscotcherrexit \ -lscotch diff --git a/wmake/scripts/have_scotch b/wmake/scripts/have_scotch index e25525926a2..8d17fa7f17f 100644 --- a/wmake/scripts/have_scotch +++ b/wmake/scripts/have_scotch @@ -37,6 +37,7 @@ no_scotch() { unset HAVE_SCOTCH SCOTCH_ARCH_PATH SCOTCH_INC_DIR SCOTCH_LIB_DIR unset SCOTCH_VERSION + unset HAVE_PTSCOTCH PTSCOTCH_ARCH_PATH PTSCOTCH_INC_DIR PTSCOTCH_LIB_DIR return 0 } @@ -48,6 +49,11 @@ echo_scotch() echo "root=$SCOTCH_ARCH_PATH" echo "include=$SCOTCH_INC_DIR" echo "library=$SCOTCH_LIB_DIR" + echo + echo "ptscotch=${HAVE_PTSCOTCH:-false}" + echo "root=$PTSCOTCH_ARCH_PATH" + echo "include=$PTSCOTCH_INC_DIR" + echo "library=$PTSCOTCH_LIB_DIR" } @@ -177,13 +183,105 @@ have_scotch() } +# Must be called after have_scotch! +# +# On success, return 0 and export variables +# -> HAVE_PTSCOTCH, PTSCOTCH_ARCH_PATH, PTSCOTCH_INC_DIR, PTSCOTCH_LIB_DIR +have_ptscotch() +{ + local prefix header library static settings warn + warn="==> skip ptscotch" + + if [ "$HAVE_SCOTCH" != true ] + then + echo "$warn (no serial scotch available?)" + return 1 + fi + + # Reuse old settings + [ -n "$PTSCOTCH_ARCH_PATH" ] || PTSCOTCH_ARCH_PATH="$SCOTCH_ARCH_PATH" + + # Location + prefix="$PTSCOTCH_ARCH_PATH" + + # Header/library names + header="ptscotch.h" + library="libptscotch$extLibso" + static="libptscotch$extLiba" + + # ---------------------------------- + if isNone "$prefix" + then + [ -n "$warn" ] && echo "$warn (disabled)" + return 1 + elif hasAbsdir "$prefix" + then + header=$(findFirstFile \ + "$prefix/include/$FOAM_MPI/$header" \ + "$prefix/include/$header" + ) + + library=$(findFirstFile \ + "$(thirdExtLib $FOAM_MPI/$library)" \ + "$(thirdExtLib $library)" \ + "$prefix/lib/$static" \ + "$prefix/lib/$library" \ + "$prefix/lib$WM_COMPILER_LIB_ARCH/$static" \ + "$prefix/lib$WM_COMPILER_LIB_ARCH/$library" \ + ) + + elif isSystem "$prefix" + then + prefix=/usr + + header=$(findFirstFile \ + "/usr/local/include/ptscotch/$header" \ + "/usr/local/include/scotch/$header" \ + "/usr/local/include/$header" \ + "/usr/include/ptscotch/$header" \ + "/usr/include/scotch/$header" \ + "/usr/include/$header" \ + ) + + case "$header" in (/usr/local/*) prefix=/usr/local ;; esac + + library=$(findFirstFile \ + "$prefix/lib/$library" \ + "$prefix/lib$WM_COMPILER_LIB_ARCH/$library" \ + ) + else + unset prefix header library + fi + # ---------------------------------- + + # Header found? + [ -n "$header" ] || { + [ -n "$warn" ] && echo "$warn (no header)" + return 2 + } + + # Library found? + [ -n "$library" ] || { + [ -n "$warn" ] && echo "$warn (no library)" + return 2 + } + + # OK + echo "ptscotch - $prefix" + export HAVE_PTSCOTCH=true + export PTSCOTCH_ARCH_PATH="$prefix" + export PTSCOTCH_INC_DIR="${header%/*}" # Basename + export PTSCOTCH_LIB_DIR="${library%/*}" # Basename +} + + # Force reset of old variables no_scotch # Testing if [ "$1" = "-test" ] then - have_scotch + have_scotch && have_ptscotch echo_scotch fi diff --git a/wmake/scripts/sysFunctions b/wmake/scripts/sysFunctions index 30de032b90a..a11f58c3c4e 100644 --- a/wmake/scripts/sysFunctions +++ b/wmake/scripts/sysFunctions @@ -48,14 +48,20 @@ then esac - # True if OS is Darwin. - # Uses libso extension to cache the value - # (instead of calling 'uname -s' each time) + # True if target OS is Darwin. + # Uses cached value from libso extension isDarwin() { test "$extLibso" = ".dylib" } + # True if target OS is Windows + # Uses cached value from libso extension + isWindows() + { + test "$extLibso" = ".dll" + } + # True if '$1' begins with '/' isAbsdir() -- GitLab