#!/bin/bash
#MSUB -A pa4674
#MSUB -q knl
#MSUB -r specfem3D_test_case_B
#MSUB -N 384
#MSUB -n 1536                     # Number of tasks to use
#MSUB -c 16                     # Number of threads per task to use
#MSUB -o specfem3D_test_case_B_irene-knl-%I.output
#MSUB -T 20200

source ../env/env_irene-knl
cd $install_dir/TestCaseB/specfem3d_globe
#Make sure that OMP_NUM_THREADS / KMP_HW_SUBSET = cpus-per-task
export KMP_HW_SUBSET=1T
export OMP_NUM_THREADS=16
ulimit -s unlimited

MESHER_EXE=./bin/xmeshfem3D
SOLVER_EXE=./bin/xspecfem3D

# backup files used for this simulation
cp DATA/Par_file OUTPUT_FILES/
cp DATA/STATIONS OUTPUT_FILES/
cp DATA/CMTSOLUTION OUTPUT_FILES/

##
## mesh generation
##
sleep 2

echo
echo `date`
echo "starting MPI mesher"
echo

MPI_PROCESS=1536 #` echo "$SLURM_NNODES*$SLURM_NTASKS_PER_NODE" | bc -l`
echo "MPI_PROCESS $MPI_PROCESS"
echo "OMP_NUM_THREADS=$OMP_NUM_THREADS"

time ccc_mprun -n ${MPI_PROCESS} ${MESHER_EXE}
echo "  mesher done: `date`"
echo

##
## forward simulation
##
sleep 2

echo
echo `date`
echo starting run in current directory $PWD
echo
time ccc_mprun -n ${MPI_PROCESS}  ${SOLVER_EXE}

echo "finished successfully"
echo `date`
