
#.... MG 2012-01-09;  target for STAMPEDE
set XHOME=/share/home/00461

if ( "$TARGETHOST" == "none" ) then
   set TARGETHOST="stampede.tacc.utexas.edu"
endif

if ( "$TARGETPREP" == "none" ) then
   set TARGETPREP=" "
endif

if ( "$RUNTIME" == "none" ) then
   set RUNTIME="24:00:00"
endif

if ( "$MPIF77_FLAGS" == "none" ) then
   set MPIF77_FLAGS="-O2 "
endif

if ( "$MPIF90_FLAGS" == "none" ) then
   set MPIF90_FLAGS="-O2 "
endif

if ( "$MPICC_FLAGS" == "none" ) then
   set MPICC_FLAGS="-g -O2 "
endif

set CORES=`echo $TOTNODES | awk '{print 16*(int(($1-1)/16+1));}'`
cat >> tmp.submit << EOF
echo === Preparing batch file for run $RUN on $TOTNODES nodes. Target: remote-tacc-stampede
echo === Location: \$USER@`hostname`:\$PWD Target: remote-tacc-stampede

mv openggcm $RUN.exe
#...... we want to run everything in the pp directory,
#...... which is supposed to be on a large file system
if [ ! -d \${HOME}/pp ];then
   cd \${HOME} && ln -s \${WORK} pp && cd -
fi

mkdir -p \${HOME}/pp/$RUN
/bin/cp -au ./* \${HOME}/pp/$RUN
cd \${HOME}/pp/$RUN
if [ -f $RUN.exe ]; then
    echo $RUN.exe exists, proceeding with job submission
else
    echo the file $RUN.exe does not exist, bailing out in $0
fi

PPN=16
NODES=\$(( ($TOTNODES + \$PPN - 1) / \$PPN))

cat > $RUN.qsub <<XEOF
#!/bin/csh
#SBATCH -n ${CORES}
#SBATCH -J ${RUN}
#SBATCH -t ${RUNTIME}
#SBATCH -p ${CLASS}


#module load autotools/1.0
cd \${HOME}/pp/$RUN
pwd
/bin/ls -al

ibrun \${HOME}/pp/$RUN/$RUN.exe >&!  \${HOME}/pp/$RUN/$RUN.log

XEOF

echo === Submitting job $RUN.qsub  Target: remote-tacc-stampede
cat $RUN.qsub 
sbatch $RUN.qsub
EOF
