Neko 1.99.7
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
gs_sx.f90
Go to the documentation of this file.
1! Copyright (c) 2020-2026, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
34module gs_sx
35 use num_types, only : rp
36 use gs_bcknd, only : gs_bcknd_t
38 use, intrinsic :: iso_c_binding, only : c_ptr
39 implicit none
40 private
41
43 type, public, extends(gs_bcknd_t) :: gs_sx_t
44 real(kind=rp), allocatable :: local_wrk(:)
45 real(kind=rp), allocatable :: shared_wrk(:)
46 integer :: nlocal
47 integer :: nshared
48 contains
49 procedure, pass(this) :: init => gs_sx_init
50 procedure, pass(this) :: free => gs_sx_free
51 procedure, pass(this) :: gather => gs_gather_sx
52 procedure, pass(this) :: scatter => gs_scatter_sx
53 end type gs_sx_t
54
55contains
56
58 subroutine gs_sx_init(this, nlocal, nshared, nlcl_blks, nshrd_blks)
59 class(gs_sx_t), intent(inout) :: this
60 integer, intent(in) :: nlocal
61 integer, intent(in) :: nshared
62 integer, intent(in) :: nlcl_blks
63 integer, intent(in) :: nshrd_blks
64
65 call this%free()
66
67 this%nlocal = nlocal
68 this%nshared = nshared
69
70 allocate(this%local_wrk(nlocal))
71 allocate(this%shared_wrk(nshared))
72
73 end subroutine gs_sx_init
74
76 subroutine gs_sx_free(this)
77 class(gs_sx_t), intent(inout) :: this
78
79 if (allocated(this%local_wrk)) then
80 deallocate(this%local_wrk)
81 end if
82
83 if (allocated(this%shared_wrk)) then
84 deallocate(this%shared_wrk)
85 end if
86
87 this%nlocal = 0
88 this%nshared = 0
89
90 end subroutine gs_sx_free
91
93 subroutine gs_gather_sx(this, v, m, o, dg, u, n, gd, nb, b, bo, op, shrd)
94 integer, intent(in) :: m
95 integer, intent(in) :: n
96 integer, intent(in) :: nb
97 class(gs_sx_t), intent(inout) :: this
98 real(kind=rp), dimension(m), intent(inout) :: v
99 integer, dimension(m), intent(inout) :: dg
100 real(kind=rp), dimension(n), intent(inout) :: u
101 integer, dimension(m), intent(inout) :: gd
102 integer, dimension(nb), intent(inout) :: b
103 integer, dimension(nb), intent(inout) :: bo
104 integer, intent(in) :: o
105 integer, intent(in) :: op
106 logical, intent(in) :: shrd
107
108 if (.not. shrd) then
109 associate(w=>this%local_wrk)
110 select case(op)
111 case (gs_op_add)
112 call gs_gather_kernel_add(v, m, o, dg, u, n, gd, nb, b, w)
113 case (gs_op_mul)
114 call gs_gather_kernel_mul(v, m, o, dg, u, n, gd, nb, b, w)
115 case (gs_op_min)
116 call gs_gather_kernel_min(v, m, o, dg, u, n, gd, nb, b, w)
117 case (gs_op_max)
118 call gs_gather_kernel_max(v, m, o, dg, u, n, gd, nb, b, w)
119 end select
120 end associate
121 else if (shrd) then
122 associate(w=>this%shared_wrk)
123 select case(op)
124 case (gs_op_add)
125 call gs_gather_kernel_add(v, m, o, dg, u, n, gd, nb, b, w)
126 case (gs_op_mul)
127 call gs_gather_kernel_mul(v, m, o, dg, u, n, gd, nb, b, w)
128 case (gs_op_min)
129 call gs_gather_kernel_min(v, m, o, dg, u, n, gd, nb, b, w)
130 case (gs_op_max)
131 call gs_gather_kernel_max(v, m, o, dg, u, n, gd, nb, b, w)
132 end select
133 end associate
134 end if
135
136 end subroutine gs_gather_sx
137
140 subroutine gs_gather_kernel_add(v, m, o, dg, u, n, gd, nb, b, w)
141 integer, intent(in) :: m
142 integer, intent(in) :: n
143 integer, intent(in) :: nb
144 real(kind=rp), dimension(m), intent(inout) :: v
145 real(kind=rp), dimension(m), intent(inout) :: w
146 integer, dimension(m), intent(inout) :: dg
147 real(kind=rp), dimension(n), intent(inout) :: u
148 integer, dimension(m), intent(inout) :: gd
149 integer, dimension(nb), intent(inout) :: b
150 integer, intent(in) :: o
151 integer :: i
152 real(kind=rp) :: tmp
153
154 v = 0d0
155 do i = 1, abs(o) - 1
156 w(i) = u(gd(i))
157 end do
158
159 do i = 1, abs(o) - 1
160 v(dg(i)) = v(dg(i)) + w(i)
161 end do
162
163 if (o .lt. 0) then
164 do i = abs(o), m
165 v(dg(i)) = u(gd(i))
166 end do
167 else
168 do i = o, m, 2
169 tmp = u(gd(i)) + u(gd(i+1))
170 v(dg(i)) = tmp
171 end do
172 end if
173
174 end subroutine gs_gather_kernel_add
175
178 subroutine gs_gather_kernel_mul(v, m, o, dg, u, n, gd, nb, b, w)
179 integer, intent(in) :: m
180 integer, intent(in) :: n
181 integer, intent(in) :: nb
182 real(kind=rp), dimension(m), intent(inout) :: v
183 real(kind=rp), dimension(m), intent(inout) :: w
184 integer, dimension(m), intent(inout) :: dg
185 real(kind=rp), dimension(n), intent(inout) :: u
186 integer, dimension(m), intent(inout) :: gd
187 integer, dimension(nb), intent(inout) :: b
188 integer, intent(in) :: o
189 integer :: i
190 real(kind=rp) :: tmp
191
192 v = 1d0
193 do i = 1, abs(o) - 1
194 w(i) = u(gd(i))
195 end do
196
197 do i = 1, abs(o) - 1
198 v(dg(i)) = v(dg(i)) * w(i)
199 end do
200
201 if (o .lt. 0) then
202 do i = abs(o), m
203 v(dg(i)) = u(gd(i))
204 end do
205 else
206 do i = o, m, 2
207 tmp = u(gd(i)) * u(gd(i+1))
208 v(dg(i)) = tmp
209 end do
210 end if
211
212 end subroutine gs_gather_kernel_mul
213
216 subroutine gs_gather_kernel_min(v, m, o, dg, u, n, gd, nb, b, w)
217 integer, intent(in) :: m
218 integer, intent(in) :: n
219 integer, intent(in) :: nb
220 real(kind=rp), dimension(m), intent(inout) :: v
221 real(kind=rp), dimension(m), intent(inout) :: w
222 integer, dimension(m), intent(inout) :: dg
223 real(kind=rp), dimension(n), intent(inout) :: u
224 integer, dimension(m), intent(inout) :: gd
225 integer, dimension(nb), intent(inout) :: b
226 integer, intent(in) :: o
227 integer :: i
228 real(kind=rp) :: tmp
229
230 v = huge(0.0_rp)
231 do i = 1, abs(o) - 1
232 w(i) = u(gd(i))
233 end do
234
235 do i = 1, abs(o) - 1
236 v(dg(i)) = min(v(dg(i)), w(i))
237 end do
238
239 if (o .lt. 0) then
240 do i = abs(o), m
241 v(dg(i)) = u(gd(i))
242 end do
243 else
244 do i = o, m, 2
245 tmp = min(u(gd(i)), u(gd(i+1)))
246 v(dg(i)) = tmp
247 end do
248 end if
249
250 end subroutine gs_gather_kernel_min
251
254 subroutine gs_gather_kernel_max(v, m, o, dg, u, n, gd, nb, b, w)
255 integer, intent(in) :: m
256 integer, intent(in) :: n
257 integer, intent(in) :: nb
258 real(kind=rp), dimension(m), intent(inout) :: v
259 real(kind=rp), dimension(m), intent(inout) :: w
260 integer, dimension(m), intent(inout) :: dg
261 real(kind=rp), dimension(n), intent(inout) :: u
262 integer, dimension(m), intent(inout) :: gd
263 integer, dimension(nb), intent(inout) :: b
264 integer, intent(in) :: o
265 integer :: i
266 real(kind=rp) :: tmp
267
268 v = -huge(0.0_rp)
269 do i = 1, abs(o) - 1
270 w(i) = u(gd(i))
271 end do
272
273 do i = 1, abs(o) - 1
274 v(dg(i)) = max(v(dg(i)), w(i))
275 end do
276
277 if (o .lt. 0) then
278 do i = abs(o), m
279 v(dg(i)) = u(gd(i))
280 end do
281 else
282 do i = o, m, 2
283 tmp = max(u(gd(i)), u(gd(i+1)))
284 v(dg(i)) = tmp
285 end do
286 end if
287
288 end subroutine gs_gather_kernel_max
289
291 subroutine gs_scatter_sx(this, v, m, dg, u, n, gd, nb, b, bo, shrd, event)
292 integer, intent(in) :: m
293 integer, intent(in) :: n
294 integer, intent(in) :: nb
295 class(gs_sx_t), intent(inout) :: this
296 real(kind=rp), dimension(m), intent(inout) :: v
297 integer, dimension(m), intent(inout) :: dg
298 real(kind=rp), dimension(n), intent(inout) :: u
299 integer, dimension(m), intent(inout) :: gd
300 integer, dimension(nb), intent(inout) :: b
301 integer, dimension(nb), intent(inout) :: bo
302 logical, intent(in) :: shrd
303 type(c_ptr) :: event
304
305 if (.not. shrd) then
306 call gs_scatter_kernel(v, m, dg, u, n, gd, nb, b, this%local_wrk)
307 else if (shrd) then
308 call gs_scatter_kernel(v, m, dg, u, n, gd, nb, b, this%shared_wrk)
309 end if
310
311 end subroutine gs_scatter_sx
312
314 subroutine gs_scatter_kernel(v, m, dg, u, n, gd, nb, b, w)
315 integer, intent(in) :: m
316 integer, intent(in) :: n
317 integer, intent(in) :: nb
318 real(kind=rp), dimension(m), intent(inout) :: v
319 real(kind=rp), dimension(m), intent(inout) :: w
320 integer, dimension(m), intent(inout) :: dg
321 real(kind=rp), dimension(n), intent(inout) :: u
322 integer, dimension(m), intent(inout) :: gd
323 integer, dimension(nb), intent(inout) :: b
324 integer :: i
325
326 !NEC$ IVDEP
327 do i = 1, m
328 w(i) = v(dg(i))
329 end do
330
331 !NEC$ IVDEP
332 do i = 1, m
333 u(gd(i)) = w(i)
334 end do
335
336 end subroutine gs_scatter_kernel
337
338end module gs_sx
Defines a gather-scatter backend.
Definition gs_bcknd.f90:34
Defines Gather-scatter operations.
Definition gs_ops.f90:34
integer, parameter, public gs_op_add
Definition gs_ops.f90:36
integer, parameter, public gs_op_max
Definition gs_ops.f90:36
integer, parameter, public gs_op_min
Definition gs_ops.f90:36
integer, parameter, public gs_op_mul
Definition gs_ops.f90:36
Generic Gather-scatter backend for NEC Vector Engines.
Definition gs_sx.f90:34
subroutine gs_gather_kernel_mul(v, m, o, dg, u, n, gd, nb, b, w)
Gather kernel for multiplication of data .
Definition gs_sx.f90:179
subroutine gs_gather_kernel_max(v, m, o, dg, u, n, gd, nb, b, w)
Gather kernel for maximum of data .
Definition gs_sx.f90:255
subroutine gs_scatter_sx(this, v, m, dg, u, n, gd, nb, b, bo, shrd, event)
Scatter kernel.
Definition gs_sx.f90:292
subroutine gs_gather_kernel_min(v, m, o, dg, u, n, gd, nb, b, w)
Gather kernel for minimum of data .
Definition gs_sx.f90:217
subroutine gs_gather_sx(this, v, m, o, dg, u, n, gd, nb, b, bo, op, shrd)
Gather kernel.
Definition gs_sx.f90:94
subroutine gs_sx_free(this)
SX backend deallocation.
Definition gs_sx.f90:77
subroutine gs_gather_kernel_add(v, m, o, dg, u, n, gd, nb, b, w)
Gather kernel for addition of data .
Definition gs_sx.f90:141
subroutine gs_scatter_kernel(v, m, dg, u, n, gd, nb, b, w)
Scatter kernel .
Definition gs_sx.f90:315
subroutine gs_sx_init(this, nlocal, nshared, nlcl_blks, nshrd_blks)
SX backend initialisation.
Definition gs_sx.f90:59
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Gather-scatter backend.
Definition gs_bcknd.f90:44
Gather-scatter backend for NEC SX-Aurora.
Definition gs_sx.f90:43
#define max(a, b)
Definition tensor.cu:40