forked from vlvovch/PHYS6350-ComputationalPhysics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.sh
70 lines (58 loc) · 2.7 KB
/
runner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Parameters
EXECUTABLE=${2:-"./matrix_mult_openmp"}
MATRIX_SIZE=${1:-500}
NUM_RUNS=10
# Check if the executable exists
if [ ! -f "$EXECUTABLE" ]; then
echo "Executable '$EXECUTABLE' not found."
exit 1
fi
echo "Threads | Avg Wall Time (ms) | Standard Error (ms) | Speedup Factor | Speedup SE | Efficiency | Efficiency SE"
echo "--------+-------------------+------------------+----------------+-------------+------------+----------------"
# Compute the baseline time
output=$(OMP_NUM_THREADS=1 $EXECUTABLE $MATRIX_SIZE 1)
baseline_time=$(echo "$output" | awk '{print $(NF-1)}')
baseline_time_error=0
# Vary the number of threads from 1 to 8
for NUM_THREADS in {1..8}; do
# Run the matrix multiplication program, calculate the average wall time, and accumulate squared differences
total_time=0
times=()
for i in $(seq 1 $NUM_RUNS); do
output=$($EXECUTABLE $MATRIX_SIZE $NUM_THREADS)
time_ms=$(echo "$output" | awk '{print $(NF-1)}')
total_time=$(echo "scale=7; $total_time + $time_ms" | bc -l)
times+=($time_ms)
done
average_time=$(echo "scale=7; $total_time / $NUM_RUNS" | bc -l)
# Calculate the standard error
squared_diff_sum=0
for time in "${times[@]}"; do
diff=$(echo "scale=7; $time - $average_time" | bc -l)
squared_diff=$(echo "scale=7; $diff * $diff" | bc -l)
squared_diff_sum=$(echo "scale=7; $squared_diff_sum + $squared_diff" | bc -l)
done
variance=$(echo "scale=7; $squared_diff_sum / ($NUM_RUNS - 1)" | bc -l)
standard_deviation=$(echo "scale=7; sqrt($variance)" | bc -l)
standard_error=$(echo "scale=7; $standard_deviation / sqrt($NUM_RUNS)" | bc -l)
# Calculate the speedup factor relative to the single-threaded case and its standard error
if [[ "$NUM_THREADS" -eq 1 ]]; then
speedup_factor="1.00"
speedup_error="0.00"
baseline_time=$average_time
baseline_time_error=$standard_error
else
speedup_factor=$(echo "scale=7; $baseline_time / $average_time" | bc -l)
speedup_error=$(echo "scale=7; $speedup_factor * sqrt((($standard_error / $average_time) ^ 2) + (($baseline_time_error / $baseline_time) ^ 2))" | bc -l)
fi
# Calculate the efficiency and its standard error
if [[ "$NUM_THREADS" -eq 1 ]]; then
efficiency="1.00"
efficiency_error="0.00"
else
efficiency=$(echo "scale=7; $speedup_factor / $NUM_THREADS" | bc -l)
efficiency_error=$(echo "scale=7; $speedup_error / $NUM_THREADS" | bc -l)
fi
printf "%-8d| %-18.2f| %-18.2f| %-15.3f | %-11.3f | %-10.3f | %-12.3f\n" "$NUM_THREADS" "$average_time" "$standard_error" "$speedup_factor" "$speedup_error" "$efficiency" "$efficiency_error"
done