51 use,
intrinsic :: iso_c_binding
57 real(kind=
rp),
allocatable :: d(:)
58 real(kind=
rp),
allocatable :: w(:)
59 real(kind=
rp),
allocatable :: r(:)
60 real(kind=
rp) :: omega
63 integer :: max_iter = 10
64 logical :: recompute_diag = .true.
74 real(kind=
rp),
allocatable :: d(:)
75 type(c_ptr) :: d_d = c_null_ptr
76 real(kind=
rp),
allocatable :: w(:)
77 type(c_ptr) :: w_d = c_null_ptr
78 real(kind=
rp),
allocatable :: r(:)
79 type(c_ptr) :: r_d = c_null_ptr
80 real(kind=
rp) :: tha, dlt
83 integer :: power_its = 250
84 integer :: max_iter = 10
85 logical :: recompute_eigs = .true.
104 integer,
intent(in) :: n
105 integer,
intent(in) :: lvl
106 integer,
intent(in) :: max_iter
118 this%max_iter = max_iter
119 this%recompute_eigs = .true.
128 if (
allocated(this%d))
then
134 if (
allocated(this%w))
then
140 if (
allocated(this%r))
then
155 integer,
intent(in) :: n
156 real(kind=
rp) :: lam, b, a, rn
157 real(kind=
rp),
parameter :: boost = 1.1_rp
158 real(kind=
rp),
parameter :: lam_factor = 30.0_rp
159 real(kind=
rp) :: wtw, dtw, dtd
160 integer,
allocatable :: fixed_seed(:), saved_seed(:)
162 associate(w => this%w, d => this%d, coef => amg%coef, gs_h => amg%gs_h, &
163 msh => amg%msh, xh => amg%Xh, blst => amg%blst)
166 call random_seed( size=rnd_n )
167 allocate(saved_seed(rnd_n))
168 allocate(fixed_seed(rnd_n))
170 call random_seed( get=saved_seed )
171 call random_seed( put=fixed_seed )
174 call random_number(rn)
179 call random_seed( put=saved_seed )
181 if (this%lvl .eq. 0)
then
182 call gs_h%op(d, n, gs_op_add)
183 call blst%apply(d, n)
186 do i = 1, this%power_its
187 call amg%matvec(w, d, this%lvl)
189 if (this%lvl .eq. 0)
then
190 wtw =
glsc3(w, coef%mult, w, n)
195 call cmult2(d, w, 1.0_rp/sqrt(wtw), n)
198 call amg%matvec(w, d, this%lvl)
200 if (this%lvl .eq. 0)
then
201 dtw =
glsc3(d, coef%mult, w, n)
202 dtd =
glsc3(d, coef%mult, d, n)
210 this%tha = (b+a)/2.0_rp
211 this%dlt = (b-a)/2.0_rp
213 this%recompute_eigs = .false.
226 integer,
intent(in) :: n
227 real(kind=rp),
dimension(n),
intent(inout) :: x
228 real(kind=rp),
dimension(n),
intent(inout) :: f
229 class(tamg_hierarchy_t),
intent(inout) :: amg
230 type(ksp_monitor_t) :: ksp_results
231 logical,
optional,
intent(in) :: zero_init
232 integer :: iter, max_iter, i
233 real(kind=rp) :: rtr, rnorm
234 real(kind=rp) :: rhok, rhokp1, s1, thet, delt, tmp1, tmp2
235 logical :: zero_initial_guess
237 if (this%recompute_eigs)
then
238 call this%comp_eig(amg, n)
240 if (
present(zero_init))
then
241 zero_initial_guess = zero_init
243 zero_initial_guess = .false.
245 max_iter = this%max_iter
247 associate( w => this%w, r => this%r, d => this%d, blst => amg%blst)
249 if (.not. zero_initial_guess)
then
250 call amg%matvec(w, x, this%lvl)
266 d(i) = 1.0_rp/thet * r(i)
272 do iter = 2, max_iter
273 call amg%matvec(w, d, this%lvl)
275 rhokp1 = 1.0_rp / (2.0_rp * s1 - rhok)
277 tmp2 = 2.0_rp * rhokp1 / delt
288 d(i) = tmp1 * d(i) + tmp2 * r(i)
302 type(tamg_hierarchy_t),
intent(inout) :: amg
303 integer,
intent(in) :: n
304 real(kind=rp) :: lam, b, a, rn
305 real(kind=rp),
parameter :: boost = 1.1_rp
306 real(kind=rp),
parameter :: lam_factor = 30.0_rp
307 real(kind=rp) :: wtw, dtw, dtd
308 integer,
allocatable :: fixed_seed(:), saved_seed(:)
310 associate(w => this%w, d => this%d, coef => amg%coef, gs_h => amg%gs_h, &
311 msh => amg%msh, xh => amg%Xh, blst => amg%blst)
314 call random_seed( size=rnd_n )
315 allocate(saved_seed(rnd_n))
316 allocate(fixed_seed(rnd_n))
318 call random_seed( get=saved_seed )
319 call random_seed( put=fixed_seed )
322 call random_number(rn)
325 call device_memcpy(this%d, this%d_d, n, host_to_device, .true.)
328 call random_seed( put=saved_seed )
330 if (this%lvl .eq. 0)
then
331 call gs_h%op(d, n, gs_op_add)
332 call blst%apply(d, n)
334 do i = 1, this%power_its
335 call amg%device_matvec(w, d, this%w_d, this%d_d, this%lvl)
337 if (this%lvl .eq. 0)
then
338 wtw = device_glsc3(this%w_d, coef%mult_d, this%w_d, n)
340 wtw = device_glsc2(this%w_d, this%w_d, n)
343 call device_cmult2(this%d_d, this%w_d, 1.0_rp/sqrt(wtw), n)
346 call amg%device_matvec(w, d, this%w_d, this%d_d, this%lvl)
348 if (this%lvl .eq. 0)
then
349 dtw = device_glsc3(this%d_d, coef%mult_d, this%w_d, n)
350 dtd = device_glsc3(this%d_d, coef%mult_d, this%d_d, n)
352 dtw = device_glsc2(this%d_d, this%w_d, n)
353 dtd = device_glsc2(this%d_d, this%d_d, n)
358 this%tha = (b+a)/2.0_rp
359 this%dlt = (b-a)/2.0_rp
361 this%recompute_eigs = .false.
374 integer,
intent(in) :: n
375 real(kind=rp),
dimension(n),
intent(inout) :: x
376 real(kind=rp),
dimension(n),
intent(inout) :: f
379 class(tamg_hierarchy_t),
intent(inout) :: amg
380 type(ksp_monitor_t) :: ksp_results
381 logical,
optional,
intent(in) :: zero_init
382 integer :: iter, max_iter
383 real(kind=rp) :: rtr, rnorm
384 real(kind=rp) :: rhok, rhokp1, s1, thet, delt, tmp1, tmp2
385 logical :: zero_initial_guess
387 if (this%recompute_eigs)
then
388 call this%device_comp_eig(amg, n)
390 if (
present(zero_init))
then
391 zero_initial_guess = zero_init
393 zero_initial_guess = .false.
395 max_iter = this%max_iter
397 associate( w_d => this%w_d, r_d => this%r_d, d_d => this%d_d, &
400 if (.not. zero_initial_guess)
then
401 call amg%device_matvec(this%w, x, w_d, x_d, this%lvl)
411 call amg_device_cheby_solve_part1(r_d, f_d, w_d, x_d, d_d, &
412 tmp1, n, zero_initial_guess)
414 do iter = 2, max_iter
415 call amg%device_matvec(this%w, this%d, w_d, d_d, this%lvl)
417 rhokp1 = 1.0_rp / (2.0_rp * s1 - rhok)
419 tmp2 = 2.0_rp * rhokp1 / delt
422 call amg_device_cheby_solve_part2(r_d, w_d, d_d, x_d, tmp1, tmp2, n)
435 integer,
intent(in) :: n
436 integer,
intent(in) :: lvl
437 integer,
intent(in) :: max_iter
444 this%max_iter = max_iter
452 if (
allocated(this%d))
then
455 if (
allocated(this%w))
then
458 if (
allocated(this%r))
then
468 type(tamg_hierarchy_t),
intent(inout) :: amg
469 integer,
intent(in) :: n
473 call tamg_sample_matrix_val(val, amg, this%lvl, i, i)
474 this%d(i) = 1.0_rp / val
476 this%recompute_diag = .false.
486 integer,
intent(in) :: n
487 real(kind=rp),
dimension(n),
intent(inout) :: x
488 real(kind=rp),
dimension(n),
intent(inout) :: f
489 class(tamg_hierarchy_t),
intent(inout) :: amg
490 type(ksp_monitor_t) :: ksp_results
491 integer,
optional,
intent(in) :: niter
492 integer :: iter, max_iter
493 real(kind=rp) :: rtr, rnorm
496 if (this%recompute_diag)
then
497 call this%comp_diag(amg, n)
500 if (
present(niter))
then
503 max_iter = this%max_iter
507 associate( w => this%w, r => this%r, d => this%d)
508 do iter = 1, max_iter
511 call amg%matvec(w, x, this%lvl)
528 x(i) = x(i) + this%omega * r(i)
537 integer,
intent(in) :: lvl
539 character(len=LOG_SIZE) :: log_buf
541 write(log_buf,
'(A8,I2,A28)')
'-- level', lvl,
'-- init smoother: Chebyshev'
542 call neko_log%message(log_buf)
543 write(log_buf,
'(A22,I6)')
'Iterations:', smoo%max_iter
544 call neko_log%message(log_buf)
548 integer,
intent(in) :: lvl
549 real(kind=rp),
intent(in) :: lam
550 character(len=LOG_SIZE) :: log_buf
552 write(log_buf,
'(A12,I2,A29,F12.3)')
'-- AMG level', lvl, &
553 '-- Chebyshev approx. max eig', lam
554 call neko_log%message(log_buf)
__device__ T solve(const T u, const T y, const T guess, const T nu, const T kappa, const T B)
Map a Fortran array to a device (allocate and associate)
Copy data between host and device (or device and device)
Unmap a Fortran array from a device (deassociate and free)
subroutine, public device_add2(a_d, b_d, n, strm)
Vector addition .
subroutine, public device_add3s2(a_d, b_d, c_d, c1, c2, n, strm)
Returns .
subroutine, public device_rzero(a_d, n, strm)
Zero a real vector.
subroutine, public device_sub2(a_d, b_d, n, strm)
Vector substraction .
subroutine, public device_copy(a_d, b_d, n, strm)
Copy a vector .
real(kind=rp) function, public device_glsc3(a_d, b_d, c_d, n, strm)
Weighted inner product .
real(kind=rp) function, public device_glsc2(a_d, b_d, n, strm)
Weighted inner product .
subroutine, public device_cmult2(a_d, b_d, c, n, strm)
Multiplication by constant c .
Implements device kernels for use with TreeAMG smoothers.
subroutine, public amg_device_cheby_solve_part1(r_d, f_d, w_d, x_d, d_d, inv_thet, n, zero_initial)
subroutine, public amg_device_cheby_solve_part2(r_d, w_d, d_d, x_d, tmp1, tmp2, n)
Device abstraction, common interface for various accelerators.
integer, parameter, public host_to_device
Implements the base abstract type for Krylov solvers plus helper types.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
subroutine, public cmult(a, c, n)
Multiplication by constant c .
subroutine, public cmult2(a, b, c, n)
Multiplication by constant c .
real(kind=rp) function, public glsc3(a, b, c, n)
Weighted inner product .
real(kind=rp) function, public glsc2(a, b, n)
Weighted inner product .
subroutine, public add2(a, b, n)
Vector addition .
subroutine, public add3s2(a, b, c, c1, c2, n)
Returns .
subroutine, public col2(a, b, n)
Vector multiplication .
subroutine, public copy(a, b, n)
Copy a vector .
subroutine, public sub2(a, b, n)
Vector substraction .
subroutine, public add2s2(a, b, c1, n)
Vector addition with scalar multiplication (multiplication on second argument)
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Implements smoothers for use with TreeAMG matrix vector product.
subroutine amg_cheby_free(this)
free cheby data
subroutine amg_jacobi_init(this, n, lvl, max_iter)
Initialization of Jacobi (this is expensive...)
subroutine amg_cheby_power(this, amg, n)
Power method to approximate largest eigenvalue.
subroutine amg_device_cheby_power(this, amg, n)
Power method to approximate largest eigenvalue.
subroutine amg_cheby_solve(this, x, f, n, amg, zero_init)
Chebyshev smoother From Saad's iterative methods textbook.
subroutine amg_cheby_init(this, n, lvl, max_iter)
Initialization of chebyshev.
subroutine amg_jacobi_free(this)
free jacobi data
subroutine amg_jacobi_diag(this, amg, n)
SAMPLE MATRIX DIAGONAL VALUES (DO NOT USE, EXPENSIVE)
subroutine amg_device_cheby_solve(this, x, f, x_d, f_d, n, amg, zero_init)
Chebyshev smoother From Saad's iterative methods textbook.
subroutine amg_jacobi_solve(this, x, f, n, amg, niter)
Jacobi smoother.
subroutine amg_smoo_monitor(lvl, smoo)
subroutine amg_cheby_monitor(lvl, lam)
Implements utilities for the TreeAMG hierarchy structure.
subroutine, public tamg_sample_matrix_val(val, amg, lvl, i, j)
Sample the values in a matix (expensive, use with caution)
Implements the base type for TreeAMG hierarchy structure.
A list of allocatable `bc_t`. Follows the standard interface of lists.
Type for storing initial and final residuals in a Krylov solver.
Type for a TreeAMG hierarchy.
Type for Chebyshev iteration using TreeAMG matvec.
Type for Chebyshev iteration using TreeAMG matvec.