Skip to content

Instantly share code, notes, and snippets.

@bessey
Last active December 14, 2015 19:48
Show Gist options
  • Save bessey/5138759 to your computer and use it in GitHub Desktop.
Save bessey/5138759 to your computer and use it in GitHub Desktop.
Run script for HPC examples / general code. Takes a submission file as an argument and works out from the submission file what output files to expect from qsub. Basically made to avoid having to customise job files to the script!
#!/bin/zsh
# Handy run script.
# Call with './run.sh <JOB_SUB> "<COMMENT>"
# <JOB_SUB> is replaced by your job submission file.
# <COMMENT> is replaced with your title for the run.
# Your <
# <COMMENT> must be in quotes.
#
# Original Author: Drummond Ogilvie
# Released under the DBAD license:
# http://www.dbad-license.org
function itsatrap()
{
echo "Aborting job $jnum"
qdel $jnum
exit 2
}
echo "Running version: '$2'"
echo -ne "Making..."
make clean; make
[[ $? == 2 ]] && echo "MAKE FAILED!!" && exit 2
echo "Done!"
j=$(qsub $1)
jnum=${j%%\.*}
echo "Submitted job $jnum."
trap 'itsatrap' 2
progb=""
i=0
errfile=$(cat $1 | sed -nr 's/#PBS -N (.+)/\1/p')
outfile=$(cat $1 | sed -nr 's/#PBS -o (.+)/\1/p')
while [[ ! -a $outfile ]]; do
echo -ne "Queued for ${i}s\r"
(( i = $i + 2 ))
sleep 2
done
echo ""
echo -ne '\a'
sleep 2
echo "Job $jnum is done"
name=$(date +"%e-%k%M")
cat =(echo "Job Tag: $2") =(echo "Errors:") "MPI.e$jnum" =(echo "Output:") $outfile =(echo "Build report:") mkreport.txt > report-${name}.txt
cat report-${name}.txt
mv report-${name}.txt reports/
echo "Output stored in file report-${name}"
echo -ne "Removing intermediate files... "
rm $errfile.* 2> /dev/null
rm $outfile 2> /dev/null
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment