makeADIOS 9.7 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) 2016-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
#
# Script
#     makeADIOS
#
# Description
mark's avatar
mark committed
17
#     Build script for ADIOS
mark's avatar
mark committed
18
#
19 20
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
mark's avatar
mark committed
21
#------------------------------------------------------------------------------
22
# Run from third-party directory only
23
cd ${0%/*} && wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
24 25 26 27 28 29
    echo "Error (${0##*/}) : not located in \$WM_THIRD_PARTY_DIR"
    echo "    Check your OpenFOAM environment and installation"
    exit 1
}
. etc/tools/ThirdPartyFunctions
#------------------------------------------------------------------------------
30 31

# ADIOS version from OpenFOAM etc/config.sh file:
32
_foamConfig ADIOS
mark's avatar
mark committed
33 34

adiosPACKAGE=${adios_version:-adios-none}
35

mark's avatar
mark committed
36 37 38 39 40 41
#------------------------------------------------------------------------------
usage() {
    exec 1>&2
    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
    cat<<USAGE

Mark Olesen's avatar
Mark Olesen committed
42
usage: ${0##*/} [OPTION] [adios-VERSION] [-- configure-options]
mark's avatar
mark committed
43
options:
44
  -cmake PATH       With cmake from the path given
mark's avatar
mark committed
45 46 47
  -gcc              Force gcc/g++ instead of the values from \$WM_CC, \$WM_CXX
  -help

mark's avatar
mark committed
48
* Build ADIOS
mark's avatar
mark committed
49 50 51 52 53 54
      $adiosPACKAGE

USAGE
    exit 1
}
#------------------------------------------------------------------------------
55
exportCompiler true     # Compiler info + flags for CMake/configure
mark's avatar
mark committed
56

57
# Parse options
mark's avatar
mark committed
58 59 60
while [ "$#" -gt 0 ]
do
    case "$1" in
61
    '') ;;      # Ignore empty
Mark Olesen's avatar
Mark Olesen committed
62
    --) break;; # Extra configure options (leave on $@ for later detection)
63 64 65
    -h | -help) usage   ;;
    -gcc)       useGcc  ;;

66 67 68 69 70 71
    -cmake)
        [ "$#" -ge 2 ] || die "'$1' option requires an argument"
        CMAKE_PATH="${2%%/}"
        shift
        ;;
    ADIOS-[1-9]* | adios-[1-9]* | ADIOS-git* | adios-git*)
mark's avatar
mark committed
72 73
        adiosPACKAGE="${1%%/}"
        ;;
Mark Olesen's avatar
Mark Olesen committed
74

mark's avatar
mark committed
75 76 77 78 79 80 81
    *)
        die "unknown option/argument: '$1'"
        ;;
    esac
    shift
done

mark's avatar
mark committed
82
[ -n "$adiosPACKAGE" ] || die "The adios-VERSION was not specified"
mark's avatar
mark committed
83

Mark Olesen's avatar
Mark Olesen committed
84
# Nothing to build
mark's avatar
mark committed
85
if _foamIsNone "$adiosPACKAGE"
mark's avatar
mark committed
86
then
mark's avatar
mark committed
87 88 89 90 91 92 93
    echo "Using adios-none (skip ThirdParty build of ADIOS)"
    exit 0
elif _foamIsSystem "$adiosPACKAGE"
then
    echo "Using adios-system"
    exit 0
fi
mark's avatar
mark committed
94

mark's avatar
mark committed
95 96 97
#------------------------------------------------------------------------------
#
# Build ADIOS
98
#   ADIOS_SOURCE_DIR : location of the original sources
99
#   ADIOS_ARCH_PATH  : installation directory
mark's avatar
mark committed
100

101
ADIOS_SOURCE_DIR=$sourceBASE/$adiosPACKAGE
mark's avatar
mark committed
102
ADIOS_ARCH_PATH=$installBASE/$adiosPACKAGE
mark's avatar
mark committed
103

mark's avatar
mark committed
104
: ${FOAM_MPI:=dummy}
mark's avatar
mark committed
105 106 107

echo
echo ========================================
mark's avatar
mark committed
108
echo "Build adios library $adiosPACKAGE for $FOAM_MPI"
mark's avatar
mark committed
109 110
echo

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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 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

