-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbenchmarks.f90
208 lines (158 loc) · 5.49 KB
/
benchmarks.f90
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
module m_benchmarks
implicit none
CONTAINS
! get elapsed (wallclock) time in seconds since an arbitrary time in the past
real(8) function wtime()
implicit none
integer(kind=8) :: count, rate
call system_clock(count, rate)
wtime = dble(count)/dble(rate)
end function wtime
! If the file 'filename' exists and contains a NAMELIST
! with variables bsp_L and bsp_G (real(8), dimension(48)),
! try to read bsp_l L(num_images()) and bsp_G(num_images()) and return them
! as via the function arguments L and G
subroutine read_bsp_params(filename, L, G)
implicit none
character(*), intent(in) :: filename
real(kind=8), intent(out) :: G, L
integer :: npmax
real(kind=8), allocatable, dimension(:) :: bsp_G, bsp_L
integer :: fu
namelist /bsp_npmax/ npmax
namelist /bsp_params/ bsp_L, bsp_G
open(newunit=fu, file=filename,action='read', status='old')
read(unit=fu, nml=bsp_npmax)
allocate(bsp_G(npmax), bsp_L(npmax))
read(unit=fu, nml=bsp_params)
close(fu)
G=0.d0
L=0.d0
if (num_images() <= npmax) then
G = bsp_G(num_images())
L = bsp_L(num_images())
end if
if (G==0.d0 .or. L==0.d0) then
if (this_image()==1) then
write(*,'(A,I3,A,A)') 'Values G and/or L for ',num_images(),' processes not available in file ',filename
end if
end if
end subroutine read_bsp_params
! measures bandwidth bw [GB/s\] and flop rate R [GFlop/s] of an axpy operation
! (y=a*x+y, two loads, one store) of given size N, averaged over ntimes instances.
! This is a sequential benchmark executed by the calling process.
subroutine bench_axpy(N, ntimes, bw, R)
implicit none
integer(kind=8), intent(in) :: N
integer(kind=8), intent(in) :: ntimes
real(kind=8), intent(out) :: bw, R
real(kind=8), dimension(N) :: x, y
real(kind=8) :: a, t0, t1
integer(kind=8) :: i, k
t0 = wtime()
do k=1,ntimes
!$omp simd
do i=1,N
y(i) = a*x(i) + y(i)
end do
end do
t1 = wtime()
bw = (24.D0*dble(N)*dble(ntimes)) / (t1-t0) * 1.0e-9
R = (2.D0 *dble(N)*dble(ntimes)) / (t1-t0) * 1.0e-9
end subroutine bench_axpy
! Measure the average wallclock-time for an "h-relation" (as defined in the BSP model by Rob Bisseling).
! For a given number of processes P and integer h>=0, an h-relation is a communication pattern where
! each process j sends h distict one-word (8 bytes here) messages to up to min(h,P) processes
real(8) function bench_hrel(h,ntimes)
implicit none
integer(kind=8), intent(in) :: h, ntimes
integer(kind=8), dimension(h) :: sendbuf
! note: we let remote processors p each write to a contiguous
! memory space recvbuf(:,p) with leading dimension a multiple of the
! cache-line length. That way, no false sharing can occur (that is,
! no synchronization because cache-line elements are updated by multiple
! processors).
integer(kind=8), allocatable :: recvbuf(:,:)[:]
integer :: i, j, np, me
integer, dimension(h) :: dest, destidx
real(kind=8) :: t0, t1
np = num_images()
me = this_image()
! let every process write to a memory location aligned to 10 cache-line (80 element) blocks
! to avoid unwanted synchronization due to cache-line sharing. Note that this
! is different from the 'interleaved' writing in the Bisseling implementation of bspbench,
! where adjacent processes write to adjancent cache-line elements and the performnace is much
! worse on modern CPUs.
allocate(recvbuf(h+modulo(h,80_8), np)[*])
! Initialize communication pattern
do i=1,h
! arbitrary data to send
sendbuf(i)= i;
! note: mod(x,0) is not defined in Fortran and leads to an FPE
if (np==1) then
dest(i) = 1
else
! destination processor is one of the p-1 others
dest(i) = modulo(me+1+modulo(i,(np-1)),np)+1
end if
end do
! Measure time of ntimes h-relations
sync all
t0 = wtime()
do j=1,ntimes
do i=1,h
recvbuf(i,me)[dest(i)] = sendbuf(i)
end do
sync all
end do
t1 = wtime()
bench_hrel = (t1-t0)/dble(ntimes)
end function bench_hrel
! Alternative function to benchmark an h-relation.
! This variant gives much better performance as it
! avoids interleaved memory accesses and may therefore be
! a better model for predicting performance of well-written
! codes.
real(8) function bench_hrel2(h,ntimes)
implicit none
integer(kind=8), intent(in) :: h, ntimes
! note: we let remote processors p each write to a contiguous
! memory space recvbuf(:,p) with leading dimension a multiple of the
! cache-line length. That way, no false sharing can occur (that is,
! no synchronization because cache-line elements are updated by multiple
! processors).
integer(kind=8), allocatable :: recvbuf(:,:)[:]
integer(kind=8), allocatable :: sendbuf(:,:)
integer :: i, j, k, np, me, bs
integer, dimension(h) :: dest, destidx
real(kind=8) :: t0, t1
np = num_images()
me = this_image()
bs = ceiling(dble(h)/dble(np))
! let every process write to a memory location aligned to 10 cache-line (80 element) blocks
! to avoid unwanted synchronization due to cache-line sharing. Note that this
! is different from the 'interleaved' writing in the Bisseling implementation of bspbench,
! where adjacent processes write to adjancent cache-line elements and the performnace is much
! worse on modern CPUs.
allocate(sendbuf(4000, np))
allocate(recvbuf(4000, np)[*])
! Initialize communication pattern
do i=1,h
! arbitrary data to send
sendbuf(i,:)= i;
end do
! Measure time of ntimes h-relations
sync all
t0 = wtime()
do j=1,ntimes
do k=1,np
do i=1,bs
recvbuf(i,me)[k] = sendbuf(i,k)
end do
end do
sync all
end do
t1 = wtime()
bench_hrel2 = (t1-t0)/dble(ntimes)
end function bench_hrel2
end module m_benchmarks