makeOPENMPI 5.96 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           | www.openfoam.com
mark's avatar
mark committed
7 8
#    \\/     M anipulation  |
#------------------------------------------------------------------------------
9 10
#     Copyright (C) 2017-2019 OpenCFD Ltd.
#------------------------------------------------------------------------------
mark's avatar
mark committed
11
# License
Mark Olesen's avatar
Mark Olesen committed
12 13
#     This file is part of OpenFOAM, licensed under GNU General Public License
#     <http://www.gnu.org/licenses/>.
mark's avatar
mark committed
14 15 16 17 18 19 20 21 22 23
#
# Script
#     makeOPENMPI
#
# Description
#     Build script for openmpi
#
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
#------------------------------------------------------------------------------
24 25
# Dynamic library ending (default is .so)
[ "$(uname -s)" = Darwin ] && EXT_SO=.dylib || EXT_SO=.so
26

mark's avatar
mark committed
27 28 29 30
# Short-circuit test for an installation
if [ "$1" = "-test" ]
then
    [ "$#" -eq 2 ] || { echo "${0##*/} -test : needs 1 argument"; exit 1; }
31
    dir="${2%/}" # <- MPI_ARCH_PATH
32
    if [ -r "$dir/lib$WM_COMPILER_LIB_ARCH/libmpi$EXT_SO" ]
mark's avatar
mark committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46
    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
47 48
cd "${0%/*}" || exit
wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
mark's avatar
mark committed
49 50 51 52 53
    echo "Error (${0##*/}) : not located in \$WM_THIRD_PARTY_DIR"
    echo "    Check your OpenFOAM environment and installation"
    exit 1
}
. etc/tools/ThirdPartyFunctions
54 55 56 57 58
# Transition
# ~~~~~~~~~~
_foamAddLib()  { true; }
_foamAddMan()  { true; }
_foamAddPath() { true; }
mark's avatar
mark committed
59 60
#------------------------------------------------------------------------------

61 62 63
WM_MPLIB=OPENMPI                                # Ensure we get the correct MPI

# openmpi version from OpenFOAM etc/config.sh file:
64
_foamConfig mpi
mark's avatar
mark committed
65 66

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

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

Mark Olesen's avatar
Mark Olesen committed
74
usage: ${0##*/} [OPTION] [openmpi-VERSION] [-- configure-options]
mark's avatar
mark committed
75
options:
76
  -gcc          Force use of gcc/g++
77
  -memcheck     Configure with --enable-memcheck (requires valgrind.h)
Mark Olesen's avatar
Mark Olesen committed
78 79
  -threaded     Configure with --enable-mpi-thread-multiple
  -no-threaded  Configure with --disable-mpi-thread-multiple
mark's avatar
mark committed
80 81 82 83 84 85 86 87 88
  -help

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

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

Mark Olesen's avatar
Mark Olesen committed
91
unset optMemchecker optThreaded
92

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

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

mark's avatar
mark committed
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 136 137 138
    *)
        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

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

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

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

Mark Olesen's avatar
Mark Olesen committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172
        # --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
173 174 175 176
        # ----------------------------

        buildDIR=$buildBASE/$mpiPACKAGE

177 178
        cd "$MPI_SOURCE_DIR" || exit
        export GIT_DIR="$PWD/.git" # Mask seeing our own git-repo
mark's avatar
mark committed
179 180 181 182 183 184 185 186 187 188
        [ -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 \
189
            --libdir=$MPI_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH \
mark's avatar
mark committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
            --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

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