diff --git a/examples/more/00_example_template/example b/examples/more/00_example_template/example index 243b72d..ab405cb 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 ac469d9..52f8eb4 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 1028c55..e79ab13 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 8ae2dfb..7410d7b 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 8418a3e..92db813 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 88460ef..220f4a7 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 03a88a2..538cebd 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 667ccc1..301d72d 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 801289c..4f5f399 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 7885edd..c68453f 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 4c2c3c1..376681b 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 bcec14e..38dbe70 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 8430ff0..5633d7c 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 838859a..14fbc48 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 bbcfa8c..a4d9d30 100755 Binary files a/examples/more/14_check_confidence_interval/example and b/examples/more/14_check_confidence_interval/example differ diff --git a/makefile b/makefile index ed68dcf..e1bc95f 100644 --- a/makefile +++ b/makefile @@ -19,3 +19,9 @@ format: squiggle.c squiggle.h lint: clang-tidy squiggle.c -- -lm clang-tidy squiggle_more.c -- -lm + +profile: + OMP_NUM_THREADS=16 sudo perf record ./examples/more/12_time_to_botec_parallel/example + sudo perf report + rm perf.data + diff --git a/scratchpad/scratchpad b/scratchpad/scratchpad index e64435f..0faebb6 100755 Binary files a/scratchpad/scratchpad and b/scratchpad/scratchpad differ diff --git a/scratchpad/scratchpad.c b/scratchpad/scratchpad.c index b2f057a..64932b6 100644 --- a/scratchpad/scratchpad.c +++ b/scratchpad/scratchpad.c @@ -19,5 +19,7 @@ int main() ci ci_90 = array_get_90_ci(xs, n); printf("Recovering confidence interval of sample_to(10, 100):\n low: %f, high: %f\n", ci_90.low, ci_90.high); + + printf("Size of uint64_t: %ld", sizeof(uint64_t*)); free(seed); } diff --git a/squiggle_more.c b/squiggle_more.c index 3211b00..d3a4f63 100644 --- a/squiggle_more.c +++ b/squiggle_more.c @@ -8,17 +8,20 @@ #include #include // memcpy -/* Parallel sampler */ +/* Cache optimizations */ #define CACHE_LINE_SIZE 64 +// getconf LEVEL1_DCACHE_LINESIZE +// typedef struct seed_cache_box_t { uint64_t seed; - char padding[CACHE_LINE_SIZE - sizeof(uint64_t*)]; + char padding[CACHE_LINE_SIZE - sizeof(uint64_t)]; + // Cache line size is 64 *bytes*, uint64_t is 64 *bits* (8 bytes). Different units! } seed_cache_box; // 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 +// Dealing with this shaves 4ms from a 12ms process, or a third of runtime +// +/* Parallel sampler */ void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_threads, int n_samples) { @@ -41,6 +44,7 @@ void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_ // 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[n_threads]; srand(1); for (int i = 0; i < n_threads; i++) { // Constraints: @@ -73,11 +77,7 @@ void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_ results[j] = sampler(&(cache_box[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(cache_box[i].seed); - } - */ + free(cache_box); }