#!/bin/bash
rm $1 > /dev/null 2>&1

if [[ $3 == "yes" ]] ; then
    gcc -O3 -march=native -fopenmp -I ../utilities  ../utilities/polybench.c $1.c -DPOLYBENCH_TIME -D$2_DATASET -o $1 -lm
else
    gcc -O3 -march=native -I ../utilities  ../utilities/polybench.c $1.c -DPOLYBENCH_TIME -D$2_DATASET -o $1 -lm
fi
MIN=9999
for i in {0..999}
do
    if [[ $3 == "yes" ]] ; then
        time_exec=`OMP_PROC_BIND=true OMP_NUM_THREADS=12 ./$1 2>&1`
    else
        time_exec=`./$1 2>&1`
    fi
    var=$(awk 'BEGIN{ print "'${time_exec}'"<"'${MIN}'" }')
    if [ "$var" -eq 1 ];then
        echo "current $time_exec"
        MIN="$time_exec"
    fi
done

echo ""
echo "real : "$MIN