######################################################################
#                            Jugene
#-------------------------------------------------------------------
# http://www.lrz.de/services/compute/supermuc/loadleveler/
######################################################################

function UJS_Submit
{
	if [ $walltime == "unlimited" ]; then
		walltime=01:00:00
	fi
	
	if [ $((npe%nppn)) -ne 0 ]; then
		echo "npe=$npe is not dividable by nppn=$nppn"
		exit
	fi
	echo ""; echo "On Jugene, using ll_submit"
	
	MYLDLPATH=/bgsys/drivers/ppcfloor/comm/lib/
	
	if [ $interactive == true ]; then
		echo "interactive mode is not supported at the moment"
	fi
	
	if [ $exclusive == true ]; then
		echo "WARNING: Exclusive not yet supported on this machine."
	fi	

	cat > $outdir/job.sh << EOF
# @ job_name = $jobname
# @ comment = $executable $args
# @ error = $outdir/job.error
# @ output = $outdir/job.output
# @ environment = COPY_ALL
# @ wall_clock_limit = $walltime
EOF
	if [ $mail == true ]; then 
		if [ -z "$UGSUBMIT_EMAIL" ]; then
			echo "please set UGSUBMIT_EMAIL or specify email with -email".
			exit
		fi

		JugeneNotification="never"
		if [ $mailStart == true ]; then
			JugeneNotification="start"
		fi
		if [ $mailEnd == true ]; then
			if [ $JugeneNotification == "never" ]; then
				JugeneNotification="stop"
			else
				JugeneNotification="always"
			fi
		fi
		if [ $mailError == true ]; then
			if [ $JugeneNotification == "never" ]; then
				JugeneNotification="error"
			else
				JugeneNotification="always"
			fi
		fi	 
		
		cat >> job.sh << EOF
# @ notification = $JugeneNotification
# @ notify_user = $UGSUBMIT_EMAIL
EOF
	fi
	cat >> job.sh << EOF
# @ job_type = bluegene
# @ bg_connection = TORUS
# @ bg_size = $npe
# @ queue
mpirun -np $npe -exe $executable -mode $JugeneMode -mapfile $JugeneMapfile -verbose $JugeneVerbose -env LD_LIBRARY_PATH=$MYLDLPATH -args $args
EOF

	echo job.sh
	if [ $test == true ]; then
		echo "test. not executing."
		echo $outdir/job.sh ":"
		cat $outdir/job.sh
		cd $outdir/..
		#rm -rf $outdir/
		exit
	fi
	
#todo: uncomment next line, get jobid=
# ll_submit $outdir/job.sh
}

function UJS_GetOptions
{
	nppnmax=4
	pemax=1024
}


function UJS_Info
{
	echo "Using Jugene"
	echo "to be implemented"
}

function UJS_Cancel
{
	echo "Using Jugene"
	echo "to be implemented. kill job $1"
}