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

Array refactoring: bp->array was float**** is now float* #9

Open
wants to merge 5 commits 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
8 changes: 4 additions & 4 deletions openmp/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
CC = cc
LD = cc
CC = mpicc
LD = mpicc
CPPFLAGS = -I.
CFLAGS = -O3 -fopenmp
LDFLAGS =
LDLIBS = -lm -lgomp

EXEC = ma.x
EXEC = miniAMR.x

OBJS = block.o check_sum.o comm_block.o comm.o comm_parent.o comm_refine.o \
comm_util.o driver.o init.o main.o move.o pack.o plot.o profile.o \
Expand All @@ -18,7 +18,7 @@ $(EXEC): $(OBJS)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $<

clean:
rm *.o ma.x
rm *.o $(EXEC)

# need dependencies

Expand Down
48 changes: 28 additions & 20 deletions openmp/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,23 @@ void split_blocks(void)
i1 *= x_block_half;
j1 *= y_block_half;
k1 *= z_block_half;
for (v = 0; v < num_vars; v++)
for (v = 0; v < num_vars; v++) {
typedef double (*block3D_t)[y_block_size+2][z_block_size+2];
block3D_t array_from = (block3D_t)&bp->array[v*block3D_size];
block3D_t array_to = (block3D_t)&bp1->array[v*block3D_size];
for (i2 = i = 1; i <= x_block_half; i++, i2+=2)
for (j2 = j = 1; j <= y_block_half; j++, j2+=2)
for (k2 = k = 1; k <= z_block_half; k++, k2+=2)
bp1->array[v][i2 ][j2 ][k2 ] =
bp1->array[v][i2+1][j2 ][k2 ] =
bp1->array[v][i2 ][j2+1][k2 ] =
bp1->array[v][i2+1][j2+1][k2 ] =
bp1->array[v][i2 ][j2 ][k2+1] =
bp1->array[v][i2+1][j2 ][k2+1] =
bp1->array[v][i2 ][j2+1][k2+1] =
bp1->array[v][i2+1][j2+1][k2+1] =
bp->array[v][i+i1][j+j1][k+k1]/8.0;
array_to[i2 ][j2 ][k2 ] =
array_to[i2+1][j2 ][k2 ] =
array_to[i2 ][j2+1][k2 ] =
array_to[i2+1][j2+1][k2 ] =
array_to[i2 ][j2 ][k2+1] =
array_to[i2+1][j2 ][k2+1] =
array_to[i2 ][j2+1][k2+1] =
array_to[i2+1][j2+1][k2+1] =
array_from[i+i1][j+j1][k+k1]/8.0;
}
}

// children all defined - connect children & disconnect parent
Expand Down Expand Up @@ -403,19 +407,23 @@ void consolidate_blocks(void)
i1 = (o%2)*x_block_half;
j1 = ((o/2)%2)*y_block_half;
k1 = (o/4)*z_block_half;
for (v = 0; v < num_vars; v++)
for (v = 0; v < num_vars; v++) {
typedef double (*block3D_t)[y_block_size+2][z_block_size+2];
block3D_t array_from = (block3D_t)&bp1->array[v*block3D_size];
block3D_t array_to = (block3D_t)&bp->array[v*block3D_size];
for (i2 = i = 1; i <= x_block_half; i++, i2+=2)
for (j2 = j = 1; j <= y_block_half; j++, j2+=2)
for (k2 = k = 1; k <= z_block_half; k++, k2+=2)
bp->array[v][i+i1][j+j1][k+k1] =
bp1->array[v][i2 ][j2 ][k2 ] +
bp1->array[v][i2+1][j2 ][k2 ] +
bp1->array[v][i2 ][j2+1][k2 ] +
bp1->array[v][i2+1][j2+1][k2 ] +
bp1->array[v][i2 ][j2 ][k2+1] +
bp1->array[v][i2+1][j2 ][k2+1] +
bp1->array[v][i2 ][j2+1][k2+1] +
bp1->array[v][i2+1][j2+1][k2+1];
array_to[i+i1][j+j1][k+k1] =
array_from[i2 ][j2 ][k2 ] +
array_from[i2+1][j2 ][k2 ] +
array_from[i2 ][j2+1][k2 ] +
array_from[i2+1][j2+1][k2 ] +
array_from[i2 ][j2 ][k2+1] +
array_from[i2+1][j2 ][k2+1] +
array_from[i2 ][j2+1][k2+1] +
array_from[i2+1][j2+1][k2+1];
}
}
// now figure out communication
for (c = 0; c < 6; c++) {
Expand Down
3 changes: 2 additions & 1 deletion openmp/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ typedef struct {
int nei_level[6]; /* 0 to 5 = W, E, S, N, D, U; use -2 for boundary */
int nei[6][2][2]; /* negative if off processor (-1 - proc) */
int cen[3];
double ****array;
double * array;
} block;
block *blocks;

Expand Down Expand Up @@ -73,6 +73,7 @@ int max_num_blocks;
int num_refine;
int uniform_refine;
int x_block_size, y_block_size, z_block_size;
int block3D_size;
int num_cells;
int num_vars;
int mat;
Expand Down
4 changes: 3 additions & 1 deletion openmp/check_sum.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ double check_sum(int var)
for (in = 0; in < sorted_index[num_refine+1]; in++) {
bp = &blocks[sorted_list[in].n];
block_sum = 0.0;
typedef double (*block3D_t)[y_block_size+2][z_block_size+2];
block3D_t array = (block3D_t)&bp->array[var*block3D_size];
for (i = 1; i <= x_block_size; i++)
for (j = 1; j <= y_block_size; j++)
for (k = 1; k <= z_block_size; k++)
block_sum += bp->array[var][i][j][k];
block_sum += array[i][j][k];
//if (!my_pe) printf("cs in %d block %d sum %lf\n", in, sorted_list[in].n, block_sum);
sum += block_sum;
}
Expand Down
Loading