diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2021-12-08 01:50:12 -0700 |
---|---|---|
committer | Logan Hunt <loganhunt@simponic.xyz> | 2021-12-08 01:50:12 -0700 |
commit | c846568cf28b4d128cf893dc0abb6ccb5ccdcc32 (patch) | |
tree | 01ad0e303ea59103f2af9b9aa007785b88fa80ca /serial | |
parent | 253b267f1cee377a834860fb4deac54ef9a78b7a (diff) | |
download | gol-c846568cf28b4d128cf893dc0abb6ccb5ccdcc32.tar.gz gol-c846568cf28b4d128cf893dc0abb6ccb5ccdcc32.zip |
Timing study
Diffstat (limited to 'serial')
-rw-r--r-- | serial/src/create_grid.c | 2 | ||||
-rw-r--r-- | serial/src/file.c | 2 | ||||
-rw-r--r-- | serial/src/game.c | 4 | ||||
-rw-r--r-- | serial/src/main.c | 11 | ||||
-rw-r--r-- | serial/timing-study/output-1-1000-1000.txt | 4 | ||||
-rw-r--r-- | serial/timing-study/output-1-1000-1250.txt | 4 | ||||
-rw-r--r-- | serial/timing-study/output-1-1000-1500.txt | 4 | ||||
-rw-r--r-- | serial/timing-study/output-1-1000-1750.txt | 4 | ||||
-rw-r--r-- | serial/timing-study/output-1-1000-2000.txt | 4 | ||||
-rw-r--r-- | serial/timing-study/output-1-1000-250.txt | 4 | ||||
-rw-r--r-- | serial/timing-study/output-1-1000-500.txt | 4 | ||||
-rw-r--r-- | serial/timing-study/output-1-1000-750.txt | 4 | ||||
-rw-r--r-- | serial/timing-study/slurm-10870643.err-kp013 | 0 | ||||
-rw-r--r-- | serial/timing-study/slurm-10870643.out-kp013 | 0 | ||||
-rw-r--r-- | serial/timing-study/timing_study.sh | 19 |
15 files changed, 69 insertions, 1 deletions
diff --git a/serial/src/create_grid.c b/serial/src/create_grid.c index d6a5b94..a48317d 100644 --- a/serial/src/create_grid.c +++ b/serial/src/create_grid.c @@ -1,5 +1,6 @@ #include "create_grid.h" +// Print entirety of a grid to verify input void print_grid(struct GAME* game) { printf("\n===GRID===\n"); for (int y = 0; y < game->height; y++) { @@ -10,6 +11,7 @@ void print_grid(struct GAME* game) { } } +// Go through user input void create_grid(int argc, char** argv) { char* filename; struct GAME game; diff --git a/serial/src/file.c b/serial/src/file.c index 3ecb613..e10b667 100644 --- a/serial/src/file.c +++ b/serial/src/file.c @@ -1,5 +1,6 @@ #include "file.h" +// Read a grid from a binary file into the space without padding void read_in(char* filename, struct GAME* game) { FILE* file = fopen(filename, "rb"); for (int i = game->padding; i < game->height+game->padding; i++) { @@ -8,6 +9,7 @@ void read_in(char* filename, struct GAME* game) { fclose(file); } +// Write a grid to a binary file into the space without padding void write_out(char* filename, struct GAME* game) { FILE* file = fopen(filename, "w+"); for (int i = game->padding; i < game->height+game->padding; i++) { diff --git a/serial/src/game.c b/serial/src/game.c index 2921e3c..ebaab1b 100644 --- a/serial/src/game.c +++ b/serial/src/game.c @@ -1,5 +1,6 @@ #include "game.h" +// Calculate the number of live neighbors a cell has int neighbors(struct GAME* game, int x, int y) { int n = 0; for (int dy = -1; dy <= 1; dy++) { @@ -15,6 +16,7 @@ int neighbors(struct GAME* game, int x, int y) { return n; } +// Compute the next iteration of a board void next(struct GAME* game) { unsigned char** newGrid = malloc(sizeof(unsigned char*) * (game->height+(game->padding*2))); int size = sizeof(unsigned char) * (game->width+(game->padding*2)); @@ -23,6 +25,7 @@ void next(struct GAME* game) { memset(newGrid[y], 0, size); } + // Iterate through each cell for (int y = 0; y < game->height+(game->padding*2); y++) { for (int x = 0; x < game->width+(game->padding*2); x++) { int my_neighbors = neighbors(game, x, y); @@ -44,6 +47,7 @@ void next(struct GAME* game) { game->grid = newGrid; } +// Randomly assign life value to each cell void randomize(struct GAME* game) { for (int y = game->padding; y < game->height+game->padding; y++) { for (int x = game->padding; x < game->width+game->padding; x++) { 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); } diff --git a/serial/timing-study/output-1-1000-1000.txt b/serial/timing-study/output-1-1000-1000.txt new file mode 100644 index 0000000..4445862 --- /dev/null +++ b/serial/timing-study/output-1-1000-1000.txt @@ -0,0 +1,4 @@ + +===Timing=== +Time computing life: 65.330000 +Clock time: 66.520000 diff --git a/serial/timing-study/output-1-1000-1250.txt b/serial/timing-study/output-1-1000-1250.txt new file mode 100644 index 0000000..5adeb8d --- /dev/null +++ b/serial/timing-study/output-1-1000-1250.txt @@ -0,0 +1,4 @@ + +===Timing=== +Time computing life: 101.210000 +Clock time: 103.190000 diff --git a/serial/timing-study/output-1-1000-1500.txt b/serial/timing-study/output-1-1000-1500.txt new file mode 100644 index 0000000..30ddd59 --- /dev/null +++ b/serial/timing-study/output-1-1000-1500.txt @@ -0,0 +1,4 @@ + +===Timing=== +Time computing life: 145.440000 +Clock time: 148.020000 diff --git a/serial/timing-study/output-1-1000-1750.txt b/serial/timing-study/output-1-1000-1750.txt new file mode 100644 index 0000000..25fa9c5 --- /dev/null +++ b/serial/timing-study/output-1-1000-1750.txt @@ -0,0 +1,4 @@ + +===Timing=== +Time computing life: 196.590000 +Clock time: 200.020000 diff --git a/serial/timing-study/output-1-1000-2000.txt b/serial/timing-study/output-1-1000-2000.txt new file mode 100644 index 0000000..3582584 --- /dev/null +++ b/serial/timing-study/output-1-1000-2000.txt @@ -0,0 +1,4 @@ + +===Timing=== +Time computing life: 256.560000 +Clock time: 260.770000 diff --git a/serial/timing-study/output-1-1000-250.txt b/serial/timing-study/output-1-1000-250.txt new file mode 100644 index 0000000..c7652f2 --- /dev/null +++ b/serial/timing-study/output-1-1000-250.txt @@ -0,0 +1,4 @@ + +===Timing=== +Time computing life: 4.560000 +Clock time: 4.830000 diff --git a/serial/timing-study/output-1-1000-500.txt b/serial/timing-study/output-1-1000-500.txt new file mode 100644 index 0000000..c6b006d --- /dev/null +++ b/serial/timing-study/output-1-1000-500.txt @@ -0,0 +1,4 @@ + +===Timing=== +Time computing life: 16.990000 +Clock time: 17.340000 diff --git a/serial/timing-study/output-1-1000-750.txt b/serial/timing-study/output-1-1000-750.txt new file mode 100644 index 0000000..fddfee8 --- /dev/null +++ b/serial/timing-study/output-1-1000-750.txt @@ -0,0 +1,4 @@ + +===Timing=== +Time computing life: 36.980000 +Clock time: 37.830000 diff --git a/serial/timing-study/slurm-10870643.err-kp013 b/serial/timing-study/slurm-10870643.err-kp013 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/serial/timing-study/slurm-10870643.err-kp013 diff --git a/serial/timing-study/slurm-10870643.out-kp013 b/serial/timing-study/slurm-10870643.out-kp013 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/serial/timing-study/slurm-10870643.out-kp013 diff --git a/serial/timing-study/timing_study.sh b/serial/timing-study/timing_study.sh new file mode 100644 index 0000000..20f405d --- /dev/null +++ b/serial/timing-study/timing_study.sh @@ -0,0 +1,19 @@ +#!/bin/bash +#SBATCH --time=0:35:00 # walltime, abbreviated by -t +#SBATCH --nodes=1 # number of cluster nodes, abbreviated by -N +#SBATCH -o slurm-%j.out-%N # name of the stdout, using the job number (%j) and the first node (%N) +#SBATCH -e slurm-%j.err-%N # name of the stderr, using job and first node values +#SBATCH --ntasks=1 # number of MPI tasks, abbreviated by -n +# additional information for allocated clusters +#SBATCH --account=usucs5030 # account - abbreviated by -A +#SBATCH --partition=kingspeak # partition, abbreviated by -p + +cd $HOME/gol/serial + +iterations=1000 +cores=1 + +for size in 250 500 750 1000 1250 1500 1750 2000 +do + ./gol simulate random $size $size $iterations 1 > timing-study/output-$cores-$iterations-$size.txt +done |