######################################################################
#                            mpi
#-------------------------------------------------------------------
# not a real job scheduler, just for completeness and tests
# todo: wait for completion of "jobs"...
######################################################################

function UJS_Submit
{
	echo "Cluster: local. Scheduler: MPI."
	jobid="?"
		
	commandline="mpirun -np $npe $executable $args"
	echo " command:      "$commandline >> info.txt
	
	if [ $exclusive == true ]; then
		echo "WARNING: Exclusive not supported for MPI."
	fi	
	
	if [ $test == true ]; then
		echo "ONLY testing - NOT executing."
		echo "Submit/Start: $commandline"
		return
	fi
	
	if [ $interactive == true ]; then
		echo "Start: $commandline"
		$commandline | tee job.output
	else
		echo "Submit: $commandline"
		nohup $commandline > job.output &
	fi
	jobid=$!
}



function UJS_GetOptions
{
	nppnmax=1
	
	# arbitrary maximum
	pemax=1024
}

function UJS_Info
{
	echo "Using MPI"
	echo "ps aux | grep $USER | grep mpirun"
	echo "JOBID STATE $(ps aux | sed -n 1p)"

	ps aux | grep -E "$USER|$UID|${USER:0:8}+" | grep "prterun\|mpirun" | grep -v grep | while read -r line ; do
		jobid=$(echo $line | grep -Eo '\s[0-9]+\b' -o -m 1 -h -a | head -1 | cut -c2-)
		echo "$jobid RUNNING $line"
	done
}


function UJS_Cancel
{
	echo "Using MPI"
	echo "kill $1"
	kill $1
}
