Skip to content

Commit

Permalink
Initialize niter=0 in gmres.
Browse files Browse the repository at this point in the history
  • Loading branch information
loiseaujc committed Jul 2, 2024
1 parent 3e70b56 commit 390473a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
44 changes: 28 additions & 16 deletions src/IterativeSolvers.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ subroutine svds_rsp(A, U, S, V, residuals, info, kdim, tolerance, verbosity)
S = svdvals_wrk(:nsv) ; residuals = residuals_wrk(:nsv)

! Singular vectors.
k = min(k, kdim_)
k = min(k, kdim_) ; info = k
do i = 1, nsv
call U(i)%zero() ; call V(i)%zero()
do j = 1, k
Expand Down Expand Up @@ -1340,7 +1340,7 @@ subroutine svds_rdp(A, U, S, V, residuals, info, kdim, tolerance, verbosity)
S = svdvals_wrk(:nsv) ; residuals = residuals_wrk(:nsv)

! Singular vectors.
k = min(k, kdim_)
k = min(k, kdim_) ; info = k
do i = 1, nsv
call U(i)%zero() ; call V(i)%zero()
do j = 1, k
Expand Down Expand Up @@ -1434,7 +1434,7 @@ subroutine svds_csp(A, U, S, V, residuals, info, kdim, tolerance, verbosity)
S = svdvals_wrk(:nsv) ; residuals = residuals_wrk(:nsv)

! Singular vectors.
k = min(k, kdim_)
k = min(k, kdim_) ; info = k
do i = 1, nsv
call U(i)%zero() ; call V(i)%zero()
do j = 1, k
Expand Down Expand Up @@ -1528,7 +1528,7 @@ subroutine svds_cdp(A, U, S, V, residuals, info, kdim, tolerance, verbosity)
S = svdvals_wrk(:nsv) ; residuals = residuals_wrk(:nsv)

! Singular vectors.
k = min(k, kdim_)
k = min(k, kdim_) ; info = k
do i = 1, nsv
call U(i)%zero() ; call V(i)%zero()
do j = 1, k
Expand Down Expand Up @@ -1584,7 +1584,7 @@ subroutine gmres_rsp(A, b, x, info, preconditioner, options, transpose)
class(abstract_precond_rsp), allocatable :: precond

! Miscellaneous.
integer :: i, k
integer :: i, k, niter
real(sp), allocatable :: alpha(:)
class(abstract_vector_rsp), allocatable :: dx, wrk

Expand Down Expand Up @@ -1621,7 +1621,7 @@ subroutine gmres_rsp(A, b, x, info, preconditioner, options, transpose)
allocate(alpha(kdim)) ; alpha = 0.0_sp
allocate(e(kdim+1)) ; e = 0.0_sp

info = 0
info = 0 ; niter = 0

! Initial Krylov vector.
if (x%norm() > 0) then
Expand Down Expand Up @@ -1670,7 +1670,7 @@ subroutine gmres_rsp(A, b, x, info, preconditioner, options, transpose)
beta = norm2(abs(e(:k+1) - matmul(H(:k+1, :k), y(:k))))

! Current number of iterations performed.
info = info + 1
niter = niter + 1

! Check convergence.
if (abs(beta) <= tol) then
Expand Down Expand Up @@ -1698,6 +1698,9 @@ subroutine gmres_rsp(A, b, x, info, preconditioner, options, transpose)

enddo gmres_iter

! Returns the number of iterations.
info = niter

return
end subroutine gmres_rsp

Expand Down Expand Up @@ -1740,7 +1743,7 @@ subroutine gmres_rdp(A, b, x, info, preconditioner, options, transpose)
class(abstract_precond_rdp), allocatable :: precond

! Miscellaneous.
integer :: i, k
integer :: i, k, niter
real(dp), allocatable :: alpha(:)
class(abstract_vector_rdp), allocatable :: dx, wrk

Expand Down Expand Up @@ -1777,7 +1780,7 @@ subroutine gmres_rdp(A, b, x, info, preconditioner, options, transpose)
allocate(alpha(kdim)) ; alpha = 0.0_dp
allocate(e(kdim+1)) ; e = 0.0_dp

info = 0
info = 0 ; niter = 0

! Initial Krylov vector.
if (x%norm() > 0) then
Expand Down Expand Up @@ -1826,7 +1829,7 @@ subroutine gmres_rdp(A, b, x, info, preconditioner, options, transpose)
beta = norm2(abs(e(:k+1) - matmul(H(:k+1, :k), y(:k))))

! Current number of iterations performed.
info = info + 1
niter = niter + 1

