38
Solution of Sparse Linear Systems Numerical Simulation CSE245 Thanks to: Kin Sou, Deepak Ramaswamy, Michal Rewienski, Jacob White, Shihhsien Kuo and Karen Veroy and especially Luca Daniel

Solution of Sparse Linear Systems

  • Upload
    cayla

  • View
    66

  • Download
    2

Embed Size (px)

DESCRIPTION

Numerical Simulation CSE245. Solution of Sparse Linear Systems. Thanks to: Kin Sou, Deepak Ramaswamy, Michal Rewienski, Jacob White, Shihhsien Kuo and Karen Veroy and especially Luca Daniel. Outline of today’s lecture. Solution of Sparse Linear Systems - PowerPoint PPT Presentation

Citation preview

Page 1: Solution of Sparse Linear Systems

Solution of Sparse Linear Systems

Numerical Simulation

CSE245

Thanks to: Kin Sou, Deepak Ramaswamy, Michal Rewienski, Jacob White, Shihhsien Kuo and Karen Veroy and

especially Luca Daniel

Page 2: Solution of Sparse Linear Systems

2

Outline of today’s lecture

• Solution of Sparse Linear SystemsSolution of Sparse Linear Systems– Examples of Problems with Sparse Matrices Examples of Problems with Sparse Matrices

• Struts and joints, resistor grids, 3-D heat flowStruts and joints, resistor grids, 3-D heat flow – Tridiagonal Matrix FactorizationTridiagonal Matrix Factorization– General Sparse FactorizationGeneral Sparse Factorization

• Fill-in and ReorderingFill-in and Reordering• Graph Based ApproachGraph Based Approach

– Sparse Matrix Data StructuresSparse Matrix Data Structures• ScatteringScattering

Page 3: Solution of Sparse Linear Systems

3

X

X

X

X

X

X

X

X

X

1

2

3

4

5

6

7

8

9

2 x 2 block

X =

Sparse MatricesApplications

Space Frame

Space FrameX

X X

X

X

X

X

X

X

X

X

X

X

X

X

X

X

X

XX

X X

X

X

X X

X

Unknowns : Joint positionsEquations : forces = 0

X

Nodal Matrix

X

X

X

X

X

X

X

XX

X

X

Page 4: Solution of Sparse Linear Systems

4

1 2 3 4 1m m

2m

1m 2m 3m 2m

( 1) ( 1)m m Unknowns : Node VoltagesEquations : currents = 0

Sparse MatricesApplications

Resistor Grid

Page 5: Solution of Sparse Linear Systems

Nodal Formulation

Matrix non-zero locations for 100 x 10 Resistor Grid

Sparse MatricesApplications

Resistor Grid

Page 6: Solution of Sparse Linear Systems

Nodal FormulationSparse MatricesApplications

Temperature in a cube

Temperature known on surface, determine interior temperature

1 2

1m 2m

2 1m 2 2m CircuitModel

Page 7: Solution of Sparse Linear Systems

7

Outline

• Solution of Dense Linear SystemsSolution of Dense Linear Systems

• Solution of Sparse Linear SystemsSolution of Sparse Linear Systems– LU Factorization Reminder.LU Factorization Reminder.– Example of Problems with Sparse MatricesExample of Problems with Sparse Matrices

• Struts and joints, resistor grids, 3-d heat flowStruts and joints, resistor grids, 3-d heat flow – Tridiagonal Matrix FactorizationTridiagonal Matrix Factorization– General Sparse FactorizationGeneral Sparse Factorization

• Fill-in and ReorderingFill-in and Reordering• Graph Based ApproachGraph Based Approach

– Sparse Matrix Data StructuresSparse Matrix Data Structures• ScatteringScattering

Page 8: Solution of Sparse Linear Systems

Nodal FormulationSparse MatricesTridiagonal Example

Matrix Form

1 2 3 4 1m m

X X

X X X

X X X

X X X

X X X

X X X

X X X

X X

m

How many operations to do LU factorization?

Page 9: Solution of Sparse Linear Systems

9

Sparse MatricesGE Algorithm

Tridiagonal Example

For i = 1 to n-1 { “For each Row”

For j = i+1 to n { “For each target Row below the source”

For k = i+1 to n { “For each Row element beyond Pivot”

} }}

Pivotjiji

