#!/bin/bash
#SBATCH --time={{{times}}}:00:00
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --mem={{{memory}}}GB
#SBATCH --job-name={{{job}}}
#SBATCH --output={{{job}}}_%j.out
#SBATCH --error={{{job}}}_%j.err
#SBATCH --account={{{account}}}
#SBATCH --array=1-{{{workers}}}

export TASKQUEUE_RESOURCE="{{{resource}}}"
tic=`date +%s`
echo "Start Time = "`date`

cd {{{working_dir}}}
echo "Working directory = {{{working_dir}}}"

{{#modules}}
module load {{.}}
{{/modules}}

#module load openmpi

module list
ulimit -s unlimited


# count the number of processors
np=`srun hostname -s | wc -l`


# generate nodelist
nodelist=`srun hostname -s | sort | tr '\n' ' '`

echo "Launching script using R"

Rscript {{{rfile}}} > {{{rout}}}.Rout

echo "All Done!"

echo "End Time = "`date`
toc=`date +%s`

elapsedTime=`expr $toc - $tic`
echo "Elapsed Time = $elapsedTime seconds"


