8.5. GMRES#
The most important use of the Arnoldi iteration is to solve the square linear system \(\mathbf{A}\mathbf{x}=\mathbf{b}\).
In Demo 8.4.3, we attempted to replace the linear system \(\mathbf{A}\mathbf{x}=\mathbf{b}\) by the lower-dimensional approximation
where \(\mathbf{K}_m\) is the Krylov matrix generated using \(\mathbf{A}\) and the seed vector \(\mathbf{b}\). This method was unstable due to the poor conditioning of \(\mathbf{K}_m\), which is a numerically poor basis for \(\mathcal{K}_m\).
The Arnoldi algorithm yields an orthonormal basis of the same space and fixes the stability problem. Set \(\mathbf{x}=\mathbf{Q}_m\mathbf{z}\) and obtain
From the fundamental Arnoldi identity (8.4.6), this is equivalent to
Note that \(\mathbf{q}_1\) is a unit multiple of \(\mathbf{b}\), so \(\mathbf{b} = \|\mathbf{b}\| \mathbf{Q}_{m+1}\mathbf{e}_1\). Thus (8.5.2) becomes
The least-squares problems (8.5.1), (8.5.2), and (8.5.3) are all \(n\times m\). But observe that for any \(\mathbf{w}\in\mathbb{C}^{m+1}\),
The first norm in that equation is on \(\mathbb{C}^n\), while the last is on the much smaller space \(\mathbb{C}^{m+1}\). Hence the least-squares problem (8.5.3) is equivalent to
which is of size \((m+1)\times m\). We call the solution of this minimization \(\mathbf{z}_m\), and then \(\mathbf{x}_m=\mathbf{Q}_m \mathbf{z}_m\) is the \(m\)th approximation to the solution of \(\mathbf{A}\mathbf{x}=\mathbf{b}\).
Given \(n\times n\) matrix \(\mathbf{A}\) and \(n\)-vector \(\mathbf{b}\):
For \(m=1,2,\ldots\), let \(\mathbf{x}_m=\mathbf{Q}_m \mathbf{z}_m\), where \(\mathbf{z}_m\) solves the linear least-squares problem (8.5.4), and \(\mathbf{Q}_m,\mathbf{H}_m\) arise from the Arnoldi iteration.
GMRES1 uses the Arnoldi iteration to minimize the residual \(\mathbf{b} - \mathbf{A}\mathbf{x}\) over successive Krylov subspaces. In exact arithmetic, GMRES should get the exact solution when \(m=n\), but the goal is to reduce the residual enough to stop at some \(m \ll n\).2
We define a triangular matrix with known eigenvalues and a random vector \(\mathbf{b}\).
λ = @. 10 + (1:100)
A = triu(rand(100,100),1) + diagm(λ)
b = rand(100);
Instead of building the Krylov matrices, we use the Arnoldi iteration to generate equivalent orthonormal vectors.
Q,H = FNC.arnoldi(A,b,60);
The Arnoldi bases are used to solve the least-squares problems defining the GMRES iterates.
resid = [norm(b);zeros(60)]
for m in 1:60
s = [norm(b); zeros(m)]
z = H[1:m+1,1:m]\s
x = Q[:,1:m]*z
resid[m+1] = norm(b-A*x)
end
The approximations converge smoothly, practically all the way to machine epsilon.
plot(0:60,resid,m=:o,
xaxis=(L"m"),yaxis=(:log10,"norm of mth residual"),
title="Residual for GMRES",leg=:none)
Compare the graph in Demo 8.5.2 to the one in Demo 8.4.3. Both start with the same linear convergence, but only the version using Arnoldi avoids the instability created by the poor Krylov basis.
A basic implementation of GMRES is given in Function 8.5.3.
GMRES for a linear system
1"""
2 gmres(A,b,m)
3
4Do `m` iterations of GMRES for the linear system `A`*x=`b`. Returns
5the final solution estimate x and a vector with the history of
6residual norms. (This function is for demo only, not practical use.)
7"""
8function gmres(A,b,m)
9 n = length(b)
10 Q = zeros(n,m+1)
11 Q[:,1] = b/norm(b)
12 H = zeros(m+1,m)
13
14 # Initial solution is zero.
15 x = 0
16 residual = [norm(b);zeros(m)]
17
18 for j in 1:m
19 # Next step of Arnoldi iteration.
20 v = A*Q[:,j]
21 for i in 1:j
22 H[i,j] = dot(Q[:,i],v)
23 v -= H[i,j]*Q[:,i]
24 end
25 H[j+1,j] = norm(v)
26 Q[:,j+1] = v/H[j+1,j]
27
28 # Solve the minimum residual problem.
29 r = [norm(b); zeros(j)]
30 z = H[1:j+1,1:j] \ r
31 x = Q[:,1:j]*z
32 residual[j+1] = norm( A*x - b )
33 end
34 return x,residual
35end
Convergence and restarting#
Thanks to Theorem 8.4.2, minimization of \(\|\mathbf{b}-\mathbf{A}\mathbf{x}\|\) over \(\mathcal{K}_{m+1}\) includes minimization over \(\mathcal{K}_m\). Hence the norm of the residual \(\mathbf{r}_m = \mathbf{b} - \mathbf{A}\mathbf{x}_m\) (being the minimized quantity) cannot increase as the iteration unfolds.
Unfortunately, making other conclusive statements about the convergence of GMRES is neither easy nor simple. Demo 8.5.2 shows the cleanest behavior: essentially linear convergence down to the range of machine epsilon. But it is possible for the convergence to go through phases of sublinear and superlinear convergence as well. There is a strong dependence on the eigenvalues of the matrix, a fact we state with more precision and detail in the next section.
One of the practical challenges in GMRES is that as the dimension of the Krylov subspace grows, the number of new entries to be found in \(\mathbf{H}_m\) and the total number of columns in \(\mathbf{Q}\) also grow. Thus both the work and the storage requirements are quadratic in \(m\), which can become intolerable in some applications. For this reason, GMRES is often used with restarting.
Suppose \(\hat{\mathbf{x}}\) is an approximate solution of \(\mathbf{A}\mathbf{x}=\mathbf{b}\). Then if we set \(\mathbf{x}=\mathbf{u}+\hat{\mathbf{x}}\), we have \(\mathbf{A}(\mathbf{u}+\hat{\mathbf{x}}) = \mathbf{b}\), or \(\mathbf{A}\mathbf{u} = \mathbf{b} - \mathbf{A}\hat{\mathbf{x}}\). The conclusion is that if we get an approximate solution and compute its residual \(\mathbf{r}=\mathbf{b} - \mathbf{A}\hat{\mathbf{x}}\), then we need only to solve \(\mathbf{A}\mathbf{u} = \mathbf{r}\) in order to get a correction to \(\hat{\mathbf{x}}\).3
Restarting guarantees a fixed upper bound on the per-iteration cost of GMRES. However, this benefit comes at a price. Even though restarting preserves progress made in previous iterations, the Krylov space information is discarded and the residual minimization process starts again over low-dimensional spaces. That can significantly retard or even stagnate the convergence.
The following experiments are based on a matrix resulting from discretization of a partial differential equation.
A = FNC.poisson(50)
n = size(A,1)
b = ones(n);
spy(A,color=:blues)
We compare unrestarted GMRES with three different thresholds for restarting. Here we are using gmres
from the IterativeSolvers
package, since our simple implementation does not offer restarting.
The syntax f(x;foo)
is shorthand for f(x,foo=foo)
.
reltol = 1e-12;
plt = plot(title="Convergence of restarted GMRES",leg=:bottomleft,
xaxis=(L"m"), yaxis=(:log10,"residual norm",[1e-8,100]))
for restart in [n,20,40,60]
x,hist = IterativeSolvers.gmres(A,b;restart,reltol,
maxiter=100,log=true)
plot!(hist[:resnorm],label="restart = $restart")
end
plt
The “pure” GMRES curve is the lowest one. All of the other curves agree with it until the first restart. Decreasing the restart value makes the convergence per iteration generally worse, but the time required per iteration smaller as well.
Restarting creates a tradeoff between the number of iterations and the speed per iteration. It’s essentially impossible in general to predict the ideal restart location in any given problem, so one goes by experience and hopes for the best.
There are other ways to avoid the growth in computational effort as the GMRES/Arnoldi iteration proceeds. Three of the more popular variations are abbreviated CGS, BiCGSTAB, and QMR. We do not describe them in this book.
Exercises#
✍ (See also Exercise 8.4.1.) Consider the linear system with
\[\begin{split} \mathbf{A}=\displaystyle \begin{bmatrix} 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 \end{bmatrix}, \qquad \mathbf{b}=\mathbf{e}_1. \end{split}\](a) Find the exact solution by inspection.
(b) Find the GMRES approximate solutions \(\mathbf{x}_m\) for \(m=1,2,3,4\).
✍ (Continuation of Exercise 8.4.3.) Show that if \(\mathbf{x}_m\in\mathcal{K}_m\), then the residual \(\mathbf{b}-\mathbf{A}\mathbf{x}_m\) is equal to \(q(\mathbf{A})\mathbf{b}\), where \(q\) is a polynomial of degree at most \(m\) and \(q(0)=1\). (This fact is a key one for many convergence results.)
✍ Explain why GMRES, in exact arithmetic, converges to the true solution in \(n\) iterations for an \(n\times n\) matrix if \(\operatorname{rank}(\mathbf{K}_n)=n\). (Hint: Consider how the algorithm is defined from first principles.)
⌨ Let \(\mathbf{A}\) be the \(n\times n\) tridiagonal matrix
\[\begin{split} \begin{bmatrix} -4 & 1 & & & \\ 1 & -4 & 1 & & \\ & \ddots & \ddots & \ddots & \\ & & 1 & -4 & 1 \\ & & & 1 & -4 \end{bmatrix} \end{split}\]and let the \(n\)-vector \(\mathbf{b}\) have elements \(b_i=i/n\). For \(n=8,16,32,64\), run Function 8.5.3 for \(m=n/2\) iterations. On one semi-log graph, plot \(\|\mathbf{r}_k\|/\|\mathbf{b}\|\) for all the cases. How does the convergence rate of GMRES seem to depend on \(n\)?
⌨ In this exercise you will see the strong effect the eigenvalues of the matrix may have on GMRES convergence. Let
\[\begin{split} \mathbf{B}= \begin{bmatrix} 1 & & & \\ & 2 & & \\ & & \ddots & \\ & & & 100 \end{bmatrix}, \end{split}\]let \(\mathbf{I}\) be a \(100\times 100\) identity, and let \(\mathbf{Z}\) be a \(100\times 100\) matrix of zeros. Also let \(\mathbf{b}\) be a \(200\times 1\) vector of ones. You will use
IterativeSolvers.gmres
with restarts, as in Demo 8.5.4.(a) Let \(\mathbf{A} = \begin{bmatrix} \mathbf{B} & \mathbf{I} \\ \mathbf{Z} & \mathbf{B} \end{bmatrix}.\) What are its eigenvalues (no computer required here)? Apply
gmres
with tolerance \(10^{-10}\) for 100 iterations without restarts, and plot the residual convergence.(b) Repeat part (a) with restarts every 20 iterations.
(c) Now let \(\mathbf{A} = \begin{bmatrix} \mathbf{B} & \mathbf{I} \\ \mathbf{Z} & -\mathbf{B} \end{bmatrix}.\) What are its eigenvalues? Repeat part (a). Which matrix is more difficult for GMRES? (Note: Even though this matrix is triangular, GMRES has no way of exploiting that fact.)
⌨ (Continuation of Exercise 8.3.5.) We again consider the \(n^2\times n^2\) sparse matrix defined by
FNC.poisson(n)
. The solution of \(\mathbf{A}\mathbf{x}=\mathbf{b}\) may be interpreted as the deflection of a lumped membrane in response to a load represented by \(\mathbf{b}\).(a) For \(n=10,15,20,25\), let \(\mathbf{b}\) be the vector of \(n^2\) ones and apply Function 8.5.3 for 50 iterations. On one semi-log graph, plot the four convergence curves \(\|\mathbf{r}_m\|/\|\mathbf{b}\|\).
(b) For the case \(n=25\) use
surface(1:n,1:n,reshape(x,25,25))
to plot the solution, which should look physically plausible (though upside-down for a weighted membrane).
- 1
GMRES stands for Generalized Minimum RESidual. We will encounter its precursor MINRES in Section 8.6.
- 2
This statement is not strictly correct for rare special cases of breakdown where the rank of \(\mathcal{K}_n\) is less than \(n\). In that situation, some additional steps must be taken that we do not discuss here.
- 3
The new problem needs to be solved for accuracy relative to \(\|\mathbf{b}\|\), not relative to \(\|\mathbf{r}\|\).