#! /bin/sh

if [ $# -ne 2 ]; then
   echo "Usage: musicrun <number of tasks> <configuration file (*.music)>"
   exit 1
fi

abspath="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
path="`dirname $abspath`"

binary=`mpirun -np $1 $path/music $2`
exitcode=$?

if [ $exitcode -ne 0 ]; then
   echo "$binary"
   exit $exitcode
fi

echo "$binary"
exit $exitcode
