#!/bin/sh
@@{PARTITION}
@@{CONSTRAINTS}
#SBATCH --nodes=@@{NNODES}-@@{NNODES}
#SBATCH --ntasks-per-node=@@{PPN}
#SBATCH --time=@@{WALLTIME}
#SBATCH -J JOB_@@{JOBID}_@@{INSTANCEID}
#SBATCH -o slurm_@@{RUNNAME}_@@{INSTANCEID}.stdout
#SBATCH -e slurm_@@{RUNNAME}_@@{INSTANCEID}.stderr
@@{REMOTEBATCHACCOUNT}

@@{ENVIRONMENT}

# RemoteBatchSLURM:makeSerialTemplate
# SubmissionScripts/Distributor/Batch/SLURM/serial

trap cleanup HUP INT QUIT ABRT TERM

cleanup()
{
   echo "Abnormal termination by signal"
   if [ ! -s @@{TS_FINISH} ] ; then
      date +"%s" > @@{TS_FINISH}
   fi
   exit 1
}

export PATH=${SLURM_SUBMIT_DIR}:${PATH}
# Change to directory where job was submitted.
cd ${SLURM_SUBMIT_DIR}

TIMEPATH=
for timePath in ${HOME}/bin/time /usr/bin/time /usr/local/bin/time ; do
   if [ -x ${timePath} ] ; then
      TIMEPATH=${timePath}
      break
   fi
done

@@{QUOTA}

date +"%s" > @@{TS_START}

@@{PREMANAGERCOMMANDS}
${TIMEPATH} --format "Command exited with status %x\nreal %e\nuser %U\nsys %S" -o @@{TIME_RESULTS} \
   @@{EXECUTABLE} @@{ARGUMENTS} < @@{STDIN} > @@{RUNNAME}_@@{INSTANCEID}.stdout 2> @@{RUNNAME}_@@{INSTANCEID}.stderr
@@{POSTMANAGERCOMMANDS}

date +"%s" > @@{TS_FINISH}
