diff options
Diffstat (limited to 'serial/src/main.c')
-rw-r--r-- | serial/src/main.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/serial/src/main.c b/serial/src/main.c index f4c8141..c7cdacf 100644 --- a/serial/src/main.c +++ b/serial/src/main.c @@ -18,6 +18,7 @@ //#define VERBOSE 1 #define SEED 100 +// Do the simulation void simulate(int argc, char** argv) { srand(SEED); char* filename; @@ -25,6 +26,7 @@ void simulate(int argc, char** argv) { game.padding = PADDING; int iterations, log_each_step; if (argc == 7) { + // Parse the arguments filename = argv[2]; game.width = atoi(argv[3]); game.height = atoi(argv[4]); @@ -48,6 +50,7 @@ void simulate(int argc, char** argv) { memset(game.grid[i], 0, game.width+(2*game.padding)); } + // Choose where to read initial position if (strcmp(filename, "random") == 0) { randomize(&game); } else { @@ -55,20 +58,25 @@ void simulate(int argc, char** argv) { } char iteration_file[1024]; + + // Timing code double time_computing_life = 0; clock_t start, end; for (int i = 0; i <= iterations; i++) { + // Iteration 0 will just be the initial grid if (i > 0) { - // Iteration 0 is just the input board start = clock(); + // Compute the next grid next(&game); end = clock(); time_computing_life += ((double) (end - start)) / CLOCKS_PER_SEC; } if (log_each_step) { + // If we are logging each step, perform IO operations #if VERBOSE == 1 printf("\n===Iteration %i===\n", i); + // Print the board without the padding elements for (int y = game.padding; y < game.height+game.padding; y++) { for (int x = game.padding; x < game.width+game.padding; x++) { printf("%s ", game.grid[y][x] ? "X" : " "); @@ -77,6 +85,7 @@ void simulate(int argc, char** argv) { } printf("===End iteration %i===\n", i); #endif + // Save to a file sprintf(iteration_file, "output/iteration-%07d.bin", i); write_out(iteration_file, &game); } |