! Check convergence.
if (abs(beta) <= tol) then
Expand Down Expand Up @@ -1854,6 +1857,9 @@ subroutine gmres_rdp(A, b, x, info, preconditioner, options, transpose)

enddo gmres_iter

! Returns the number of iterations.
info = niter

return
end subroutine gmres_rdp

Expand Down Expand Up @@ -1896,7 +1902,7 @@ subroutine gmres_csp(A, b, x, info, preconditioner, options, transpose)
class(abstract_precond_csp), allocatable :: precond

! Miscellaneous.
integer :: i, k
integer :: i, k, niter
complex(sp), allocatable :: alpha(:)
class(abstract_vector_csp), allocatable :: dx, wrk

Expand Down Expand Up @@ -1933,7 +1939,7 @@ subroutine gmres_csp(A, b, x, info, preconditioner, options, transpose)
allocate(alpha(kdim)) ; alpha = 0.0_sp
allocate(e(kdim+1)) ; e = 0.0_sp

info = 0
info = 0 ; niter = 0

! Initial Krylov vector.
if (x%norm() > 0) then
Expand Down Expand Up @@ -1982,7 +1988,7 @@ subroutine gmres_csp(A, b, x, info, preconditioner, options, transpose)
beta = norm2(abs(e(:k+1) - matmul(H(:k+1, :k), y(:k))))

! Current number of iterations performed.
info = info + 1
niter = niter + 1

! Check convergence.
if (abs(beta) <= tol) then
Expand Down Expand Up @@ -2010,6 +2016,9 @@ subroutine gmres_csp(A, b, x, info, preconditioner, options, transpose)

enddo gmres_iter

! Returns the number of iterations.
info = niter

return
end subroutine gmres_csp

Expand Down Expand Up @@ -2052,7 +2061,7 @@ subroutine gmres_cdp(A, b, x, info, preconditioner, options, transpose)
class(abstract_precond_cdp), allocatable :: precond

! Miscellaneous.
integer :: i, k
integer :: i, k, niter
complex(dp), allocatable :: alpha(:)
class(abstract_vector_cdp), allocatable :: dx, wrk

Expand Down Expand Up @@ -2089,7 +2098,7 @@ subroutine gmres_cdp(A, b, x, info, preconditioner, options, transpose)
allocate(alpha(kdim)) ; alpha = 0.0_dp
allocate(e(kdim+1)) ; e = 0.0_dp

info = 0
info = 0 ; niter = 0

! Initial Krylov vector.
if (x%norm() > 0) then
Expand Down Expand Up @@ -2138,7 +2147,7 @@ subroutine gmres_cdp(A, b, x, info, preconditioner, options, transpose)
beta = norm2(abs(e(:k+1) - matmul(H(:k+1, :k), y(:k))))

! Current number of iterations performed.
info = info + 1
niter = niter + 1

! Check convergence.
if (abs(beta) <= tol) then
Expand Down Expand Up @@ -2166,6 +2175,9 @@ subroutine gmres_cdp(A, b, x, info, preconditioner, options, transpose)

enddo gmres_iter

! Returns the number of iterations.
info = niter

return
end subroutine gmres_cdp

Expand Down
11 changes: 7 additions & 4 deletions src/IterativeSolvers.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ contains
S = svdvals_wrk(:nsv) ; residuals = residuals_wrk(:nsv)

! Singular vectors.
k = min(k, kdim_)
k = min(k, kdim_) ; info = k
do i = 1, nsv
call U(i)%zero() ; call V(i)%zero()
do j = 1, k
Expand Down Expand Up @@ -547,7 +547,7 @@ contains
class(abstract_precond_${type[0]}$${kind}$), allocatable :: precond

! Miscellaneous.
integer :: i, k
integer :: i, k, niter
${type}$, allocatable :: alpha(:)
class(abstract_vector_${type[0]}$${kind}$), allocatable :: dx, wrk

Expand Down Expand Up @@ -584,7 +584,7 @@ contains
allocate(alpha(kdim)) ; alpha = 0.0_${kind}$
allocate(e(kdim+1)) ; e = 0.0_${kind}$

info = 0
info = 0 ; niter = 0

! Initial Krylov vector.
if (x%norm() > 0) then
Expand Down Expand Up @@ -633,7 +633,7 @@ contains
beta = norm2(abs(e(:k+1) - matmul(H(:k+1, :k), y(:k))))

! Current number of iterations performed.
info = info + 1
niter = niter + 1

! Check convergence.
if (abs(beta) <= tol) then
Expand Down Expand Up @@ -661,6 +661,9 @@ contains

enddo gmres_iter

! Returns the number of iterations.
info = niter

return
end subroutine gmres_${type[0]}$${kind}$

Expand Down

0 comments on commit 390473a

Please sign in to comment.