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)
265 d(i) = 1.0_rp/thet * r(i)
271 do iter = 2, max_iter
272 call amg%matvec(w, d, this%lvl)
274 rhokp1 = 1.0_rp / (2.0_rp * s1 - rhok)
276 tmp2 = 2.0_rp * rhokp1 / delt
286 d(i) = tmp1 * d(i) + tmp2 * r(i)
300 type(tamg_hierarchy_t),
intent(inout) :: amg
301 integer,
intent(in) :: n
302 real(kind=rp) :: lam, b, a, rn
303 real(kind=rp),
parameter :: boost = 1.1_rp
304 real(kind=rp),
parameter :: lam_factor = 30.0_rp
305 real(kind=rp) :: wtw, dtw, dtd
306 integer,
allocatable :: fixed_seed(:), saved_seed(:)
308 associate(w => this%w, d => this%d, coef => amg%coef, gs_h => amg%gs_h, &
309 msh => amg%msh, xh => amg%Xh, blst => amg%blst)
312 call random_seed( size=rnd_n )
313 allocate(saved_seed(rnd_n))
314 allocate(fixed_seed(rnd_n))
316 call random_seed( get=saved_seed )
317 call random_seed( put=fixed_seed )
320 call random_number(rn)
323 call device_memcpy(this%d, this%d_d, n, host_to_device, .true.)
326 call random_seed( put=saved_seed )
328 if (this%lvl .eq. 0)
then
329 call gs_h%op(d, n, gs_op_add)
330 call blst%apply(d, n)
332 do i = 1, this%power_its
333 call amg%device_matvec(w, d, this%w_d, this%d_d, this%lvl)
335 if (this%lvl .eq. 0)
then
336 wtw = device_glsc3(this%w_d, coef%mult_d, this%w_d, n)
338 wtw = device_glsc2(this%w_d, this%w_d, n)
341 call device_cmult2(this%d_d, this%w_d, 1.0_rp/sqrt(wtw), n)
344 call amg%device_matvec(w, d, this%w_d, this%d_d, this%lvl)
346 if (this%lvl .eq. 0)
then
347 dtw = device_glsc3(this%d_d, coef%mult_d, this%w_d, n)
348 dtd = device_glsc3(this%d_d, coef%mult_d, this%d_d, n)
350 dtw = device_glsc2(this%d_d, this%w_d, n)
351 dtd = device_glsc2(this%d_d, this%d_d, n)
356 this%tha = (b+a)/2.0_rp
357 this%dlt = (b-a)/2.0_rp
359 this%recompute_eigs = .false.
372 integer,
intent(in) :: n
373 real(kind=rp),
dimension(n),
intent(inout) :: x
374 real(kind=rp),
dimension(n),
intent(inout) :: f
377 class(tamg_hierarchy_t),
intent(inout) :: amg
378 type(ksp_monitor_t) :: ksp_results
379 logical,
optional,
intent(in) :: zero_init
380 integer :: iter, max_iter
381 real(kind=rp) :: rtr, rnorm
382 real(kind=rp) :: rhok, rhokp1, s1, thet, delt, tmp1, tmp2
383 logical :: zero_initial_guess
385 if (this%recompute_eigs)
then
386 call this%device_comp_eig(amg, n)
388 if (
present(zero_init))
then
389 zero_initial_guess = zero_init
391 zero_initial_guess = .false.
393 max_iter = this%max_iter
395 associate( w_d => this%w_d, r_d => this%r_d, d_d => this%d_d, &
398 if (.not. zero_initial_guess)
then
399 call amg%device_matvec(this%w, x, w_d, x_d, this%lvl)
409 call amg_device_cheby_solve_part1(r_d, f_d, w_d, x_d, d_d, &
410 tmp1, n, zero_initial_guess)
412 do iter = 2, max_iter
413 call amg%device_matvec(this%w, this%d, w_d, d_d, this%lvl)
415 rhokp1 = 1.0_rp / (2.0_rp * s1 - rhok)
417 tmp2 = 2.0_rp * rhokp1 / delt
420 call amg_device_cheby_solve_part2(r_d, w_d, d_d, x_d, tmp1, tmp2, n)
433 integer,
intent(in) :: n
434 integer,
intent(in) :: lvl
435 integer,
intent(in) :: max_iter
442 this%max_iter = max_iter
450 if (
allocated(this%d))
then
453 if (
allocated(this%w))
then
456 if (
allocated(this%r))
then
466 type(tamg_hierarchy_t),
intent(inout) :: amg
467 integer,
intent(in) :: n
471 call tamg_sample_matrix_val(val, amg, this%lvl, i, i)
472 this%d(i) = 1.0_rp / val
474 this%recompute_diag = .false.
484 integer,
intent(in) :: n
485 real(kind=rp),
dimension(n),
intent(inout) :: x
486 real(kind=rp),
dimension(n),
intent(inout) :: f
487 class(tamg_hierarchy_t),
intent(inout) :: amg
488 type(ksp_monitor_t) :: ksp_results
489 integer,
optional,
intent(in) :: niter
490 integer :: iter, max_iter
491 real(kind=rp) :: rtr, rnorm
494 if (this%recompute_diag)
then
495 call this%comp_diag(amg, n)
498 if (
present(niter))
then
501 max_iter = this%max_iter
505 associate( w => this%w, r => this%r, d => this%d)
506 do iter = 1, max_iter
509 call amg%matvec(w, x, this%lvl)
526 x(i) = x(i) + this%omega * r(i)
535 integer,
intent(in) :: lvl
537 character(len=LOG_SIZE) :: log_buf
539 write(log_buf,
'(A8,I2,A28)')
'-- level', lvl,
'-- init smoother: Chebyshev'
540 call neko_log%message(log_buf)
541 write(log_buf,
'(A22,I6)')
'Iterations:', smoo%max_iter
542 call neko_log%message(log_buf)
546 integer,
intent(in) :: lvl
547 real(kind=rp),
intent(in) :: lam
548 character(len=LOG_SIZE) :: log_buf
550 write(log_buf,
'(A12,I2,A29,F12.3)')
'-- AMG level', lvl, &
551 '-- Chebyshev approx. max eig', lam
552 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.