Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination...

28
CONJUGATE GRADIENT METHOD Monica Garika Chandana Guduru

Transcript of Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination...

Page 1: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

CONJUGATE GRADIENT METHOD

Monica GarikaChandana Guduru

Page 2: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

METHODS TO SOLVE LINEAR SYSTEMSDirect methods Gaussian elimination method LU method for factorization Simplex method of linear programmingIterative method Jacobi method Gauss-Seidel method Multi-grid method Conjugate gradient method

Page 3: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Conjugate Gradient methodThe CG is an algorithm for the numerical solution of particular system of linear equations

Ax=b. Where A is symmetric i.e., A = AT and positive

definite i.e.,

xT * A * x > 0 for all nonzero vectorsIf A is symmetric and positive definite then the

function Q(x) = ยฝ x`Ax โ€“ x`b + c

Page 4: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Conjugate gradient methodConjugate gradient method builds up a

solution x*โ‚ฌ Rn

in at most n steps in the absence of

round off errors.Considering round off errors more than n

steps may be needed to get a good approximation of exact solution x*

For sparse matrices a good approximation of exact solution can be achieved in less than n steps in also with round off errors.

Page 5: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

In oil reservoir simulation, The number of linear equations corresponds to the number of grids of a reservoirThe unknown vector x is the oil pressure of

reservoirEach element of the vector x is the oil

pressure of a specific grid of the reservoir

Practical Example

Page 6: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Linear System

Square matrixUnknown vector

(what we want to find)Known vector

Page 7: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Matrix Multiplication

Page 8: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Positive Definite Matrix

> 0[ x1 x2 โ€ฆ xn ]

Page 9: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

ProcedureFinding the initial guess for solution ๐‘ฅ0Generates successive approximations to ๐‘ฅ0Generates residualsSearching directions

Page 10: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

x0 = 0, r0 = b, p0 = r0

for k = 1, 2, 3, . . . ฮฑk = (rT

k-1rk-1) / (pTk-1Apk-1) step length

xk = xk-1 + ฮฑk pk-1 approximate solution

rk = rk-1 โ€“ ฮฑk Apk-1 residual

ฮฒk = (rTk rk) / (rT

k-1rk-1) improvement

pk = rk + ฮฒk pk-1 search direction

Conjugate gradient iteration

Page 11: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Iteration of conjugate gradient method is of the form

x(t) = x(t-1) + s(t)d(t) where, x(t) is function of old value of vector x s(t) is scalar step size x

d(t) is direction vector Before first iteration, values of x(0), d(0) and g(0) must be set

