makeOPENMPI 5.87 KB
Newer Older
mark's avatar
mark committed
1 2 3 4 5
#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
6
#   \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
mark's avatar
mark committed
7 8 9
#    \\/     M anipulation  |
#------------------------------------------------------------------------------
# License
Mark Olesen's avatar
Mark Olesen committed
10 11
#     This file is part of OpenFOAM, licensed under GNU General Public License
#     <http://www.gnu.org/licenses/>.
mark's avatar
mark committed
12 13 14 15 16 17 18 19 20 21
#
# Script
#     makeOPENMPI
#
# Description
#     Build script for openmpi
#
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
#------------------------------------------------------------------------------
22 23 24
# Dynamic library endings (default is .so)
[ "$(uname -s)" = Darwin ] && SO=dylib || SO=so

mark's avatar
mark committed
25 26 27 28 29
# Short-circuit test for an installation
if [ "$1" = "-test" ]
then
    [ "$#" -eq 2 ] || { echo "${0##*/} -test : needs 1 argument"; exit 1; }
    dir="$2" # <- MPI_ARCH_PATH
30
    if [ -r "$dir/lib$WM_COMPILER_LIB_ARCH/libmpi.$SO" ]
mark's avatar
mark committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44
    then
        echo "    Have openmpi shared library (${dir##*/})"
        exit 0
    elif [ -r "$dir/lib$WM_COMPILER_LIB_ARCH/libmpi.a" ]
    then
        echo "    Have openmpi static library (${dir##*/})"
        exit 0
    else
        echo "No openmpi libraries found: ${dir:-not-specified}"
        exit 2
    fi
fi
#------------------------------------------------------------------------------
# Run from third-party directory only
45
cd ${0%/*} && wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
mark's avatar
mark committed
46 47 48 49 50
    echo "Error (${0##*/}) : not located in \$WM_THIRD_PARTY_DIR"
    echo "    Check your OpenFOAM environment and installation"
    exit 1
}
. etc/tools/ThirdPartyFunctions
51 52 53 54 55
# Transition
# ~~~~~~~~~~
_foamAddLib()  { true; }
_foamAddMan()  { true; }
_foamAddPath() { true; }
mark's avatar
mark committed
56 57
#------------------------------------------------------------------------------

58 59 60
WM_MPLIB=OPENMPI                                # Ensure we get the correct MPI

# openmpi version from OpenFOAM etc/config.sh file:
61
_foamConfig mpi
mark's avatar
mark committed
62 63

mpiPACKAGE=${FOAM_MPI:-openmpi-system}
64

mark's avatar
mark committed
65 66 67 68 69 70
#------------------------------------------------------------------------------
usage() {
    exec 1>&2
    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
    cat<<USAGE

Mark Olesen's avatar
Mark Olesen committed
71
usage: ${0##*/} [OPTION] [openmpi-VERSION] [-- configure-options]
mark's avatar
mark committed
72
options:
73 74
  -gcc          Force gcc/g++ instead of the values from \$WM_CC, \$WM_CXX
  -memcheck     Configure with --enable-memcheck (requires valgrind.h)
Mark Olesen's avatar
Mark Olesen committed
75 76
  -threaded     Configure with --enable-mpi-thread-multiple
  -no-threaded  Configure with --disable-mpi-thread-multiple
mark's avatar
mark committed
77 78 79 80 81 82 83 84 85
  -help

* build openmpi with
      ${mpiPACKAGE:-'unspecified openmpi version'}

USAGE
    exit 1
}
#------------------------------------------------------------------------------
86
exportCompiler          # Compiler info for CMake/configure
mark's avatar
mark committed
87

Mark Olesen's avatar
Mark Olesen committed
88
unset optMemchecker optThreaded
89

mark's avatar
mark committed
90 91 92 93
# Parse options
while [ "$#" -gt 0 ]
do
    case "$1" in
94
    '') ;;      # Ignore empty
Mark Olesen's avatar
Mark Olesen committed
95
    --) break;; # Extra configure options (leave on $@ for later detection)
