Lect09 Solver LU Sparse
Lect09 Solver LU Sparse
Lecture 9.
Linear Solver:
LU Solver and Sparse Matrix
2010-11-15 Slide 1
Outline
Part 1:
• Gaussian Elimination
• LU Factorization
• Pivoting
• Doolittle method and Crout’s Method
• Summary
Part 2: Sparse Matrix
⎛A 0 0 ⎞⎛ i ⎞ ⎛ 0 ⎞
⎜ T ⎟⎜ ⎟
⎜0 I −A ⎟ v = ⎜ 0 ⎟
⎜ ⎟ ⎜ ⎟
⎜K i
⎝ Kv 0 ⎟⎠ ⎜⎝ e ⎟⎠ ⎜⎝ S ⎟⎠ ⎡1 1 1⎤
⎢R + G 2 + R −G 2 − ⎥
R 3 ⎛ e1 ⎞ ⎛ 0 ⎞
⎢ 1 3
⎥⎜ ⎟ = ⎜ ⎟
⎢ 1 1 1 ⎥ ⎝e2 ⎠ ⎝ I S 5 ⎠
⎢ − +
⎣ R3 R 4 R 3 ⎥⎦
⎛2 1 5⎞
1
⎛2 1 5⎞ ⎜ ⎧x = 2
3 ⎟⎟
−
⎨
⎜0 3
2
⎜ 1 2 4⎟ ⎩y = 1
⎝ ⎠ ⎝ 2 2⎠
⎛ 1 0 ⎞⎛ 2 1 ⎞
⎛ 2 1 ⎞ ⎜ ⎟⎜
⎜ 1 2⎟ = ⎜ 1 3⎟ LU factorization
⎝ ⎠ 1 ⎟⎜ 0 ⎟
⎝2 ⎠⎝ 2⎠
1. Let y = Ux.
2. Solve y from Ly = b
3. Solve x from Ux = y
Ax = b
a11 a12 a13 a1n b1
a 21 a 22 a 23 a 2n b2
a 31 a 32 a 33 a 3n b3
an 1 an 2 an 3 ann bn
Eliminate the lower triangular part
2010-11-15 Lecture 9 slide 11
Gaussian Elimination
a11 ≠ 0 a11 a12 a13 a1n b1
ai 1 a 21 a 22 a 23 a 2n b2
− a 31 a 32 a 33 a 3n b3
a11
an 1 an 2 an 3 ann bn
⎢ ⎥
⎢ (n ) ⎥ b (n )
⎣0 0 0 ann ⎦ n
2010-11-15 Lecture 9 slide 15
Triangular System
Gaussian elimination ends up with the following
upper triangular system of equations
⎡ 1 0 0 0⎤
⎢a ⎥ ⎡a11 a12 a13 a1n ⎤
⎢ 21 1 0 0⎥ ⎢ (2) (2) ⎥
⎢ a 11 ⎥ ⎢ 0 a 22 a 23 a 2(2)
n ⎥
⎢ ⎥
⎢ a 31 a (2 )
32
1 0⎥ ⎢0 0 a 33(3)
a 3(3) ⎥
⎢ a 11 a (2 ) ⎥ ⎢ n ⎥
22
⎢ ⎥
⎢ ⎥ ⎢ ⎥
⎢ (2 ) ⎥ ⎢ (n ) ⎥
⎢a n1 a n 2
* 1 ⎥ ⎣0 0 0 ann ⎦
⎢⎣ a 1 1 a (2 )
22 ⎥⎦
an1
−
a 11
an 1 an 2 an 3 ann
n
1
∑
i =1
i = n (n + 1)(2n + 1) ∼ O (n 3 )
6
2
n
1
Total # of mul / div = ∑ i
i =1
= n (n + 1)
2
∼ O (n 2
)
Gaussian elimination
cannot continue
⎡ 1 . 25 × 10 −4
1 . 25 ⎤ ⎡ x1 ⎤ ⎡ 6 . 25 ⎤
⎢ ⎥⎢ ⎥ = ⎢ ⎥
⎢⎣ − 6 . 25 × 10
5
⎢⎣ 0 − 1 . 25 × 10 5
⎥⎦ ⎣ 2 ⎦
x ⎥⎦
Reason:
a11 (the pivot) is too small relative to the other numbers!
x− y =0
x+ y =1
x− y =0 x+ y =1
x− y =0
x− y =0
x − 1 . 01 y = 0 . 01
Í resulting in numerical errors
ill-conditioned
2. Complete Pivoting
3. Threshold Pivoting
k
a rk (k )
= max a jk
(k )
j = k ,..., n
U
k
Rows k to n L r
Search Area
a rs ( k ) = max a ij ( k ) k
U
i = k ,..., n
j = k ,..., n L r
rows k to n; s
cols k to n
Search Area
user specified
a rk ( k ) = max a jk
(k )
U
j = k ,..., n
L r
a rs ( k ) = max a ij ( k ) s
i = k ,..., n
j = k ,..., n
Implemented in Spice 3f4
A = LU = U
L Reuse the storage
⎡a 21 ⎤ ⎡ 21 ⎤
⎢a ⎥ ⎢ ⎥
⎢ 31 ⎥ = ⎢ 31 ⎥
u 11 u11 = a11
⎢ ⎥ ⎢ ⎥
⎢a ⎥ ⎢ ⎥
⎣ n1 ⎦ ⎣ n1 ⎦
21 (u12 u13 u 1n ) + (u 22 u 23 u 2n )
= (a 22 a 23 a 2n )
L \U =
1
3
5
2 4 6
⎡ 11 0 0 0 ⎤ ⎡1 u 12 u 13 u1n ⎤
⎢ ⎢0 1 u u 2n ⎥
A = LU = U 0 0 ⎥ ⎢ 23 ⎥
⎢ 21 22 ⎥
L ⎢ 31 32 33 0 ⎥ ⎢0 0 1 u 3n ⎥
⎢ ⎥ ⎢ ⎥
⎢ ⎥ ⎢ ⎥
⎢⎣ n1 n2 n3 nn ⎥
⎦ ⎢⎣0 0 0 1 ⎥⎦
The diagonals of U
The computation order of the Crout Method: are normalized !
L \U = 2
4
6
1 3 5
2010-11-15 Lecture 9 slide 35
Storage of LU Factorization
Using only one 2-dimensional array !
U
U
L L
A (3) A (4)
Part 2.
Programming Techniques
for Sparse Matrices
2010-11-15 Slide 38
Outline
• Why Sparse Matrix Techniques?
• Sparse Matrix Data Structure
• Markowitz Pivoting
• Diagonal Pivoting for MNA Matrices
• Modified Markowitz pivoting
• How to Handle Sparse RHS
• Summary
Exploiting Sparsity
– MNA Î 3 nonzeros / row
– Can reach complexity for Gaussian elimination
• ~ O(n1.1) – O(n1.5) (Empirical complexity)
-1 3 4 5 0 6 0 0 1 2 8 3 4 5 0 6 0 0 1 2 8
3 0 0 0 -1 0 0 3 -2 4 0 -4 -5 0 -7 0 0 2 -4 -4
5 0 -3 2 6 1 2 7 0 0 5 0 -3 2 6 1 2 7 0 0
0 4 8 0 10 0 0 2 2 3 0 4 8 0 10 0 0 2 2 3
1 5 4 0 0 0 0 1 0 6 1 5 4 0 0 0 0 1 0 6
fill-ins
After row/col
reordering no fill-ins
introduced
x x x x 4
x x x 3 # NZ this row
x x 2
A(k) x x 2
(row degrees)
x x 2
3 3 2 2 3 ci \ ri
struct elem{
real value;
int row;
int col;
struct elem *next_in_row;
struct elem *next_in_col;
} Element;
FirstInRow[2] 1.5 2 2
diag[2]
FirstInRow[3] 2.1 3 1 1.7 3 3
diag[3]
2.1 3 1
dx Update stamps
C = f (x ,t )
dt related to time
Cx n +1 = Cx n + h ⋅ f (x n +1 ,t n +1 ) +
⎡ ∂f ⎤ Newton-Raphson
Cx n(k+)1 = ⎢ ⎥ ⎡ x n(k+)1 − x n(k+1−1) ⎤ +
⎣ ∂x ⎦ ⎣ ⎦ (at point x)
Invoke linear solver
A=
(
∂f x n(k+1−1) ,t n +1 ) x := x + Δx
∂x t := t + Δt
Newton-Raphson
(at point x)
Invoke linear solver
x := x + Δx
t := t + Δt
At each time point, Ax = b has to be solved for many times
time t
time points
2010-11-15 Lecture 9 slide 50
Structure of Matrix Stamps
• In circuit simulation, matrix being solved
repeatedly is of the same structur;
• only some entries vary at different frequency
or time points.
Typical matrix structure
T C
X T
A= T C X X
C = Constant
T T = Time varying
C X C X = Nonlinear (varying even at
C X the same time point)
• Strategies:
– Weighted Markowitz Product
– Reuse the LU factorization
– Iterative solver (by conditioning)
– ...
M.R. Garey and D.S. Johnson, Computers and Intractibility: A Guide to the Theory of NP-Completeness
W.H. Freeman, New York, 1979.