-
Notifications
You must be signed in to change notification settings - Fork 0
/
omp_ocean.c
40 lines (37 loc) · 1.17 KB
/
omp_ocean.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <omp.h>
void ocean (int **grid[2], int xdim, int ydim, int timesteps)
{
/********************************************************
* algorithm
*
* Two grids are passed in through the grid argument.
* Each grid itself is an int**, which is a pointer to
* an array of pointers (see the initialization code).
*
* Iterate over the grid[0], performing the Ocean
* algorithm (described in wiki). Write the result to
* the other grid. Then, swap the grids for the next
* iteration.
******************************************************/
int i,j,temp;
int **temp_grid;
while (timesteps-- >= 0)
{
#pragma omp parallel for shared(grid, xdim, ydim) private(i,j) schedule(static,16)
for (i = 1; i < xdim - 1; i++)
{
//printf("Taken for computation\n");
for (j = 1; j < ydim - 1 ; j++)
{
//calculating the value and storing it in the new grid
grid[1][i][j] = 0.2 * (grid[0][i][j] + grid[0][i][j-1] + grid[0][i-1][j] + grid[0][i][j+1] + grid[0][i+1][j]);
}
//printf("Done computation\n");
}
//swap the grid now
temp_grid = grid[0];
grid[0] = grid[1];
grid[1] = temp_grid;
}
}