#!/usr/bin/env bash
cd /mnt/matylda3/xtikho00/XLM/wrappers
. ./path.sh
( echo '#' Running on `hostname`
  echo '#' Started at `date`
  echo -n '# '; cat <<EOF
python test.py 
EOF
) >test.log
if ! which free-gpus.sh &> /dev/null; then
   echo 'command not found: free-gpus.sh not found.'
   exit 1
fi
gpuid=$(free-gpus.sh 0)
if [[ ${gpuid} == -1 ]]; then
   echo 'Failed to find enough free GPUs: 0'
   exit 1
fi
echo "Free GPU(s): ${gpuid}" >>test.log
export CUDA_VISIBLE_DEVICES=${gpuid}
time1=`date +"%s"`
 ( python test.py  ) 2>>test.log >>test.log
ret=$?
time2=`date +"%s"`
echo '#' Accounting: time=$(($time2-$time1)) threads=1 >>test.log
echo '#' Finished at `date` with status $ret >>test.log
[ $ret -eq 137 ] && exit 100;
touch ./q/sync/done.6419
exit $[$ret ? 1 : 0]
## submitted with:
# qsub -v PATH -cwd -S /bin/bash -j y -l arch=*64* -o ./q/test.log    /mnt/matylda3/xtikho00/XLM/wrappers/./q/test.sh >>./q/test.log 2>&1
