trapped_signals="HUP INT QUIT ILL ABRT SEGV FPE ALRM TERM USR1 USR2 BUS"
+die () {
+ printf '[%s] ** error: %s. Aborting.\n' "$(basename $0)" "$*" >&2
+ exit 1
+}
+
smpirun_cleanup()
{
if [ -z "${KEEP}" ] ; then
"-platform")
PLATFORM="$2"
if [ ! -f "${PLATFORM}" ]; then
- echo "[`basename $0`] ** error: the file '${PLATFORM}' does not exist. Aborting."
- exit 1
+ die "the file '${PLATFORM}' does not exist"
fi
shift 2
;;
"-hostfile")
HOSTFILE="$2"
if [ ! -f "${HOSTFILE}" ]; then
- echo "[`basename $0`] ** error: the file '${HOSTFILE}' does not exist. Aborting."
- exit 1
+ die "the file '${HOSTFILE}' does not exist"
fi
shift 2
;;
"-machinefile")
HOSTFILE="$2"
if [ ! -f "${HOSTFILE}" ]; then
- echo "[`basename $0`] ** error: the file '${HOSTFILE}' does not exist. Aborting."
- exit 1
+ die "the file '${HOSTFILE}' does not exist"
fi
shift 2
;;
UNROLLEDHOSTFILETMP=0
#parse if our lines are terminated by :num_process
-multiple_processes=`grep -c ":" $HOSTFILE`
+multiple_processes=$(grep -c ":" $HOSTFILE)
if [ "${multiple_processes}" -gt 0 ] ; then
UNROLLEDHOSTFILETMP=1
UNROLLEDHOSTFILE="$(mktemp smpitmp-hostfXXXXXX)"
fi
# Don't use wc -l to compute it to avoid issues with trailing \n at EOF
-hostfile_procs=`grep -c "[a-zA-Z0-9]" $HOSTFILE`
+hostfile_procs=$(grep -c "[a-zA-Z0-9]" $HOSTFILE)
if [ ${hostfile_procs} = 0 ] ; then
- echo "[`basename $0`] ** error: the hostfile '${HOSTFILE}' is empty. Aborting." >&2
- exit 1
+ die "the hostfile '${HOSTFILE}' is empty"
fi
if [ -z "${NUMPROCS}" ] ; then
## hostfile has less than i lines.
##----------------------------------------------------------
-HAVE_SEQ="`which seq 2>/dev/null`"
+HAVE_SEQ="$(which seq 2>/dev/null)"
if [ -n "${HAVE_SEQ}" ]; then
- SEQ=`${HAVE_SEQ} 0 $((${NUMPROCS}-1))`
+ SEQ=$(${HAVE_SEQ} 0 $(( NUMPROCS - 1)))
else
cnt=0
while [ $cnt -lt ${NUMPROCS} ] ; do
for i in ${SEQ}
do
- j=$(( $i % ${hostfile_procs} + 1 ))
+ j=$(( i % hostfile_procs + 1 ))
host=$(eval "echo \${$j}")
##---- optional display of ranks to actor mapping