add code comment about cache sharing

This commit is contained in:
NunoSempere 2024-01-12 00:33:46 +01:00
parent 2b5b496c25
commit bbe0116381

View File

@ -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)
{