# Do the time measurement for the HiPCiP project - Two-Dimensional XY Model
# Coded by Chris
# 27/05/1999

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

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

# Forbid dynamic adjustment of thread number
export OMP_DYNAMIC=FALSE


#
# Performance measurement for the parallel Monte Carlo sweep using uni()
# for a small system
#

# Measure performance of parallel Monte Carlo sweep using uni()
# for a small system
echo -e >h4perf.dat "1\nf\n20\n2000\n0.5\n0.2\nt\n1000"
timex 2>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=1
echo -e >h4perf.dat "3\nf\n20\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=2
echo -e >h4perf.dat "3\nf\n20\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=3
echo -e >h4perf.dat "3\nf\n20\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=4
echo -e >h4perf.dat "3\nf\n20\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
awk -f h4perf.awk1 h4perf.out >SpeedUpSmallUni.dat
awk -f h4perf.awk2 h4perf.out >EfficiencySmallUni.dat

# Measure performance of parallel Monte Carlo sweep using uni()
# for a medium system
echo -e >h4perf.dat "1\nf\n60\n2000\n0.5\n0.2\nt\n1000"
timex 2>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=1
echo -e >h4perf.dat "3\nf\n60\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=2
echo -e >h4perf.dat "3\nf\n60\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=3
echo -e >h4perf.dat "3\nf\n60\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=4
echo -e >h4perf.dat "3\nf\n60\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
awk -f h4perf.awk1 h4perf.out >SpeedUpMediumUni.dat
awk -f h4perf.awk2 h4perf.out >EfficiencyMediumUni.dat

# Measure performance of parallel Monte Carlo sweep using uni()
# for a big system
echo -e >h4perf.dat "1\nf\n100\n2000\n0.5\n0.2\nt\n1000"
timex 2>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=1
echo -e >h4perf.dat "3\nf\n100\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=2
echo -e >h4perf.dat "3\nf\n100\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=3
echo -e >h4perf.dat "3\nf\n100\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=4
echo -e >h4perf.dat "3\nf\n100\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
awk -f h4perf.awk1 h4perf.out >SpeedUpBigUni.dat
awk -f h4perf.awk2 h4perf.out >EfficiencyBigUni.dat


#
# Performance measurement for the parallel Monte Carlo sweep using puni()
# for a small system
#

# Measure performance of parallel Monte Carlo sweep using puni()
# for a small system
echo -e >h4perf.dat "1\nf\n20\n2000\n0.5\n0.2\nt\n1000"
timex 2>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=1
echo -e >h4perf.dat "4\nf\n20\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=2
echo -e >h4perf.dat "4\nf\n20\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=3
echo -e >h4perf.dat "4\nf\n20\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=4
echo -e >h4perf.dat "4\nf\n20\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
awk -f h4perf.awk1 h4perf.out >SpeedUpSmallPUni.dat
awk -f h4perf.awk2 h4perf.out >EfficiencySmallPUni.dat

# Measure performance of parallel Monte Carlo sweep using puni()
# for a medium system
echo -e >h4perf.dat "1\nf\n60\n2000\n0.5\n0.2\nt\n1000"
timex 2>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=1
echo -e >h4perf.dat "4\nf\n60\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=2
echo -e >h4perf.dat "4\nf\n60\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=3
echo -e >h4perf.dat "4\nf\n60\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=4
echo -e >h4perf.dat "4\nf\n60\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
awk -f h4perf.awk1 h4perf.out >SpeedUpMediumPUni.dat
awk -f h4perf.awk2 h4perf.out >EfficiencyMediumPUni.dat

# Measure performance of parallel Monte Carlo sweep using puni()
# for a big system
echo -e >h4perf.dat "1\nf\n100\n2000\n0.5\n0.2\nt\n1000"
timex 2>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=1
echo -e >h4perf.dat "4\nf\n100\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=2
echo -e >h4perf.dat "4\nf\n100\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=3
echo -e >h4perf.dat "4\nf\n100\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
export OMP_NUM_THREADS=4
echo -e >h4perf.dat "4\nf\n100\n2000\n0.5\n0.2\nt\n1000"
timex 2>>h4perf.out ./HiPCiP4 <h4perf.dat >/dev/null
awk -f h4perf.awk1 h4perf.out >SpeedUpBigPUni.dat
awk -f h4perf.awk2 h4perf.out >EfficiencyBigPUni.dat

rm h4perf.dat h4perf.out h4perf.awk1 h4perf.awk2




