#!/bin/bash

# note:
# - for final results add -w volta02
# - possibly change to --gpus=V100:2, if you want to use 2 GPUs

if [ -z "$1" ]; then
	echo "No input file specified."
	echo "Usage: $0 <input_file_name>"
	exit 1
fi

ACCOUNT=nprg042s
PARTITION=gpu-short-teach
EXEC='./sycl-neighbor-coverage'

DATA_DIR='./data'
INPUT_FILE="$DATA_DIR/$1"
if [ ! -f "$INPUT_FILE" ]; then
	echo "Input file $INPUT_FILE does not exist in $DATA_DIR directory"
	exit 1
fi
SERIAL_OUT="./$1.serial"
PARALLEL_OUT="./$1.parallel"

# change to `make purge all` if you want to rebuild the solution every time
echo "Building the solution..."
srun -p $PARTITION -A $ACCOUNT --gpus=V100:1 make

echo "Benchmarking $1 ..."
ST=`srun -p $PARTITION -A $ACCOUNT -w volta02 --gpus=V100:2 -n 1 -c 32 "$EXEC" --algorithm serial --r 1.0 "$INPUT_FILE" "$SERIAL_OUT"`
echo "Serial time: $ST us"

PT=`srun -p $PARTITION -A $ACCOUNT -w volta02 --gpus=V100:2 -n 1 -c 32 "$EXEC" --algorithm sycl --r 1.0 "$INPUT_FILE" "$PARALLEL_OUT"`
echo "Parallel time: $PT us"

echo -n "Speedup: "
echo "$ST/$PT" | bc -l

echo "Verifying results using diff..."
diff "$SERIAL_OUT" "$PARALLEL_OUT"
if [[ $? == 0 ]]; then
	echo "Verification OK"
else
	echo "Verification (possibly) FAILED"
fi
