#!/bin/bash # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 # # Permission is hereby granted, free of charge, to any person obtaining a copy of this # software and associated documentation files (the "Software"), to deal in the Software # without restriction, including without limitation the rights to use, copy, modify, # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. set -e MPAS_DEFAULT_VERSION="7.1" MPAS_URL="https://github.com/MPAS-Dev/MPAS-Model.git" MODULES_PATH="/usr/share/Modules/modulefiles" DEPENDS_ON="hdf5-parallel/1.10.6 pnetcdf/1.12.2 netcdf-c/4.7.4 netcdf-fortran/4.5.3 pio/2.5.4" ENVIRONMENT="intel/2022.2.0;intel/2022.2.0" # Help Options show_help() { cat << EOF Usage: ${0##*/} [-h] [-v MPAS_VERSION] Do stuff with FILE and write the result to standard output. With no FILE or when FILE is -, read standard input. -h display this help and exit -v MPAS_VERSION MPAS version number EOF } show_default() { MPAS_VERSION=${MPAS_DEFAULT_VERSION} cat << EOF No MPAS Version specified Using default: ${MPAS_DEFAULT_VERSION} EOF } # Parse options OPTIND=1 # Reset if getopts used previously if (($# == 0)); then show_default fi while getopts ":v:h:" opt; do case ${opt} in v ) MPAS_VERSION=$OPTARG ;; h ) show_help exit 0 ;; * ) MPAS_VERSION=${MPAS_DEFAULT_VERSION} ;; esac done yum install -y \ environment-modules \ gcc \ gcc-c++ \ gcc-gfortran \ git \ hostname \ make \ man \ man-pages #Load module source /etc/profile.d/modules.sh # Find parent path PARENT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) # Modules function source ${PARENT_PATH}/modules_functions.sh #Load compilers for comp_mpi in $ENVIRONMENT do load_environment $comp_mpi "$DEPENDS_ON" MPAS_PATH="/opt/mpas-omp/${MPAS_VERSION}/${compiler_name}/${compiler_version}" # Check if already installed if [ -d ${MPAS_PATH} ]; then echo "MPAS already installed in ${MPAS_PATH}" continue fi # Create build directory in /tmp WORKDIR=`mktemp -d -p /tmp -t mpas_XXXXXXXXXXXX` cd ${WORKDIR} # Retreive mpas from git repo git clone -b v"${MPAS_VERSION}" ${MPAS_URL} cd MPAS-Model # Link NETCDF C and Fortran ln -sf $NETCDF_FORTRAN_HOME/include/* $NETCDF_C_HOME/include/ find -L $NETCDF_FORTRAN_HOME/lib -maxdepth 1 -name "*" -type f -exec ln -sf {} $NETCDF_C_HOME/lib/ \; find -L $NETCDF_FORTRAN_HOME/lib/pkgconfig -maxdepth 1 -name "*" -type f -exec ln -sf {} $NETCDF_C_HOME/lib/pkgconfig/ \; # Set env var for MPAS export PHDF5=$HDF5_PARALLEL_HOME export NETCDF=$NETCDF_C_HOME export PNETCDF=$PNETCDF_HOME export PIO=$PIO_HOME if [[ "${compiler_name}" == "intel" ]]; then MPAS_CONFIG="ifort" elif [[ "${compiler_name}" == "gcc" ]]; then MPAS_CONFIG="gfortran" fi make clean CORE=atmosphere PRECISION=single make -j $(nproc) ${MPAS_CONFIG} CORE=atmosphere PRECISION=single USE_PIO2=true OPENMP=true make clean CORE=init_atmosphere PRECISION=single make -j $(nproc) ${MPAS_CONFIG} CORE=init_atmosphere PRECISION=single USE_PIO2=true OPENMP=true mkdir -p ${MPAS_PATH}/bin cp atmosphere_model ${MPAS_PATH}/bin cp init_atmosphere_model ${MPAS_PATH}/bin mkdir -p ${MODULES_PATH}/mpas-omp #Create module file cat > ${MODULES_PATH}/mpas-omp/${MPAS_VERSION}-${compiler_name}-${compiler_version} << EOF #%Module # NOTE: This is an automatically-generated file! proc ModulesHelp { } { puts stderr "This module adds MPAS v${MPAS_VERSION} to various paths" } module-whatis "Sets up MPAS v${MPAS_VERSION} in your environment" EOF for i in ${MODULE_DEPENDENCIES} do cat >> ${MODULES_PATH}/mpas-omp/${MPAS_VERSION}-${compiler_name}-${compiler_version} << EOF module load ${i} EOF done cat >> ${MODULES_PATH}/mpas-omp/${MPAS_VERSION}-${compiler_name}-${compiler_version} << EOF prepend-path PATH "${MPAS_PATH}/bin" EOF #Clean up cd rm -rf ${WORKDIR} done # Retreive mpas from git repo MPAS_SRC_PATH="/opt/mpas-omp/src" mkdir -p ${MPAS_SRC_PATH} git clone -b v"${MPAS_VERSION}" ${MPAS_URL} ${MPAS_SRC_PATH}