#!/bin/bash 
#!
# @ shell = /usr/bin/ksh
# @ job_name = MPI_config
# @ output = out.$(job_name).$(jobid)
# @ error =  err.$(job_name).$(jobid)
# @ job_type = parallel
# @ total_tasks = NPROCS
# @ wall_clock_limit = 0:30:00
# @ resources = ConsumableMemory(1562mb)
# @ class = parallel
# @ node_usage = shared
# @ notification = error
# @ task_affinity = core
# @ group = science
# @ queue

ulimit -c unlimited
ulimit -s unlimited
#
# Test specific settings. Do not hand edit these lines; the fcm_job.sh script will set these
# (via sed operating on this template job file). 
#
  OCEANCORES=NPROCS
  export SETTE_DIR=DEF_SETTE_DIR

###############################################################
#
# set up mpp computing environment
#
# Local settings for machine IBM Power7 (hpc2e at UK Met Office)
#
export MPIRUN="poe -pgmodel $MP_PGMMODEL -n $OCEANCORES -cmdfile"

#
# load sette functions (only post_test_tidyup needed)
#
  . ${SETTE_DIR}/all_functions.sh

# Don't remove neither change the following comment line
# BODY


#
# These variables are needed by post_test_tidyup function in all_functions.sh
#
  export EXE_DIR=DEF_EXE_DIR
  export INPUT_DIR=DEF_INPUT_DIR
  export CONFIG_DIR=DEF_CONFIG_DIR
  export TOOLS_DIR=DEF_TOOLS_DIR
  export NEMO_VALIDATION_DIR=DEF_NEMO_VALIDATION
  export NEW_CONF=DEF_NEW_CONF
  export CMP_NAM=DEF_CMP_NAM
  export TEST_NAME=DEF_TEST_NAME
#
# end of set up


###############################################################
#
# change to the working directory 
#
cd ${EXE_DIR}

  echo Running on host `hostname`
  echo Time is `date`
  echo Directory is `pwd`
# 
#  Run the parallel MPI executable 
#
  if [ MPI_FLAG == "yes" ]; then
     n=1
     echo "./opa" > ./alltasks
     while [ $n -lt $OCEANCORES ]
     do
       echo "./opa" >> ./alltasks
       n=$(( $n + 1 ))
     done
     time ${MPIRUN} ./alltasks
  else
     time ./opa
  fi


#
  post_test_tidyup

# END_BODY
# Don't remove neither change the previous comment line

  exit