96 97
    -h | -help) usage   ;;
    -gcc)       useGcc  ;;
98
    -memcheck*) optMemchecker=true ;;
Mark Olesen's avatar
Mark Olesen committed
99 100
    -thread*)   optThreaded=enable ;;
    -no-thread*) optThreaded=disable ;;
101

mark's avatar
mark committed
102 103 104
    openmpi-[0-9]* | openmpi_[0-9]* | openmpi-system )
        mpiPACKAGE="${1%%/}"
        ;;
Mark Olesen's avatar
Mark Olesen committed
105

mark's avatar
mark committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    *)
        die "unknown option/argument: '$1'"
        ;;
    esac
    shift
done

[ -n "$mpiPACKAGE" ] || die "The openmpi-VERSION was not specified"

# Nothing to build
if _foamIsNone "$mpiPACKAGE"
then
    echo "Using openmpi-none (skip ThirdParty build of openmpi)"
    exit 0
elif _foamIsSystem "$mpiPACKAGE"
then
    echo "Using openmpi-system (skip ThirdParty build of openmpi)"
    exit 0
fi

#------------------------------------------------------------------------------
#
# Build openmpi
#
#   MPI_SOURCE_DIR : location of the original sources
#   MPI_ARCH_PATH  : installation directory

MPI_SOURCE_DIR=$sourceBASE/$mpiPACKAGE
MPI_ARCH_PATH=$installBASE/$mpiPACKAGE

136
if [ -r "$MPI_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libmpi.$SO" ]
mark's avatar
mark committed
137
then
138
    echo "Already has shared library: $MPI_ARCH_PATH"
mark's avatar
mark committed
139 140
elif [ -r "$MPI_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libmpi.a" ]
then
141
    echo "Already has static library: $MPI_ARCH_PATH"
mark's avatar
mark committed
142 143 144 145 146
else
    echo "Starting build: $WM_MPLIB ($mpiPACKAGE)"
    echo

    (
Mark Olesen's avatar
Mark Olesen committed
147
        # Configuration options:
mark's avatar
mark committed
148 149 150
        # Start with GridEngine support - builds without external libraries
        configOpt="--with-sge"

Mark Olesen's avatar
Mark Olesen committed
151
        if [ -n "$optMemchecker" ]
152 153 154 155
        then
            configOpt="$configOpt --enable-memchecker --with-valgrind"
        fi

Mark Olesen's avatar
Mark Olesen committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169
        # --enable-mpi-thread-multiple / --disable-mpi-thread-multiple
        if [ -n "$optThreaded" ]
        then
            configOpt="$configOpt --${optThreaded}-mpi-thread-multiple"
        fi

        # Additional configure options
        if [ "$1" = "--" ]
        then
            shift
            configOpt="$configOpt $@"
        fi

        # End of configuration options
mark's avatar
mark committed
170 171 172 173 174
        # ----------------------------

        buildDIR=$buildBASE/$mpiPACKAGE

        cd $MPI_SOURCE_DIR || exit 1
175
        export GIT_DIR=$PWD/.git # Mask seeing our own git-repo
mark's avatar
mark committed
176 177 178 179 180 181 182 183 184 185
        [ -e Makefile ] && make distclean 2>/dev/null

        rm -rf $MPI_ARCH_PATH
        rm -rf $buildDIR
        mkdir -p $buildDIR
        cd $buildDIR

        set -x
        $MPI_SOURCE_DIR/configure \
            --prefix=$MPI_ARCH_PATH \
186
            --libdir=$MPI_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH \
mark's avatar
mark committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
            --disable-orterun-prefix-by-default \
            --enable-shared --disable-static \
            --enable-mpi-fortran=none \
            $configOpt \
        && set +x \
        && make -j $WM_NCOMPPROCS \
        && make install \
        && echo "Built: $mpiPACKAGE" \
        && pkgconfigAdjust $MPI_ARCH_PATH
    ) || {
        echo "Error building: $mpiPACKAGE"
        exit 1
    }
fi

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