ii

MM

M

Multiplier

jk jk ji ikM M M M Order n Operations!

Page 10: Solution of Sparse Linear Systems

10

Outline

• Solution of Dense Linear SystemsSolution of Dense Linear Systems

• Solution of Sparse Linear SystemsSolution of Sparse Linear Systems– LU Factorization Reminder.LU Factorization Reminder.– Example of Problems with Sparse MatricesExample of Problems with Sparse Matrices

• Struts and joints, resistor grids, 3-d heat flowStruts and joints, resistor grids, 3-d heat flow – Tridiagonal Matrix FactorizationTridiagonal Matrix Factorization– General Sparse FactorizationGeneral Sparse Factorization

• Fill-in and ReorderingFill-in and Reordering• Graph Based ApproachGraph Based Approach

– Sparse Matrix Data StructuresSparse Matrix Data Structures• ScatteringScattering

Page 11: Solution of Sparse Linear Systems

11

1R

5R

3R

Sparse MatricesSparse Matrix Fill-In

4R

2R1V 2V

3V

1Si

1

1

2

3

0

0

S

V

V

iV

1

1

R 2

1

R

2

1

R

2

1

R

2

1

R 3

1

R

4

1

R

4

1

R

4

1

R

4

1

R 5

1

R

SymmetricDiagonally Dominant

Nodal Matrix

Resistor Example

Example

0

Page 12: Solution of Sparse Linear Systems

12

Sparse MatricesFill-In

Example

X X X

X X 0

X 0 X

X X X

X X 0

X 0 X

X

X

X X

X= Non zero

Matrix Non zero structure Fill Ins

X X

X = fill in where 0 became non-zero

Page 13: Solution of Sparse Linear Systems

13

Sparse MatricesFill-In

Second Example

X X X X

X X 0 0

0 X X 0

X 0 00

Fill-ins Propagate

XX

X

X

X

X X

X

X X

Fill-ins from Step 1 result in Fill-ins in step 2

Page 14: Solution of Sparse Linear Systems

14

Sparse MatricesFill-In

Reordering

1V 2V

3V

0

x x x

x x x

x x x

Fill-ins

Node Reordering - Can reduce fill-in - Preserves properties (Symmetry, Diagonal Dominance) - Equivalent to swapping rows and columns

No Fill-ins2V 1V

3V

0

x x 0

x x x

0 x x

Page 15: Solution of Sparse Linear Systems

15

Sparse MatricesFill-In

Reordering

Where can fill-in occur ?

x

x x

x x

x x

x

x

Multipliers

Already Factored

Possible Fill-inLocations

Fill-in Estimate = (Non zeros in unfactored part of Row -i) (Non zeros in unfactored part of Col -i) MarkowitzMarkowitz product

0 0

x 0

0 x

Page 16: Solution of Sparse Linear Systems

16

Sparse MatricesFill-In

Reordering

Markowitz Reordering

tor oF 1i n with min Mard kowitz Productiagonan lFi d ij

anSw d rows columns a p j ji i the new row and determine fiFactor ll-insi

End

Greedy Algorithm !

Page 17: Solution of Sparse Linear Systems

17

Sparse MatricesFill-In

Why only try diagonals ?

• Corresponds to node reordering in Nodal formulation

03

1 2

02

3 1

• Reduces search cost • Preserves Matrix Properties - Diagonal Dominance - Symmetry

Reordering

Page 18: Solution of Sparse Linear Systems

18

Sparse Matrices Fill-In

Pattern of a Filled-in Matrix

Very Sparse

Very Sparse

Dense

Page 19: Solution of Sparse Linear Systems

19

Sparse Matrices Fill-In

Unfactored Random Matrix

Symmetric

Page 20: Solution of Sparse Linear Systems

20

Sparse Matrices Fill-In

Factored Random Matrix

Symmetric

Page 21: Solution of Sparse Linear Systems

21

Outline

• Solution of Dense Linear SystemsSolution of Dense Linear Systems

• Solution of Sparse Linear SystemsSolution of Sparse Linear Systems– LU Factorization Reminder.LU Factorization Reminder.– Example of Problems with Sparse MatricesExample of Problems with Sparse Matrices

