which will return some information about the iteration, e.g., stat.residuals. Is there a way to also return the intermediate x’s for diagnostic purposes? By changing the verbose keyword does not seem to do it. I looked through documentation here but couldn’t find anything relevant.
Does anyone have experience with this GMRES implementation?
Thank you for your answer. I looked at Callbacks but cannot see how the callback function can access intermediate variables from the solver. Can you elaborate a little more?
FOM, GMRES and GPMR are the only methods in Krylov.jl that compute the solution x at the last iteration.
We can’t update x because x = V * y where y is the solution of a triangular system Ry = z. At each iteration, the coefficients of y are different if we perform the backward substitution.
However, you can create a callback that compute each xk. The initial goal of a callback is to add new stopping conditions but you can also use it to see the current state of the KrylovSolver (workspace).
T = eltype(b)
global X = Vector{T}[]
function jinml_callback(solver)
z = solver.z
k = solver.inner_iter
nr = sum(1:k)
V = solver.V
R = solver.R
y = copy(z)
for i = k : -1 : 1
pos = nr + i - k # position of rᵢ.ₖ
for j = k : -1 : i+1
y[i] = y[i] - R[pos] * y[j] # yᵢ ← yᵢ - rᵢⱼyⱼ
pos = pos - j + 1 # position of rᵢ.ⱼ₋₁
end
y[i] = y[i] / R[pos] # yᵢ ← yᵢ / rᵢᵢ
end
xk = sum(V[i] * y[i] for i = 1:k)
push!(X, xk)
return false
end
x, stats = gmres(A, b, itmax=3000, memory=500, history=true, callback=jinml_callback)
stats.residuals
residuals2 = [norm(b - A * X[i]) for i = 1:stats.niter]
@amontoison It is the intermediate solutions to a wave equation using GMRES converging to the final result. The wave equation describes a wave traveling through two penetrable obstacles, and was focused by the convex shape of the obstacle.