CSCI 317 Mike Heroux1 Sparse Matrix Computations CSCI 317 Mike Heroux.

Slides:



Advertisements
Similar presentations
Partial Differential Equations
Advertisements

Block LU Factorization Lecture 24 MA471 Fall 2003.
Algebraic, transcendental (i.e., involving trigonometric and exponential functions), ordinary differential equations, or partial differential equations...
MATH 685/ CSI 700/ OR 682 Lecture Notes
Solving Linear Systems (Numerical Recipes, Chap 2)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Parallel Programming in C with MPI and OpenMP Michael J. Quinn.
CISE301_Topic3KFUPM1 SE301: Numerical Methods Topic 3: Solution of Systems of Linear Equations Lectures 12-17: KFUPM Read Chapter 9 of the textbook.
Rayan Alsemmeri Amseena Mansoor. LINEAR SYSTEMS Jacobi method is used to solve linear systems of the form Ax=b, where A is the square and invertible.
Numerical Algorithms Matrix multiplication
Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Refresher: Vector and Matrix Algebra Mike Kirkpatrick Department of Chemical Engineering FAMU-FSU College of Engineering.
Iterative Methods and QR Factorization Lecture 5 Alessandra Nardi Thanks to Prof. Jacob White, Suvranu De, Deepak Ramaswamy, Michal Rewienski, and Karen.
Maths for Computer Graphics
Finite Element Method Introduction General Principle
Sparse Matrix Algorithms CS 524 – High-Performance Computing.
1 Systems of Linear Equations Iterative Methods. 2 B. Iterative Methods 1.Jacobi method and Gauss Seidel 2.Relaxation method for iterative methods.
Avoiding Communication in Sparse Iterative Solvers Erin Carson Nick Knight CS294, Fall 2011.
October, 1998DARPA / Melamed / Singh1 Parallelization of Search Algorithms for Modeling QTES Processes Joshua Kramer and Santokh Singh Rutgers University.
Solving Linear Systems: Iterative Methods and Sparse Systems COS 323.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Parallel Programming in C with MPI and OpenMP Michael J. Quinn.
CS240A: Conjugate Gradients and the Model Problem.
Thomas algorithm to solve tridiagonal matrices
Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.
MOHAMMAD IMRAN DEPARTMENT OF APPLIED SCIENCES JAHANGIRABAD EDUCATIONAL GROUP OF INSTITUTES.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
CE 311 K - Introduction to Computer Methods Daene C. McKinney
By Mary Hudachek-Buswell. Overview Atmospheric Turbulence Blur.
Systems of Linear Equations Iterative Methods
Eigenvalue Problems Solving linear systems Ax = b is one part of numerical linear algebra, and involves manipulating the rows of a matrix. The second main.
Linear Algebra/Eigenvalues and eigenvectors. One mathematical tool, which has applications not only for Linear Algebra but for differential equations,
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Solving Scalar Linear Systems Iterative approach Lecture 15 MA/CS 471 Fall 2003.
Systems of Linear Equation and Matrices
Review of Matrices Or A Fast Introduction.
Scientific Computing Partial Differential Equations Poisson Equation.
Copyright © 2013, 2009, 2005 Pearson Education, Inc. 1 5 Systems and Matrices Copyright © 2013, 2009, 2005 Pearson Education, Inc.
8.1 Matrices & Systems of Equations
Linear Systems Iterative Solutions CSE 541 Roger Crawfis.
Linear algebra: matrix Eigen-value Problems Eng. Hassan S. Migdadi Part 1.
Elliptic PDEs and the Finite Difference Method
2009/9 1 Matrices(§3.8)  A matrix is a rectangular array of objects (usually numbers).  An m  n (“m by n”) matrix has exactly m horizontal rows, and.
Working with Arrays in MATLAB
Solution of Sparse Linear Systems
Discrete Mathematics 1 Kemal Akkaya DISCRETE MATHEMATICS Lecture 16 Dr. Kemal Akkaya Department of Computer Science.
Parallel Solution of the Poisson Problem Using MPI
CS240A: Conjugate Gradients and the Model Problem.
Case Study in Computational Science & Engineering - Lecture 5 1 Iterative Solution of Linear Systems Jacobi Method while not converged do { }
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
Meeting 18 Matrix Operations. Matrix If A is an m x n matrix - that is, a matrix with m rows and n columns – then the scalar entry in the i th row and.
CS 484. Iterative Methods n Gaussian elimination is considered to be a direct method to solve a system. n An indirect method produces a sequence of values.
Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.
Arab Open University Faculty of Computer Studies M132: Linear Algebra
Matrices and Matrix Operations. Matrices An m×n matrix A is a rectangular array of mn real numbers arranged in m horizontal rows and n vertical columns.
Lab 3. Why Compressed Row Storage –A sparse matrix has a lot of elements of value zero. –Using a two dimensional array to store a sparse matrix wastes.
Monte Carlo Linear Algebra Techniques and Their Parallelization Ashok Srinivasan Computer Science Florida State University
2.5 – Determinants and Multiplicative Inverses of Matrices.
5 5.1 © 2016 Pearson Education, Ltd. Eigenvalues and Eigenvectors EIGENVECTORS AND EIGENVALUES.
L20: Sparse Matrix Algorithms, SIMD review November 15, 2012.
Solution of Sparse Linear Systems Numerical Simulation CSE245 Thanks to: Kin Sou, Deepak Ramaswamy, Michal Rewienski, Jacob White, Shihhsien Kuo and Karen.
Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Matrices. Variety of engineering problems lead to the need to solve systems of linear equations matrixcolumn vectors.
Conjugate gradient iteration One matrix-vector multiplication per iteration Two vector dot products per iteration Four n-vectors of working storage x 0.
1 SYSTEM OF LINEAR EQUATIONS BASE OF VECTOR SPACE.
Parallel Direct Methods for Sparse Linear Systems
Lecture 19 MA471 Fall 2003.
CSCE569 Parallel Computing
Solving Linear Systems: Iterative Methods and Sparse Systems
Linear Algebra Lecture 16.
Ax = b Methods for Solution of the System of Equations:
Ax = b Methods for Solution of the System of Equations (ReCap):
Presentation transcript:

