#!/bin/bash
###############################################################################
# This hook is the command that is executed every run.
# Check the examples in examples/
#
# This hook is run in the execution directory (execDir, --exec-dir),
# the same directory where hook-evaluate is executed. Hence, you may
# need to copy extra files needed by the executable to this directory.
#
#
# PARAMETERS:
# $1 is the instance name
# $2 is the candidate number
# The rest ($* after `shift 2') are parameters to the run
#
# RETURN VALUE:
# This script should print nothing.
# Exit with 0 if no error, with 1 in case of error
###############################################################################
EXE=~/bin/program
FIXED_PARAMS=""
INSTANCE=$1
CANDIDATE=$2
shift 2 || exit 1
CAND_PARAMS=$*

STDOUT=c${CANDIDATE}.stdout
STDERR=c${CANDIDATE}.stderr

# We use 'exec' to avoid creating another process. There can be no
# other commands after exec.
exec qsub <<EOF
#!/bin/bash
#$ -N irace-$PPID-$CANDIDATE
#$ -l xeon5410
# -l long
#$ -m as
#$ -j yes
#$ -o /dev/null
#$ -e /dev/null
#$ -cwd
TMP=\$(mktemp -d)
exec 2> \$TMP/$STDERR
$EXE ${FIXED_PARAMS} --input $INSTANCE ${CAND_PARAMS} 1> \$TMP/$STDOUT
RET=\$?
echo "OK" >& 2
mv \$TMP/* ./
rmdir -p \$TMP &> /dev/null
exit \$RET
EOF
