slighgly simplify parallel time to botec example

This commit is contained in:
NunoSempere 2023-11-19 15:50:01 +00:00
parent f6af0c33fa
commit 0a660ce6a5
13 changed files with 20 additions and 18 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,5 @@
#include "../../../squiggle.h"
#include "../../../squiggle_more.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -22,12 +21,9 @@ int main()
return sample_mixture(samplers, weights, n_dists, seed);
}
int n_samples = 1000 * 1000;
int n_threads = 16;
int n_samples = 1000 * 1000, n_threads = 16;
double* results = malloc(n_samples * sizeof(double));
parallel_sampler(sampler_result, results, n_threads, n_samples);
double avg = array_sum(results, n_samples)/n_samples;
printf("Avg: %f", avg);
printf("Avg: %f", array_sum(results, n_samples)/n_samples);
free(results);
}

View File

@ -46,6 +46,8 @@ all:
$(CC) $(OPTIMIZED) $(DEBUG) 08_algebra_and_conversion/$(SRC) $(DEPS) -o 08_algebra_and_conversion/$(OUTPUT)
$(CC) $(OPTIMIZED) $(DEBUG) 09_ergonomic_algebra/$(SRC) $(DEPS) -o 09_ergonomic_algebra/$(OUTPUT)
$(CC) $(OPTIMIZED) $(DEBUG) 10_twitter_thread_example/$(SRC) $(DEPS) -o 10_twitter_thread_example/$(OUTPUT)
$(CC) $(OPTIMIZED) $(DEBUG) 11_billion_lognormals_paralell/$(SRC) $(DEPS) -o 11_billion_lognormals_paralell/$(OUTPUT)
$(CC) $(OPTIMIZED) $(DEBUG) 12_time_to_botec_parallel/$(SRC) $(DEPS) -o 12_time_to_botec_parallel/$(OUTPUT)
format-all:
$(FORMATTER) 00_example_template/$(SRC)
@ -59,6 +61,8 @@ format-all:
$(FORMATTER) 08_algebra_and_conversion/$(SRC)
$(FORMATTER) 09_ergonomic_algebra/$(SRC)
$(FORMATTER) 10_twitter_thread_example/$(SRC)
$(FORMATTER) 11_billion_lognormals_paralell/$(SRC)
$(FORMATTER) 12_time_to_botec_parallel/$(SRC)
run-all:
00_example_template/$(OUTPUT)
@ -72,6 +76,8 @@ run-all:
08_algebra_and_conversion/$(OUTPUT)
09_ergonomic_algebra/$(OUTPUT)
10_twitter_thread_example/$(OUTPUT)
11_billion_lognormals_paralell/$(OUTPUT)
12_time_to_botec_parallel/$(OUTPUT)
## make one DIR=06_nuclear_recovery
one: $(DIR)/$(SRC)
@ -89,7 +95,7 @@ run-one: $(DIR)/$(OUTPUT)
time-linux-one: $(DIR)/$(OUTPUT)
@echo "Requires /bin/time, found on GNU/Linux systems" && echo
@echo "Running 100x and taking avg time $(DIR)/$(OUTPUT)"
@t=$$(/usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do $(DIR)/$(OUTPUT); done' 2>&1 >/dev/null | grep real | awk '{print $$2}' ); echo "scale=2; 1000 * $$t / 100" | bc | sed "s|^|Time using 1 thread: |" | sed 's|$$|ms|' && echo
@t=$$(/usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do $(DIR)/$(OUTPUT); done' 2>&1 >/dev/null | grep real | awk '{print $$2}' ); echo "scale=2; 1000 * $$t / 100" | bc | sed "s|^|Time: |" | sed 's|$$|ms|' && echo
## e.g., make profile-linux-one DIR=06_nuclear_recovery
profile-linux-one: