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;
}
fprintf(file, "\n");
- /* close and chown if run with sudo */
+ /* close */
fclose(file);
return;
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);
+}
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 */
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;
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));
/* 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;
- }
}
/* ================================================================ */
if(e_finalize() != E_OK) FAIL("Can't finalize!\n");
fixsudo("populations.dat");
+ fixsudo("timers.dat");
printf("\nProgram finished successfully.\n");
printf("Convert ...\n");