Skip to content

Instantly share code, notes, and snippets.

@stefanahman
Last active December 27, 2015 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanahman/7401807 to your computer and use it in GitHub Desktop.
Save stefanahman/7401807 to your computer and use it in GitHub Desktop.
This bash script runs a time measuring program N times and takes the average (takes the speed up of a reference program). The program will run with different number of threads (1-8). Requires that the program prints a time at the end. Usage: ./multiple_runs.sh [N] [prog] [ref-prog]
#! /bin/bash
export OMP_NUM_THREADS=1
nparam=$#
runs=$1
app=$2
ref=$3
# Init
tsup=0
teff=0
reftime=1
function calculate {
tsum=0
for i in $(seq 1 $runs); do
out=`./$1`
t=`expr match "$out" '.*\(.[0-9]*\.[0-9]*\)'`
tsum=$(echo $tsum + $t | bc)
done
tsum=$(echo "scale=2; $tsum/$runs" | bc -l)
if [ $nparam == 3 ]; then
tsup=$(echo "scale=2; $reftime/$tsum" | bc -l)
teff=$(echo "scale=2; $tsup/$OMP_NUM_THREADS" | bc -l)
fi
}
if [ $nparam == 3 ]; then
echo "========================"
echo "Running original program"
calculate $ref
reftime=$tsum
echo "Time: " $tsum "seconds"
fi
for i in {1..8}; do
echo "========================="
echo "Running with $i thread(s)"
OMP_NUM_THREADS=$i
calculate $app
echo "Time:" $tsum "seconds"
if [ $nparam == 3 ]; then
echo "Speed up:" $tsup
echo "Efficency:" $teff
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment