#!/bin/bash
#
# Script to run all the Benchmarks executables that are
# generated by just issuing the command
#     make
# the script takes a single argument that specifies the
# directory name to be used within the Results/Benchmarks
# directory for storing the generated results files.
#
# If the directory name already exists, the user is required
# to confirm his intention to overwrite existing files.
#

# Check we have at least one argument and take the first if 
# more than one. If no arguments output error message
# and exit
if [ $# -eq 0 ];
then
  echo "runBenchmarks called without directory argument"
  echo "Exiting without running executables"
  exit
fi

# Set up the relative directory name given the argument
Prefix=../Results/Benchmarks/$1/

# If directory requested already exists ask user for 
# confirmation. If it doesn't exist, create it.
if [ -d ${Prefix} ];
then 
  read -p "Directory ${Prefix} exists, continue [Yn]:" x
  if [ "$x" = "Y" ]; 
  then
    echo "Overwriting existing results files"
  else
    echo "Exiting without executing benchmark codes"
    exit
  fi
else
  echo "Creating directory: ${Prefix}"
  mkdir -p ${Prefix}
fi

# Set name for separate error LOG
ERRORLOG=RunErrorLog

# Now run the executables
./sdBenchOrigBlas > ${Prefix}OrigBlas.txt 2>${ERRORLOG}
./sdBenchBlue > ${Prefix}Blue.txt 2>>${ERRORLOG}
./sdBenchBlueCsum > ${Prefix}BlueCsum.txt 2>>${ERRORLOG}
./sdBenchOrigKahan > ${Prefix}OrigKahan.txt 2>>${ERRORLOG}
./sdBenchLa > ${Prefix}La.txt 2>>${ERRORLOG}
./sdBenchLaCsum > ${Prefix}LaCsum.txt 2>>${ERRORLOG}
./sdBenchLaCsSc > ${Prefix}LaCsSc.txt 2>>${ERRORLOG}
./sdBenchNewBlue > ${Prefix}NewBlue.txt 2>>${ERRORLOG}
./sdBenchNewOrig > ${Prefix}NewOrig.txt 2>>${ERRORLOG}
./sdBenchNewOrigCsum > ${Prefix}NewOrigCsum.txt 2>>${ERRORLOG}
./sdBenchNorm2 > ${Prefix}Norm2.txt 2>>${ERRORLOG}
./sdBenchOnePassKahan > ${Prefix}OnePassKahan.txt 2>>${ERRORLOG}
