51 real(kind=
rp),
allocatable :: w(:)
52 real(kind=
rp),
allocatable :: r(:)
53 real(kind=
rp),
allocatable :: p(:)
54 real(kind=
rp),
allocatable :: z(:)
55 type(c_ptr) :: w_d = c_null_ptr
56 type(c_ptr) :: r_d = c_null_ptr
57 type(c_ptr) :: p_d = c_null_ptr
58 type(c_ptr) :: z_d = c_null_ptr
59 type(c_ptr) :: gs_event = c_null_ptr
71 class(
pc_t),
optional,
intent(inout),
target :: M
72 integer,
intent(in) :: n
73 integer,
intent(in) :: max_iter
74 real(kind=
rp),
optional,
intent(inout) :: rel_tol
75 real(kind=
rp),
optional,
intent(inout) :: abs_tol
94 if (
present(rel_tol) .and.
present(abs_tol))
then
95 call this%ksp_init(max_iter, rel_tol, abs_tol)
96 else if (
present(rel_tol))
then
97 call this%ksp_init(max_iter, rel_tol=rel_tol)
98 else if (
present(abs_tol))
then
99 call this%ksp_init(max_iter, abs_tol=abs_tol)
101 call this%ksp_init(max_iter)
113 if (
allocated(this%w))
then
117 if (
allocated(this%r))
then
121 if (
allocated(this%p))
then
125 if (
allocated(this%z))
then
131 if (c_associated(this%w_d))
then
135 if (c_associated(this%r_d))
then
139 if (c_associated(this%p_d))
then
143 if (c_associated(this%z_d))
then
147 if (c_associated(this%gs_event))
then
154 function cg_device_solve(this, Ax, x, f, n, coef, blst, gs_h, niter)
result(ksp_results)
156 class(
ax_t),
intent(inout) :: ax
157 type(
field_t),
intent(inout) :: x
158 integer,
intent(in) :: n
159 real(kind=
rp),
dimension(n),
intent(inout) :: f
160 type(
coef_t),
intent(inout) :: coef
162 type(
gs_t),
intent(inout) :: gs_h
164 integer,
optional,
intent(in) :: niter
165 real(kind=
rp),
parameter :: one = 1.0
166 real(kind=
rp),
parameter :: zero = 0.0
167 integer :: iter, max_iter
168 real(kind=
rp) :: rnorm, rtr, rtr0, rtz2, rtz1
169 real(kind=
rp) :: beta, pap, alpha, alphm, norm_fac
174 if (
present(niter))
then
177 max_iter = this%max_iter
179 norm_fac = one/sqrt(coef%volume)
187 rnorm = sqrt(rtr)*norm_fac
188 ksp_results%res_start = rnorm
189 ksp_results%res_final = rnorm
191 if(
abscmp(rnorm, zero))
return
192 do iter = 1, max_iter
193 call this%M%solve(this%z, this%r, n)
197 if (iter .eq. 1) beta = zero
200 call ax%compute(this%w, this%p, coef, x%msh, x%Xh)
201 call gs_h%op(this%w, n, gs_op_add, this%gs_event)
213 if (iter .eq. 1) rtr0 = rtr
214 rnorm = sqrt(rtr)*norm_fac
215 if (rnorm .lt. this%abs_tol)
then
219 ksp_results%res_final = rnorm
220 ksp_results%iter = iter
Return the device pointer for an associated Fortran array.
Map a Fortran array to a device (allocate and associate)
Defines a Matrix-vector product.
Defines a boundary condition.
Defines various Conjugate Gradient methods for accelerators.
type(ksp_monitor_t) function cg_device_solve(this, Ax, x, f, n, coef, blst, gs_h, niter)
Standard PCG solve.
subroutine cg_device_init(this, n, max_iter, M, rel_tol, abs_tol)
Initialise a device based PCG solver.
subroutine cg_device_free(this)
Deallocate a device based PCG solver.
subroutine, public device_add2s1(a_d, b_d, c1, n)
subroutine, public device_rzero(a_d, n)
subroutine, public device_add2s2(a_d, b_d, c1, n)
real(kind=rp) function, public device_glsc3(a_d, b_d, c_d, n)
subroutine, public device_copy(a_d, b_d, n)
Device abstraction, common interface for various accelerators.
subroutine, public device_event_sync(event)
Synchronize an event.
subroutine, public device_free(x_d)
Deallocate memory on the device.
subroutine, public device_event_destroy(event)
Destroy a device event.
subroutine, public device_event_create(event, flags)
Create a device event queue.
Implements the base abstract type for Krylov solvers plus helper types.
integer, parameter, public ksp_max_iter
Maximum number of iters.
integer, parameter, public rp
Global precision used in computations.
Base type for a matrix-vector product providing .
A list of boundary conditions.
Device based preconditioned conjugate gradient method.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Type for storing initial and final residuals in a Krylov solver.
Base abstract type for a canonical Krylov method, solving .
Defines a canonical Krylov preconditioner.