#!/bin/sh

BINDIR=$1
EXECDIR=$2
shift 2

#MACHINE=opteron244
#MACHINE=opteron2216
#MACHINE=xeon5410
MACHINE=opteron6128


exec qsub <<EOF
#!/bin/bash
#$ -N irace-$$
#$ -l $MACHINE
#$ -l long
#$ -S /bin/bash
#$ -m ase
#      b     Mail is sent at the beginning of the job.
#      e     Mail is sent at the end of the job.
#      a     Mail is sent when the job is aborted or rescheduled.
#      s     Mail is sent when the job is suspended.
#$ -o $EXECDIR/irace-$$.stdout
#$ -e $EXECDIR/irace-$$.stderr
#$ -cwd

# Working on /tmp should be faster
TMP=\$(mktemp -d)
$BINDIR/irace --exec-dir=\$TMP $* 
RET=\$?
cp -R \$TMP/./ $EXECDIR/
rm -rf \$TMP
exit \$RET
EOF
