#!/bin/bash
#PBS -N wDashGo
#PBS -A P28100045
#PBS -l walltime=12:00:00
#PBS -l job_priority=economy
#PBS -q main
#PBS -j oe
#PBS -l select=8:ncpus=128:mpiprocs=2:ompthreads=64+3:ncpus=128:mpiprocs=1:ompthreads=128
#PBS -m abe

echo "Job $PBS_JOBID started at `date` on `hostname` in directory `pwd`."

echo 'Setting up MAGE environment.'
source $KAIJUROOTDIR/scripts/setupEnvironment.sh

echo 'Loading modules.'
module --force purge
module load $MODULE_LIST
echo 'The following modules are loaded:'
module list

echo 'Setting environment variables.'
MPICOMMAND="mpiexec $KAIJUHOME/scripts/preproc/pinCpuCores.sh"
export TMPDIR=/glade/work/ewinter/mage_testing/derecho/tmp
export OMP_NUM_THREADS=128
export MPI_TYPE_DEPTH=32
export KMP_STACKSIZE=128M
echo 'The active environment variables are:'
printenv

# Run the model.
$MPICOMMAND ./voltron_mpi.x weeklyDashGo.xml > weeklyDashGo.out

# Generate the report.
export MAGE_TEST_ROOT='/glade/work/ewinter/mage_testing/derecho'
export CONDARC="${MAGE_TEST_ROOT}/condarc"
export CONDA_ENVS_PATH="${MAGE_TEST_ROOT}/conda"
mage_miniconda3="${MAGE_TEST_ROOT}/miniconda3"
mage_conda="${mage_miniconda3}/bin/conda"
__conda_setup="$($mage_conda 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "$mage_miniconda3/etc/profile.d/conda.sh" ]; then
        . "$mage_miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="$mage_miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
conda activate kaiju-3.8-testing
python $KAIJUHOME/testingScripts/weeklyDashReport.py -dlv >& weeklyDashReport.out

echo "Job $PBS_JOBID ended at `date` on `hostname` in directory `pwd`."
