From 1bc7c90fcfe0d61ce5f0e84c7e8e1a9127f497b0 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sat, 18 Nov 2023 22:59:03 +0000 Subject: [PATCH] tweak: savepoint; test hypothesis over previous stuff. --- C/alt/05-refactor-split-array/samples.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/C/alt/05-refactor-split-array/samples.c b/C/alt/05-refactor-split-array/samples.c index d84eebcf..8bdc8a5e 100644 --- a/C/alt/05-refactor-split-array/samples.c +++ b/C/alt/05-refactor-split-array/samples.c @@ -180,19 +180,26 @@ float mixture(float (*samplers[])(uint32_t*), float* weights, int n_dists, uint3 // Parallization function void paralellize(float (*sampler)(uint32_t* seed), float* results, int n_threads, int n_samples){ + if((N_SAMPLES % n_threads) != 0){ fprintf(stderr, "Number of samples isn't divisible by number of threads, aborting\n"); exit(1); } - // int n_samples_per_thread = N_SAMPLES / n_thread; - int sample_index, i, split_array_length; + int n_samples_per_thread = N_SAMPLES / n_threads; + + float** split_results = malloc(n_threads * sizeof(float*)); + for(int i=0; i