Presentation is loading. Please wait.

Presentation is loading. Please wait.

Stencil Pattern ITCS 4/5145 Parallel computing, UNC-Charlotte, B. Wilkinson Jan 28, 2016 1.

Similar presentations


Presentation on theme: "Stencil Pattern ITCS 4/5145 Parallel computing, UNC-Charlotte, B. Wilkinson Jan 28, 2016 1."— Presentation transcript:

1 Stencil Pattern ITCS 4/5145 Parallel computing, UNC-Charlotte, B. Wilkinson Jan 28, 2016 1

2 Stencil Pattern Examples
A stencil describes a 2- or 3- dimensional layout of processes, with each process able to communicate only with its neighbors. Appears in simulating many real-life situations. Examples Solving partial differential equations using discretized methods, which may be for: Modeling engineering structures Weather forecasting, see intro to course slides1a-1 Particle dynamics simulations Modeling chemical and biological structures 2

3 Stencil pattern On each iteration, each node communicates
with neighbors to get stored computed values Two-way connection Compute node Source/sink 3

4 (Iterative synchronous) stencil pattern
Often globally synchronous and iterative: Processes compute and communicate only with their neighbors, exchanging results Check termination condition Repeat Stop 4

5 Solving Laplace’s Equation
Application example of stencil pattern Solving Laplace’s Equation Solve for f over the two-dimensional x-y space. For computer solution, finite difference methods appropriate Two-dimensional solution space “discretized” into large number of solution points.

6 Finite Difference Method

7 Point to the left Point to the right Point below Point above Average of the 4 neighboring points

8 Known as a Jacobi iteration – each value is computed from the values of the previous iteration.

9 Heat Distribution Problem -- Steady State Heat Equation
Finding the static distribution of heat in a space (which is Laplace’s equation). Suppose a 2 dimensional space: An area has known temperatures along each of its borders (boundary conditions). Find the temperature distribution within. Each point taken to be the average of the four neighboring points There are points at the boundaries with fixed values. 9

10 Jacobi Iteration int main() { int i, j; double A[N][M], B[N][M]; … // A is initialized with data somehow for (time = 0; time < MAX_ITERATION; time++) { for (i = 1; i < N-1; i++) for (j = 1; j < M-1; j++) B[i][j] = (A[i-1][j] + A[i+1][j] + A[i][j-1] + A[i][j+1]) * 0.25; A[i][j] = B[i][j]; } ... Skip the boundary values Newly computed values are placed in a new array. Multiplying by 0.25 is faster than dividing by 4.0 Then copied back to the original.

11 Improved Jacobi Iteration
int main() { int i, j, current, next; double A[2][N][M]; current = 0; next = 1; … // A[current][N][M] is initialized with data somehow for (time = 0; time < MAX_ITERATION; time++) { for (i = 1; i < N-1; i++) for (j = 1; j < M-1; j++) A[next][i][j] = (A[current][i-1][j] + A[current][i+1][j] + A[current][i][j-1] + A[current][i][j+1]) * 0.25; current = next; // swap values of current and next next = 1 - current; } // Final result is in A[current] ... Add another dimension of size 2 to A. A[0] is old A and A[1] is old B This avoids copying values back into the original array. We toggle between copies of the array

12 Application Example A room has four walls and a fireplace. Temperature of wall is 20°C, and temperature of fireplace is 100°C. Write a parallel program using Jacobi iteration to compute the temperature inside the room and plot (preferably in color) temperature contours at 10°C intervals. 12

13 Sample student output 13

14 Questions


Download ppt "Stencil Pattern ITCS 4/5145 Parallel computing, UNC-Charlotte, B. Wilkinson Jan 28, 2016 1."

Similar presentations


Ads by Google