CSCI 317 Mike Heroux1 Sparse Matrix Computations CSCI 317 Mike Heroux

CSCI 317 Mike Heroux2 Matrices Matrix (defn): (not rigorous) An m-by-n, 2 dimensional array of numbers. Examples: A = a 11 a 12 a 13 A = a 21 a 22 a 23 a 31 a 32 a 33

CSCI 317 Mike Heroux3 Sparse Matrices Sparse Matrix (defn): (not rigorous) An m-by-n matrix with enough zero entries that it makes sense to keep track of what is zero and nonzero. Example: a 11 a a 21 a 22 a A = 0 a 32 a 33 a a 43 a 44 a a 54 a 55 a a 65 a 66

4 Dense vs Sparse Costs What is the cost of storing the tridiagonal matrix with all entries? What is the cost if we store each of the diagonals as vector? What is the cost of computing y = Ax for vectors x (known) and y (to be computed): –If we ignore sparsity? –If we take sparsity into account? CSCI 317 Mike Heroux

5 Origins of Sparse Matrices In practice, most large matrices are sparse. Specific sources: –Differential equations. Encompasses the vast majority of scientific and engineering simulation. E.g., structural mechanics. –F = ma. Car crash simulation. –Stochastic processes. Matrices describe probability distribution functions. –Networks. Electrical and telecommunications networks. Matrix element a ij is nonzero if there is a wire connecting point i to point j. –And more… CSCI 317 Mike Heroux

6 Example: 1D Heat Equation (Laplace Equation) The one-dimensional, steady-state heat equation on the interval [0,1] is as follows: The solution u(x), to this equation describes the distribution of heat on a wire with temperature equal to a and b at the left and right endpoints, respectively, of the wire. CSCI 317 Mike Heroux

7 Finite Difference Approximation The following formula provides an approximation of u”(x) in terms of u: For example if we want to approximate u”(0.5) with h = 0.25: CSCI 317 Mike Heroux

8 1D Grid x 0 = 0x 4 = 1x 1 = 0.25x 2 = 0.5x 3 = 0.75 x:x: u(x): u(0)=a = u 0 u(0.25)=u 1 u(0.5)=u 2 u(0.75)=u 3 u(1)=b = u 4 Note that it is impossible to find u(x) for all values of x. Instead we: Create a “grid” with n points. Then find an approximate to u at these grid points. If we want a better approximation, we increase n. Interval: Note: We know u 0 and u 4. We know a relationship between the u i via the finite difference equations. We need to find u i for i=1, 2, 3. CSCI 317 Mike Heroux

