PHAS0102-Python代写-Assignment 2
时间:2022-11-04
PHAS0102: Techniques of
High-Performance Computing
Shameless self-promotion
d 24hourmaths.com
a @24hmaths
Assignment 2
● On Moodle and mscroggs.co.uk/phas0102
● Deadline: 5pm on Thursday 3 November
Example problem
● Poisson problem
Finite differences
0 1 2 ... N
N+1 N+2 N+3 … 2N+1
2N+2 … 3N+2
N2+N … (N+1)2 - 1
[live code demo]
Sparse matrix storage
● We would like to not have to store all the 0s in the
matrix in memory.
● Ideas?
COO (coordinate) format
● Store two lists of integers and one list of data:
– First integer list is rows
– Second integer list is columns
– Data list is values in (row, column)
● eg
– [0, 1]
– [1,0]
– [0.5, 0.7]
● COO is the easiest format to use to create a sparse matrix
CSR (compressed sparse rows) format
● Store two lists of integers and one list of data:
– First integer list is columns
– Second integer list is when row changes
– Data list is values in (row, column)
● eg
– [0, 1]
– [1]
– [0.5, 0.7]
● CSR uses less storage space, and is used by many sparse solvers.
CSC (compressed sparse columns) format
● This is the same as CSR, but with the role of rows
and columns swapped.
[live code demo]
Other formats
● There are lots of other sparse matrix formats,
including:
– LIL (list of lists)
– DOK (dictionary of keys)
– DIA (diagonal storage)
– BSR (block sparse rows)