Sparse Solvers
Sparse Solvers
and Preconditioning
Per-Olof Persson
[email protected]
Department of Mathematics
University of California, Berkeley
direct methods
Residual r = b−Ax
may be faster than direct −5
10
methods
may handle special structures −10
Iterative
10
0 5 10 15 20 25 30
Iteration
Two Classes of Iterative Methods
In MATLAB:
n=8; h=1/(n+1); e=ones(n,1);
A1=spdiags([-e,2*e,-e],-1:1,n,n);
A=kron(A1,speye(n,n))+kron(speye(n,n),A1);
f=h^2*ones(n^2,1);
0
or simply
10
A=delsq(numgrid(’S’,n+2)); 20
50
60
0 20 40 60
nz = 288
Eigenvalues of Model Problem
Kn = b, Ab, . . . , An−1 b
rnT rj = 0 (j < n)
Proofs. Textbook/black-board
Optimality of Conjugate Gradients
ken kA kp(A)e0 kA
= inf ≤ inf max |p(λ)|
ke0 kA p∈Pn ke0 kA p∈Pn λ∈Λ(A)
Then ke0 k2A = j a2j λj and kp(A)e0 k2A = j a2j λj (p(λj ))2 ,
P P
which implies the inequality.
Rate of Convergence
Proof. Textbook
In general: CG performs well with clustered eigenvalues
Sparse vs. Dense Matrices
Most operations should give the same results for sparse and
full matrices
Sparse matrices are never created automatically, but once
created they propagate
Performance is important – but usability, simplicity,
completeness, and robustness are more important
Storage for a sparse matrix should be O(nonzeros)
Time for a sparse operation should be close to O(flops)
Data Structures for Matrices
Full: 31 0 53
Storage: Array of real (or complex) numbers 0 59 0
Memory: nrows*ncols 41 26 0
double *A
1 3 7 1 3 7
Symmetric Gaussian
Elimination:
8 6 8 6
for j = 1 to N
Add edges between
4 10 4 10
j 0 s higher-numbered
neighbors
9 5 2 9 5 2
G(A) G+ (A)
Permutations of the 2-D Model Problem
Nested dissection:
Find a separator, number it last, proceed recursively
Theory: Approximately optimal separators =⇒ approximately
optimal fill and flop count
Practice: Often wins for very large problems
The best modern general-purpose orderings are ND/MD
hybrids
Fill-Reducing Permutations in Matlab
Reverse Cuthill-McKee:
p=symrcm(A);
Symmetric permutation: A(p,p) often has smaller bandwidth
than A
Symmetric approximate minimum degree:
p=symamd(A);
Symmetric permutation: chol(A(p,p)) sparser than chol(A)
Nonsymmetric approximate minimum degree:
p=colamd(A);
Column permutation: lu(A(:,p)) sparser than lu(A)
Symmetric nested dissection:
Not built into MATLAB, several versions in the MESHPART
toolbox
Complexity of Direct Methods
Ax = b
M −1 Ax = M −1 b
−→ ×
A RT R
Unpredictable storage
requirements 2 3 2 3
Choice of parameters
Good: Smooth transition from iterative to direct methods
Bad: Very ad hoc, problem-dependent
Trade-off: Time per iteration vs # of iterations (more fill →
more time
but fewer iterations)
Effectiveness
Condition number usually improves (only) by constant factor
(except MIC for some problems from PDEs)
Still, often good when tuned for a particular class of problems
Parallelism
Triangular solves are not very parallel
Reordering for parallel triangular solve by graph coloring
Complexity of Linear Solvers
Time to solve the Poisson model problem on regular mesh
with N nodes: