#!/bin/csh
#
# This sccript is generated by Make from lrun.txt
#
# $Id: lrun.txt 3915 2009-07-21 07:10:21Z tbailey $
# $Log$
# Revision 1.1  2005/08/25 20:18:02  nadya
# use vavriable for setting mpi-lam direcotry
#
#

# Assumes that USE_LAM has been used

#default arguments
set NOPTARG = -O
set VERBARG = ' '
set DEBUGARG = ' '
set NOHEADER = -H
set EXECARG = binary_not_specified

if ( $?PBS_NODEFILE ) then
      set NPROCARG = `cat $PBS_NODEFILE | wc -l`
 endif

#Analyse input parameters
while (1)
   switch($1)
      case -h:
      case -help:
             echo " "
             echo " lrun - simplified interface to running an MPI jobs using"
             echo "        LAM both under PBS and as interactive processes"
             echo " "
             echo " Options:"
             echo " "
             echo "   -n N   specifies number of MPI processes - under PBS the"
             echo "          default is the number of cpus requested (-lncpus),"
             echo "          there is no default for interactive use"
             echo " "
             echo "   -v     specifies verbose output and logging"
             echo " "
             exit
             breaksw
      case -n:
         shift
         set NPROCARG = $1
         shift
         breaksw
      case -NO:
         set NOPTARG = $1
         shift
         breaksw
      case -v:
         set VERBARG = $1
         set NOHEADER = ' '
         shift
         breaksw
      case -d:
         set DEBUGARG = $1
         shift
         breaksw
      default:
         set EXECARG = "$argv[1-]"
         break
   endsw
end

if ( ! $?NPROCARG ) then
    echo "Error: must specify number of MPI processes (-n)"
    exit
endif

if ( $NPROCARG < 1 || $NPROCARG > 100 ) then
    echo "Error: number of MPI processes (-n) is out of range"
    exit
endif

if ( $VERBARG == "-v") then
      echo " "
      echo "Starting lamd ..."
      echo " "
endif

@LAM_BIN@/lamboot $NOHEADER $VERBARG $DEBUGARG

sleep 1

if ( $VERBARG == "-v") then
      echo " "
      echo "Running MPI job ..."
      echo " "
endif

@LAM_BIN@/mpirun -np $NPROCARG $VERBARG $NOPTARG $EXECARG

# Now lets cleanup
if ( $VERBARG == "-v") then
      echo " "
      echo "Cleaning up ..."
      echo " "
endif

@LAM_BIN@/lamhalt $VERBARG

if ( $VERBARG == "-v") then
      echo " "
      echo "Done\!"
      echo " "
endif

sleep 1
