diff --git a/examples/more/00_example_template/example b/examples/more/00_example_template/example index cc23c9f..0955afb 100755 Binary files a/examples/more/00_example_template/example and b/examples/more/00_example_template/example differ diff --git a/examples/more/01_sample_from_cdf/example b/examples/more/01_sample_from_cdf/example index e7a51ff..c3c651a 100755 Binary files a/examples/more/01_sample_from_cdf/example and b/examples/more/01_sample_from_cdf/example differ diff --git a/examples/more/02_sample_from_cdf_beta/example b/examples/more/02_sample_from_cdf_beta/example index 39569f4..25d745b 100755 Binary files a/examples/more/02_sample_from_cdf_beta/example and b/examples/more/02_sample_from_cdf_beta/example differ diff --git a/examples/more/03_ci_beta/example b/examples/more/03_ci_beta/example index 0dd6da1..c2ccfe2 100755 Binary files a/examples/more/03_ci_beta/example and b/examples/more/03_ci_beta/example differ diff --git a/examples/more/04_nuclear_war/example b/examples/more/04_nuclear_war/example index b296d20..0ba93e2 100755 Binary files a/examples/more/04_nuclear_war/example and b/examples/more/04_nuclear_war/example differ diff --git a/examples/more/05_burn_10kg_fat/example b/examples/more/05_burn_10kg_fat/example index 4a5c586..3e48983 100755 Binary files a/examples/more/05_burn_10kg_fat/example and b/examples/more/05_burn_10kg_fat/example differ diff --git a/examples/more/06_nuclear_recovery/example b/examples/more/06_nuclear_recovery/example index df19be6..feec296 100755 Binary files a/examples/more/06_nuclear_recovery/example and b/examples/more/06_nuclear_recovery/example differ diff --git a/examples/more/07_algebra/example b/examples/more/07_algebra/example index ae1efe9..3b401e8 100755 Binary files a/examples/more/07_algebra/example and b/examples/more/07_algebra/example differ diff --git a/examples/more/08_algebra_and_conversion/example b/examples/more/08_algebra_and_conversion/example index 8405818..da3d70b 100755 Binary files a/examples/more/08_algebra_and_conversion/example and b/examples/more/08_algebra_and_conversion/example differ diff --git a/examples/more/09_ergonomic_algebra/example b/examples/more/09_ergonomic_algebra/example index 611b4e9..d975de5 100755 Binary files a/examples/more/09_ergonomic_algebra/example and b/examples/more/09_ergonomic_algebra/example differ diff --git a/examples/more/10_twitter_thread_example/example b/examples/more/10_twitter_thread_example/example index 95b1d1c..3de3b14 100755 Binary files a/examples/more/10_twitter_thread_example/example and b/examples/more/10_twitter_thread_example/example differ diff --git a/examples/more/11_billion_lognormals_paralell/example b/examples/more/11_billion_lognormals_paralell/example index e65a0d7..ba25d1d 100755 Binary files a/examples/more/11_billion_lognormals_paralell/example and b/examples/more/11_billion_lognormals_paralell/example differ diff --git a/examples/more/12_time_to_botec_parallel/example b/examples/more/12_time_to_botec_parallel/example index caf0fd2..79f5bdb 100755 Binary files a/examples/more/12_time_to_botec_parallel/example and b/examples/more/12_time_to_botec_parallel/example differ diff --git a/examples/more/13_parallelize_min/example b/examples/more/13_parallelize_min/example index 6544858..151155a 100755 Binary files a/examples/more/13_parallelize_min/example and b/examples/more/13_parallelize_min/example differ diff --git a/examples/more/14_check_confidence_interval/example b/examples/more/14_check_confidence_interval/example index 9322f3a..c0fbd4f 100755 Binary files a/examples/more/14_check_confidence_interval/example and b/examples/more/14_check_confidence_interval/example differ diff --git a/squiggle_more.c b/squiggle_more.c index 9271530..0146707 100644 --- a/squiggle_more.c +++ b/squiggle_more.c @@ -9,6 +9,12 @@ #include // memcpy /* Parallel sampler */ +#define CACHE_LINE_SIZE 64 +typedef struct padded_seed_t { + uint64_t* seed; + char padding[CACHE_LINE_SIZE - sizeof(uint64_t*)]; +} padded_seed; + void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_threads, int n_samples) { @@ -29,14 +35,15 @@ void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_ int quotient = n_samples / n_threads; int divisor_multiple = quotient * n_threads; - uint64_t** seeds = malloc((size_t)n_threads * sizeof(uint64_t*)); + // uint64_t** seeds = malloc((size_t)n_threads * sizeof(uint64_t*)); + padded_seed* seeds = (padded_seed*) malloc(sizeof(padded_seed) * (size_t)n_threads); srand(1); for (int i = 0; i < n_threads; i++) { - seeds[i] = malloc(sizeof(uint64_t)); + seeds[i].seed = malloc(sizeof(uint64_t*)); // Constraints: // - xorshift can't start with 0 // - the seeds should be reasonably separated and not correlated - *seeds[i] = (uint64_t)rand() * (UINT64_MAX / RAND_MAX); + *(seeds[i].seed) = (uint64_t)rand() * (UINT64_MAX / RAND_MAX); // printf("#%ld: %lu\n",i, *seeds[i]); // Other initializations tried: @@ -53,17 +60,17 @@ void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_ int lower_bound_inclusive = i * quotient; 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(seeds[i]); + results[j] = sampler(seeds[i].seed); } } } for (int j = divisor_multiple; j < n_samples; j++) { - results[j] = sampler(seeds[0]); + results[j] = sampler(seeds[0].seed); // we can just reuse a seed, this isn't problematic because we are not doing multithreading } for (int i = 0; i < n_threads; i++) { - free(seeds[i]); + free(seeds[i].seed); } free(seeds); } @@ -109,7 +116,7 @@ static double quickselect(int k, double xs[], int n) double *ys = malloc((size_t)n * sizeof(double)); memcpy(ys, xs, (size_t)n * sizeof(double)); - // ^: don't make this operation "destructive" + // ^: don't rearrange item order in the original array int low = 0; int high = n - 1;