24 use,
intrinsic :: iso_fortran_env
34 integer,
public,
parameter :: &
35 SK_CG = 1, & !< Conjugate Gradient Method
62 integer :: solver_type
63 integer :: krylov_size
64 integer :: preconditioning
68 real(real64) :: residual_norm
69 real(real64) :: rel_tolerance
70 real(real64) :: abs_tolerance
72 real(real64),
allocatable :: sk_work(:), sk_b(:), sk_y(:)
75 real(real64) :: fpar(16)
80 subroutine cg(n, rhs, sol, ipar, fpar, w)
82 real*8 rhs(n), sol(n), fpar(16), w(n,*)
85 subroutine cgnr(n, rhs, sol, ipar, fpar, wk)
87 real*8 rhs(n),sol(n),fpar(16),wk(n,*)
90 subroutine bcg(n, rhs, sol, ipar, fpar, w)
92 real*8 fpar(16), rhs(n), sol(n), w(n,*)
95 subroutine dbcg(n, rhs, sol, ipar, fpar, w)
97 real*8 rhs(n), sol(n), fpar(16), w(n,*)
100 subroutine bcgstab(n, rhs, sol, ipar, fpar, w)
102 real*8 rhs(n), sol(n), fpar(16), w(n,8)
105 subroutine tfqmr(n, rhs, sol, ipar, fpar, w)
107 real*8 rhs(n), sol(n), fpar(16), w(n,*)
110 subroutine fom(n, rhs, sol, ipar, fpar, w)
112 real*8 rhs(n), sol(n), fpar(16), w(*)
115 subroutine gmres(n, rhs, sol, ipar, fpar, w)
117 real*8 rhs(n), sol(n), fpar(16), w(*)
120 subroutine dqgmres(n, rhs, sol, ipar, fpar, w)
122 real*8 rhs(n), sol(n), fpar(16), w(*)
125 subroutine fgmres(n, rhs, sol, ipar, fpar, w)
127 real*8 rhs(n), sol(n), fpar(16), w(*)
136 integer,
intent(in) :: n
138 logical,
intent(in) :: is_complex
140 integer :: workspace_size, m
144 sk%is_complex = is_complex
191 sk%preconditioning = 0
201 call parse_variable(namespace,
'SPARSKITMaxIter', 5000, sk%maxiter)
211 call parse_variable(namespace,
'SPARSKITIterOut', -1, sk%iter_out)
222 call parse_variable(namespace,
'SPARSKITRelTolerance', 1e-8_real64, sk%rel_tolerance)
233 call parse_variable(namespace,
'SPARSKITAbsTolerance', 1e-10_real64, sk%abs_tolerance)
242 call parse_variable(namespace,
'SPARSKITVerboseSolver', .false., sk%verbose)
256 if (mod(m, 2) /= 0) m = m + 1
258 select case (sk%solver_type)
260 message(1) =
'Info: SPARSKIT solver type: Conjugate Gradient Method'
261 workspace_size = 5*sk%size
263 message(1) =
'Info: SPARSKIT solver type: Conjugate Gradient Method (Normal Residual equation)'
264 workspace_size = 5*sk%size
266 message(1) =
'Info: SPARSKIT solver type: Bi-Conjugate Gradient Method'
267 workspace_size = 7*sk%size
269 message(1) =
'Info: SPARSKIT solver type: BCG with partial pivoting'
270 workspace_size = 11*sk%size
272 message(1) =
'Info: SPARSKIT solver type: BCG stabilized'
273 workspace_size = 8*sk%size
275 message(1) =
'Info: SPARSKIT solver type: Transpose-Free Quasi-Minimum Residual method'
276 workspace_size = 11*sk%size
278 message(1) =
'Info: SPARSKIT solver type: Full Orthogonalization Method'
279 workspace_size = (sk%size+3)*(m+2) + (m+1)*m/2
281 message(1) =
'Info: SPARSKIT solver type: Generalized Minimum Residual method'
282 workspace_size = (sk%size+3)*(m+2) + (m+1)*m/2
284 message(1) =
'Info: SPARSKIT solver type: Flexible version of Generalized Minimum Residual method'
285 workspace_size = 2*sk%size*(m+1) + (m+1)*m/2 + 3*m + 2
287 message(1) =
'Info: SPARSKIT solver type: Direct versions of Quasi-Generalized Minimum Residual method'
288 workspace_size = sk%size + (m+1) * (2*sk%size+4)
290 write(
message(1),
'(a,i4,a)')
"Input: '", sk%solver_type, &
291 "' is not a valid SPARSKIT Solver"
292 message(2) =
'( SPARSKIT Solver = cg | cgnr | bcg | dbcg | bcgstab | tfqmr | fom | gmres | fgmres | dqgmres )'
307 sk%ipar(4) = workspace_size
308 sk%ipar(5) = sk%krylov_size
311 sk%ipar(6) = sk%maxiter
314 sk%fpar(1) = sk%rel_tolerance
317 sk%fpar(2) = sk%abs_tolerance
320 safe_allocate(sk%sk_b(1:sk%size))
321 safe_allocate(sk%sk_y(1:sk%size))
322 safe_allocate(sk%sk_work(1:workspace_size))
336 safe_deallocate_a(sk%sk_b)
337 safe_deallocate_a(sk%sk_y)
338 safe_deallocate_a(sk%sk_work)
350 sko%is_complex = ski%is_complex
352 sko%solver_type = ski%solver_type
353 sko%krylov_size = ski%krylov_size
354 sko%preconditioning = ski%preconditioning
355 sko%maxiter = ski%maxiter
356 sko%used_iter = ski%used_iter
357 sko%iter_out = ski%iter_out
358 sko%residual_norm = ski%residual_norm
359 sko%rel_tolerance = ski%rel_tolerance
360 sko%abs_tolerance = ski%abs_tolerance
361 safe_allocate_source_a(sko%sk_work, ski%sk_work)
362 safe_allocate_source_a(sko%sk_b, ski%sk_b)
363 safe_allocate_source_a(sko%sk_y, ski%sk_y)
366 sko%verbose = ski%verbose
373#include "sparskit_inc.F90"
376#include "complex.F90"
377#include "sparskit_inc.F90"
real(real64), parameter, public m_zero
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public sparskit_solver_init(namespace, n, sk, is_complex)
integer, parameter, public sk_gmres
Generalized Minimum Residual method.
subroutine, public dsparskit_solver_run(namespace, sk, op, opt, sol, rhs)
subroutine, public zsparskit_solver_run(namespace, sk, op, opt, sol, rhs)
subroutine, public sparskit_solver_end(sk)
subroutine, public sparskit_solver_copy(sko, ski)
integer, parameter, public sk_dbcg
BCG with partial pivoting.
integer, parameter, public sk_bcg
Bi-Conjugate Gradient Method.
integer, parameter, public sk_dqgmres
Direct versions of Quasi Generalized Minimum Residual method.
integer, parameter, public sk_minval
integer, parameter, public sk_fom
Full Orthogonalization Method.
integer, parameter, public sk_bcgstab
BCG stabilized.
integer, parameter, public sk_cgnr
Conjugate Gradient Method (Normal Residual equation)
integer, parameter, public sk_maxval
integer, parameter, public sk_tfqmr
Transpose-Free Quasi-Minimum Residual method.
integer, parameter, public sk_fgmres
Flexible version of Generalized Minimum Residual method.