Directsparsematrices
Directsparsematrices
Matrices
Miroslav Tůma
1
This is a lecture prepared for the SEMINAR ON NUMERICAL
ANALYSIS: Modelling and Simulation of Challenging Engineer-
ing Problems, held in Ostrava, February 7–11, 2005. Its purpose
is to serve as a first introduction into the field of direct methods
for sparse matrices. Therefore, it covers only the most classical
results of a part of the field, typically without citations. The
lecture is a first of the three parts which will be presented in
the future. The contents of subsequent parts is indicated in the
outline.
2
Outline
1. Part I.
2. Sparse matrices, their graphs, data structures
3. Direct methods
4. Fill-in in SPD matrices
5. Preprocessing for SPD matrices
6. Algorithmic improvements for SPD decompositions
7. Sparse direct methods for SPD matrices
8. Sparse direct methods for nonsymmetric matrices
3
Outline (continued)
4
1. Sparse matrices, their graphs, data structures
50
100
150
200
250
300
350
400
0 50 100 150 200 250 300 350 400
5
1.a) Concept of sparse matrices: other definitions
6
1.a) Concept of sparse matrices: an example showing
importance of the small exponent γ for n = 104
γ n1+γ
0.1 25119
0.2 63096
0.3 158489
0.4 398107
0.5 1000000
7
1.b) Matrices and their graphs: introduction
• undirected graph
• directed graph
• bipartite graph
8
1.b) Matrices and their graphs: undirected graphs
9
1.b) Matrices and their graphs: directed graphs
10
1.b) Matrices and their graphs: bipartite graphs
11
1.b) Matrices and their graphs: relation matrix → graph
Definition 8
{x, y} ∈ E or (x, y) ∈ E ⇔ vertices x and y are adjacent
∗ ∗
∗ ∗ ∗
∗ ∗
∗ ∗
∗ ∗
∗ ∗ ∗
12
1.b) Matrices and their graphs: relation matrix → graph
∗ ∗ ∗
∗ ∗ ∗
∗ ∗ ∗
∗ ∗
∗ ∗
∗ ∗ ∗
13
1.c) Data structures for sparse matrices: sparse vectors
³ ´T
v = 3.1 0 2.8 0 0 5 4.3
JV 1 3 6 7
14
1.c) Data structures for sparse matrices: static data
structures
15
1.c) Data structures for sparse matrices: CSR format
example
T
3.1 2.8
5 4.3
2 6 1
1
JA 1 3 3 4 1 2 4 1
IA 1 3 5 8 9
16
1.c) Data structures for sparse matrices: dynamic data
structures
2 6 1
17
1.c) Data structures for sparse matrices: static versus
dynamic data structures
18
2. Direct methods
20
Algorithm 1 ikj lu decomposition (delayed row dense algorithm)
l = In
u = On
u11:n = a1,1:n
for i=2:n
i
for k=1:i-1
lik = aik /akk
for j=k+1:n
aij = aij − lik ∗ akj
end
end
uii:n = aii:n
21
end
Algorithm 2 ijk lu decomposition (dot product - based row
dense algorithm)
l = In , u = On , u11:n = a11:n
for i=2:n
for j=2:i
lij−1 = aij−1 /aj−1j−1
for k=1:j-1
aij = aij − lik ∗ akj
i
end
end
for j=i+1:n
for k=1:i-1
aij = aij − lik ∗ akj
end
end
ui,i:n = ai,i:n 22
end
Algorithm 3 jki lu decomposition (delayed column dense algo-
rithm)
for s=j:n
lsj−1 = asj−1/aj−1j−1
end
for k=1:j-1
for i=k+1:n
end
end
u1:jj = a1:jj 23
end
Algorithm 4 jik lu decomposition (dot product - based column
dense algorithm)
l = In , u11 = a11
for j=2:n
for s=j:n
lsj−1 = asj−1/aj−1j−1
end
j
for i=2:j
for k=1:i-1
end
end
for i=j+1:n
for k=1:j-1
end
end 24
u1:jj = a1:jj
Algorithm 5 kij lu decomposition (row oriented submatrix dense
algorithm)
l = In
u = On
for k=1:n-1
k
for i=k+1:n
for j=k+1:n
end
end
ukk:n = akk:n
end 25
unn = ann
Algorithm 6 kji lu decomposition (column oriented submatrix
dense algorithm)
l = In , u = On
for k=1:n-1
for s=k+1:n
lsk = as,k /ak,k
k
end
for j=k+1:n
for i=k+1:n
end
end
ukk:n = akk:n
end 26
unn = ann
2.b) Sparse direct methods: existence of fill-in
0 0
50 50
100 100
150 150
200 200
250 250
300 300
350 350
400 400
0 50 100 150 200 250 300 350 400 0 50 100 150 200 250 300 350 400
27
2.b) Sparse direct methods: fill-in
• Arrow matrix
∗ ∗ ∗ ∗ ∗ ∗ ∗
∗ ∗ ∗ ∗
∗ ∗ ∗ ∗
∗ ∗ ∗ ∗
∗ ∗ ∗ ∗ ∗ ∗ ∗
28
2.b) Sparse direct methods: fill-in description
29
2.b) Sparse direct methods: fill-in illustration for a
symmetric matrix
30
2.b) Sparse direct methods: fill-in path theorem
(k)
Theorem 1 (fill-in path theorem) Let i > j, k < n. Then aij 6=
0 ⇔ ∃ a path xi, xp1 , . . . , xpt , xj in G(A) such that (∀l ∈ t̂)(pl < k).
31
2.b) Sparse direct methods: path theorem illustration for
a symmetric matrix
k *
l * *
j * *
i * * * *
32
3. Fill-in in SPD matrices
33
3.b) Elimination tree: introduction
34
3.b) Elimination tree: illustration
∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
∗ ∗ ∗ ∗ ∗ ∗ f ∗ ∗
∗ ∗ ∗ ∗ ∗ ∗
∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
∗ ∗ ∗ ∗ ∗ f ∗ ∗ f ∗
∗ ∗ ∗ ∗ ∗ ∗ f ∗ f ∗
∗ ∗ ∗ ∗ f ∗ ∗
∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
35
3.b) Elimination tree: illustration (II.)
6
5 4
2 3
37
3.b) Elimination tree: natural source of parallelism
x_i x_j
T[x_i]
T[x_j]
38
3.b) Elimination tree: full characterization of entries of L
k*
j * *
i * *
i * *
j* * * * *
initiating edge
k
edges in G(L)
edge (j,i) in G(L)
39
3.b) Elimination tree: row structure of L is given by a row
subtree of the elimination tree
i
i
k k’ k’’
k k’ k’’
k’’’
k’’’
40
3.c) Computation of row (and column) counts: algorithm
k k’ k’’
k’’’
42
3.d) Column structure of L: introduction
Lemma 6
S
Struct(L∗j ) = Struct(A∗j ) ∪ i,lij 6=0 Struct(L∗i) \ {1, . . . , j − 1}.
****
*
*
*
*
*
*
*
43
3.d) Column structure of L: an auxiliary result
44
3.d) Column structure of L: final formula
Consequently:
[
Struct(L∗j ) = Struct(A∗j ) ∪ Struct(L∗i) \ {1, . . . , j − 1}.
i,j=parent(i)
45
3.d) Column structure of L: algorithm
for j = 1 to n do
listxj = ∅
end j
for j = 1 to n do
col(j) = adj(xj ) \ {x1, . . . , xj−1}
for xk ∈ listxj do
col(j) = col(j) ∪ col(k) \ {xj }
end xk
if col(j) 6= 0 then
p = min{i | xi ∈ col(j)}
listxp = listxp ∪ {xj }
end if
end j
end i
46
3.d) Column structure of L: symbolic factorization
47
3.e) Elimination tree construction: algorithm
(complexity: O(|A|, α(|A|, n)))
for i = 1 to n do
parent(i) = 0
for k such that xk ∈ adj(xi) ∧ k < i do
j=k
i
while (parent(j) 6= 0 ∧ parent(j) 6= i) do
r = parent(j)
end while
k k’ k’’
if parent(j) = 0 then parent(j) = i
end k k’’’
end i
48
4. Preprocessing for SPD matrices
Factorize
P T AP = LLT ,
Compute y from
Ly = P T b,
Compute x from
LT P T x = y.
50
4.c) Static reorderings: local and global reorderings
Static reorderings
51
4.d) Local reorderings: minimum degree (MD): the basic
algorithm
G = G(A)
for i = 1 to n do
find v such that degG(v) = minv∈V degG(v)
G = Gv
end i
The order of found vertices induces their new renumbering
52
4.d) Local reorderings: minimum degree (MD): an
example
G G_v
v v
53
4.d) Local reorderings: minimum degree (MD):
indistinguishability
54
4.d) Local reorderings: minimum degree (MD):
indistinguishability (example)
G G_v
u v u v
55
4.d) Local reorderings: minimum degree (MD):
dominance
56
4.d) Local reorderings: minimum degree (MD):
implementation
57
4.d) Local reorderings: minimum degree (MD):
implementation (II.)
Lemma 10
t
X
|K| < |Ksi |
i=1
for merging t cliques Ksi into K.
58
4.d) Local reorderings: minimum degree (MD): multiple
elimination
59
4.d) Local reorderings: minimum degree (MD): MMD
algorithm
G = G(A)
while G 6= ∅
find all vj , j = 1, . . . , s such that
degG(vj ) = minv∈V (G)degG(v) and adj(vj ) ∩ adj(vk ) pro j 6= k
for j = 1 to s do
G = Gvj
end for
end while
The order of found vertices induces their new renumbering
60
4.d) Local reorderings: other family members
61
4.d) Local reorderings: illustration of minimum fill-in
reordering
62
4.e) Global reorderings: nested dissection
Find separator
Reorder the matrix numbering nodes in the separator last
Do it recursively
C_1 C_2
Vertex separator S
63
4.e) Global reorderings: nested dissection after one level
of recursion
C_1 C_2 S
C_1
C_2
64
4.d) Global reorderings: nested dissection with more levels
1 7 4 43 22 28 25
3 8 6 44 24 29 27
2 9 5 45 23 30 36
19 20 21 46 40 41 42
10 16 13 47 31 37 34
12 17 15 48 33 38 36
11 18 14 49 32 39 35
65
4.e) Global reorderings: nested dissection with more
levels: elimination tree
49
48
47
46
45
44
43
21 42
20 41
19 40
9 18 30 39
8 17 29 38
7 16 28 37
3 6 12 15 24 27 33 36
1 2 4 5 10 11 13 14 22 23 25 26 31 32 34 35
66
4.f) Static reorderings: a preliminary summary
67
4.f) Static reorderings: classical schemes based on
pushing nonzeros towards the diagonal
** **
**** ****
***** *****
****** ******
***** *****
***** *****
****** ******
*** ***
*** ***
6 6
Band Profile
**
Moving ****
window - * *****
*****
*****
*****
******
***
***
Frontal method - dynamic band
68
4.f) Static reorderings: classical schemes based on
pushing nonzeros towards the diagonal: an important
reason for their use
Band(L + LT ) = Band(A)
69
4.f) Static reorderings: classical schemes based on
pushing nonzeros towards the diagonal: pros and cons
71
5. Algorithmic improvements for SPD
decompositions
72
5.b) Supernodes and blocks: supernodes
s *
**
s−t+1 ***
****
****
****
****
****
73
5.b) Supernodes and blocks: blocks
74
5.b) Supernodes and blocks: some notes
75
5.c) Reorderings based on the elimination tree:
topological reorderings
8 8
7 7
6 6
5 4 5 2
2 3 4 1
1 3
76
5.c) Reorderings based on the elimination tree:
postorderings
8 8
7 7
6 6
5 4 4 5
2 3 3 1
1 2
Postordered tree
77
5.c) Reorderings based on the elimination tree:
postorderings
78
5.c) Reorderings based on the elimination tree:
postorderings: example
9 9
8 7
1 8
7 5
2 6
6 3 4
3
5 4 1 2
79
6. Sparse direct methods for SPD matrices
80
6.b) Work and memory
n
X n
X
|L| = η(L∗i) = η(Li∗)
i=1 i=1
n
X
µ(L) = [η(L∗j ) − 1][η(L∗j ) + 2]/2
j=1
81
6.c) Methods: rough classification
82
6.d) Methods: sparse SPD columnwise decomposition
Preprocessing
– prepares the matrix so that the fill-in would be as small as
possible
Symbolic factorization
– determines structures of columns of L. Consequently, L can
be allocated and used for the actual decomposition
– due to a lot of enhancements the boundary between the first
two steps is somewhat blurred
Numeric factorization
– the actual decomposition to obtain numerical values of the
factor L
83
6.d) Methods: sparse SPD columnwise decomposition:
numeric decomposition
* * * *
* *
*
*
* *
84
6.e) Methods: sparse SPD multifrontal decomposition
85
6.e) Methods: sparse SPD multifrontal decomposition:
illustration
−1
1) = stack
−1
= stack
2)
3) −1 = stack
4) + + +
86
7. Sparse direct methods for nonsymmetric
systems
87