From a002f1340f05792cc14950f7d91bdea1b7620267 Mon Sep 17 00:00:00 2001 From: Dorian Stoll <dorian.stoll@uni-potsdam.de> Date: Mon, 10 Jun 2024 13:47:11 +0200 Subject: [PATCH] zellularautomat: c: Merge program into one C file --- src/benchmarks/zellularautomat/c/ca_common.c | 51 ------------------ src/benchmarks/zellularautomat/c/ca_common.h | 35 ------------- .../zellularautomat/c/{ca_openmp.c => main.c} | 52 ++++++++++++++++++- src/benchmarks/zellularautomat/c/meson.build | 3 +- 4 files changed, 52 insertions(+), 89 deletions(-) delete mode 100644 src/benchmarks/zellularautomat/c/ca_common.c delete mode 100644 src/benchmarks/zellularautomat/c/ca_common.h rename src/benchmarks/zellularautomat/c/{ca_openmp.c => main.c} (63%) diff --git a/src/benchmarks/zellularautomat/c/ca_common.c b/src/benchmarks/zellularautomat/c/ca_common.c deleted file mode 100644 index 3e0d9ace..00000000 --- a/src/benchmarks/zellularautomat/c/ca_common.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * common functions for (parallel) cellular automaton - * - * (c) 2016 Steffen Christgau - * - * configuration initialization based on - * (c) 1996,1997 Peter Sanders, Ingo Boesnach - * - */ -#include <stdint.h> -#include <stdlib.h> -#include <stdio.h> -#include <assert.h> - -#include "ca_common.h" - -void ca_init(int argc, char** argv, int *lines, int *its) -{ - assert(argc == 3); - - *lines = atoi(argv[1]); - *its = atoi(argv[2]); - - assert(*lines > 0); -} - -/* random starting configuration */ -void ca_init_config(line_t *buf, int lines) -{ - srand(424243); - - for (int y = 1; y <= lines; y++) { - for (int x = 1; x <= XSIZE; x++) { - buf[y][x] = rand() % 2; - } - } -} - -static void ca_clean_ghost_zones(line_t *buf, int lines) -{ - for (int y = 0; y < lines; y++) { - buf[y][0] = 0; - buf[y][XSIZE + 1] = 0; - } -} - -void ca_report(line_t *buf, int lines) -{ - ca_clean_ghost_zones(buf, lines); - fwrite(buf, sizeof(*buf), lines, stdout); -} diff --git a/src/benchmarks/zellularautomat/c/ca_common.h b/src/benchmarks/zellularautomat/c/ca_common.h deleted file mode 100644 index 2ef4d570..00000000 --- a/src/benchmarks/zellularautomat/c/ca_common.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef CA_COMMON_H -#define CA_COMMON_H - -#include <stdint.h> -#include <stddef.h> - -/* a: pointer to array; x,y: coordinates; result: n-th element of anneal, - where n is the number of neighbors */ -#define transition(a, x, y) \ - (anneal[(a)[(y)-1][(x)-1] + (a)[(y)][(x)-1] + (a)[(y)+1][(x)-1] +\ - (a)[(y)-1][(x) ] + (a)[(y)][(x) ] + (a)[(y)+1][(x) ] +\ - (a)[(y)-1][(x)+1] + (a)[(y)][(x)+1] + (a)[(y)+1][(x)+1]]) - - -#ifdef __cplusplus -extern "C" { -#endif - -/* horizontal size of the configuration */ -#define XSIZE 1024 -#define LINE_SIZE (XSIZE + 2) - -/* "ADT" State and line of states (plus border) */ -typedef uint8_t cell_state_t; -typedef cell_state_t line_t[XSIZE + 2]; - -void ca_init(int argc, char** argv, int *lines, int *its); -void ca_init_config(line_t *buf, int lines); -void ca_report(line_t *buf, int lines); - -#ifdef __cplusplus -} -#endif - -#endif /* CA_COMMON_H */ diff --git a/src/benchmarks/zellularautomat/c/ca_openmp.c b/src/benchmarks/zellularautomat/c/main.c similarity index 63% rename from src/benchmarks/zellularautomat/c/ca_openmp.c rename to src/benchmarks/zellularautomat/c/main.c index 00a3fb2d..66536f49 100644 --- a/src/benchmarks/zellularautomat/c/ca_openmp.c +++ b/src/benchmarks/zellularautomat/c/main.c @@ -10,10 +10,60 @@ * #2: Number of iterations to be simulated * */ + +#include <assert.h> #include <stdio.h> #include <stdlib.h> +#include <stdint.h> + +/* a: pointer to array; x,y: coordinates; result: n-th element of anneal, + where n is the number of neighbors */ +#define transition(a, x, y) \ + (anneal[(a)[(y)-1][(x)-1] + (a)[(y)][(x)-1] + (a)[(y)+1][(x)-1] +\ + (a)[(y)-1][(x) ] + (a)[(y)][(x) ] + (a)[(y)+1][(x) ] +\ + (a)[(y)-1][(x)+1] + (a)[(y)][(x)+1] + (a)[(y)+1][(x)+1]]) + +/* horizontal size of the configuration */ +#define XSIZE 1024 +#define LINE_SIZE (XSIZE + 2) + +/* "ADT" State and line of states (plus border) */ +typedef uint8_t cell_state_t; +typedef cell_state_t line_t[XSIZE + 2]; + +/* ------------------------- CA utils -------------------------------- */ + +static void ca_init(int argc, char** argv, int *lines, int *its) +{ + assert(argc == 3); + + *lines = atoi(argv[1]); + *its = atoi(argv[2]); + + assert(*lines > 0); +} -#include "ca_common.h" +/* random starting configuration */ +static void ca_init_config(line_t *buf, int lines) +{ + srand(424243); + + for (int y = 1; y <= lines; y++) { + for (int x = 1; x <= XSIZE; x++) { + buf[y][x] = rand() % 2; + } + } +} + +static void ca_report(line_t *buf, int lines) +{ + for (int y = 0; y < lines; y++) { + buf[y][0] = 0; + buf[y][XSIZE + 1] = 0; + } + + fwrite(buf, sizeof(*buf), lines, stdout); +} /* --------------------- CA simulation -------------------------------- */ diff --git a/src/benchmarks/zellularautomat/c/meson.build b/src/benchmarks/zellularautomat/c/meson.build index 0552fee1..cb54c9c4 100644 --- a/src/benchmarks/zellularautomat/c/meson.build +++ b/src/benchmarks/zellularautomat/c/meson.build @@ -1,6 +1,5 @@ sources = [ - 'ca_common.c', - 'ca_openmp.c', + 'main.c', ] dependencies = [ -- GitLab