d2q9: rename BLOCK_{X,Y} to BLOCKS_{X,Y}
authorSebastian <git@sraa.de>
Wed, 13 Aug 2014 16:59:55 +0000 (16:59 +0000)
committerSebastian <git@sraa.de>
Wed, 13 Aug 2014 16:59:55 +0000 (16:59 +0000)
makes naming consistent with CORES_{X,Y}

d2q9/esrc/d2q9.c
d2q9/esrc/main.c
d2q9/hsrc/data.c
d2q9/shared.h

index 84ff33228e67b069eb3dd5e95259c5ffd9fed409..bbe6091c360b7612887cab6a7474b651f22a7999 100644 (file)
@@ -21,8 +21,8 @@ static const FLOAT d2q9_w[9] = { 4./9.,
 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];
 
@@ -73,10 +73,10 @@ void d2q9_stream(d2q9_block_t f, int x, int y)
                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) */
@@ -108,8 +108,8 @@ void d2q9_stream(d2q9_block_t f, int x, int y)
 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] +
index 057fb789b3918fa39914f76161b75b0bf225dbd3..2a0cfb7d1b5f3351d3b88d3909c7a6cd6331959a 100644 (file)
@@ -28,10 +28,10 @@ unsigned int row, col, core;
 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);
@@ -61,8 +61,8 @@ int main()
 
 #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 */
@@ -71,23 +71,23 @@ int main()
                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 */
@@ -100,16 +100,16 @@ int main()
                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
index 675fe50507b224ad1a8ce62c83dea730dd79e3a2..487768d2bb5bbea04e7c2c8f89063f176fceca0e 100644 (file)
@@ -30,13 +30,13 @@ void write_populations(d2q9_block_t lattice[CORES_Y][CORES_X], int iter)
        }
 
        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]);
@@ -65,15 +65,16 @@ void write_image(d2q9_block_t lattice[CORES_Y][CORES_X], int iter)
                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];
@@ -88,9 +89,9 @@ void write_image(d2q9_block_t lattice[CORES_Y][CORES_X], int iter)
 
        /* 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);
index 7182e93177772bdbd5cc53281fb1896317dfb88e..0634f1ad8886a8255a00c192735c7a78b8e00469 100644 (file)
@@ -18,8 +18,8 @@
 #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
 
@@ -33,7 +33,7 @@ typedef float FLOAT;
 
 /* 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 {