• Struts and joints, resistor grids, 3-d heat flowStruts and joints, resistor grids, 3-d heat flow – Tridiagonal Matrix FactorizationTridiagonal Matrix Factorization– General Sparse FactorizationGeneral Sparse Factorization

• Fill-in and ReorderingFill-in and Reordering• Graph Based ApproachGraph Based Approach

– Sparse Matrix Data StructuresSparse Matrix Data Structures• ScatteringScattering

Page 22: Solution of Sparse Linear Systems

22

X

X

X

X

X

X

X X

X

XX

X

X

X X 1

2

4

3

5

• One Node Per Matrix Row

• One Edge Per Off-diagonal Pair

X

X

Sparse MatricesMatrix Graphs

Construction

Structurally Symmetric Matrices and Graphs

Page 23: Solution of Sparse Linear Systems

23

Sparse MatricesMatrix Graphs

Markowitz Products

X

X

X

X

X

X

X X

X

XX

X

X

X X

X

X 1

2

4

3

5

Markowitz Products = (Node Degree)2

11 3 3 9M 2(degree 1) 933

22 2 2 4M 2(deg ree 2) 422

33 3 3 9M 2(deg ree 3) 933

44 2 2 4M 2(degree 4) 422

55 2 2 4M 2(degree 5) 422

Page 24: Solution of Sparse Linear Systems

24

X

X

X

X

X

X

X X

X

XX

X

X

X X 1

2

4

3

5

• Delete the node associated with pivot row

• “Tie together” the graph edges

X

X

X

X

X

Sparse MatricesMatrix Graphs

Factorization

X

One Step of LU Factorization

Page 25: Solution of Sparse Linear Systems

25

Sparse MatricesMatrix Graphs

Example

x x x x

x x x

x x x x

x x x x

x x x x

1 2 3 4 5

Graph

Markowitz products( = Node degree)

Col Row

3 3 9

2 2 4

3 3 9

3 3 9

3 3 9

1

2

3

4

5

Page 26: Solution of Sparse Linear Systems

26

Sparse MatricesMatrix Graphs

Example

x x x

x x 0 x x

x 0 x x x

x x x x

x x x x

Swap 2 with 1

X

X

2 3 4 5

Graph

2 3 4 5

Eliminate 1

112

Page 27: Solution of Sparse Linear Systems

27

1 2 3 4 1m m

2m

1m 2m 3m 2m

( 1) ( 1)m m Unknowns : Node VoltagesEquations : currents = 0

Sparse MatricesGraphs

Resistor Grid Example

Page 28: Solution of Sparse Linear Systems

28

Sparse MatricesMatrix Graphs

Grid Example

Page 29: Solution of Sparse Linear Systems

29

Sparse Matrices For growth control?Or to avoid fill-ins?

What should you pivot for?

A) LU factorization applied to a strictly diagonally dominant matrix will never produce a zero pivot

B) The matrix entries produced by LU factorization applied to a strictly diagonally dominant matrix will never increase by more than a factor 2(n-1)

[which is anyway the best you can do by pivoting for growth control]

Bottom line:if your matrix is strictly diagonally dominantno need for numerical pivot for growth control!

Page 30: Solution of Sparse Linear Systems

Sparse Factorization Approach

1)1) Assume matrix requires NO numerical pivoting.Assume matrix requires NO numerical pivoting.Diagonally dominant or symmetric positive definite.Diagonally dominant or symmetric positive definite.

2)2) Pre-Process:Pre-Process:• Use Graphs to Determine Matrix OrderingUse Graphs to Determine Matrix Ordering

• Many graph manipulation tricks used.Many graph manipulation tricks used.

• Form Data Structure for Storing Filled-in MatrixForm Data Structure for Storing Filled-in Matrix• Lots of additional non-zero addedLots of additional non-zero added

3)3) Put numerical values in Data Structure and factorPut numerical values in Data Structure and factorComputation must be organized carefully!Computation must be organized carefully!

Page 31: Solution of Sparse Linear Systems

Summary of Sparse Systems

• LU Factorization and Diagonal Dominance.LU Factorization and Diagonal Dominance.– Factor without numerical pivotingFactor without numerical pivoting

• Sparse Matrices Sparse Matrices – Struts, resistor grids, 3-d heat flow -> O(N) non-zerosStruts, resistor grids, 3-d heat flow -> O(N) non-zeros

