From 7ab62b4a715bc76f22234495464d3d722134b53a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 25 Jul 2014 20:45:11 +0000 Subject: [PATCH] timers: save timer values to timers.dat 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 | 29 +++++++++++++++++++++++++---- lb/hsrc/main.c | 28 ++++++++++------------------ 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/lb/hsrc/data.c b/lb/hsrc/data.c index 81ecd39..a0482a7 100644 --- a/lb/hsrc/data.c +++ b/lb/hsrc/data.c @@ -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); +} diff --git a/lb/hsrc/main.c b/lb/hsrc/main.c index 3c33f0c..41ec1b1 100644 --- a/lb/hsrc/main.c +++ b/lb/hsrc/main.c @@ -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"); -- 2.30.2