commit eb1c59261072d5d9e037b66bcd51a5d183762df5
parent dd6bb53f1bf252880638f6d1c6155839f45d3d6a
Author: NunoSempere <nuno.sempere@protonmail.com>
Date: Fri, 12 Jan 2024 23:55:09 +0100
formatting pass.
Diffstat:
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/squiggle_more.c b/squiggle_more.c
@@ -43,7 +43,7 @@ void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_
int divisor_multiple = quotient * n_threads;
// uint64_t** seeds = malloc((size_t)n_threads * sizeof(uint64_t*));
- seed_cache_box* cache_box = (seed_cache_box*) malloc(sizeof(seed_cache_box) * (size_t)n_threads);
+ seed_cache_box* cache_box = (seed_cache_box*)malloc(sizeof(seed_cache_box) * (size_t)n_threads);
// seed_cache_box cache_box[n_threads]; // we could use the C stack. On normal linux machines, it's 8MB ($ ulimit -s). However, it doesn't quite feel right.
srand(1);
for (int i = 0; i < n_threads; i++) {
@@ -69,12 +69,12 @@ void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_
int upper_bound_not_inclusive = ((i + 1) * quotient); // note the < in the for loop below,
for (int j = lower_bound_inclusive; j < upper_bound_not_inclusive; j++) {
results[j] = sampler(&(cache_box[i].seed));
- // In principle, these results[j] could also result in two threads competing for the same cache line.
+ // In principle, these results[j] could also result in two threads competing for the same cache line.
// In practice, though,
// a) this would happen infrequently
- // b)
- }
-
+ // b) trying to unroll loops actually makes the code slower
+ // c) 8 results[j] are 8 doubles, which fit a cache line. If n_samples/n_threads
+ }
}
}
for (int j = divisor_multiple; j < n_samples; j++) {
@@ -124,7 +124,7 @@ static double quickselect(int k, double xs[], int n)
{
// https://en.wikipedia.org/wiki/Quickselect
- double *ys = malloc((size_t)n * sizeof(double));
+ double* ys = malloc((size_t)n * sizeof(double));
memcpy(ys, xs, (size_t)n * sizeof(double));
// ^: don't rearrange item order in the original array