forked from personal/squiggle.c
formatting pass.
This commit is contained in:
parent
dd6bb53f1b
commit
eb1c592610
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user