#!/bin/bash

set -euo pipefail

if [[ ! -e o2_nrConfs.txt ]]; then
  echo "o2_nrConfs.txt not found, exiting"
  exit 1
fi
NR_CONFS=$(cat o2_nrConfs.txt)
NAME=$(basename $(pwd))
find "scratch/o3/" -mindepth 1 -maxdepth 1 -name "generate-*.log" -print0 | xargs -0 -P 3 -n 100 -r rm


# sequential version:
echo "Generating all versions, logs will be written to scratch/o3/."
echo ""
for i in $(seq 1 ${NR_CONFS}); do
  echo -ne "\r  $i / ${NR_CONFS}"
  java -XX:+UseG1GC -cp ../compiler_expl.jar Main ../settings.txt knowledge.txt ../platform.txt $i &> scratch/o3/generate-$i.log
done
echo -e "\rdone"
#####################

# parallel version using slurm:
#sbatch -n 1 -c 1 --mem=10000 --array=1-${NR_CONFS} -o scratch/o3/generate-%a.log -e scratch/o3/generate-%a.log --parsable --nice=500 --job-name "pExpl gen ${NAME}" --time=15 "$@" --wrap 'java -XX:+UseG1GC -cp ../compiler_expl.jar Main ../settings.txt knowledge.txt ../platform.txt $SLURM_ARRAY_TASK_ID' | tee o3.sid
#####################
