makeSCOTCH 8.36 KB
Newer Older
1 2 3 4 5
#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
6
#   \\  /    A nd           | www.openfoam.com
7 8
#    \\/     M anipulation  |
#------------------------------------------------------------------------------
9 10
#     Copyright (C) 2019 OpenCFD Ltd.
#------------------------------------------------------------------------------
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# 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
27 28
cd "${0%/*}" || exit
wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    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}"

129
[ -d "$SCOTCH_SOURCE_DIR/src" ] || {
130
    echo "Missing sources: '$scotchPACKAGE'"
131 132
    showDownloadHint SCOTCH
    exit 2
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
}

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
    }

160 161 162
    cd "$SCOTCH_SOURCE_DIR/src" || exit
    export GIT_DIR="$SCOTCH_SOURCE_DIR/.git" # Mask seeing our own git-repo
    rm -rf "$SCOTCH_ARCH_PATH"
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

    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"
225
    exit 2
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
}

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
    }

245 246
    cd "$SCOTCH_SOURCE_DIR/src" || exit
    export GIT_DIR="$SCOTCH_SOURCE_DIR/.git" # Mask seeing our own git-repo
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
    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

#------------------------------------------------------------------------------