









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!










Jingke Li
Portland State University
Jingke Li (Portland State University) CS 415/515 Numerical Algorithms 1 / 30
Compute: y = Ax
A is an n × n matrix, x, y are n × 1 vectors
Sequential Algorithm:
procedure MAT_VECT(A,x,y) begin for i:=0 to n-1 do y[i] := 0; for j:=0 to n-1 do y[i] := y[i] + A[i,j] * x[j]; endfor endfor end MAT_VECT
Sequential Complexity: T = O(n^2 )
Jingke Li (Portland State University) CS 415/515 Numerical Algorithms 3 / 30
Parallel Complexity: Tp ≈ n
2 p +^ ts^ log^ p^ +^ tw^ n
Jingke Li (Portland State University) CS 415/515 Numerical Algorithms 7 / 30
Jingke Li (Portland State University) CS 415/515 Numerical Algorithms 9 / 30
p ×
p 2D topology.
p iterations of the following steps:
A 00 A 11 A 22 A 33
A 00 A 11 A 22 A 33
A 00 A 00 A 00 A 11 A 11 A 11 A 22 A 22 A 22 A 33 A 33 A 33
B 11
B 01 B 02 B 03 B 10 B 12 B 13 B 20 B 21 B 22 B 23 B 30 B 31 B 32 B 33
B 00 B 11
B 01 B 02 B 03
B 10 B 12 B 13 B 20 B 21 B 22 B 23 B 30 B 31 B 32 B 33 B 00
(a)
(c)
A 00 B 00 (b)
A 00 A 00 A 00
A 22
A 11
A 33
A 11 A 11 A 11 A 22 A 22 A 22 A 33 A 33 A 33
B 01 B 02 B 03 B 10 B 20 B 30
B 11 B 12 B 13 B 21 B 22 B 23 B 31 B 32 B 33
Complexity: Tp ≈ n
3 p +^ ts^ log^ p^ + 2tw √n^2 p
Jingke Li (Portland State University) CS 415/515 Numerical Algorithms 13 / 30
For multiplying two n × n matrices:
Complexity: Tp ≈ n 3 p +^ ts^ log^ p^ +^ tw^
n^2 p^2 /^3 log p
The operations are:
Jingke Li (Portland State University) CS 415/515 Numerical Algorithms 15 / 30
2.0 x1 + 1.0 x2 + 3.0 x3 + 4.0 x4 = 29. 5.0 x1 + 2.0 x2 + 0.0 x3 + 1.0 x4 = 13. 1.0 x1 + 0.0 x2 + 0.0 x3 + 1.0 x4 = 5. 3.0 x1 + 1.0 x2 + 1.0 x3 + 0.0 x4 = 8.
=> 2.0 x1 + 1.0 x2 + 3.0 x3 + 4.0 x4 = 29.
=> x1 = 1, x2 =2, x3 = 3, x4 = 4
The Naive algorithm runs into trouble when a pivot element is zero. (In fact, it runs into trouble whenever a pivot element is “small.”) Partial-Pivoting — Search the column below the diagonal and find the largest element in absolute magnitude; perform row interchange to bring this element to the diagonal. An example:
Initial: => Pivoting: 2.0 1.0 3.0 4.0 29.0 5.0 2.0 0.0 1.0 13. 1.0 0.0 0.0 1.0 5.0 1.0 0.0 0.0 1.0 5. 3.0 1.0 1.0 0.0 8.0 3.0 1.0 1.0 0.0 8. 5.0 2.0 0.0 1.0 13.0 2.0 1.0 3.0 4.0 29.
=> Elimination: 5.0 2.0 0.0 1.0 13. 0.0 -0.4 0.0 0.8 2. 0.0 -0.2 1.0 -0.6 0. 0.0 0.2 3.0 3.6 23.
Continue for other columns ...
Jingke Li (Portland State University) CS 415/515 Numerical Algorithms 19 / 30
Complexity:
Tp =
n(n − 1) + ts n log n +
tw n(n − 1) log n
Jingke Li (Portland State University) CS 415/515 Numerical Algorithms 21 / 30
Problems with the Simple Algorithm — The partition is fine-grained, and towards the end, the active region of the matrix is shrinking towards lower right corner; implies that processes fall idle.
Solutions: block and cyclic partitions.
Jingke Li (Portland State University) CS 415/515 Numerical Algorithms 25 / 30
Laplace Equations:
φi ,j =
(φi +1,j + φi − 1 ,j + φi ,j+1 + φi ,j− 1 ) 0 < i, j < n
This is a linear system, and can be made into Ax = b form — Let I = i · n + j, then the equations become:
φI +n + φI −n + φI +1 + φI − 1 − 4 φI = 0 0 < I < n^2
In matrix form:
-4 1 0 0 ... 1 0 0 ... 1 -4 1 0 ... 0 1 0 ... 0 1 -4 1 ... 0 0 1 ... 0 0 1 - ... ... ... ... ... ... ... ... ... ... ... 1 0 0 .. ... ... ... ... 0 1 0 .. ... ... ... ... ... ... ... ... ... ... ...
The matrix is very large, yet sparse.
Better Approach — Directly solve the system on the original domain.
Parallel Jacobi Algorithm: (Assume an n × n mesh and p processors.)
n √ p
of the mesh.
Problems —
Jingke Li (Portland State University) CS 415/515 Numerical Algorithms 27 / 30
begin ... // initialize boundary and inner point values do diff = 0 for i = 1 to n do for j = 1 to n do newx[i][j] = (x[i-1][j] + x[i][j-1]