# Do the time measurement for the HiPCiP project - Practical: Fluid Dynamics
# Coded by Chris
# 29/04/1999

# Create scripts for awk
echo  >h3perf.awk1 "/real/ {count = count + 1;"
echo >>h3perf.awk1 "        t2 = substr(\$2,1,index(\$2,\":\")-1);"
echo >>h3perf.awk1 "        t2 = 60 * t2 + substr(\$2,index(\$2,\":\")+1);"
echo >>h3perf.awk1 "        if (t1) print count,t1/t2;"
echo >>h3perf.awk1 "        else {t1 = t2; count=0;}}"

echo  >h3perf.awk2 "/real/ {count = count + 1;"
echo >>h3perf.awk2 "        t2 = substr(\$2,1,index(\$2,\":\")-1);"
echo >>h3perf.awk2 "        t2 = 60 * t2 + substr(\$2,index(\$2,\":\")+1);"
echo >>h3perf.awk2 "        if (t1) print count,t1/(t2 * count);"
echo >>h3perf.awk2 "        else {t1 = t2; count=0;}}"


#
# Performance measurement for the Jacobi PDE solver
#

# Forbid dynamic adjustment of thread number
export OMP_DYNAMIC=FALSE

# Measure performance of Jacobi PDE solver for a small system
echo -e >h3perf.dat "1\n30"
timex 2>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=1
echo -e >h3perf.dat "5\n30"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=2
echo -e >h3perf.dat "5\n30"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=3
echo -e >h3perf.dat "5\n30"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=4
echo -e >h3perf.dat "5\n30"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
awk -f h3perf.awk1 h3perf.out >SpeedUpSmallJ.dat
awk -f h3perf.awk2 h3perf.out >EfficiencySmallJ.dat

# Measure performance of Jacobi PDE solver for a medium system
echo -e >h3perf.dat "1\n60"
timex 2>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=1
echo -e >h3perf.dat "5\n60"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=2
echo -e >h3perf.dat "5\n60"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=3
echo -e >h3perf.dat "5\n60"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=4
echo -e >h3perf.dat "5\n60"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
awk -f h3perf.awk1 h3perf.out >SpeedUpMediumJ.dat
awk -f h3perf.awk2 h3perf.out >EfficiencyMediumJ.dat

# Measure performance of Jacobi PDE solver for a big system
echo -e >h3perf.dat "1\n90"
timex 2>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=1
echo -e >h3perf.dat "5\n90"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=2
echo -e >h3perf.dat "5\n90"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=3
echo -e >h3perf.dat "5\n90"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=4
echo -e >h3perf.dat "5\n90"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
awk -f h3perf.awk1 h3perf.out >SpeedUpBigJ.dat
awk -f h3perf.awk2 h3perf.out >EfficiencyBigJ.dat


#
# Performance measurement for the Gauss-Seidel PDE solver
#

# Measure performance of Jacobi PDE solver for a small system
echo -e >h3perf.dat "4\n30"
timex 2>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=1
echo -e >h3perf.dat "6\n30"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=2
echo -e >h3perf.dat "6\n30"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=3
echo -e >h3perf.dat "6\n30"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=4
echo -e >h3perf.dat "6\n30"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
awk -f h3perf.awk1 h3perf.out >SpeedUpSmallGS.dat
awk -f h3perf.awk2 h3perf.out >EfficiencySmallGS.dat

# Measure performance of Jacobi PDE solver for a medium system
echo -e >h3perf.dat "4\n60"
timex 2>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=1
echo -e >h3perf.dat "6\n60"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=2
echo -e >h3perf.dat "6\n60"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=3
echo -e >h3perf.dat "6\n60"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=4
echo -e >h3perf.dat "6\n60"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
awk -f h3perf.awk1 h3perf.out >SpeedUpMediumGS.dat
awk -f h3perf.awk2 h3perf.out >EfficiencyMediumGS.dat

# Measure performance of Jacobi PDE solver for a big system
echo -e >h3perf.dat "4\n90"
timex 2>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=1
echo -e >h3perf.dat "6\n90"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=2
echo -e >h3perf.dat "6\n90"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=3
echo -e >h3perf.dat "6\n90"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
export OMP_NUM_THREADS=4
echo -e >h3perf.dat "6\n90"
timex 2>>h3perf.out ./HiPCiP3 <h3perf.dat >/dev/null
awk -f h3perf.awk1 h3perf.out >SpeedUpBigGS.dat
awk -f h3perf.awk2 h3perf.out >EfficiencyBigGS.dat

rm h3perf.dat h3perf.out h3perf.awk1 h3perf.awk2