9 What We Know CSCI 317 Mike Heroux

10 Write in Matrix Form This is a linear system with 3 equations and three unknowns. We can easily solve. Note that n=5 generates this 3 equation system. In general, for n grid points on [0, 1], we will have n-2 equations and unknowns. CSCI 317 Mike Heroux

11 General Form of 1D Finite Difference Matrix CSCI 317 Mike Heroux

12 A View of More Realistic Problems The previous example is very simple. But basic principles apply to more complex problems. Finite difference approximations exist for any differential equation. Leads to far more complex matrix patterns. For example… CSCI 317 Mike Heroux

13 “Tapir” Matrix (John Gilbert) CSCI 317 Mike Heroux

14 Corresponding Mesh CSCI 317 Mike Heroux

15 Sparse Linear Systems: Problem Definition A frequent requirement for scientific and engineering computing is to solve: Ax = b where A is a known large (sparse) matrix a linear operator, b is a known vector, x is an unknown vector. NOTE: We are using x differently than before. Previous x: Points in the interval [0, 1]. New x:Vector of u values. Goal: Find x. Method: We will look at two different methods: Jacobi and Gauss-Seidel. CSCI 317 Mike Heroux

16 Iterative Methods Given an initial guess for x, called x (0), (x (0) = 0 is acceptable) compute a sequence x (k), k = 1,2, … such that each x (k) is “closer” to x. Definition of “close”: –Suppose x (k) = x exactly for some value of k. –Then r (k) = b – Ax (k) = 0 (the vector of all zeros). –And norm(r (k) ) = sqrt( ) = 0 (a number). –For any x (k), let r (k) = b – Ax (k) –If norm(r (k) ) = sqrt( ) is small (< 1.0E-6 say) then we say that x (k) is close to x. –The vector r is called the residual vector. CSCI 317 Mike Heroux

17 Linear Conjugate Gradient Methods scalar product defined by vector space vector-vector operations linear operator applications Scalar operations Types of operationsTypes of objects Linear Conjugate Gradient Algorithm CSCI 317 Mike Heroux

18 General Sparse Matrix Example: a a 16 0 a 22 a A = 0 a 32 a 33 0 a a a 53 0 a 55 a 56 a a 65 a 66

CSCI 317 Mike Heroux19 Compressed Row Storage (CRS) Format Idea: Create 3 length m arrays of pointers 1 length m array of ints : double ** values = new double *[m]; double** diagonals = new double*[m]; int ** indices = new int*[m]; int * numEntries = new int[m];

CSCI 317 Mike Heroux20 Compressed Row Storage (CRS) Format Fill arrays as follows: for (i=0; i<m; i++) { // for each row numEntries[i] = numRowEntries, number of nonzero entries in row i. values[i] = new double[numRowEntries]; indices[i] = new int[numRowEntries]; for (j=0; j<numRowEntries; j++) { // for each entry in row i values[i][j] = value of j th row entry. indices[i][j] = column index of j th row entry. if (i==column index) diagonal[i] = &(values[i][j]); }

CSCI 317 Mike Heroux21 CRS Example (diagonal omitted)

CSCI 317 Mike Heroux22 Matrix, Scalar-Matrix and Matrix-Vector Operations Given vectors w, x and y, scalars alpha and beta and matrices A and B we define: matrix trace: –alpha = tr(A) α = a 11 + a a nn matrix scaling: –B = alpha * A b ij = α a ij matrix-vector multiplication (with update): –w = alpha * A * x + beta * y w i = α (a i1 x 1 + a i2 x a in x n ) + βy i

CSCI 317 Mike Heroux23 Common operations (See your notes) Consider the following operations: –Matrix trace. –Matrix scaling. –Matrix-vector product. Write mathematically and in C/C++.

CSCI 317 Mike Heroux24 Complexity (arithmetic) complexity (defn) The total number of arithmetic operations performed using a given algorithm. –Often a function of one or more parameters. parallel complexity (defn) The number parallel operations performed assuming an infinite number of processors.

CSCI 317 Mike Heroux25 Complexity Examples (See your notes) What is the complexity of: –Sparse Matrix trace? –Sparse Matrix scaling. –Sparse Matrix-vector product? What is the parallel complexity of these operations?