Sparse Matrices. sparse many elements are zero dense few elements are zero

Similar documents
Abstract Data Type array. 1D Array Representation In C++ Space Overhead. Data Structures and Programming 資料結構與程式設計. Topic 5 Arrays and Matrices

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.

UNIT 2 ARRAYS 2.0 INTRODUCTION. Structure. Page Nos.

How to declare an array in C?

2.1.5 Miscellaneous Topics

Applications of Linked Lists

Spare Matrix Formats, and The Standard Template Library

Methods of solving sparse linear systems. Soldatenko Oleg SPbSU, Department of Computational Physics

Data Structures and Algorithms(12)

Fall, 2015 Prof. Jungkeun Park

Chapter Introduction

1. Represent each of these relations on {1, 2, 3} with a matrix (with the elements of this set listed in increasing order).

Data Structures Through C. Student Workbook

Data Structures for sparse matrices

Chapter 4. Matrix and Vector Operations

Monday, October 24, 2016

Computers in Engineering. Linear Algebra Michael A. Hawker

Computers in Engineering COMP 208. Representing Vectors. Vector Operations 11/29/2007. Scaling. Adding and Subtracting

Uppsala University Department of Information technology. Hands-on 1: Ill-conditioning = x 2

0_PreCNotes17 18.notebook May 16, Chapter 12

Computational Methods CMSC/AMSC/MAPL 460. Vectors, Matrices, Linear Systems, LU Decomposition, Ramani Duraiswami, Dept. of Computer Science

Wednesday, March 14, 2018

Exercise Set Decide whether each matrix below is an elementary matrix. (a) (b) (c) (d) Answer:

PARDISO Version Reference Sheet Fortran

Matrix Multiplication

PetShop (BYU Students, SIGGRAPH 2006)

Arrays, Vectors, Matrices

Optimizing the operations with sparse matrices on Intel architecture

Matrix Multiplication

1) Give a set-theoretic description of the given points as a subset W of R 3. a) The points on the plane x + y 2z = 0.

MATH 423 Linear Algebra II Lecture 17: Reduced row echelon form (continued). Determinant of a matrix.

(Sparse) Linear Solvers

Numerical Linear Algebra

Ashish Gupta, Data JUET, Guna

abstract classes & types

Adjacency Matrix Undirected Graph. » Matrix [ p, q ] is 1 (True) if < p, q > is an edge in the graph. Graphs Representation & Paths

Review of Elementary Data. Manoj Kumar DTU, Delhi

Module 6: Array in C

Aim. Structure and matrix sparsity: Part 1 The simplex method: Exploiting sparsity. Structure and matrix sparsity: Overview

Multiple View Geometry in Computer Vision

MODULE 3: LINKED LIST

Sparse Multifrontal Performance Gains via NVIDIA GPU January 16, 2009

Linked Lists in C and C++

CSE 230 Intermediate Programming in C and C++ Arrays and Pointers

CT5510: Computer Graphics. Transformation BOCHANG MOON

PENLIB/SDP User s Guide

Sparse matrices: Basics

Digraphs and Matlab. 1 Digraphs. David Arnold. August 31, 1996

Haar Wavelet Image Compression

CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs

Chapter 18 Indexing Structures for Files

Teaching Manual Math 2131

Chapter 13: Indexing. Chapter 13. ? value. Topics. Indexing & Hashing. value. Conventional indexes B-trees Hashing schemes (self-study) record

Previous Year Nagarro Questions

Matrices 4: use of MATLAB

Contents. F10: Parallel Sparse Matrix Computations. Parallel algorithms for sparse systems Ax = b. Discretized domain a metal sheet

PENBMI User s Guide. We solve the SDP problem with linear and bilinear matrix inequality constraints:

STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY

ECEN 615 Methods of Electric Power Systems Analysis Lecture 11: Sparse Systems

How to perform HPL on CPU&GPU clusters. Dr.sc. Draško Tomić

Lecture 5: Matrices. Dheeraj Kumar Singh 07CS1004 Teacher: Prof. Niloy Ganguly Department of Computer Science and Engineering IIT Kharagpur

Matrix algebra. Basics

CSE 599 I Accelerated Computing - Programming GPUS. Parallel Pattern: Sparse Matrices

CHAPTER 5 SYSTEMS OF EQUATIONS. x y

Computational Methods CMSC/AMSC/MAPL 460. Vectors, Matrices, Linear Systems, LU Decomposition, Ramani Duraiswami, Dept. of Computer Science

