#!/usr/bin/env bash

set -e  # Exit immediately if a command exits with a non-zero status.

# Generate a timestamp for the log file
dt=$(date +%d-%m-%Y_%H.%M.%S)

# Set PETSc environment variables
export PETSC_DIR=/Users/fcaro/petsc
export PETSC_ARCH=arch-cmplx-opt

# Navigate to the PETSc directory
cd $PETSC_DIR

# Configure PETSc build
echo "Configuring PETSc..." >> PETSc_opt_$dt.log
./configure --with-cc=gcc-13 --with-cxx=g++-13 --with-fc=/usr/local/bin/gfortran-13 --with-fc=/usr/local/bin/gfortran-13 \
    --with-debugging=no --with-scalar-type=complex --with-openmp \
    --download-mpich --download-fblaslapack --download-scalapack \
    --download-mumps --download-metis --download-parmetis --download-hwloc \
    COPTFLAGS="-O3" CXXOPTFLAGS="-O3" FOPTFLAGS="-Ofast" $PETSC_ARCH >> PETSc_opt_$dt.log 2>&1

# Build PETSc
echo "Building PETSc..." >> PETSc_opt_$dt.log
make $PETSC_DIR $PETSC_ARCH all check >> PETSc_opt_$dt.log 2>&1

# Optional: Display a message when the script completes
echo "Opt version of PETSc installation completed."



