Skip to content

Instantly share code, notes, and snippets.

@martok
Created March 28, 2018 15:03
Show Gist options
  • Save martok/39cf1d437930ee231629b09e03bc7c5f to your computer and use it in GitHub Desktop.
Save martok/39cf1d437930ee231629b09e03bc7c5f to your computer and use it in GitHub Desktop.
Start a program using mpirun with multi-user-friendly options
#!/bin/bash
{
NPROCS=4
NICE=10
STDOUT=/dev/stdout
print_usage()
{
cat <<END
Usage: `basename $0` [OPTIONS] program args
Start a program using mpirun with multi-user-friendly options
-h
This help message
-np <procs>
Number of processors to run on [default: ${NPROCS}]
-o <filename>
Redirect stdout to filename [default: ${STDOUT}]
-omp <threads>
Number of OpenMP threads [default: ${OMP_NUM_THREADS}]
-p <niceness>
Add integer niceness [default: ${NICE}]
END
}
if [ $# -lt 1 ] ; then
print_usage
exit 1
fi
while [ $# -ge 1 ] ; do
case $1 in
-h)
print_usage
exit 1
;;
-np)
shift
NPROCS=$1
;;
-o)
shift
STDOUT=$1
;;
-omp)
shift
export OMP_NUM_THREADS=$1
;;
-p)
shift
NICE=$1
;;
*)
break
;;
esac
shift
done
if [ $# -lt 1 ] ; then
echo "ERROR: no program specified"
exit 1
fi
nice -n $NICE mpirun --bind-to none -np $NPROCS $* > $STDOUT
exit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment