Chapter 17 C-implementation PAP’ = LDL’ Speaker: Lung-Sheng Chien Reference: [1] H. M. Deitel, P. J. Deitel, C++ How to Program 5-th edition.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Chapter 7: Arrays In this chapter, you will learn about
Introduction to arrays
Block LU Factorization Lecture 24 MA471 Fall 2003.
Chapter 4 Systems of Linear Equations; Matrices
F UNCTION O VERLOADING Chapter 5 Department of CSE, BUET 1.
Chapter 11 Gaussian Elimination (I)
Chapter 13 Gaussian Elimination (III) Bunch-Parlett diagonal pivoting
Matrices CSE, POSTECH.
MATH 685/ CSI 700/ OR 682 Lecture Notes
Scientific Computing Linear Systems – Gaussian Elimination.
Systems of Linear Equations
Chapter 9 Imperative and object-oriented languages 1.
Speaker: Lung-Sheng Chien
Chapter 2, Linear Systems, Mainly LU Decomposition.
1cs542g-term Notes  Assignment 1 is out (due October 5)  Matrix storage: usually column-major.
Passing Parameters. Different Techniques Pass by Value Pass by Reference Pass by Result Pass by Value-Result Pass by Name.
Chapter 15 C-implementation PA = LU Speaker: Lung-Sheng Chien.
Chapter 16 high precision package Speaker: Lung-Sheng Chien Reference: high precision package in and
Main Index Contents 11 Main Index Contents Pointer Illustration Pointer Illustration Vertical / Horizontal View. Vertical / Horizontal View. Data Addresses.
Main Index Contents 11 Main Index Contents Pointer Illustration Pointer Illustration Vertical / Horizontal View. Vertical / Horizontal View. Data Addresses.
Chapter 8 Arrays and Strings
Mujahed AlDhaifallah (Term 342) Read Chapter 9 of the textbook
1 CMSC 132: Object-Oriented Programming II Java Constructs Department of Computer Science University of Maryland, College Park.
Chapter 12 Gaussian Elimination (II) Speaker: Lung-Sheng Chien Reference book: David Kincaid, Numerical Analysis Reference lecture note: Wen-wei Lin, chapter.
MATRICES. Matrices A matrix is a rectangular array of objects (usually numbers) arranged in m horizontal rows and n vertical columns. A matrix with m.
CE 311 K - Introduction to Computer Methods Daene C. McKinney
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
Pointer Data Type and Pointer Variables
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
CSEB114: PRINCIPLE OF PROGRAMMING Chapter 8: Arrays.
Chapter 8 Arrays and Strings
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
 6.2 Pivoting Strategies 1/17 Chapter 6 Direct Methods for Solving Linear Systems -- Pivoting Strategies Example: Solve the linear system using 4-digit.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Direct Methods for Sparse Linear Systems Lecture 4 Alessandra Nardi Thanks to Prof. Jacob White, Suvranu De, Deepak Ramaswamy, Michal Rewienski, and Karen.
