-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmark.sh
executable file
·159 lines (125 loc) · 6.44 KB
/
benchmark.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#! /bin/bash
# Vincent Magnin, 2021-05-09
# Ryan Bignell, 2024-01-17
# Last modification: 2024-09-04
# Launch the Pi Monte Carlo benchmark
# MIT license
# Verified with shellcheck
# Strict mode:
set -uo pipefail
# Launches N times the a.out executable and copy the output in a file.
launch_N_times()
{
# Input parameters:
local readonly N="$1"
local readonly filename="$2"
local readonly executable="$3"
for ((i = 1 ; i <= N ; i++)) ; do
${executable} | tee -a "$filename"
done
}
# Compute the computation mean time using the times in the file.
mean_time()
{
# Input parameters:
local readonly testname="$1"
# We grep real numbers with 3 decimals followed by a space (CPU times)
# and we compute their mean value using awk:
echo $(grep -oE '[0-9]+\.[0-9]{3} ' "${testname}.txt" | awk '{ total += $1 } END { printf "%5.2f", total/NR }')
}
#***************
# Main program:
#***************
readonly runs=10
readonly threads=2
# Environment variables for OpenMP and Coarrays (ifort):
export OMP_NUM_THREADS="${threads}"
export FOR_COARRAY_NUM_IMAGES="${threads}"
# Cleanup:
rm -f gfortran*.txt
rm -f ifort*.txt
rm -f ifx*.txt
# All examples are compiled and launched several times, and the results are
# copied into a txt file:
test_name="gfortran_serial"
echo "$test_name"
gfortran -O3 m_xoroshiro128plus.f90 pi_monte_carlo_serial.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="ifort_serial"
echo "$test_name"
ifort -O3 m_xoroshiro128plus.f90 pi_monte_carlo_serial.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="ifx_serial"
echo "$test_name"
ifx -O3 m_xoroshiro128plus.f90 pi_monte_carlo_serial.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="gfortran_openmp"
echo "$test_name"
gfortran -O3 -fopenmp m_xoroshiro128plus.f90 pi_monte_carlo_openmp.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="ifort_openmp"
echo "$test_name"
ifort -O3 -qopenmp m_xoroshiro128plus.f90 pi_monte_carlo_openmp.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="ifx_openmp"
echo "$test_name"
ifx -O3 -qopenmp m_xoroshiro128plus.f90 pi_monte_carlo_openmp.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="gfortran_coarrays"
echo "$test_name"
caf -O3 m_xoroshiro128plus.f90 pi_monte_carlo_coarrays.f90 && launch_N_times "$runs" "$test_name.txt" "cafrun -n ${threads} ./a.out"
test_name="ifort_coarrays"
echo "$test_name"
ifort -O3 -coarray m_xoroshiro128plus.f90 pi_monte_carlo_coarrays.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="ifx_coarrays"
echo "$test_name"
ifx -O3 -coarray=shared -coarray-num-images=${threads} m_xoroshiro128plus.f90 pi_monte_carlo_coarrays.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="gfortran_coarrays_steady"
echo "$test_name"
caf -O3 m_xoroshiro128plus.f90 pi_monte_carlo_coarrays_steady.f90 && launch_N_times "$runs" "$test_name.txt" "cafrun -n ${threads} ./a.out"
test_name="ifort_coarrays_steady"
echo "$test_name"
ifort -O3 -coarray m_xoroshiro128plus.f90 pi_monte_carlo_coarrays_steady.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="ifx_coarrays_steady"
echo "$test_name"
ifx -O3 -coarray=shared -coarray-num-images=${threads} m_xoroshiro128plus.f90 pi_monte_carlo_coarrays_steady.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="gfortran_co_sum"
echo "$test_name"
caf -O3 -flto m_xoroshiro128plus.f90 pi_monte_carlo_co_sum.f90 && launch_N_times "$runs" "$test_name.txt" "cafrun -n ${threads} ./a.out"
test_name="ifort_co_sum"
echo "$test_name"
ifort -O3 -coarray m_xoroshiro128plus.f90 pi_monte_carlo_co_sum.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="ifx_co_sum"
echo "$test_name"
ifx -coarray=shared -coarray-num-images=${threads} -O3 -coarray m_xoroshiro128plus.f90 pi_monte_carlo_co_sum.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="gfortran_co_sum_steady"
echo "$test_name"
caf -O3 m_xoroshiro128plus.f90 pi_monte_carlo_co_sum_steady.f90 && launch_N_times "$runs" "$test_name.txt" "cafrun -n ${threads} ./a.out"
test_name="ifort_co_sum_steady"
echo "$test_name"
ifort -O3 -coarray m_xoroshiro128plus.f90 pi_monte_carlo_co_sum_steady.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="ifx_co_sum_steady"
echo "$test_name"
ifx -O3 -coarray=shared -coarray-num-images=${threads} m_xoroshiro128plus.f90 pi_monte_carlo_co_sum_steady.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="gfortran_co_sum_openmp"
echo "$test_name"
caf -O3 -fopenmp -flto m_xoroshiro128plus.f90 pi_monte_carlo_co_sum_openmp.f90 && launch_N_times "$runs" "$test_name.txt" "cafrun -n ${threads} ./a.out"
test_name="ifort_co_sum_openmp"
echo "$test_name"
ifort -O3 -qopenmp -coarray m_xoroshiro128plus.f90 pi_monte_carlo_co_sum_openmp.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
test_name="ifx_co_sum_openmp"
echo "$test_name"
ifx -coarray=shared -coarray-num-images=${threads} -qopenmp -O3 -coarray m_xoroshiro128plus.f90 pi_monte_carlo_co_sum_openmp.f90 && launch_N_times "$runs" "$test_name.txt" "./a.out"
# The CPU times mean values are computed with each txt file:
echo '****************************************'
echo ' STATISTICS (Markdown table)'
echo '****************************************'
echo '| Version | gfortran | ifort | ifx |'
echo '| -------------------- | -------- | ------- | ------- |'
echo "| Serial | $(mean_time 'gfortran_serial') | $(mean_time 'ifort_serial') | $(mean_time 'ifx_serial') |"
echo "| OpenMP | $(mean_time 'gfortran_openmp') | $(mean_time 'ifort_openmp') | $(mean_time 'ifx_openmp') |"
echo "| Coarrays | $(mean_time 'gfortran_coarrays') | $(mean_time 'ifort_coarrays') | $(mean_time 'ifx_coarrays') |"
echo "| Coarrays steady | $(mean_time 'gfortran_coarrays_steady') | $(mean_time 'ifort_coarrays_steady') | $(mean_time 'ifx_coarrays_steady') |"
echo "| Co_sum | $(mean_time 'gfortran_co_sum') | $(mean_time 'ifort_co_sum') | $(mean_time 'ifx_co_sum') |"
echo "| Co_sum steady | $(mean_time 'gfortran_co_sum_steady') | $(mean_time 'ifort_co_sum_steady') | $(mean_time 'ifort_co_sum_steady') |"
echo "| Co_sum & openMP | $(mean_time 'gfortran_co_sum_openmp') | $(mean_time 'ifort_co_sum_openmp') | $(mean_time 'ifx_co_sum_openmp') |"
echo
echo "Compilers versions:"
echo "-------------------"
gfortran --version
ifort --version
ifx --version