#
# Manual adjustments to adios config
#
adjustADIOS()
{
    # Rename libraries according to FOAM_MPI
    (
        cd $ADIOS_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH || exit 1

        if [ "$FOAM_MPI" != dummy ]
        then
            \mv -f libadios.a       libadios_$FOAM_MPI.a
            \mv -f libadiosread.a   libadiosread_$FOAM_MPI.a
        fi
        \mv -f libadios_nompi.a     libadios_dummy.a
        \mv -f libadiosread_nompi.a libadiosread_dummy.a

        echo
        echo "ADIOS library renamed to libadios_$FOAM_MPI"
        echo
    )

    # We don't need/use XML things
    \rm -f $ADIOS_ARCH_PATH/bin/adios_lint

    # Replace resolved paths with variables
    echo "Adjust prefix for ADIOS"
    for i in \
        $ADIOS_ARCH_PATH/bin/adios_config \
        $ADIOS_ARCH_PATH/etc/adios_config.flags \
    ;
    do
        [ -f "$i" ] || {
            echo "    no such file - '$i'"
            continue
        }
        if sed -i -e 's|'"$WM_THIRD_PARTY_DIR"'|$WM_THIRD_PARTY_DIR|g' $i
        then
            echo "    '$i'"
        else
            echo "    problems with '$i'"
        fi
    done

    # Adjust the config flags file:
    # * Remove references to Fortran libraries (disabled in configure)
    # * Remove references to deprecated version 1 API
    # * Cleanup excessive whitespace
    # * Handle renamed libraries:
    #   - libadios       -> libadios_$FOAM_MPI
    #   - libadios_nompi -> libadios_dummy
    #
    echo "Adjust library names for ADIOS"
    for i in \
        $ADIOS_ARCH_PATH/etc/adios_config.flags \
    ;
    do
        [ -f "$i" ] || {
            echo "    no such file - '$i'"
            continue
        }

        if sed -i \
            -e '/_FLIB=/d' \
            -e '/_V1_INC=/d' \
            -e 's|  *| |g' \
            -e 's|\(-ladios[a-z]*_\)nompi |\1dummy |g' \
            $i
        then
            echo "    '$i'"
        else
            echo "    problems with '$i'"
        fi

        if [ "$FOAM_MPI" != dummy ]
        then
            sed -i -e 's|\(-ladios[a-z]*\) |\1_'"$FOAM_MPI |g" $i || \
            echo "    problems with '$i'"
        fi
    done
}

#
# List ADIOS methods/configuration
#
listMethods()
{
    [ -f $ADIOS_ARCH_PATH/bin/adios_config ] || {
        echo "Warning: no adios_config"
        return 1
    }

    echo "==============="

    # May have problems listing parallel methods (eg, transport key missing)
    if $ADIOS_ARCH_PATH/bin/adios_config -m >/dev/null 2>&1
    then
        $ADIOS_ARCH_PATH/bin/adios_config -m 2>/dev/null
    else
        echo "Warning: could not list parallel methods"
        # Fallback to serial methods
        $ADIOS_ARCH_PATH/bin/adios_config -s -m 2>/dev/null
    fi || echo "Warning: could not list configured methods"
    echo "==============="

}


mark's avatar
mark committed
220 221 222
# Needs future adjustment
# - for shared library
# - for mpi-specific library locations
mark's avatar
mark committed
223
if [ -f $ADIOS_ARCH_PATH/include/adios.h \
mark's avatar
mark committed
224
  -a -r $ADIOS_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libadios_${FOAM_MPI}.a ]
mark's avatar
mark committed
225 226
then
    echo "    ADIOS header in $ADIOS_ARCH_PATH/include"
227 228
    ### echo "    ADIOS libs   in $FOAM_EXT_LIBBIN"           # dynamic
    echo "    ADIOS libs   in $ADIOS_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH" # static
229 230 231 232
    listMethods
elif [ -z "$CMAKE_PATH" ]
then
    echo "Starting build: $adiosPACKAGE (using configure)"
mark's avatar
mark committed
233
    echo
