Skip to content

Commit 01f5f56

Browse files
haampielopezm94
authored andcommitted
Update, not reset the solution at restart (#119)
* Update, not reset the solution at restart * Add test for optimality condition GMRES
1 parent c7984db commit 01f5f56

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/gmres.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function gmres_method!(log::ConvergenceHistory, x, A, b;
114114

115115
@eval a = $(VERSION < v"0.4-" ? Triangular(H[1:N, 1:N], :U) \ s[1:N] : UpperTriangular(H[1:N, 1:N]) \ s[1:N])
116116
w = a[1:N] * K
117-
@blas! x = solve(Pr,w) #Right preconditioner
117+
@blas! x += solve(Pr,w) #Right preconditioner
118118

119119
if (rho<tol) | ((macroiter-1)*restart+N >= maxiter)
120120
setconv(log, rho<tol)

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ for T in (Float32, Float64, Complex64, Complex128)
7474
F = lufact(A)
7575
b = b/norm(b)
7676

77+
# Test optimality condition: residual should be non-increasing
78+
x_gmres, c_gmres = gmres(A, b, log = true, restart = 3, maxiter = 10);
79+
@fact all(diff(c_gmres[:resnorm]) .<= 0.0) --> true
80+
7781
x_gmres, c_gmres = gmres(A, b, Pl=L, Pl=R, log=true)
7882
@fact c_gmres.isconverged --> true
7983
@fact norm(A*x_gmres - b) --> less_than(eps(real(one(T))))
@@ -103,6 +107,10 @@ for T in (Float64, Complex128)
103107
F = lufact(A)
104108
b = b / norm(b)
105109

110+
# Test optimality condition: residual should be non-increasing
111+
x_gmres, c_gmres = gmres(A, b, log = true, restart = 3, maxiter = 10);
112+
@fact all(diff(c_gmres[:resnorm]) .<= 0.0) --> true
113+
106114
x_gmres, c_gmres= gmres(A, b, Pl=L, Pr=R, log=true)
107115
@fact c_gmres.isconverged --> true
108116
@fact norm(A*x_gmres - b) --> less_than(eps(real(one(T))))

0 commit comments

Comments
 (0)