#!/bin/csh
#
#  Sample Batch Script for a p=2 Platinum cluster job
#
#  Submit this script using the command: qsub cpgm2.job
#
#  Use the "qstat" command to check the status of a job.
#
# The following are embedded QSUB options. The syntax is #PBS (the # does
# _not_  denote that the lines are commented out so do not remove).
#
# resource limits  walltime: maximum wall clock time (hh:mm:ss)
#                  nodes: number of 2-processor nodes
#                  ppn: how many processors per node to use (1 or 2)
#                      (you are always charged for the entire node)
#                  prod: resource = production Platinum cluster nodes
#PBS -l walltime=00:30:00,nodes=1:ppn=2:prod
#
# queue name
#PBS -q standard
#
# export all my environment variables to the job
#PBS -V
#
# Charge job to project MCS572 nfa
# [If project is invalid, a valid project will be automatically selected]
#PBS -A nfa
# 
# job name (default = name of script file)
#PBS -N cpgm2mss
#
# filename for standard output (default = <job_name>.o<job_id>)
#PBS -o cpgm2mss.out
#
# filename for standard error (default = <job_name>.e<job_id>)
#PBS -e cpgm2mss.err
# 
# send mail when the job begins and ends (optional)
#PBS -m be
# End of embedded QSUB options

#set echo               # echo commands before execution; use for debugging

# Create the scratch directory for the job and cd to it
setenv SCR `set_SCR`
if ($SCR != "") cd $SCR

# Get files cpgm2mss executable and cdata data from directory in UniTree:
# Note1: must first compile cpgm2mss.c with mpi options to get cpgm2mss:
# Note2: must first store them from $HOME:% msscmd put cdata,put cpgm2mss
msscmd get cdata,get cpgm2mss

chmod u+x cpgm2 # Since UniTree gives you the same permissions as 
                     # what your umask is set to (generally only read 
                     # and write), you need to give yourself
                     # executable permission to run cpgm2
                     # If set properly you do not need to chmod.

# Run the MPI program on all nodes/processors requested by the job
# (program reads from cdata and writes to file cpgm2mss.output)
vmirun "cpgm2mss < cdata >& cpgm2mss.output"

# After the job is done, save the output file to UniTree
msscmd put cpgm2mss.output
# Finally retrieve to $HOME:% msscmd get cpgm2mss.output
