void d2q9_init(d2q9_block_t block)
{
/* all with rho = 0.1 */
- for(int y = 0; y < BLOCK_Y; y++)
- for(int x = 0; x < BLOCK_X; x++)
+ for(int y = 0; y < BLOCKS_Y; y++)
+ for(int x = 0; x < BLOCKS_X; x++)
for(int q = 0; q < 9; q++)
block[y][x][q] = 0.1 * d2q9_w[q];
int next_y = y + d2q9_v[q][1];
/* inner borders (extend) */
- if(next_x < 0) { next_col--; next_x += BLOCK_X; }
- else if(next_x >= BLOCK_X) { next_col++; next_x -= BLOCK_X; }
- if(next_y < 0) { next_row--; next_y += BLOCK_Y; }
- else if(next_y >= BLOCK_Y) { next_row++; next_y -= BLOCK_Y; }
+ if(next_x < 0) { next_col--; next_x += BLOCKS_X; }
+ else if(next_x >= BLOCKS_X) { next_col++; next_x -= BLOCKS_X; }
+ if(next_y < 0) { next_row--; next_y += BLOCKS_Y; }
+ else if(next_y >= BLOCKS_Y) { next_row++; next_y -= BLOCKS_Y; }
#if 0
/* outer borders (wrap around) */
void d2q9_collide_stream_bulk(d2q9_block_t f, FLOAT omega)
{
/* don't touch the border nodes */
- for(int x = 1; x < BLOCK_X-1; x++) {
- for(int y = 1; y < BLOCK_Y-1; y++) {
+ for(int x = 1; x < BLOCKS_X-1; x++) {
+ for(int y = 1; y < BLOCKS_Y-1; y++) {
/* macroscopic */
FLOAT rho = f[y][x][0] + f[y][x][1] + f[y][x][2] +
f[y][x][3] + f[y][x][4] + f[y][x][5] +
void init(void)
{
/* compile-time checks */
- BUILD_BUG(BLOCK_X * BLOCK_Y * sizeof(d2q9_node_t) > 24*1024);
- BUILD_BUG(BLOCK_X < 3 || BLOCK_Y < 3);
- BUILD_BUG(CORES_X < 1 || CORES_Y < 1);
- BUILD_BUG(CORES_X > 4 || CORES_Y > 4);
+ BUILD_BUG(BLOCKS_X * BLOCKS_Y * sizeof(d2q9_node_t) > 24*1024);
+ BUILD_BUG(BLOCKS_X < 3 || BLOCKS_Y < 3);
+ BUILD_BUG(CORES_X < 1 || CORES_Y < 1);
+ BUILD_BUG(CORES_X > 4 || CORES_Y > 4);
/* core index */
e_coords_from_coreid(e_get_coreid(), &col, &row);
#if 1
/* collide all nodes */
- for(int y = 0; y < BLOCK_Y; y++)
- for(int x = 0; x < BLOCK_X; x++)
+ for(int y = 0; y < BLOCKS_Y; y++)
+ for(int x = 0; x < BLOCKS_X; x++)
d2q9_collide(*block, x, y, omega);
/* synchronize */
READ_TIMER(2);
/* stream all nodes */
- for(int y = 0; y < BLOCK_Y; y++)
- for(int x = 0; x < BLOCK_X; x++)
+ for(int y = 0; y < BLOCKS_Y; y++)
+ for(int x = 0; x < BLOCKS_X; x++)
d2q9_stream(*block, x, y);
READ_TIMER(3);
#else
/* collide boundaries: top, bottom */
- for(int x = 0; x < BLOCK_X; x++) {
- d2q9_collide(*block, x, 0, omega);
- d2q9_collide(*block, x, BLOCK_Y-1, omega);
+ for(int x = 0; x < BLOCKS_X; x++) {
+ d2q9_collide(*block, x, 0, omega);
+ d2q9_collide(*block, x, BLOCKS_Y-1, omega);
}
READ_TIMER(1);
/* collide boundaries: left, right */
- for(int y = 1; y < BLOCK_Y-1; y++) {
+ for(int y = 1; y < BLOCKS_Y-1; y++) {
d2q9_collide(*block, 0, y, omega);
- d2q9_collide(*block, BLOCK_X-1, y, omega);
+ d2q9_collide(*block, BLOCKS_X-1, y, omega);
}
/* synchronize */
READ_TIMER(4);
/* stream the boundaries: top, bottom */
- for(int x = 0; x < BLOCK_X; x++) {
- d2q9_stream(*block, x, 0 );
- d2q9_stream(*block, x, BLOCK_Y-1);
+ for(int x = 0; x < BLOCKS_X; x++) {
+ d2q9_stream(*block, x, 0 );
+ d2q9_stream(*block, x, BLOCKS_Y-1);
}
READ_TIMER(5);
/* stream the boundaries: left, right */
- for(int y = 1; y < BLOCK_Y-1; y++) {
- d2q9_stream(*block, 0, y);
- d2q9_stream(*block, BLOCK_X-1, y);
+ for(int y = 1; y < BLOCKS_Y-1; y++) {
+ d2q9_stream(*block, 0, y);
+ d2q9_stream(*block, BLOCKS_X-1, y);
}
READ_TIMER(6);
#endif
}
for(int cy = 0; cy < CORES_Y; cy++) {
- for(int y = 0; y < BLOCK_Y; y++) {
+ for(int y = 0; y < BLOCKS_Y; y++) {
for(int cx = 0; cx < CORES_X; cx++) {
- for(int x = 0; x < BLOCK_X; x++) {
+ for(int x = 0; x < BLOCKS_X; x++) {
fprintf(file, "%3d: [%3d,%3d]: ",
iter,
- cx * BLOCK_X + x,
- cy * BLOCK_Y + y
+ cx * BLOCKS_X + x,
+ cy * BLOCKS_Y + y
);
for(int q = 0; q < 9; q++) {
fprintf(file, "%.5f ", lattice[cy][cx][y][x][q]);
perror("write_image/fopen");
return;
}
- fprintf(file, "P5\n%d %d\n%d\n", CORES_X*BLOCK_X, CORES_Y*BLOCK_Y, 255);
+ fprintf(file, "P5\n%d %d\n%d\n",
+ CORES_X*BLOCKS_X, CORES_Y*BLOCKS_Y, 255);
/* calculate all densities and remember min/max */
FLOAT min = 1.0, max = 0;
- FLOAT rhos[CORES_Y][BLOCK_Y][CORES_X][BLOCK_X];
+ FLOAT rhos[CORES_Y][BLOCKS_Y][CORES_X][BLOCKS_X];
for(int cy = 0; cy < CORES_Y; cy++) {
- for(int y = 0; y < BLOCK_Y; y++) {
+ for(int y = 0; y < BLOCKS_Y; y++) {
for(int cx = 0; cx < CORES_X; cx++) {
- for(int x = 0; x < BLOCK_X; x++) {
+ for(int x = 0; x < BLOCKS_X; x++) {
FLOAT rho = 0;
for(int q = 0; q < 9; q++)
rho += lattice[cy][cx][y][x][q];
/* scale values and write them to the image */
for(int cy = 0; cy < CORES_Y; cy++) {
- for(int y = 0; y < BLOCK_Y; y++) {
+ for(int y = 0; y < BLOCKS_Y; y++) {
for(int cx = 0; cx < CORES_X; cx++) {
- for(int x = 0; x < BLOCK_X; x++) {
+ for(int x = 0; x < BLOCKS_X; x++) {
unsigned char gray;
gray = (255. * (rhos[cy][y][cx][x]-min) / (max-min));
fwrite(&gray, 1, 1, file);
#define NUM_CORES (CORES_X * CORES_Y)
/* size of per-core subgrid */
-#define BLOCK_X 26
-#define BLOCK_Y 26
+#define BLOCKS_X 26
+#define BLOCKS_Y 26
#define TIMERS 12
/* node and block type (D2Q9) */
typedef FLOAT d2q9_node_t[9];
-typedef d2q9_node_t d2q9_block_t[BLOCK_Y][BLOCK_X];
+typedef d2q9_node_t d2q9_block_t[BLOCKS_Y][BLOCKS_X];
/* shared memory structure */
typedef struct {