Skip to content

Instantly share code, notes, and snippets.

@3ximus
Last active April 28, 2021 15:25
Show Gist options
  • Save 3ximus/0980bb0c3e9514f4ac4965f715e28552 to your computer and use it in GitHub Desktop.
Save 3ximus/0980bb0c3e9514f4ac4965f715e28552 to your computer and use it in GitHub Desktop.
Install script for netcdf with a bunch of dependencies with intel fortran compiler. And ww3 setup.
#!/bin/bash
# vi: foldmethod=marker
# This script install most of the dependencies needed along with intel compiler
# - zlib
# - hdf5
# - netcdf4
# - netcdf4-fortran
# - eccodes
# - cdo
# - nco
# Missing from this script are (
# - wgrib2
set -e
# Instalation paths
# All the dependencies are also installed into $NETCDF_PATH
NETCDF_PATH=/usr/local
ZLIB_PATH=/usr/local
HDF_PATH=/usr/local
ECCODES_PATH=/usr/local
CDO_PATH=/usr/local
NCO_PATH=/usr/local
# Define desired versions here
HDF5_VERSION=1.10.7
ZLIB_VERSION=1.2.8
NETCDF_VERSION=4.7.4
NETCDF_FORTRAN_VERSION=4.5.3
ECCODES_VERSION=2.18.0
CDO_VERSION=1.9.9
NCO_VERSION=4.9.8
# INSTALL INTEL OPENAPI HIGH PERFORMANCE COMPUTING KIT {{{
if [[ "$(awk -F= '/^NAME/{print $2}' /etc/os-release)" == '"Ubuntu"' ]] ; then
echo -e " -- \033[1;33mInstalling OpenAPI Intel on UBUNTU\033[m"
# UBUNTU INSTALATION
cd /tmp
# fetch the Intel repository public key
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
# add to your apt sources keyring so that archives signed with this key will be trusted.
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
# remove the public key
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
# add intel repo for intel-hpckit
echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
sudo apt update
# install intel dev kit
sudo apt install -y intel-hpckit m4 curl
elif [[ "$(awk -F= '/^NAME/{print $2}' /etc/os-release)" == '"Red Hat Enterprise Linux"' ]] ; then
echo -e " -- \033[1;33mInstalling OpenAPI Intel on RED HAT ENTERPRISE LINUX\033[m"
tee > /tmp/oneAPI.repo << EOF
[oneAPI]
name=Intel(R) oneAPI repository
baseurl=https://yum.repos.intel.com/oneapi
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://yum.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
EOF
# Setup the new repo
sudo mv /tmp/oneAPI.repo /etc/yum.repos.d
# install intel hpc dev kit
sudo dnf install -y intel-hpckit curl gsl-devel udunits2-devel
else
echo "This Distribution is not supported"
exit 1
fi
# }}}
export LD_LIBRARY_PATH="/opt/intel/oneapi/compiler/latest/linux/compiler/lib/intel64:${NETCDF_PATH}/lib:${HDF_PATH}/lib:${ZLIB_PATH}/lib:${ECCODES_PATH}:${LD_LIBRARY_PATH}"
export PATH="$PATH:/opt/intel/oneapi/compiler/latest/linux/bin/intel64/"
export LDFLAGS="-L${ZLIB_PATH}/lib -I${ZLIB_PATH}/include -L${HDF_PATH}/lib -I${HDF_PATH}/include"
export CC=icc
export CXX=icpc
export FC=ifort
export F77=ifort
export F90=ifort
export CPP='icc -E'
export CXXCPP='icpc -E'
export CPPFLAGS="${LDFLAGS}"
FLAGS="-O3 -xHost -ip -no-prec-div -static-intel -fPIC ${LDFLAGS}"
export CFLAGS=" ${FLAGS}"
export CXXFLAGS=" ${FLAGS}"
export FCFLAGS=" ${FLAGS}"
export F77FLAGS=" ${FLAGS}"
export F90FLAGS=" ${FLAGS}"
# Install zlib {{{
if [[ -f $HDF_PATH/lib/libz.so ]] ; then
echo -e " -- \033[1;32mlibz already installed, skipping...\033[m"
else
{
echo -e " -- \033[1;33mInstalling zlib\033[m"
cd /tmp/ &&
wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/zlib-${ZLIB_VERSION}.tar.gz &&
tar -xf zlib-${ZLIB_VERSION}.tar.gz && rm zlib-${ZLIB_VERSION}.tar.gz &&
cd zlib-${ZLIB_VERSION} &&
./configure --prefix=$ZLIB_PATH &&
make &&
make check &&
sudo make install
} || exit 1
fi
# }}}
# Install hdf5 {{{
if [[ -f $HDF_PATH/lib/libhdf5.so ]] ; then
echo -e " -- \033[1;32mhdf5 already installed, skipping...\033[m"
else
{
echo -e " -- \033[1;33mInstalling hdf5\033[m"
cd /tmp &&
wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-${HDF5_VERSION%.*}/hdf5-${HDF5_VERSION}/src/hdf5-${HDF5_VERSION}.tar.gz &&
tar -xf hdf5-${HDF5_VERSION}.tar.gz && rm hdf5-${HDF5_VERSION}.tar.gz
cd hdf5-${HDF5_VERSION} &&
./configure --enable-build-mode=production --enable-shared --enable-hl --prefix=$HDF_PATH &&
make -j10 &&
# make check && # Takes a million years...
sudo PATH="$PATH:/opt/intel/oneapi/compiler/latest/linux/bin/intel64/" make install
} || exit 1
fi
# }}}
# Install netcdf4 {{{
if [[ -f $HDF_PATH/lib/libnetcdf.so ]] ; then
echo -e " -- \033[1;32mnecdf4 already installed, skipping...\033[m"
else
{
echo -e " -- \033[1;33mInstalling netcdf4\033[m"
cd /tmp/ &&
wget http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-c-${NETCDF_VERSION}.tar.gz &&
tar -xf netcdf-c-${NETCDF_VERSION}.tar.gz && rm netcdf-c-${NETCDF_VERSION}.tar.gz &&
cd netcdf-c-${NETCDF_VERSION} &&
./configure --prefix=$NETCDF_PATH --enable-large-file-tests --with-pic --enable-netcdf-4 --enable-shared --disable-dap --enable-fortran &&
make &&
make check &&
sudo make install
} || exit 1
fi
# }}}
# Install netcdf4 fortran {{{
if [[ -f $HDF_PATH/lib/libnetcdff.so ]] ; then
echo -e " -- \033[1;32mnecdf4-fortran already installed, skipping...\033[m"
else
{
cd /tmp/ &&
wget http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-fortran-${NETCDF_FORTRAN_VERSION}.tar.gz &&
tar -xf netcdf-fortran-${NETCDF_FORTRAN_VERSION}.tar.gz && rm netcdf-fortran-${NETCDF_FORTRAN_VERSION}.tar.gz &&
cd netcdf-fortran-${NETCDF_FORTRAN_VERSION} &&
./configure --prefix=$NETCDF_PATH --enable-large-file-tests --with-pic --enable-shared &&
make &&
make check &&
sudo make install
} || exit 1
fi
# }}}
# Optional eccodes {{{
if [[ -f $HDF_PATH/lib/libeccodes.so ]] ; then
echo -e " -- \033[1;32meccodes already installed, skipping...\033[m"
else
{
echo -e " -- \033[1;33mInstalling eccodes\033[m"
cd /tmp/ &&
wget https://confluence.ecmwf.int/download/attachments/45757960/eccodes-${ECCODES_VERSION}-Source.tar.gz &&
tar -xf eccodes-${ECCODES_VERSION}-Source.tar.gz && rm eccodes-${ECCODES_VERSION}-Source.tar.gz &&
cd eccodes-${ECCODES_VERSION}-Source &&
mkdir build && cd $_ &&
cmake -DCMAKE_INSTALL_PREFIX=${ECCODES_PATH} ../ &&
make -j10 &&
sudo make install
} || exit 1
fi
#}}}
# Optional install cdo {{{
if [[ -f $HDF_PATH/bin/cdo ]] ; then
echo -e " -- \033[1;32mcdo already installed, skipping...\033[m"
else
{
echo -e " -- \033[1;33mInstalling cdo\033[m"
cd /tmp/ &&
wget https://code.mpimet.mpg.de/attachments/download/23323/cdo-${CDO_VERSION}.tar.gz &&
tar -xf cdo-${CDO_VERSION}.tar.gz && rm cdo-${CDO_VERSION}.tar.gz &&
cd cdo-${CDO_VERSION} &&
./configure --prefix=${CDO_PATH} --with-netcdf=${NETCDF_PATH} --with-zlib=${ZLIB_PATH} --with-hdf5=${HDF_PATH} --with-eccodes=${ECCODES_PATH} --enable-shared &&
make -j10 &&
# make check &&
sudo make install
} || exit 1
fi
# }}}
# Optional install nco {{{
{
# Dependency needed to use ncap2
echo -e " -- \033[1;33mInstalling antlr2\033[m"
cd /tmp/
git clone https://github.com/nco/antlr2.git &&
cd antlr2 &&
./configure --prefix=${NCO_PATH} &&
make -j10 &&
sudo make install &&
echo -e " -- \033[1;33mInstalling nco\033[m"
cd /tmp/ &&
# git clone https://github.com/nco/nco.git && cd nco &&
# git checkout ${NCO_VERSION} &&
wget https://github.com/nco/nco/archive/${NCO_VERSION}.tar.gz -O nco-${NCO_VERSION}.tar.gz &&
tar -xf nco-${NCO_VERSION}.tar.gz && rm nco-${NCO_VERSION}.tar.gz &&
cd nco-${NCO_VERSION} &&
# NOTE, if udunits2 does not work on RHEL and you have udunits2-devel you will have to
# create a link for this file in /usr/include/udunits2/udunits2.h /usr/include because NCO won't find it there
./configure --prefix=${NCO_PATH} --enable-udunits2 &&
make -j10 &&
sudo make install
} || exit 1
#}}}
echo -e "\033[1;32mInstallation sucessfull\033[m"
#!/bin/bash
set -e
# Setup path with intel compiler
export PATH=$PATH:/opt/intel/oneapi/compiler/latest/linux/bin/intel64/
# Add intel libraries and netcdf to the path
export LD_LIBRARY_PATH="/opt/intel/oneapi/compiler/latest/linux/compiler/lib/intel64:/usr/local/netcdf4/lib/:${LD_LIBRARY_PATH}"
# Add compilation flags to use hdf5 and netcf4 libs
export LDFLAGS="-L/usr/lib/x86_64-linux-gnu/hdf5/serial -I/usr/include/hdf5/serial -L/usr/local/netcdf4/lib -I/usr/local/netcdf4/include"
# Setup the compilers
export CC=icc
export CXX=icpc
export FC=ifort
export F77=ifort
export F90=ifort
export CPP='icc -E'
export CXXCPP='icpc -E'
export CPPFLAGS="${LDFLAGS}"
# Setup compiler flags
OPTIM="-O3 -ip -no-prec-div -static-intel -fPIC ${LDFLAGS}"
export CFLAGS=" ${OPTIM}"
export CXXFLAGS=" ${OPTIM}"
export FCFLAGS=" ${OPTIM}"
export F77FLAGS=" ${OPTIM}"
export F90FLAGS=" ${OPTIM}"
# WW3 Configuration to use netcdf4
export WWATCH3_NETCDF=NC4
export NETCDF_CONFIG=/usr/local/netcdf4/bin/nf-config
SWITCH_CONTENT="F90 NC4 NOGRB SHRD OMPG OMPX PR3 UQ FLX0 LN1 ST4 STAB0 NL1 IC0 IS0 REF0 BT1 DB1 MLIM TR0 BS0 XX0 WNX1 WNT1 CRX1 CRT1 O0 O1 O2
O3 O4 O5 O6 O7 O11"
# if the repository doesn't exist clone it
[[ ! -d WW3 ]] && git clone "https://github.com/NOAA-EMC/WW3"
cd WW3/
# Base setip
echo -e "\033[1;32mSetting FORTRAN compiler to ifort and C compiler to icc\033[m"
printf 'y\n\nifort\nicc\n\n\n\ny\n' | ./model/bin/w3_setup model
# If large files don't exist download them
if [[ ! -d './cases' ]] && [[ $(du -s './regtests' | awk '{print $1}') -lt 100000 ]] ; then
echo -e "\033[1;32mDownloading large files\033[m" ;
printf '.\ny\ny\n' | ./model/bin/ww3_from_ftp.sh
else # Query user if they want to download files
if [[ "$(read -e -p 'Download large files? [y/N]> ';echo $REPLY)" == [Yy]* ]] ; then
printf '.\ny\ny\n' | ./model/bin/ww3_from_ftp.sh
else
echo -e "\033[1;32mSkyping download\033[m" ;
fi
fi
# Create the custom switch file
echo -e "\033[1;32mCreating new Switch:\033[m\n$SWITCH_CONTENT\n"
echo $SWITCH_CONTENT > ./model/bin/switch_mod
# Run the setup
printf 'n\n' | ./model/bin/w3_setup ./model -c intel -s mod
# Replace -openmp with -openmp (old syntax)
sed -i 's/openmp/qopenmp/' ./model/bin/comp ./model/bin/link
# For some reason this option gets reapeated, so remove one of them
sed -i 's/\(-xhost.*\) -xhost/\1/' ./model/bin/comp ./model/bin/link
# Run automake
echo -e "\033[1;32mRunning automake\033[m"
./model/bin/w3_automake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment