From c846568cf28b4d128cf893dc0abb6ccb5ccdcc32 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Wed, 8 Dec 2021 01:50:12 -0700 Subject: Timing study --- openmp/src/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'openmp/src/main.c') diff --git a/openmp/src/main.c b/openmp/src/main.c index 68ec0bd..50fb096 100644 --- a/openmp/src/main.c +++ b/openmp/src/main.c @@ -19,6 +19,7 @@ //#define VERBOSE 1 #define SEED 100 +// Do the simulation void simulate(int argc, char** argv) { srand(SEED); char* filename; @@ -26,6 +27,7 @@ void simulate(int argc, char** argv) { game.padding = PADDING; int iterations, log_each_step, threads; if (argc == 8) { + // Parse the arguments filename = argv[2]; game.width = atoi(argv[3]); game.height = atoi(argv[4]); @@ -51,6 +53,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 { @@ -62,16 +65,19 @@ void simulate(int argc, char** argv) { double 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 = omp_get_wtime(); + // Compute the next grid with threads next(&game, threads); end = omp_get_wtime(); time_computing_life += ((double) (end - start)); } 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" : " "); @@ -80,6 +86,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); } -- cgit v1.2.3-70-g09d2