diff --git a/examples/more/00_example_template/example b/examples/more/00_example_template/example index f2b1432..1999f3a 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 4920d36..7d52316 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 521640a..97de4a4 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 a0cde1d..acc4457 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 522f037..8feeb70 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 6482272..524792d 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 0a8f642..e0c3992 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 e4cf037..6419e15 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 094dc39..f585d22 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 273445c..ebd9f55 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 1960f0d..d29c37c 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 f46aaef..aa06dd8 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 ae9c70d..8110f21 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 a6bce2c..c43ae15 100755 Binary files a/examples/more/13_parallelize_min/example and b/examples/more/13_parallelize_min/example differ diff --git a/examples/more/13_parallelize_min/example.c b/examples/more/13_parallelize_min/example.c index cf1f9ea..c8ba6b9 100644 --- a/examples/more/13_parallelize_min/example.c +++ b/examples/more/13_parallelize_min/example.c @@ -15,7 +15,7 @@ int main() // Question being asked: what is the distribution of sampling 1000 times and taking the min? double sample_min_of_n(uint64_t* seed, int n){ double min = sample_normal(5, 2, seed); - for(int i=0; i<(n-2); i++){ + for(int i=0; i<(n-1); i++){ double sample = sample_normal(5, 2, seed); if(sample < min){ min = sample; @@ -27,7 +27,7 @@ int main() return sample_min_of_n(seed, 1000); } - int n_samples = 1000000, n_threads = 16; + int n_samples = 10000, n_threads = 16; double* results = malloc(n_samples * sizeof(double)); parallel_sampler(sampler_min_of_1000, results, n_threads, n_samples); printf("Mean of the distribution of (taking the min of 1000 samples of a normal(5,2)): %f\n", array_mean(results, n_samples)); @@ -41,27 +41,29 @@ int main() int quotient = n / 16; int remainder = n % 16; - uint64_t seed = 1000; + uint64_t seed = 100; double result_remainder = sample_min_of_n(&seed, remainder); double sample_min_of_quotient(uint64_t* seed) { - return sample_min_of_n(seed, quotient); + double result = sample_min_of_n(seed, quotient); + // printf("Result: %f\n", result); + return result; } - double* results_quotient = malloc(quotient * sizeof(double)); - parallel_sampler(sample_min_of_quotient, results_quotient, n_threads, quotient); + double* results = malloc(n_threads * sizeof(double)); + parallel_sampler(sample_min_of_quotient, results, n_threads, n_threads); - double min = results_quotient[0]; - for(int i=1; i results_quotient[i]){ - min = results_quotient[i]; + double min = results[0]; + for(int i=1; i results[i]){ + min = results[i]; } } if(min > result_remainder){ min = result_remainder; } - free(results_quotient); + free(results); return min; } - printf("Minimum of 1M samples of normal(5,2): %f\n", sample_n_parallel(1000000)); + printf("Minimum of 10M samples of normal(5,2): %f\n", sample_n_parallel(1000 * 1000)); } diff --git a/squiggle_more.c b/squiggle_more.c index 6f63de3..ad51b9c 100644 --- a/squiggle_more.c +++ b/squiggle_more.c @@ -326,14 +326,25 @@ void parallel_sampler(double (*sampler)(uint64_t* seed), double* results, int n_ int divisor_multiple = quotient * n_threads; uint64_t** seeds = malloc(n_threads * sizeof(uint64_t*)); + // printf("UINT64_MAX: %lu\n", UINT64_MAX); + srand(1); for (uint64_t i = 0; i < n_threads; i++) { seeds[i] = malloc(sizeof(uint64_t)); - *seeds[i] = i + 1; // xorshift can't start with 0 + // 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); + // printf("#%ld: %lu\n",i, *seeds[i]); + + // Other initializations tried: + // *seeds[i] = 1 + i; + // *seeds[i] = (i + 0.5)*(UINT64_MAX/n_threads); + // *seeds[i] = (i + 0.5)*(UINT64_MAX/n_threads) + constant * i; } int i; #pragma omp parallel private(i) - { + { #pragma omp for for (i = 0; i < n_threads; i++) { int lower_bound_inclusive = i * quotient;