timers: save timer values to timers.dat
authorSebastian <git@sraa.de>
Fri, 25 Jul 2014 20:45:11 +0000 (20:45 +0000)
committerSebastian <git@sraa.de>
Fri, 25 Jul 2014 20:45:11 +0000 (20:45 +0000)
it is reasonably impossible to calculate the standard inside epiphany,
since there is no 128 bit datatype (as needed for storing the squares).
the required sqrtf will already overflow the internal code memory, adding
bignum stuff won't help. even float ceils.

so put the burden of statistics on the host.

lb/hsrc/data.c
lb/hsrc/main.c

index 81ecd393b19e8e54bb8edd0293bb6d0f9c14a8b5..a0482a74dc061ea891730c3726f43554a0c495b5 100644 (file)
@@ -24,9 +24,7 @@ void fixsudo(const char *filename)
 void write_populations(d2q9_block_t lattice[CORES_Y][CORES_X],
        int core_x, int core_y, int iter)
 {
-       char *name = "populations.dat";
-
-       FILE *file = fopen(name, "a");
+       FILE *file = fopen("populations.dat", "a");
        if(!file) {
                perror("write_populations/fopen");
                return;
@@ -43,7 +41,7 @@ void write_populations(d2q9_block_t lattice[CORES_Y][CORES_X],
        }
        fprintf(file, "\n");
 
-       /* close and chown if run with sudo */
+       /* close */
        fclose(file);
 
        return;
@@ -112,3 +110,26 @@ void write_animation(void)
 
        return;
 }
+
+/* write timer values */
+void write_timers(uint32_t timers[CORES_Y][CORES_X][TIMERS], uint32_t iter)
+{
+       FILE *file = fopen("timers.dat", "ab");
+       if(!file) {
+               perror("write_timers/fopen");
+               return;
+       }
+
+       fprintf(file, "Timers: i=%d\n", iter);
+       for(int y = 0; y < CORES_Y; y++) {
+               for(int x = 0; x < CORES_X; x++) {
+                       fprintf(file, "[%d,%d]: ", x, y);
+                       for(int t = 0; t < TIMERS; t++) {
+                               fprintf(file, "%8d ", timers[y][x][t]);
+                       }
+                       fprintf(file, "\n");
+               }
+       }
+
+       fclose(file);
+}
index 3c33f0c13885e3b09292568cd8b9550d36024d86..41ec1b14855116045140d31a149fdacc589fb7c7 100644 (file)
@@ -17,6 +17,7 @@ void fixsudo(const char *filename);
 void write_populations(d2q9_block_t lattice[CORES_Y][CORES_X], int core_x, int core_y, int iter);
 void write_image(d2q9_block_t lattice[CORES_Y][CORES_X], int iter);
 void write_animation(void);
+void write_timers(uint32_t timers[CORES_Y][CORES_X][TIMERS], uint32_t iter);
 
 /* globals */
 static states_t laststates, states;    /* old state value */
@@ -27,7 +28,7 @@ int main()
        char *filename = "bin/lb_2d.srec";
 
        /* remove old results */
-       int dummy = system("rm -f ./tmp/i*.ppm ./tmp/anim.gif populations.dat");
+       int dummy = system("rm -f ./tmp/i*.ppm ./tmp/anim.gif populations.dat timers.dat");
        (void)dummy;
 
        e_epiphany_t dev;
@@ -77,6 +78,11 @@ int main()
                if(e_read(&mem, 0, 0, (off_t)0, &shm, sizeof(shm_t)) == E_ERR)
                        FAIL("Can't read shm!\n");
 
+               /* finish if done */
+               if(states[0][0] == -1) {
+                       break;
+               }
+
                /* save (updated) states */
                memcpy(&states,     &shm, sizeof(states_t));
                memcpy(&laststates, &shm, sizeof(states_t));
@@ -97,26 +103,11 @@ int main()
                /* write data */
                static uint32_t old0 = -1;
                if(states[0][0] != old0) {
-                       //write_populations(shm.lattice, 0, 0, states[0][0]);
+                       write_populations(shm.lattice, 0, 0, states[0][0]);
                        write_image(shm.lattice, states[0][0]);
+                       write_timers(shm.timers, states[0][0]);
                        old0 = states[0][0];
                }
-
-               /* print timers */
-               printf("Timers:\n");
-               for(int y = 0; y < CORES_Y; y++) {
-                       for(int x = 0; x < CORES_X; x++) {
-                               printf("[%d,%d] ", x, y);
-                               for(int i = 0; i < TIMERS; i++) {
-                                       printf("%8d  ", shm.timers[y][x][i]);
-                               }
-                               printf("\n");
-                       }
-               }
-
-               if(states[0][0] == -1) {
-                       break;
-               }
        }
        /* ================================================================ */
 
@@ -125,6 +116,7 @@ int main()
        if(e_finalize()  != E_OK) FAIL("Can't finalize!\n");
 
        fixsudo("populations.dat");
+       fixsudo("timers.dat");
 
        printf("\nProgram finished successfully.\n");
        printf("Convert ...\n");