Page 12: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Steps to find conjugate gradient methodEvery iteration t calculates x(t) in four steps : Step 1: Compute the gradient g(t) = Ax(t-1) โ€“ b Step 2: Compute direction vector d(t) = - g(t) + [g(t)` g(t) / g(t-1)` g(t-1)] d(t-1) Step 3: Compute step size s(t) = [- d(t)` g(t)]/d(t)โ€™ A d(t)] Step 4: Compute new approximation of x x(t) = x(t-1) + s(t)d(t)

Page 13: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Sequential Algorithm1) ๐‘ฅ0 = 02) ๐‘Ÿ0 := ๐‘ โˆ’ ๐ด๐‘ฅ03) ๐‘0 := ๐‘Ÿ04) ๐‘˜ := 05) ๐พ๐‘š๐‘Ž๐‘ฅ := maximum number of iterations to be done6) if ๐‘˜ < ๐‘˜๐‘š๐‘Ž๐‘ฅ then perform 8 to 167) if ๐‘˜ = ๐‘˜๐‘š๐‘Ž๐‘ฅ then exit8) calculate ๐‘ฃ = ๐ด๐‘k

9) ฮฑk : = rkT rk/pT

k v

10) ๐‘ฅk+1:= ๐‘ฅk + ak pk

11) ๐‘Ÿk+1 := ๐‘Ÿk โˆ’ ak v

12) if ๐‘Ÿk+1 is sufficiently small then go to 16

end if13) ๐›ฝk :=( r T

k+1 r k+1)/(rTk ๐‘Ÿk)

14) ๐‘k+1 := ๐‘Ÿk+1 +ฮฒk pk

15) ๐‘˜ := ๐‘˜ + 116) ๐‘Ÿ๐‘’๐‘ ๐‘ข๐‘™๐‘ก = ๐‘ฅk+1

Page 14: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Complexity analysisTo Identify Data DependenciesTo identify eventual communicationsRequires large number of operationsAs number of equations increases complexity

also increases .

Page 15: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Why To Parallelize?Parallelizing conjugate gradient method is a

way to increase its performanceSaves memory because processors only store

the portions of the rows of a matrix A that contain non-zero elements.

It executes faster because of dividing a matrix into portions

Page 16: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

How to parallelize?For example , choose a row-wise block

striped decomposition of A and replicate all vectors

Multiplication of A and vector may be performed without any communication

But all-gather communication is needed to replicate the result vector

Overall time complexity of parallel algorithm is

ฮ˜(n^2 * w / p + nlogp)

Page 17: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Row wise Block Striped Decomposition of a Symmetrically Banded Matrix

( a) ( b )

Page 18: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Dependency Graph in CG

Page 19: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Algorithm of a Parallel CG on each Computing Worker (cw)1) Receive ๐‘๐‘ค๐‘Ÿ0,๐‘๐‘ค ๐ด,๐‘๐‘ค ๐‘ฅ02) ๐‘๐‘ค๐‘0 =๐‘๐‘ค ๐‘Ÿ03) ๐‘˜ := 04) ๐พ๐‘š๐‘Ž๐‘ฅ := maximum number of iterations to be done5) if ๐‘˜ < ๐‘˜๐‘š๐‘Ž๐‘ฅ then perform 8 to 166) if ๐‘˜ = ๐‘˜๐‘š๐‘Ž๐‘ฅ then exit7) ๐‘ฃ =๐‘๐‘ค ๐ด๐‘๐‘ค๐‘๐‘˜8) ๐‘๐‘ค๐‘๐›ผ๐‘˜9) ๐‘๐‘ค๐ท๐›ผ๐‘˜10) Send ๐‘๐›ผ๐‘˜,๐ท๐›ผ๐‘˜11) Receive ๐›ผ๐‘˜12) ๐‘ฅ๐‘˜+1 = ๐‘ฅ๐‘˜ + ๐›ผ๐‘˜๐‘๐‘˜13) Compute Partial Result of ๐‘Ÿ๐‘˜+1: ๐‘Ÿ๐‘˜+1 =๐‘Ÿ๐‘˜ โˆ’ ๐›ผ๐‘˜๐‘ฃ14) Send ๐‘ฅ๐‘˜+1, ๐‘Ÿ๐‘˜+115) Receive ๐‘ ๐‘–๐‘”๐‘›๐‘Ž๐‘™16) if ๐‘ ๐‘–๐‘”๐‘›๐‘Ž๐‘™ = ๐‘ ๐‘œ๐‘™๐‘ข๐‘ก๐‘–๐‘œ๐‘›๐‘Ÿ๐‘’๐‘Ž๐‘โ„Ž๐‘’๐‘‘ go to 2317) ๐‘๐‘ค๐‘๐›ฝ๐‘˜18) ๐‘๐‘ค๐ท๐›ฝ๐‘˜19) Send ๐‘๐‘ค๐‘๐›ฝ๐‘˜ , ๐‘๐‘ค๐ท๐›ฝ๐‘˜20) Receive ๐›ฝ๐‘˜21) ๐‘๐‘ค๐‘๐‘˜+1 =๐‘๐‘ค ๐‘Ÿ๐‘˜+1 + ๐›ฝ๐‘˜ ๐‘๐‘ค๐‘๐‘˜22) ๐‘˜ := ๐‘˜ + 123) Result reached

Page 20: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Speedup of Parallel CG on Grid Versus Sequential CG on Intel

Page 21: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Communication and Waiting Time of the Parallel CG on Grid

Page 22: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

We consider the difference between f at the solution x and any other vector p:

1)

21

) 21 1

) ( )2 2

1 1simplify) ( )

2 21 1

replace ) ( )2 2

1 1

2 2

t

t

t t

t t

t t t t

t t

i f

ii f

ii i f f

f f

f f

t

t

t t

t t

p p Ap b p c

x x Ax b x c

x p x Ax b x c p Ap b p c

x p x Ax b x p Ap b p

b x p x Ax x Ax p Ap x Ap

x Ax p A

1

2positive-definitess) ( ) 0

t

t

f f

p x Ap

x p A x p

x p

Page 23: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

Parallel Computation Designโ€“ Iterations of the conjugate gradient method can be executed only in sequence, so the most advisable approach is to parallelize the computations, that are carried out at each iteration The most time-consuming computations are the

multiplication of matrix A by the vectors x and dโ€“ Additional operations, that have the lower computational complexity order, are different vector processing procedures (inner product, addition and subtraction, multiplying by a scalar).While implementing the parallel conjugate gradient method, it can be used parallel algorithms of matrix-vector multiplication,

Parallel Computation Design

Page 24: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

โ€œPureโ€ Conjugate Gradient Method (Quadratic Case)

0 - Starting at any x0 define d0 = -g0 = b - Q x0 , where gk is the column vector of gradients of the objective function at point f(xk)

1 - Using dk , calculate the new point xk+1 = xk + ak dk , where

2 - Calculate the new conjugate gradient direction dk+1 , according to: dk+1 = - gk+1 + bk dk

where

T a k = -

gk dkdkTQdk

b k = gk+1TQd kdkTQd k

Page 25: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

ADVANTAGES Advantages:1) Gradient is always nonzero and linearly

independent of all previous direction vectors.2) Simple formula to determine the new

direction. Only slightly more complicated than steepest descent.

3) Process makes good progress because it is based on gradients.

Page 26: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

ADVANTAGESAttractive are the simple formulae for

updating the direction vector.Method is slightly more complicated than

steepest descent, but converges faster.Conjugate gradient method is an Indirect SolverUsed to solve large systemsRequires small amount of memoryIt doesnโ€™t require numerical linear algebra

Page 27: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

ConclusionConjugate gradient method is a linear solver

tool which is used in a wide range of engineering and sciences applications.

However, conjugate gradient has a complexity drawback due to the high number of arithmetic operations involved in matrix vector and vector-vector multiplications.

Our implementation reveals that despite the communication cost involved in a parallel CG, a performance improvement compared to a sequential algorithm is still possible.

Page 28: Monica Garika Chandana Guduru. METHODS TO SOLVE LINEAR SYSTEMS Direct methods Gaussian elimination method LU method for factorization Simplex method of.

ReferencesParallel and distributed computing systems by

Dimitri P. Bertsekas, John N.TsitsiklisParallel programming for multicore and cluster

systems by Thomas Rauber,Gudula RungerScientific computing . An introduction with parallel

computing by Gene Golub and James M.OrtegaParallel computing in C with Openmp and mpi by

Michael J.QuinnJonathon Richard Shewchuk, โ€An Introduction to

the Conjugate Gradient Method Without the Agonizing Painโ€, School of Computer Science, Carnegie Mellon University, Edition 1 1/4