234
    (
Mark Olesen's avatar
Mark Olesen committed
235
        # Configuration options:
236
        unset configOpt
mark's avatar
mark committed
237

238 239 240 241 242 243
        # Add InfiniBand support
        ibDir=/usr/local/ofed
        if [ -d "$ibDir" -a "$FOAM_MPI" != dummy ]
        then
            configOpt="$configOpt --with-infiniband=$ibDir"
        fi
mark's avatar
mark committed
244

245
        # Transport layers
Mark Olesen's avatar
Mark Olesen committed
246
        if [ -f /usr/include/bzlib.h ]
247 248 249
        then
            configOpt="$configOpt --with-bzip2"
        fi
mark's avatar
mark committed
250

Mark Olesen's avatar
Mark Olesen committed
251
        if [ -f /usr/include/zlib.h ]
252 253 254 255 256
        then
            configOpt="$configOpt --with-zlib"
        fi

        # Other types of support
Mark Olesen's avatar
Mark Olesen committed
257 258
        ## configOpt="$configOpt --with-hdf5=..."
        ## configOpt="$configOpt --with-lustre=..."
259 260
        ## configOpt="$configOpt --enable-research-transports"

Mark Olesen's avatar
Mark Olesen committed
261 262 263 264 265 266 267 268
        # Additional configure options
        if [ "$1" = "--" ]
        then
            shift
            configOpt="$configOpt $@"
        fi

        # End of configuration options
269 270
        # ----------------------------
        buildDIR=$buildBASE/$adiosPACKAGE
mark's avatar
mark committed
271

272
        cd $ADIOS_SOURCE_DIR || exit 1
273
        export GIT_DIR=$PWD/.git # Mask seeing our own git-repo
mark's avatar
mark committed
274

275
        [ -e Makefile ] && make distclean 2>/dev/null
mark's avatar
mark committed
276

277 278
        applyPatch $adiosPACKAGE $ADIOS_SOURCE_DIR

279 280 281 282
        # Remove any existing build folder and recreate
        rm -rf $ADIOS_ARCH_DIR
        rm -rf $buildDIR 2>/dev/null
        mkdir -p $buildDIR
mark's avatar
mark committed
283

284 285 286 287
        [ -f configure ] || {
            echo "no configure for $adiosPACKAGE ... trying autogen"
            ./autogen.sh
        }
mark's avatar
mark committed
288

289 290 291 292 293 294 295 296
        # May not work properly with FOAM_MPI = dummy
        if [ "$FOAM_MPI" = dummy ]
        then
            configOpt="$configOpt --without-mpi"
        else
            CC=mpicc
            CXX=mpicxx
        fi
mark's avatar
mark committed
297

298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
        # Install into lib64/
        cd $buildDIR && $ADIOS_SOURCE_DIR/configure \
            --prefix=$ADIOS_ARCH_PATH \
            --libdir=$ADIOS_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH \
            --disable-fortran \
            --with-pic \
            --without-fastbit \
            $configOpt \
        && make -j $WM_NCOMPPROCS all \
        && make install \
        && echo "Built: $adiosPACKAGE" \
        && adjustADIOS \
        && listMethods
    ) || {
        echo "Error building: $adiosPACKAGE"
mark's avatar
mark committed
313
    }
314 315 316 317 318 319 320
else
    # CMake options often lag the configure ones
    echo "Starting build: $adiosPACKAGE (using cmake)"
    echo
    (
        buildDIR=$buildBASE/$adiosPACKAGE
        cd $ADIOS_SOURCE_DIR || exit 1
321
        export GIT_DIR=$PWD/.git # Mask seeing our own git-repo
322

323 324
        applyPatch $adiosPACKAGE $ADIOS_SOURCE_DIR

325 326 327 328 329 330 331
        # Remove any existing build folder and recreate
        rm -rf $ADIOS_ARCH_DIR
        rm -rf $buildDIR 2>/dev/null
        mkdir -p $buildDIR

        # May not work properly with FOAM_MPI = dummy
        if [ "$FOAM_MPI" = dummy ]
mark's avatar
mark committed
332
        then
333 334 335 336
            configOpt="$configOpt --without-mpi"
        else
            CC=mpicc
            CXX=mpicxx
mark's avatar
mark committed
337 338
        fi

339 340 341 342 343 344
        cmake=$(findCMake)

        # Install into lib64/
        cd $buildDIR && $cmake \
            -DCMAKE_INSTALL_PREFIX=$ADIOS_ARCH_PATH \
            -DCMAKE_BUILD_TYPE=Release \
345
            -DBUILD_FORTRAN=FALSE \
346
            ${WM_QUIET:+-DCMAKE_RULE_MESSAGES=OFF} \
347 348 349 350 351 352 353 354
            $ADIOS_SOURCE_DIR \
        && make -j $WM_NCOMPPROCS all \
        && make install \
        && echo "Built: $adiosPACKAGE" \
        && adjustADIOS \
        && listMethods
    ) || {
        echo "Error building: $adiosPACKAGE"
355
    }
mark's avatar
mark committed
356 357
fi

358
# -----------------------------------------------------------------------------