sparse matrices example of sparse matrices
play

Sparse Matrices Example Of Sparse Matrices diagonal tridiagonal - PDF document

Sparse Matrices Example Of Sparse Matrices diagonal tridiagonal sparse many elements are zero lower triangular (?) dense few elements are zero These are structured sparse matrices. May be mapped into a 1D array so that a mapping


  1. Sparse Matrices Example Of Sparse Matrices diagonal tridiagonal sparse … many elements are zero lower triangular (?) dense … few elements are zero These are structured sparse matrices. May be mapped into a 1D array so that a mapping function can be used to locate an element. Unstructured Sparse Matrices Unstructured Sparse Matrices Airline flight matrix. Web page matrix. � airports are numbered 1 through n web pages are numbered 1 through n � flight(i,j) = list of nonstop flights from airport i web(i,j) = number of links from page i to page j to airport j � n = 1000 (say) Web analysis. � n x n array of list references => 4 million bytes authority page … page that has many links to it � total number of flights = 20,000 (say) hub page … links to many authority pages � need at most 20,000 list references => at most 80,000 bytes

  2. Web Page Matrix Representation Of Unstructured Sparse Matrices � n = 2 billion (and growing by 1 million a day) � n x n array of ints => 16 * 10 18 bytes (16 * 10 9 Single linear list in row-major order. GB) scan the nonzero elements of the sparse matrix in row- � each page links to 10 (say) other pages on major order average each nonzero element is represented by a triple � on average there are 10 nonzero entries per row (row, column, value) � space needed for nonzero elements is the list of triples may be an array list or a linked list approximately 20 billion x 4 bytes = 80 billion (chain) bytes (80 GB) Array Linear List Representation Single Linear List Example row 1 1 2 2 4 4 list = column 3 5 3 4 2 3 value 3 4 5 7 2 6 0 0 3 0 4 list = row 1 1 2 2 4 4 0 0 5 7 0 element 0 1 2 3 4 5 column 3 5 3 4 2 3 0 0 0 0 0 row 1 1 2 2 4 4 0 2 6 0 0 value 3 4 5 7 2 6 column 3 5 3 4 2 3 value 3 4 5 7 2 6

  3. Single Chain Chain Representation Node structure. row 1 1 2 2 4 4 list = column 3 5 3 4 2 3 value 3 4 5 7 2 6 row col value next 1 3 1 5 2 3 2 4 4 2 4 3 3 4 5 7 2 6 null firstNode Array Of Row Chains One Linear List Per Row Node structure. row1 = [(3, 3), (5,4)] 0 0 3 0 4 row2 = [(3,5), (4,7)] 0 0 5 7 0 next col value row3 = [] 0 0 0 0 0 row4 = [(2,2), (3,6)] 0 2 6 0 0

  4. Array Of Row Chains Orthogonal List Representation Both row and column lists. null 3 3 5 4 Node structure. 0 0 3 0 4 null 0 0 5 7 0 3 5 4 7 row col value down next 0 0 0 0 0 null 0 2 6 0 0 null 2 2 3 6 row[] Row Lists Column Lists 1 3 3 1 5 4 1 3 3 1 5 4 n n 0 0 3 0 4 0 0 3 0 4 0 0 5 7 0 0 0 5 7 0 2 3 5 2 4 7 2 3 5 2 4 7 n 0 0 0 0 0 0 0 0 0 0 0 2 6 0 0 0 2 6 0 0 null 4 2 2 4 3 6 4 2 2 4 3 6 n n n

  5. Orthogonal Lists Variations 1 3 3 1 5 4 May use circular lists instead of chains. n n 0 0 3 0 4 0 0 5 7 0 2 3 5 2 4 7 n 0 0 0 0 0 0 2 6 0 0 null 4 2 2 4 3 6 n n n row[] Runtime Performance Approximate Memory Requirements Matrix Transpose 500 x 500 matrix with 1994 nonzero elements 500 x 500 matrix with 1994 nonzero elements 2D array 500 x 500 x 4 = 1million bytes 2D array 210 ms Single Array List 3 x 1994 x 4 = 23,928 bytes Single Array List 6 ms One Chain Per Row 23928 + 500 x 4 = 25,928 One Chain Per Row 12 ms

  6. Performance Matrix Addition. 500 x 500 matrices with 1994 and 999 nonzero elements 2D array 880 ms Single Array List 18 ms One Chain Per Row 29 ms

Recommend


More recommend