Presentation is loading. Please wait.

Presentation is loading. Please wait.

Notes on Assignment 3 OpenMP Stencil Pattern

Similar presentations


Presentation on theme: "Notes on Assignment 3 OpenMP Stencil Pattern"— Presentation transcript:

1 Notes on Assignment 3 OpenMP Stencil Pattern
ITCS 4/5145 Parallel computing, UNC-Charlotte, B. Wilkinson Feb 25, Assign3Notes.ppt 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 Finite Difference Method
Example application Finite Difference Method Find values of f(x,y) in this area, given boundary conditions. Divide space into an array of solution points

6 Example (Static) heat distribution
Static heat equation (Laplace’s equation):

7 Value of f(x,y) given by average of four neighboring point
(left, right, up, down).

8 Sequential Code Assume N x N array of points, h[i][j], including fixed boundary points. Using a fixed number of iterations for (iteration = 0; iteration < limit; iteration++) { for (i = 1; i < n-1; i++) for (j = 1; j < n-1; j++) g[i][j] = 0.25*(h[i-1][j]+h[i+1][j]+h[i][j-1]+h[i][j+1]); for (i = 1; i < n; i++) /* update points */ for (j = 1; j < n; j++) h[i][j] = g[i][j]; } 1 to n-2, skip boundary edges (values 0 and n-1) Newly computed values are placed in a new array. Then copied back to the original. Called a Jacobi iteration when next iteration use only last iteration values Multiplying by 0.25 faster than dividing by 4 6b.8

9 Improved Jacobi Iteration
int main() { int i, j, current, next; double A[2][N][M]; // A[0] is initialized with data somehow and duplicated into A[1] current = 0; next = (current + 1) % 2; 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; } // Final result is in A[current] ... Add another dimension of size 2 to A. A[0] is h and A[1] is g, alternating. We toggle between copies of the array Avoids copying values back into original array.

10 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. 10

11 Sample student output 11

12 Adding heat sources One can add heat sources inside the room such as humans (stationary). Just make these points of fixed values in array Similar problems -- heat distribution on a printed circuit board.

13 Extra credit Dynamic Heat Equation

14

15 Possible code for (int t=t0; t<t1; t++) for (int x=1; x<M; x++)
for (int y=1; y<L; y++) F(t+1,x,y) = F(t, x, y) + CX * (F(t,x-1,y) + F(t,x+1,y) -2*F(t,x,y)) + CY * (F(t,x,y-1) + F(t,x,y+1) -2*F(t,x,y)); where:CX =α∆t/∆x2, and CY = α∆t/∆y2 See

16 Questions


Download ppt "Notes on Assignment 3 OpenMP Stencil Pattern"

Similar presentations


Ads by Google