Files
ThirdParty-common/makeSCOTCH
2019-11-19 16:17:01 +01:00

295 lines
8.4 KiB
Bash
Executable File

#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2019 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# Script
# makeSCOTCH
#
# Description
# Build the SCOTCH and PTSCOTCH libraries
#
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Run from third-party directory only
cd "${0%/*}" || exit
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<<USAGE
Usage: ${0##*/} [OPTION] [libso] [scotch-VERSION]
options:
-gcc Force use of gcc/g++
-no-mpi Suppress build of pt-scotch
-help
* Compile SCOTCH
$kahipPACKAGE
USAGE
exit 1
}
#------------------------------------------------------------------------------
# Parse options
while [ "$#" -gt 0 ]
do
case "$1" in
'') ;; # Ignore empty
-h | -help) usage ;;
-gcc) useGcc ;;
-no-mpi)
unset withMPI
;;
scotch-[1-9]* | scotch-git | scotch_* | scotch-[1-9]*)
scotchPACKAGE="${1%%/}"
unset SCOTCH_ARCH_PATH # Avoid inconsistency
;;
*)
die "unknown option/argument: '$1'"
;;
esac
shift
done
[ -n "$scotchPACKAGE" ] || die "The scotch-VERSION was not specified"
# Nothing to build
if _foamIsNone $scotchPACKAGE
then
echo "Using scotch-none (skip ThirdParty build of SCOTCH)"
exit 0
elif _foamIsSystem $scotchPACKAGE
then
echo "Using scotch-system"
exit 0
fi
#------------------------------------------------------------------------------
# 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
# The relative link location within the "scotch/src/" directory
makefileInc="../../$scotchMakefile"
#------------------------------------------------------------------------------
#
# Build SCOTCH
#
# SCOTCH_ARCH_PATH : installation directory
# SCOTCH_SOURCE_DIR : location of the original sources
SCOTCH_SOURCE_DIR=$sourceBASE/$scotchPACKAGE
: "${SCOTCH_ARCH_PATH:=$installBASE$WM_SIZE_OPTIONS/$scotchPACKAGE}"
[ -d "$SCOTCH_SOURCE_DIR/src" ] || {
echo "Missing sources: '$scotchPACKAGE'"
showDownloadHint SCOTCH
exit 2
}
echo
echo ========================================
echo "scotch decomposition ($scotchPACKAGE)"
echo " Makefile.inc : ${makefileInc##*/}"
# Test installation. May or may not have libscotcherrexit.so
if [ -f "$SCOTCH_ARCH_PATH/include/scotch.h" ] \
&& [ -r "$FOAM_EXT_LIBBIN/libscotch$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
export GIT_DIR="$SCOTCH_SOURCE_DIR/.git" # Mask seeing our own git-repo
rm -rf "$SCOTCH_ARCH_PATH"
applyPatch "$scotchPACKAGE" .. # 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
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 <scotch.h> found"
exit 2
}
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
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
#------------------------------------------------------------------------------