CHAPTER 4 LINKED LISTS

Lecture 10. Graphs Vertices, edges, paths, cycles Sparse and dense graphs Representations: adjacency matrices and adjacency lists Implementation notes

Math 355: Linear Algebra: Midterm 1 Colin Carroll June 25, 2011

Lists (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

Solving Sparse Linear Systems. Forward and backward substitution for solving lower or upper triangular systems

Matrix Multiplication in MapReduce. Overview. Matrix Multiplication. .. CSC 369 Distributed Computing Alexander Dekhtyar.. Matrix Multiplication:

UNIT-1. Chapter 1(Introduction and overview) 1. Asymptotic Notations 2. One Dimensional array 3. Multi Dimensional array 4. Pointer arrays.

Teachers Teaching with Technology (Scotland) Teachers Teaching with Technology. Scotland T 3. Matrices. Teachers Teaching with Technology (Scotland)

Week 5. Muhao Chen.

University of California, Berkeley College of Engineering

x = 12 x = 12 1x = 16

Computer Science 136. Midterm Examination

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

Multidimensional Arrays & Graphs. CMSC 420: Lecture 3

國立清華大學電機工程學系. Outline

13.4 Case Study: vector<t>-based Matrices

Data Structures and Algorithms (DSA) Course 9 Lists / Graphs / Trees. Iulian Năstac

BLAS and LAPACK + Data Formats for Sparse Matrices. Part of the lecture Wissenschaftliches Rechnen. Hilmar Wobker

January 16 Do not hand in a listing of the file InvalidRowCol.java.

Classification s of Data Structures

2.3 Algorithms Using Map-Reduce

Graphs & Digraphs Tuesday, November 06, 2007

CSCE 5160 Parallel Processing. CSCE 5160 Parallel Processing

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

Data Structure. Chapter 4 List (Part II) Department of Communication Engineering National Central University Jhongli, Taiwan.

Matrix Multiplication. (Dynamic Programming)

10/26/ Solving Systems of Linear Equations Using Matrices. Objectives. Matrices

ft-uiowa-math2550 Assignment HW8fall14 due 10/23/2014 at 11:59pm CDT 3. (1 pt) local/library/ui/fall14/hw8 3.pg Given the matrix

AH Matrices.notebook November 28, 2016

CS , Fall 2001 Exam 2

CS 231: Algorithmic Problem Solving

Study of Butterfly Patterns of Matrix in Interconnection Network

FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx

For example, the system. 22 may be represented by the augmented matrix

Transcription:

Sparse Matrices sparse many elements are zero dense few elements are zero

Special Matrices A square matrix has the same number of rows and columns. Some special forms of square matrices are Diagonal: M(i,j) = 0 for i j Tridiagonal: M(i,j) = 0 for i-j < 1 Lower triangular: M(i,j) = 0 for i < j Upper triangular: M(i,j) = 0 for i > j Symmetric M(i,j) = M(j,i) for all i and j See Figure 2

Special Matrices 3

Example Of Sparse Matrices Diagonal Tri-diagonal lower triangular (?) Two possible representations of sparse matrix: 1. array 2. linked list

For example consider a matrix having 100 row and 100 column that have only 2000 non zero elements. Space required by above matrix is 1000,000. So we can store all the non-zero elements of above matrix in a 1D matrix of size 2000. or Create a linked list of non-zero elements.

Array Representation of Sparse Matrix The nonzero entries may be mapped into a 1D array in row-major order To reconstruct the matrix structure, need to record the row and column each nonzero comes from 6

Linked Representation of Sparse Matrix A shortcoming of the 1-D array of a sparse matrix is that we need to know the number of nonzero terms in each of the sparse matrices when the array is created. A linked representation can overcome this shortcoming. 7

Unstructured Sparse Matrices Airline flight matrix. airports are numbered 1 through n flight(i,j) = list of nonstop flights from airport i to airport j n = 1000 (say) n x n array of list references => 4 million bytes total number of flights = 20,000 (say) need at most 20,000 list references => at most 80,000 bytes

Representation Of Unstructured Sparse Matrices Single linear list in row-major order. scan the nonzero elements of the sparse matrix in rowmajor order. each nonzero element is represented by a triple (row, column, value) the list of triples may be an array list or a linked list (chain)

Single Linear List Example 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 list = row 1 1 2 2 4 4 column 3 5 3 4 2 3 value 3 4 5 7 2 6

Array Linear List Representation row 1 1 2 2 4 4 list = column 3 5 3 4 2 3 value 3 4 5 7 2 6 element 0 1 2 3 4 5 row 1 1 2 2 4 4 column 3 5 3 4 2 3 value 3 4 5 7 2 6

Node structure. Chain Representation row value col next

Single Chain row 1 1 2 2 4 4 list = column 3 5 3 4 2 3 value 3 4 5 7 2 6 1 3 1 5 2 3 2 4 4 2 4 3 3 4 5 7 2 6 null firstnode

Multi-Linked Lists A multilinked list is a more general linked list with multiple links from nodes. In multi-linked list, each node can have any number of pointers to other nodes, and there may or may not be inverses for each pointer. Multi-lists are essentially the technique of embedding multiple lists into a single data structure. A multi-list has more than one next pointer, like a doubly linked list, but the pointers create separate lists

head Multi-lists

head Multi-lists

Linked Structures A doubly-linked list or multi-list is a data structure with multiple pointers in each node. In a doubly-linked list the two pointers create bidirectional links. In a multi-list the pointers used to make multiple link routes through the data.

Example : List of List Suppose you want to make list of all Customers in particular bank. Bank will have multiple branches. Each branch will have multiple customers.

Multi-list linked representation of Sparse Matrix

3-Tuple Representation Of Sparse Matrix 1 0 0 0 0 0 0 4 0 sparse matrix 3-Tuple Representation Of Sparse Matrix Using Array: no of row no of col no of non zero value 3 3 2 0 0 1 2 1 4

Elements in the first row represents the number of rows, columns and non-zero values in sparse matrix. First Row - 3 3 2 3 - rows 3 - columns 2 - non- zero values Elements in the other rows gives information about the location and value of non-zero elements. 0 0 1 ( Second Row) - represents value 1 at 0th Row, 0th column 2 1 4 (Third Row) - represents value 4 at 2nd Row, 1st column

Multi-list Representation Both row and column lists. Node structure. row col value down next

Row Lists 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 null 1 3 3 1 5 4 n 2 3 5 2 4 7 n 4 2 2 4 3 6 n

Column Lists 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 1 3 3 1 5 4 n 2 3 5 2 4 7 4 2 2 4 3 6 n n

Muti linked Lists 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 null 1 3 3 1 5 4 n n 2 3 5 2 4 7 n row[] 4 2 2 4 3 6 n n n

* structure for col headnode */ struct cheadnode { int colno ; struct node *down ; struct cheadnode *next ; } ; /* structure for row headnode */ struct rheadnode { int rowno ; struct node * right ; struct rheadnode *next ; } ;

/* structure for node to store element */ struct node { int row ; int col ; int val ; struct node *right ; struct node *down ; } ; /* structure for special headnode */ struct spmat { struct rheadnode *firstrow ; struct cheadnode *firstcol ; int noofrows ; int noofcols ; } ;

struct sparse { int *sp ; int row ; struct spmat *smat ; struct cheadnode *chead[max2] ; struct rheadnode *rhead[max1] ; struct node *nd ; } ;

One Linear List Per Row 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 row1 = [(3, 3), (5,4)] row2 = [(3,5), (4,7)] row3 = [] row4 = [(2,2), (3,6)]

Node structure. Array Of Row Chains col next value

Array Of Row Chains null 3 3 5 4 0 0 3 0 4 null 0 0 5 7 0 3 5 4 7 0 0 0 0 0 0 2 6 0 0 null null 2 2 3 6 row[]

Orthogonal List Representation Both row and column lists. Node structure. row down col next value

Row Lists 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 null 1 3 3 1 5 4 n 2 3 5 2 4 7 n 4 2 2 4 3 6 n

Column Lists 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 1 3 3 1 5 4 n 2 3 5 2 4 7 4 2 2 4 3 6 n n

Orthogonal Lists 0 0 3 0 4 0 0 5 7 0 0 0 0 0 0 0 2 6 0 0 null 1 3 3 1 5 4 n n 2 3 5 2 4 7 n row[] 4 2 2 4 3 6 n n n

Variations May use circular lists instead of chains.

Approximate Memory Requirements 500 x 500 matrix with 1994 nonzero elements 2D array 500 x 500 x 4 = 1million bytes Single Array List 3 x 1994 x 4 = 23,928 bytes One Chain Per Row 23928 + 500 x 4 = 25,928

Runtime Performance Matrix Transpose 500 x 500 matrix with 1994 nonzero elements 2D array Single Array List One Chain Per Row 210 ms 6 ms 12 ms

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