CSC 8505 Compiler Construction Runtime Environments.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – August 23, 2001.
Assembly - Arrays תרגול 7 מערכים.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Linear Systems Dinesh A.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Chapter 1 C++ Templates (Sections 1.6, 1.7). Templates Type-independent patterns that can work with multiple data types. Function Templates  These define.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review 2.
Gaoal of Chapter 2 To develop direct or iterative methods to solve linear systems Useful Words upper/lower triangular; back/forward substitution; coefficient;
1 Chapter 1 C++ Templates Readings: Sections 1.6 and 1.7.
1 Data Structures and Algorithms Outline This topic will describe: –The concrete data structures that can be used to store information –The basic forms.
Two dimensional arrays A two dimensional m x n array A is a collection of m. n elements such that each element is specified by a pair of integers (such.
Pointer Variables A pointer is a variable that contains a memory address The address is commonly the location of another variable in memory This pointer.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
LDL’ = PAP’ Speaker : 高崇閔. Program structure[1] Use high precision Main function 1_1 pivot do 1_1 pivot in case_1 to case_3 main.cpp test_matrix.cpp test.
Learners Support Publications Constructors and Destructors.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Templates Linked Lists.
Constructors and Destructors
Chapter 7: User-Defined Functions II
Chapter 2, Linear Systems, Mainly LU Decomposition
Linear Systems, Mainly LU Decomposition
Report Implement PAP’ = LDL’ and linear solver in C/C++ ( ok )
Constructor & Destructor
User-Defined Functions
Constructors and Destructors
Pointer Variables A pointer is a variable that contains a memory address The address is commonly the location of another variable in memory This pointer.
Presentation transcript:

Chapter 17 C-implementation PAP’ = LDL’ Speaker: Lung-Sheng Chien Reference: [1] H. M. Deitel, P. J. Deitel, C++ How to Program 5-th edition

OutLine Data structure of lower triangle matrix Function overloading in C++ Implementation of PAP’ =LDL’

Logical index : 2D row-major based col-major based row-major versus col-major We choose col-major representation

column-major based column-major: method 1 (square-matrix based) is useless 1 2 is forbidden 3 Keep properties 4 is valid only for ? 5

column-major based column-major: method 2 (triangle-matrix based) is useless 1 2 is forbidden 3 Keep properties 4 Index rule is more complicated

Data structure of matrix and its method lowerTriangleMatrix.h The same name as those in matrix.h A is symmetric, but we only store lower triangle part method 1

Constructor [1] lowerTriangleMatrix.cpp

Constructor [2] lowerTriangleMatrix.cpp When matrix A is symmetric, it must be square and we store lower triangle part of A, Difference from full matrix is 34 Index rule

destructor lowerTriangleMatrix.cpp free pointer array 3 free lowerTriangleMatrix handler Pointer arithmetic, remember to do casting

Input/Output lowerTriangleMatrix.cpp No matter what A is symmetric or not, we only report lower triangle part

Simple driver main.cpp Advantage of method 1: index rule is the same as that of full matrix, one only notices is valid only for Question: how can we verify is valid only for automatically?

duplicate of a lower triangle matrix lowerTriangleMatrix.cpp Question: This copy routine is different from that in matrix.cpp, which one is better?

Matrix norm [1] lowerTriangleMatrix.cpp “norm_sym” and “norm_nonsym” are private, means that user don’t need to know them and we declare them in lowerTriangleMatrix.cpp, NOT in lowerTriangleMatrix.h which user looks at

lowerTriangleMatrix.cpp Matrix norm [2] symmetric : norm_sym nonsymmetric : norm_nonsym

y = Ax only A is lower trianlge matrix (either symmetric or non-symmetric), x and y are full matrices.

OutLine Data structure of lower triangle matrix Function overloading in C++ Implementation of PAP’ =LDL’

Function overloading in C++ C++ enables several functions fo the same name to be defined, as long as these functions have different sets of parameter (1) parameter type (2) number of parameters (3) order of parameter type when an overloaded function is called, the C++ compiler selects the proper function by examining (1) number (2) types (3) order of the arguments in the call. the only one function which cannot be overloaded is "main" since it is the entry point. Advantage: overloading functions that perform closely related tasks can make programs more readable

void zeros( matrixHandler *, integer m, integer n, orderVar sel ) ; void zeros( int_matrixHandler *, integer m, integer n, orderVar sel ) ; void zeros( lowerTriangleMatrixHandler*, integer m, integer n, orderVar sel, int isSym ) ; Function overloading of matrix data type constructor 1 void dealloc( matrixHandler Ah ) ; void dealloc( int_matrixHandler Ah ) ; void dealloc( lowerTriangleMatrixHandler Ah ) ; destructor 2 void disp( matrixHandler Ah, ostream& out ) ; void disp( int_matrixHandler Ah, ostream& out ) ; void disp( lowerTriangleMatrixHandler Ah, ostream& out ) ; I/O 3 doublereal norm( matrixHandler Ah, matrix_keyword p ) ; doublereal norm( lowerTriangleMatrixHandler Ah, matrix_keyword p ) ; metric 4

OutLine Data structure of lower triangle matrix Function overloading in C++ Implementation of PAP’ =LDL’

Algorithm ( PAP’ = LDL’, partial pivot ) [1] Given symmetric indefinite matrix, construct initial lower triangle matrix use permutation vector to record permutation matrix let, and verification

we have compute update original matrix combines all lower triangle matrix and store in while, where Algorithm ( PAP’ = LDL’, partial pivot ) [2] (1) we store lower triangle matrix L and block diagonal matrix D into storage of matrix A (2) permutation matrix P and pivot sequence pivot are of type int_matrix

Algorithm ( PAP’ = LDL’, partial pivot ) [3] compute 1 Case 1:pivotno interchange do 1x1 pivot : 2 then Technique problem: if we store L into memory block of A, then will overwritesuch that fails. We use a temporary storage

Algorithm ( PAP’ = LDL’, partial pivot ) [4] do 1x1 pivot : We must update lower triangle part of matrix A only.

Algorithm ( PAP’ = LDL’, partial pivot ) [5] 3 and When case 1 is not satisfied, we compute maximum of off-diagonal elements in column r

Algorithm ( PAP’ = LDL’, partial pivot ) [6] 4 Case 2: pivot no interchange do 1x1 pivot : 5 then 6 and The same as code in case 1

Algorithm ( PAP’ = LDL’, partial pivot ) [7] Case 3:pivotdo interchange define permutationto do symmetric permutation 7 To compute, we only update lower triangle of

Algorithm ( PAP’ = LDL’, partial pivot ) [8] then

Algorithm ( PAP’ = LDL’, partial pivot ) [9] To compute We only update lower triangle matrix 9 then we store lower triangle matrix L into storage of matrix A

Algorithm ( PAP’ = LDL’, partial pivot ) [10] do 1x1 pivot : 10 then 11 and The same as code in case 1 Case 4:pivotdo interchange define permutation, changeto 12

Algorithm ( PAP’ = LDL’, partial pivot ) [11] To compute, we only update lower triangle of do interchange row/col 13

Algorithm ( PAP’ = LDL’, partial pivot ) [12] then 14 do interchange row do 2x2 pivot : 15 then

Algorithm ( PAP’ = LDL’, partial pivot ) [13] do 2x2 pivot :

Algorithm ( PAP’ = LDL’, partial pivot ) [14] 16 and endwhile

Example: partial pivot Bunch-Kaufman (partial pivot)

driver for example [1] main.cpp Test example We need full matrix representation ofof linear system and permutation matrix P, pivot sequence pivot

driver for example [2]

Report Implement PAP’ = LDL’ and linear solver in C/C++ describe program structure How to verify your program Comparison with MATLAB implementation Memory usage (do you need extra storage?) Speedup strategy