#!/bin/bash
set -eu

## Constants
VER="3.15.3"

# Download source
$ISSM_DIR/scripts/DownloadExternalPackage.sh "https://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-lite-${VER}.tar.gz" "petsc-${VER}.tar.gz"

# Unpack source
tar -zxvf petsc-${VER}.tar.gz

# Cleanup
rm -rf install src
mkdir install src

# Move source to 'src' directory
mv petsc-${VER}/* src/
rm -rf petsc-${VER}

cd src
./config/configure.py \
        COPTFLAGS="-g -O3" CXXOPTFLAGS="-g -O3" FOPTFLAGS="-g -O3" \
		  --with-make-np=20 \
        --with-blas-lapack-dir=$MKL_ROOT \
        --with-mpi-dir="/optnfs/el7/mpich/3.3-intel19.3/" \
        --known-mpi-shared-libraries=1 \
        --known-mpi-long-double=1 \
        --known-mpi-int64_t=1 \
        --known-mpi-c-double-complex=1 \
        --with-debugging=0 \
        --with-valgrind=0 \
        --with-x=0 \
        --with-ssl=0 \
        --with-pic=1 \
        --download-metis=1 \
        --download-parmetis=1 \
        --download-scalapack=1 \
        --download-mumps=1

# Compile and install
make
make install
