diff --git a/examples/01_one_sample/example b/examples/01_one_sample/example index 84f385e..9c9a4ae 100755 Binary files a/examples/01_one_sample/example and b/examples/01_one_sample/example differ diff --git a/examples/02_many_samples_time_to_botec/example b/examples/02_many_samples_time_to_botec/example index 3a56c3b..bb4ba8f 100755 Binary files a/examples/02_many_samples_time_to_botec/example and b/examples/02_many_samples_time_to_botec/example differ diff --git a/examples/03_gcc_nested_function/example b/examples/03_gcc_nested_function/example index 0d8507e..62d1419 100755 Binary files a/examples/03_gcc_nested_function/example and b/examples/03_gcc_nested_function/example differ diff --git a/examples/04_sample_from_cdf_simple/example b/examples/04_sample_from_cdf_simple/example index a2f9d85..40d44cf 100755 Binary files a/examples/04_sample_from_cdf_simple/example and b/examples/04_sample_from_cdf_simple/example differ diff --git a/examples/05_sample_from_cdf_beta/example b/examples/05_sample_from_cdf_beta/example index 5f5422b..4d13845 100755 Binary files a/examples/05_sample_from_cdf_beta/example and b/examples/05_sample_from_cdf_beta/example differ diff --git a/examples/06_gamma_beta/example b/examples/06_gamma_beta/example index cc00739..5ea6a71 100755 Binary files a/examples/06_gamma_beta/example and b/examples/06_gamma_beta/example differ diff --git a/examples/16_100_lognormal_samples/example b/examples/16_100_lognormal_samples/example new file mode 100755 index 0000000..4268e04 Binary files /dev/null and b/examples/16_100_lognormal_samples/example differ diff --git a/examples/16_100_lognormal_samples/example.c b/examples/16_100_lognormal_samples/example.c new file mode 100644 index 0000000..84156d2 --- /dev/null +++ b/examples/16_100_lognormal_samples/example.c @@ -0,0 +1,17 @@ +#include "../../squiggle.h" +#include +#include +#include + +// Estimate functions +int main(){ + // set randomness seed + uint64_t* seed = malloc(sizeof(uint64_t)); + *seed = 1000; // xorshift can't start with 0 + + for(int i=0; i<100; i++){ + double sample = sample_lognormal(0,10, seed); + printf("%f\n", sample); + } + free(seed); +} diff --git a/examples/16_100_lognormal_samples/makefile b/examples/16_100_lognormal_samples/makefile new file mode 100644 index 0000000..ef385f7 --- /dev/null +++ b/examples/16_100_lognormal_samples/makefile @@ -0,0 +1,53 @@ +# Interface: +# make +# make build +# make format +# make run + +# Compiler +CC=gcc +# CC=tcc # <= faster compilation + +# Main file +SRC=example.c ../../squiggle.c +OUTPUT=example + +## Dependencies +MATH=-lm + +## Flags +DEBUG= #'-g' +STANDARD=-std=c99 +WARNINGS=-Wall +OPTIMIZED=-O3 #-Ofast +# OPENMP=-fopenmp + +## Formatter +STYLE_BLUEPRINT=webkit +FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT) + +## make build +build: $(SRC) + $(CC) $(OPTIMIZED) $(DEBUG) $(SRC) $(MATH) -o $(OUTPUT) + +format: $(SRC) + $(FORMATTER) $(SRC) + +run: $(SRC) $(OUTPUT) + OMP_NUM_THREADS=1 ./$(OUTPUT) && echo + +time-linux: + @echo "Requires /bin/time, found on GNU/Linux systems" && echo + + @echo "Running 100x and taking avg time $(OUTPUT)" + @t=$$(/usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do $(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 + +## Profiling + +profile-linux: + echo "Requires perf, which depends on the kernel version, and might be in linux-tools package or similar" + echo "Must be run as sudo" + $(CC) $(SRC) $(MATH) -o $(OUTPUT) + sudo perf record ./$(OUTPUT) + sudo perf report + rm perf.data diff --git a/examples/16_100_lognormal_samples/run-sorted.sh b/examples/16_100_lognormal_samples/run-sorted.sh new file mode 100644 index 0000000..b7c3750 --- /dev/null +++ b/examples/16_100_lognormal_samples/run-sorted.sh @@ -0,0 +1 @@ +./example | sort -h