#! /bin/sh
if [ "$MPIR_HOME" = "" ] ; then
    MPIR_HOME=#MPIR_HOME#
fi
if [ "$MPIR_HOME" = "#""MPIR_HOME""#" ] ; then
    MPIR_HOME=`pwd`/..
fi
if [ "#MPIRUN_BIN#" = "#""MPIRUN_BIN""#" ] ; then
    MPIRUN_HOME=$MPIR_HOME/bin
else
    MPIRUN_HOME=$MPIR_HOME/#MPIRUN_BIN#
fi
if [ "$argsset" = "" ] ; then
   . $MPIRUN_HOME/mpirun.args
   argsset=1
fi
#
#  set arguments for batch mode -- cjbr
#
if [ -n "$batch" ] ; then
   cjarg=
   if [ -n "$stdinfile" ] ; then
      cjarg="-i $stdinfile"
   else
      cjarg=
   fi
   if [ -n "$stdoutfile" ] ; then
      cjarg="$cjarg -o $stdoutfile"
   fi
   if [ -n "$stderrfile" ] ; then
      cjarg="$cjarg -e $stderrfile"
   fi
fi
#
#  get number of processors available
#
free=`cjpes | fgrep ST_PE_ACTIV | wc -l`
#
#   Specify request (only active for GMD)
#
#   if [ $free -lt $np ] ; then
#      if [ $mpirun_verbose = 1 ] ; then
#         echo requesting $np processors
#      fi
#
#      $Show /vol/local/bin/request_nodes $np
#   fi
#
#   Execute Job in batch mode or interactive
#
    if [ -n "$batch" ] ; then
       if [ $mpirun_verbose = 1 ] ; then
          echo executing job in batch mode
       fi

       $Show cjbr $cjarg $np $progname $cmdLineArgs
#
    else
       if [ $mpirun_verbose = 1 -o $free -lt $np ] ; then
          echo waiting for $np processors available
       fi
#
       $Show cjsh -w -n $np $progname $cmdLineArgs
    fi
