#!/bin/bash
######################################################################
#                    UJS cluster template
#-------------------------------------------------------------------
# created by Martin Rupp 28.03.2012
# use this to create your own job scheduler implementation
######################################################################

# if you want to use PBS (qsub, qstat ...) check the "hermit" script in this directory
# if you want to use SLURM (salloc, sinfo ...) check the "cekon" script in this directory
# if you want to use the IBM LoadLeveler (ll_submit, ...) check the "jugene" script in this directory
# todo: add scripts pbs, slurm and IBMLoadLeveler

function UJS_Submit
{
	# submit a job
	# see ugsubmit for a complete list of variables you can use.
	# most important are
	# $UGSUBMIT_EMAIL
	# $nppn
	# $npe
	# $mail (true or false)
	# $jobname
	# $executable
	# $args
	# $interactive
	
	# your current directory is $outdir, it is where all output should be stored
	# the output of the executable should be stored in job.output and the error in job.error
	
	# additional information about the job scheduling should be appended to the file info.txt
	
	if [ $verbose == true ]; then
		# display more information, and also the actual call to the scheduler
	fi
	
	if [ $exclusive == true ]; then
		echo "WARNING: Exclusive not yet supported on this machine."
		# exclusive mode means no "sharing" of half nodes with other jobs.
	fi	
	
	# use this if you don't want to support unlimited walltimes.
	if [ $walltime == "unlimited" ]; then
		$walltime=01:00:00
	fi

	# call your scheduler command

	# please check the return of your scheduler command:
	
	return=$?
	if [ ! $return == 0 ]; then
		echo "ERROR: scheduler returned $return. Job has NOT been scheduled."		
		exit
	fi
	
	# you should write the job id in the variable jobid, for example	
	# sleep 1
	# jobid=`cat job.output | sed -n 1p | sed 's/.* \([0-9]*\).*/\1/'`
	# this will return the last number in the first string e.g. 'salloc: Granted job 25182' -> 25182
	# otherwise, set jobid to ?
}


function UJS_GetOptions
{
	### set maximal ppn and pe. 
	#nppnmax=4
	#pemax=1024	
}

function UJS_Info
{
	### call a command which prints scheduled jobs
}

function UJS_Cancel
{
	### call a command which cancels the job with job id $1	
}