• Tridiagonal Matrix FactorizationTridiagonal Matrix Factorization– Factor in O(N) operationsFactor in O(N) operations

• General Sparse FactorizationGeneral Sparse Factorization– Markowitz Reordering to minimize fillMarkowitz Reordering to minimize fill

• Graph Based ApproachGraph Based Approach– Factorization and Fill-inFactorization and Fill-in– Useful for estimating Sparse GE complexityUseful for estimating Sparse GE complexity

Page 32: Solution of Sparse Linear Systems

32

Outline

• Solution of Sparse Linear SystemsSolution of Sparse Linear Systems– Example of Problems with Sparse MatricesExample of Problems with Sparse Matrices– Tridiagonal Matrix FactorizationTridiagonal Matrix Factorization– General Sparse FactorizationGeneral Sparse Factorization

• Fill-in and ReorderingFill-in and Reordering• Graph Based ApproachGraph Based Approach• Summary of the AlgorithmSummary of the Algorithm

– Sparse Matrix Data StructuresSparse Matrix Data Structures• Scattering and symbolic fill inScattering and symbolic fill in

Page 33: Solution of Sparse Linear Systems

33

Sparse Matrices Sparse Data Structure

Val 11

Col 11

Val 12

Col 12

Val 1K

Col 1K

Val 21

Col 21

Val 22

Col 22

Val 2L

Col 2L

Val N1

Col N1

Val N2

Col N2

Val Nj

Col Nj

1

N

Arrays of Data in a RowVector of row pointers

Matrix entriesColumn index

Row pointersColumn Indices

Goal:Never store a 0Never multiply by 0

Page 34: Solution of Sparse Linear Systems

34

Sparse Matrices Sparse Data Structure

Problem of Misses

, 1 , 4 , 5 , 7 , 9 , 12 , 15

1 4 5 7 9 12 15j k j k j k j k j k j k j kM M M M M M M

k k k k k k k

, 1 , 7 , 15

1 7 15i k i k i kM M M

k k k

Eliminating Source Row i from Target row j

Row i

Row j

Must read all the row j entries to find the 3 that match row i

Page 35: Solution of Sparse Linear Systems

35

Sparse Matrices Sparse Data Structure

Data on Misses

Rows Ops Misses

Res 300 904387 248967

RAM 2806 1017289 3817587

Grid 4356 3180726 3597746

Every Miss is an unneeded Memory Reference!

More missesthanops!

Page 36: Solution of Sparse Linear Systems

36

Sparse Matrices Sparse Data Structure

Scattering for Miss Avoidance

Row j

, 1j kM , 4j kM , 5j kM , 7j kM , 9j kM , 12j kM , 15j kM

Use target row approach – Row j is the target.1) Read all the elements in Row j, and scatter them in an n-length vector2) Access only the needed elements using array indexing!

, 1 , 4 , 5 , 7 , 9 , 12 , 15

1 4 5 7 9 12 15j k j k j k j k j k j k j kM M M M M M M

k k k k k k k

Page 37: Solution of Sparse Linear Systems

37

Sparse Matrices – Another Data StructureOrthogonal linked list

But if fill in occurs, pointer structures change. What do we do?

Pre-compute pivoting order and sparse fill in structure symbolically

Page 38: Solution of Sparse Linear Systems

38

Summary of Sparse Systems

• LU Factorization and Diagonal Dominance.LU Factorization and Diagonal Dominance.– Factor without numerical pivotingFactor without numerical pivoting– hard problems (ill-conditioned)hard problems (ill-conditioned)

• Sparse Matrices Sparse Matrices – Struts, resistor grids, 3-d heat flow -> O(N) nonzerosStruts, resistor grids, 3-d heat flow -> O(N) nonzeros

• Tridiagonal Matrix FactorizationTridiagonal Matrix Factorization– Factor in O(N) operationsFactor in O(N) operations

• General Sparse FactorizationGeneral Sparse Factorization– Markowitz Reordering to minimize fillMarkowitz Reordering to minimize fill

• Graph Based ApproachGraph Based Approach– Factorization and Fill-inFactorization and Fill-in– Useful for estimating Sparse GE complexityUseful for estimating Sparse GE complexity

• Sparse Data StructuresSparse Data Structures– Scattering and symbolic fill inScattering and symbolic fill in