Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stencil_calc OpenMP implementation #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openmp/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CC = cc
LD = cc
CC = mpicc
LD = mpicc
CPPFLAGS = -I.
CFLAGS = -O3 -fopenmp
LDFLAGS =
Expand Down
12 changes: 5 additions & 7 deletions openmp/stencil.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ void stencil_driver(int var, int cacl_stage)
void stencil_calc(int var, int stencil_in)
{
int i, j, k, in;
double sb, sm, sf, work[x_block_size+2][y_block_size+2][z_block_size+2];
double sb, sm, sf;
block *bp;

int tid;

if (stencil_in == 7) {
#pragma omp parallel default(shared) private(i, j, k, bp)
{
#pragma omp parallel for default(shared) private(i, j, k, bp)
for (in = 0; in < sorted_index[num_refine+1]; in++) {
bp = &blocks[sorted_list[in].n];
double work[x_block_size+2][y_block_size+2][z_block_size+2];
for (i = 1; i <= x_block_size; i++)
for (j = 1; j <= y_block_size; j++)
for (k = 1; k <= z_block_size; k++)
Expand All @@ -107,15 +107,14 @@ void stencil_calc(int var, int stencil_in)
for (k = 1; k <= z_block_size; k++)
bp->array[var][i][j][k] = work[i][j][k];
}
}

total_fp_divs += (double) num_active*num_cells;
total_fp_adds += (double) 6*num_active*num_cells;
} else {
#pragma omp parallel default(shared) private (i, j, k, bp, sb, sm, sf)
{
#pragma omp parallel for default(shared) private (i, j, k, bp, sb, sm, sf)
for (in = 0; in < sorted_index[num_refine+1]; in++) {
bp = &blocks[sorted_list[in].n];
double work[x_block_size+2][y_block_size+2][z_block_size+2];
for (i = 1; i <= x_block_size; i++)
for (j = 1; j <= y_block_size; j++)
for (k = 1; k <= z_block_size; k++) {
Expand Down Expand Up @@ -153,7 +152,6 @@ void stencil_calc(int var, int stencil_in)
for (k = 1; k <= z_block_size; k++)
bp->array[var][i][j][k] = work[i][j][k];
}
}

total_fp_divs += (double) num_active*num_cells;
total_fp_adds += (double) 26*num_active*num_cells;
Expand Down