


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
a0,0 a0, a1,
a0, m − 2
a n −1,
a0, m − 1
a n −2, a n −1, m − 2 a n −1, m − 1
a n −2, m − 1
a1,1 a1, m − 2 a1, m − 1
a n −2,1 a n −2, m - a n −1,
Row
Column
Figure 10.1 An n × m matrix.
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
Involves adding corresponding elements of each matrix to form the result matrix.
Given the elements of A as ai , j and the elements of B as bi , j , each element of C is computed as ci , j = ai , j + bi , j (0 ≤ i < n , 0 ≤ j < m )
Multiplication of two matrices, A and B , produces the matrix C whose elements, ci , j ( ≤ i < n , 0 ≤ j < m ), are computed as follows:
where A is an n × l matrix and B is an l × m matrix.
ci , j ai,kbk,j k = 0
l – 1
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
A system of linear equations can be written in matrix form Ax = b
Matrix A holds the a constants x is a vector of the unknowns b is a vector of the b constants.
Assume throughout that the matrices are square ( n × n matrices). The sequential code to compute A × B could simply be for (i = 0; i < n; i++) for (j = 0; j < n; j++) { c[i][j] = 0; for (k = 0; k < n; k++) c[i][j] = c[i][j] + a[i][k] * b[k][j]; } This algorithm requires n^3 multiplications and n^3 additions, leading to a sequential time complexity of Ο( n^3 ).
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
With n processors (and n × n matrices): Can obtain:
Ο(log n ) lower bound for parallel matrix multiplication.
Suppose the matrix is divided into s^2 submatrices. Each submatrix has n / s × n / s elements. Using the notation Ap,q as the submatrix in submatrix row p and submatrix column q :
for (p = 0; p < s; p++) for (q = 0; q < s; q++) { Cp,q = 0; / clear elements of submatrix / for (r = 0; r < m; r++) / submatrix multiplication and / Cp,q = Cp,q + Ap,r * Br,q;/ add to accumulating submatrix / } The line Cp,q = Cp,q + Ap,r * Br,q; means multiply submatrix Ap,r and Br,q using matrix multiplication and add to submatrix Cp,q using matrix addition. Known as block matrix multiplication.
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
b[][j]
Row i a[i][]
Column j
c[i][j]
Processor Pi , j
Figure 10.6 Direct implementation of matrix multiplication.
One processor to compute each element of C - n^2 processors would be needed. One row of elements of A and one column of elements of B needed. Some of same elements sent to more than one processor. Can use submatrices.
Assuming n × n matrices and not submatrices.
With separate messages to each of the n^2 slave processors: t comm = n^2 ( t startup + 2 nt data) + n^2 ( t startup + t data) = n^2 (2 t startup + (2 n + 1) t data) A broadcast along a single bus would yield t comm = ( t startup + n^2 t data) + n^2 ( t startup + t data) Dominant time now is in returning the results.
Each slave performs in parallel n multiplications and n additions; i.e., t comp = 2 n
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
Figure 10.7 Accumulation using a tree construction.
Using tree construction n numbers can be added in log n steps using n processors:
Computational time complexity of Ο(log n ) using n^3 processors.
App
Aqp Aqq
Apq
i j i
j
Bpp
Bqp Bqq
Bpq Cpp
Cqp Cqq
Cpq
P 0 P 1 P 2 P 3 P 0 + P 1
P 4 + P 5 P 6 + P 7
P 2 + P 3
P 4 P 5 P 6 P 7
Figure 10.8 Submatrix multiplication and summation.
Apply same algorithm on each submatrix recursivly.
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
Figure 10.9 Movement of A and B elements.
j
i
Pi , j
Figure 10.10 Step 2 — Alignment of elements of A and B.
j
i
bi +j, j
ai , j + i
i places
j places
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
Figure 10.11 Step 4 — One-place shift of elements of A and B.
j
i
Pi , j
Given s^2 submatrices, each of size m × m , the initial alignment requires a maximum of s − 1 shift (communication) operations. After that, there will be s − 1 shift operations. Each shift operation involves m × m elements. t comm = 2( s − 1)( t startup + m^2 t data) or a communication time complexity of Ο( sm^2 ) or Ο( mn ).
Each submatrix multiplication requires m^3 multiplications and m^3 additions. Hence, with s − 1 shifts, t comp = 2 sm^3 = 2 m^2 n or a computational time complexity of Ο( m^2 n ).
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
c 0
c 1
c 2
c 3
b 3 b 2 b 1 b 0
a 0,3 a 0,2 a 0,1 a 0,
a 3,3 a 3,2 a 3,1 a 3,
a 2,3 a 2,2 a 2,1 a 2,
a 1,3 a 1,2 a 1,1 a 1,
Figure 10.13 Matrix-vector multiplication using a systolic array.
Pumping action
an −1,0 x 0 + an −1,1 x 1 + an −1,2 x 2 … + an −1, n − 1 xn − 1 = bn − 1 . . . a 2,0 x 0 + a 2,1 x 1 + a 2,2 x 2 … + a 2, n − 1 xn − 1 = b 2 a 1,0 x 0 + a 1,1 x 1 + a 1,2 x 2 … + a 1, n − 1 xn − 1 = b 1 a 0,0 x 0 + a 0,1 x 1 + a 0,2 x 2 … + a 0, n − 1 xn − 1 = b 0
which, in matrix form, is Ax = b Objective of solving this system of equations is to find values for the unknowns, x 0 , x 1 , …, xn − 1 , given values for a 0,0, a 0,1, …, an −1, n − 1 , and b 0 , …, bn.
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
Objective is to convert the general system of linear equations into a triangular system of equations which can then be solved by Back Substitution.
Uses the characteristic of linear equations that any row can be replaced by that row added to another row multiplied by a constant.
Starts at the first row and works toward the bottom row. At the i th row, each row j below the i th row is replaced by row j + (row i ) (− aj,i / ai,i ). The constant used for row j is − aj,i / ai,i. Has the effect of making all the elements in the i th column below the i th row zero because
a (^) j i , a (^) j i , ai i , – a^ a^ j i , i i ,
Cleared Already to zero cleared to zero
Row i
Column i
Column
Row
Figure 10.14 Gaussian elimination.
Row j
Step through
aji
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
Already
Row i
Column
Row
Figure 10.15 Broadcast in parallel implementation of Gaussian elimination.
Broadcast i th row
(including b[i])
cleared to zero
n − 1 broadcasts performed sequentially. i th broadcast contains n − i + 1 elements.
or a time complexity of Ο( n^2 ).
After row broadcast, each processor Pj beyond broadcast processor Pi will compute its multiplier, and operate upon n − j + 2 elements of its row. Ignoring the computation of the multiplier, there are n − j + 2 multiplications and n − j + 2 subtractions.
Efficiency will be relatively low because all the processors before the processor holding row i do not participate in the computation again.
t comm ( t (^) startup +( n – i + 1 ) t data) i = 0
n – 2
t comp 2 ( n – j + 2 ) j = 1
n – 1
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
Broadcast
Figure 10.16 Pipeline implementation of Gaussian elimination.
P 0 P 1 P 2 Pn − 1
rows
Row
0
n / p
2 n / p
3 n / p
Figure 10.17 Strip partitioning.
Row
Processors do not participate in computation after their last row is processed.
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
Objective is to solve for f over the two-dimensional space having coordinates x and y.
For a computer solution, finite difference methods are appropriate
Two-dimensional solution space is “discretized” into a large number of solution points.
∂^2 f ∂ x^2
-------- f
∂ y^2
f ( x , y )
Solution space
y x
Figure 10.19 Finite difference method.
Slides for Parallel Programming: Techniques and Applications using Networked Workstations and Parallel Computers Barry Wilkinson and Michael Allen Prentice Hall, 1999. All rights reserved.
If the distance between the points in the x and y directions, ∆, is made small enough:
Substituting into Laplace’s equation, we get
Rearranging, we get
The formula can be rewritten as an iterative formula:
f k ( x , y ) is value obtained from k th iteration, f k −^1 ( x , y ) is value obtained from ( k − 1)th iteration.
∂^2 f ∂ x^2
≈^ ------^ [ f ( x +∆ , y ) – 2 f ( x y , )+ f ( x – ∆, y )]
∂^2 f ∂ y^2
≈^ ------^ [ f ( x y , +∆) – 2 f ( x y , )+ f ( x y , – ∆)]
------ [ f ( x +∆ , y ) + f ( x – ∆, y ) + f ( x y , +∆) + f ( x y , – ∆) – 4 f ( x y , )] = 0
f ( x y , ) = [-----------------------------------------------------------------------------------------------------------------------------------^ f^ (^ x^ – ∆^ , y )^ +^ f^ (^ x y ,^ – ∆)^ + 4 f^ (^ x^ +^ ∆, y )^ + f^ (^ x y ,^ +∆)]-
f k^ ( x y , ) f^ [ k^ –^1 ( x – ∆, y ) + f k^ –^1 ( x y , – ∆) + f k^ –^1 ( x +∆ , y ) + f k^ –^1 ( x y , +∆)] = ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 4 -
x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9
x 31 x 32 x 33 x 34 x 35 x 36 x 37 x 38 x 39 x 41 x 42 x 43 x 44 x 45 x 46 x 47 x 48 x 49 x 51 x 52 x 53 x 54 x 55 x 56 x 57 x 58 x 59 x 61 x 62 x 63 x 64 x 65 x 66 x 67 x 68 x 69 x 71 x 72 x 73 x 74 x 75 x 76 x 77 x 78 x 79
x 11 x 12 x 13 x 14 x 15 x 16 x 17 x 18 x 19 x 21 x 22 x 23 x 24 x 25 x 26 x 27 x 28 x 29
x 81 x 82 x 83 x 84 x 85 x 86 x 87 x 88 x 89
x 60 x 70 x 80 x 90
x 40 x 50
x 30
x 20
x 10
x 91 x 92 x 93 x 94 x 95 x 96 x 97 x 98 x 99 x 100
Boundary points (see text)
Figure 10.20 Mesh of points numbered in natural order.