summaryrefslogtreecommitdiff
path: root/src/modules/sparkler
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2017-09-08 19:09:57 -0700
committerVito Caputo <vcaputo@pengaru.com>2017-09-14 17:52:34 -0700
commit7e999e37a5cf65e466091f4d8eeb36a6cea20f52 (patch)
treefa1778c1daf753f46dcc1ca16d492dfa888f6fd3 /src/modules/sparkler
parent77f6d721564ceba589af14554685821aedfc8462 (diff)
*: use fragment generator
Rather than laying out all fragments in a frame up-front in ray_module_t.prepare_frame(), return a fragment generator (rototiller_fragmenter_t) which produces the numbered fragment as needed. This removes complexity from the serially-executed prepare_frame() and allows the individual fragments to be computed in parallel by the different threads. It also eliminates the need for a fragments array in the rototiller_frame_t, indeed rototiller_frame_t is eliminated altogether.
Diffstat (limited to 'src/modules/sparkler')
-rw-r--r--src/modules/sparkler/sparkler.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/modules/sparkler/sparkler.c b/src/modules/sparkler/sparkler.c
index a2210dc..13b1563 100644
--- a/src/modules/sparkler/sparkler.c
+++ b/src/modules/sparkler/sparkler.c
@@ -18,6 +18,7 @@
typedef struct sparkler_context_t {
particles_t *particles;
+ unsigned n_cpus;
} sparkler_context_t;
extern particle_ops_t simple_ops;
@@ -58,12 +59,19 @@ static void sparkler_destroy_context(void *context)
}
-static void sparkler_prepare_frame(void *context, unsigned ncpus, fb_fragment_t *fragment, rototiller_frame_t *res_frame)
+static int sparkler_fragmenter(void *context, const fb_fragment_t *fragment, unsigned num, fb_fragment_t *res_fragment)
{
sparkler_context_t *ctxt = context;
- fb_fragment_divide(fragment, ncpus, res_frame->fragments);
- res_frame->n_fragments = ncpus;
+ return fb_fragment_divide_single(fragment, ctxt->n_cpus, num, res_fragment);
+}
+
+static void sparkler_prepare_frame(void *context, unsigned ncpus, fb_fragment_t *fragment, rototiller_fragmenter_t *res_fragmenter)
+{
+ sparkler_context_t *ctxt = context;
+
+ *res_fragmenter = sparkler_fragmenter;
+ ctxt->n_cpus = ncpus;
particles_sim(ctxt->particles);
particles_add_particles(ctxt->particles, NULL, &simple_ops, INIT_PARTS / 4);
© All Rights Reserved