From bbe0116381f797bb29b92d3f2b1429583f4bcf0f Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Fri, 12 Jan 2024 00:33:46 +0100 Subject: [PATCH] add code comment about cache sharing --- squiggle_more.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/squiggle_more.c b/squiggle_more.c index 766a66f..4e3fce4 100644 --- a/squiggle_more.c +++ b/squiggle_more.c @@ -14,7 +14,10 @@ typedef struct seed_cache_box_t { uint64_t* seed; char padding[CACHE_LINE_SIZE - sizeof(uint64_t*)]; } seed_cache_box; -// This avoid false sharing. Dealing with this shaves ~2ms. +// This avoids "false sharing", i.e., different threads competing for the same cache line +// It's possible dealing with this shaves ~2ms +// However, it's possible it doesn't, since pointers aren't changed, just their contents (and the location of their contents doesn't necessarily have to be close, since they are malloc'ed sepately) +// Still, I thought it was interesting void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_threads, int n_samples) {