diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-09-22 22:45:18 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-09-22 22:45:18 +0300 |
| commit | b1d67364b4b4832b8efed112f7b0ead1a0b3cd3b (patch) | |
| tree | 7926bfb428703515438c08b98c61cbffd34b3cbb /src/clock_domain.c | |
| parent | 32f9719e29762001f73460acd31f2a6da8fd6298 (diff) | |
| download | gran-b1d67364b4b4832b8efed112f7b0ead1a0b3cd3b.tar.gz gran-b1d67364b4b4832b8efed112f7b0ead1a0b3cd3b.zip | |
start experimenting with processor grids
Diffstat (limited to 'src/clock_domain.c')
| -rw-r--r-- | src/clock_domain.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/clock_domain.c b/src/clock_domain.c index 65dc72a..6610d8f 100644 --- a/src/clock_domain.c +++ b/src/clock_domain.c @@ -12,12 +12,10 @@ #include <assert.h> #include <gran/clock_domain.h> - -#define MAX_COMPONENTS 512 +#include <gran/vec.h> struct clock_domain { - size_t num_components; - struct component *components[MAX_COMPONENTS]; + struct vec components; struct clock_time time; tick period; @@ -44,21 +42,23 @@ struct clock_domain *create_clock_domain(tick period) clk->period = period; mtx_init(&clk->mtx, mtx_plain); + clk->components = vec_create(sizeof(struct component *)); return clk; } void destroy_clock_domain(struct clock_domain *clk) { - for (size_t i = 0; i < clk->num_components; ++i) - destroy(clk->components[i]); + for (size_t i = 0; i < vec_len(&clk->components); ++i) + destroy(vect_at(struct component *, clk->components, i)); + vec_destroy(&clk->components); free(clk); } stat clock_domain_add(struct clock_domain *clk, struct component *component) { - clk->components[clk->num_components++] = component; + vect_append(struct component *, clk->components, &component); return OK; } @@ -80,18 +80,11 @@ static void clocked_component_tick(struct clock_domain *clk, stat clock_domain_tick(struct clock_domain *clk) { - /* openmp on gcc apparently doesn't really handle if conditionals - * particularly efficiently, so it's faster to do it manually */ - if (clk->num_components == 1) { - clocked_component_tick(clk, clk->components[0]); - advance_clock(clk); - return clk->ret; + for (size_t i = 0; i < vec_len(&clk->components); ++i) { + clocked_component_tick(clk, + vect_at(struct component *, clk->components, i)); } -#pragma omp parallel for - for (size_t i = 0; i < clk->num_components; ++i) - clocked_component_tick(clk, clk->components[i]); - advance_clock(clk); return clk->ret; } |
