diff --git a/examples/more/00_example_template/example b/examples/more/00_example_template/example new file mode 100755 index 0000000..23217fb Binary files /dev/null and b/examples/more/00_example_template/example differ diff --git a/examples/more/00_example_template/example.c b/examples/more/00_example_template/example.c new file mode 100644 index 0000000..8c3e1ca --- /dev/null +++ b/examples/more/00_example_template/example.c @@ -0,0 +1,16 @@ +#include "../../../squiggle.h" +#include "../../../squiggle_more.h" +#include +#include +#include + +int main() +{ + // set randomness seed + uint64_t* seed = malloc(sizeof(uint64_t)); + *seed = 1000; // xorshift can't start with 0 + + // ... + + free(seed); +} diff --git a/examples/more/01_sample_from_cdf/example b/examples/more/01_sample_from_cdf/example new file mode 100755 index 0000000..9bff001 Binary files /dev/null and b/examples/more/01_sample_from_cdf/example differ diff --git a/examples/more/04_sample_from_cdf_simple/example.c b/examples/more/01_sample_from_cdf/example.c similarity index 98% rename from examples/more/04_sample_from_cdf_simple/example.c rename to examples/more/01_sample_from_cdf/example.c index 5d3f246..ffb7acc 100644 --- a/examples/more/04_sample_from_cdf_simple/example.c +++ b/examples/more/01_sample_from_cdf/example.c @@ -1,5 +1,5 @@ #include "../../../squiggle.h" -#include "../../squiggle_more.h" +#include "../../../squiggle_more.h" #include #include #include diff --git a/examples/more/05_sample_from_cdf_beta/example b/examples/more/02_sample_from_cdf_beta/example similarity index 55% rename from examples/more/05_sample_from_cdf_beta/example rename to examples/more/02_sample_from_cdf_beta/example index 79b7f0f..983af2c 100755 Binary files a/examples/more/05_sample_from_cdf_beta/example and b/examples/more/02_sample_from_cdf_beta/example differ diff --git a/examples/more/05_sample_from_cdf_beta/example.c b/examples/more/02_sample_from_cdf_beta/example.c similarity index 99% rename from examples/more/05_sample_from_cdf_beta/example.c rename to examples/more/02_sample_from_cdf_beta/example.c index 706dad0..2ff6650 100644 --- a/examples/more/05_sample_from_cdf_beta/example.c +++ b/examples/more/02_sample_from_cdf_beta/example.c @@ -1,5 +1,5 @@ #include "../../../squiggle.h" -#include "../../squiggle_more.h" +#include "../../../squiggle_more.h" #include #include #include diff --git a/examples/more/07_ci_beta/example b/examples/more/03_ci_beta/example similarity index 100% rename from examples/more/07_ci_beta/example rename to examples/more/03_ci_beta/example diff --git a/examples/more/07_ci_beta/example.c b/examples/more/03_ci_beta/example.c similarity index 93% rename from examples/more/07_ci_beta/example.c rename to examples/more/03_ci_beta/example.c index a10c075..1dddc86 100644 --- a/examples/more/07_ci_beta/example.c +++ b/examples/more/03_ci_beta/example.c @@ -1,5 +1,5 @@ #include "../../../squiggle.h" -#include "../../squiggle_more.h" +#include "../../../squiggle_more.h" #include #include #include diff --git a/examples/more/08_nuclear_war/example b/examples/more/04_nuclear_war/example similarity index 74% rename from examples/more/08_nuclear_war/example rename to examples/more/04_nuclear_war/example index fa73522..41d18c1 100755 Binary files a/examples/more/08_nuclear_war/example and b/examples/more/04_nuclear_war/example differ diff --git a/examples/more/08_nuclear_war/example.c b/examples/more/04_nuclear_war/example.c similarity index 98% rename from examples/more/08_nuclear_war/example.c rename to examples/more/04_nuclear_war/example.c index 6cb883c..11d961a 100644 --- a/examples/more/08_nuclear_war/example.c +++ b/examples/more/04_nuclear_war/example.c @@ -1,5 +1,5 @@ #include "../../../squiggle.h" -#include "../../squiggle_more.h" +#include "../../../squiggle_more.h" #include #include #include diff --git a/examples/more/08_nuclear_war/scratchpad/example b/examples/more/04_nuclear_war/scratchpad/example similarity index 100% rename from examples/more/08_nuclear_war/scratchpad/example rename to examples/more/04_nuclear_war/scratchpad/example diff --git a/examples/more/08_nuclear_war/scratchpad/example.c b/examples/more/04_nuclear_war/scratchpad/example.c similarity index 100% rename from examples/more/08_nuclear_war/scratchpad/example.c rename to examples/more/04_nuclear_war/scratchpad/example.c diff --git a/examples/more/08_nuclear_war/scratchpad/makefile b/examples/more/04_nuclear_war/scratchpad/makefile similarity index 100% rename from examples/more/08_nuclear_war/scratchpad/makefile rename to examples/more/04_nuclear_war/scratchpad/makefile diff --git a/examples/more/04_sample_from_cdf_simple/example b/examples/more/04_sample_from_cdf_simple/example deleted file mode 100755 index 96a5bf4..0000000 Binary files a/examples/more/04_sample_from_cdf_simple/example and /dev/null differ diff --git a/examples/more/05_burn_10kg_fat/example b/examples/more/05_burn_10kg_fat/example new file mode 100755 index 0000000..3ee2ce3 Binary files /dev/null and b/examples/more/05_burn_10kg_fat/example differ diff --git a/examples/more/09_burn_10kg_fat/example.c b/examples/more/05_burn_10kg_fat/example.c similarity index 97% rename from examples/more/09_burn_10kg_fat/example.c rename to examples/more/05_burn_10kg_fat/example.c index 2184e51..728ca30 100644 --- a/examples/more/09_burn_10kg_fat/example.c +++ b/examples/more/05_burn_10kg_fat/example.c @@ -1,5 +1,5 @@ #include "../../../squiggle.h" -#include "../../squiggle_more.h" +#include "../../../squiggle_more.h" #include #include #include diff --git a/examples/more/06_nuclear_recovery/example b/examples/more/06_nuclear_recovery/example new file mode 100755 index 0000000..238e434 Binary files /dev/null and b/examples/more/06_nuclear_recovery/example differ diff --git a/examples/more/10_nuclear_recovery/example.c b/examples/more/06_nuclear_recovery/example.c similarity index 99% rename from examples/more/10_nuclear_recovery/example.c rename to examples/more/06_nuclear_recovery/example.c index 8434af6..afc774b 100644 --- a/examples/more/10_nuclear_recovery/example.c +++ b/examples/more/06_nuclear_recovery/example.c @@ -1,5 +1,5 @@ #include "../../../squiggle.h" -#include "../../squiggle_more.h" +#include "../../../squiggle_more.h" #include #include #include diff --git a/examples/more/11_algebra/example b/examples/more/07_algebra/example similarity index 75% rename from examples/more/11_algebra/example rename to examples/more/07_algebra/example index c880c3b..1476a0e 100755 Binary files a/examples/more/11_algebra/example and b/examples/more/07_algebra/example differ diff --git a/examples/more/11_algebra/example.c b/examples/more/07_algebra/example.c similarity index 96% rename from examples/more/11_algebra/example.c rename to examples/more/07_algebra/example.c index d621a3a..a6d30d0 100644 --- a/examples/more/11_algebra/example.c +++ b/examples/more/07_algebra/example.c @@ -1,5 +1,5 @@ #include "../../../squiggle.h" -#include "../../squiggle_more.h" +#include "../../../squiggle_more.h" #include #include #include diff --git a/examples/more/12_algebra_and_conversion/example b/examples/more/08_algebra_and_conversion/example similarity index 75% rename from examples/more/12_algebra_and_conversion/example rename to examples/more/08_algebra_and_conversion/example index 8aa4528..bc5eeb3 100755 Binary files a/examples/more/12_algebra_and_conversion/example and b/examples/more/08_algebra_and_conversion/example differ diff --git a/examples/more/12_algebra_and_conversion/example.c b/examples/more/08_algebra_and_conversion/example.c similarity index 97% rename from examples/more/12_algebra_and_conversion/example.c rename to examples/more/08_algebra_and_conversion/example.c index d5fafdd..0dfba6f 100644 --- a/examples/more/12_algebra_and_conversion/example.c +++ b/examples/more/08_algebra_and_conversion/example.c @@ -1,5 +1,5 @@ #include "../../../squiggle.h" -#include "../../squiggle_more.h" +#include "../../../squiggle_more.h" #include #include #include diff --git a/examples/more/09_burn_10kg_fat/example b/examples/more/09_burn_10kg_fat/example deleted file mode 100755 index 55e5d88..0000000 Binary files a/examples/more/09_burn_10kg_fat/example and /dev/null differ diff --git a/examples/more/13_ergonomic_algebra/example b/examples/more/09_ergonomic_algebra/example similarity index 75% rename from examples/more/13_ergonomic_algebra/example rename to examples/more/09_ergonomic_algebra/example index c882715..a293464 100755 Binary files a/examples/more/13_ergonomic_algebra/example and b/examples/more/09_ergonomic_algebra/example differ diff --git a/examples/more/13_ergonomic_algebra/example.c b/examples/more/09_ergonomic_algebra/example.c similarity index 95% rename from examples/more/13_ergonomic_algebra/example.c rename to examples/more/09_ergonomic_algebra/example.c index 39785fb..a944683 100644 --- a/examples/more/13_ergonomic_algebra/example.c +++ b/examples/more/09_ergonomic_algebra/example.c @@ -1,5 +1,5 @@ #include "../../../squiggle.h" -#include "../../squiggle_more.h" +#include "../../../squiggle_more.h" #include #include #include diff --git a/examples/more/10_nuclear_recovery/example b/examples/more/10_nuclear_recovery/example deleted file mode 100755 index 3d42ab5..0000000 Binary files a/examples/more/10_nuclear_recovery/example and /dev/null differ diff --git a/examples/more/14_twitter_thread_example/example b/examples/more/10_twitter_thread_example/example similarity index 70% rename from examples/more/14_twitter_thread_example/example rename to examples/more/10_twitter_thread_example/example index d13bff5..ad080d3 100755 Binary files a/examples/more/14_twitter_thread_example/example and b/examples/more/10_twitter_thread_example/example differ diff --git a/examples/more/14_twitter_thread_example/example.c b/examples/more/10_twitter_thread_example/example.c similarity index 96% rename from examples/more/14_twitter_thread_example/example.c rename to examples/more/10_twitter_thread_example/example.c index ba0f8eb..7d892e7 100644 --- a/examples/more/14_twitter_thread_example/example.c +++ b/examples/more/10_twitter_thread_example/example.c @@ -1,5 +1,5 @@ #include "../../../squiggle.h" -#include "../../squiggle_more.h" +#include "../../../squiggle_more.h" #include #include #include diff --git a/examples/more/makefile b/examples/more/makefile index 821add6..689ed6f 100644 --- a/examples/more/makefile +++ b/examples/more/makefile @@ -1,58 +1,102 @@ # Interface: -# make -# make build -# make format -# make run +# make all +# make format-all +# make run-all +# make one DIR=06_nuclear_recovery +# make format-one DIR=06_nuclear_recovery +# make run-one DIR=06_nuclear_recovery +# make time-linux-one DIR=06_nuclear_recovery +# make profile-one DIR=06_nuclear_recovery # Compiler -CC=gcc # required for nested functions +CC=gcc # CC=tcc # <= faster compilation # Main file -SRC=example.c ../../squiggle.c ../../squiggle_more.c -OUTPUT=./example +SRC=example.c +OUTPUT=example ## Dependencies -OPENMP=-fopenmp +SQUIGGLE=../../squiggle.c +SQUIGGLE_MORE=../../squiggle_more.c MATH=-lm -DEPENDENCIES=$(MATH) $(OPENMP) -# OPENMP=-fopenmp +OPENMP=-fopenmp +DEPS=$(SQUIGGLE) $(SQUIGGLE_MORE) $(MATH) $(OPENMP) ## Flags DEBUG= #'-g' -STANDARD=-std=c99 ## gnu99 allows for nested functions. -EXTENSIONS= #-fnested-functions +STANDARD=-std=c99 WARNINGS=-Wall -OPTIMIZED=-O3#-Ofast -CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED) +OPTIMIZED=-O3 #-Ofast ## Formatter STYLE_BLUEPRINT=webkit FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT) -## make build -build: $(SRC) - # gcc -std=gnu99 example.c -lm -o example - $(CC) $(CFLAGS) $(SRC) $(DEPENDENCIES) -o $(OUTPUT) +## make all +all: + $(CC) $(OPTIMIZED) $(DEBUG) 00_example_template/$(SRC) $(DEPS) -o 00_example_template/$(OUTPUT) + $(CC) $(OPTIMIZED) $(DEBUG) 01_sample_from_cdf/$(SRC) $(DEPS) -o 01_sample_from_cdf/$(OUTPUT) + $(CC) $(OPTIMIZED) $(DEBUG) 02_sample_from_cdf_beta/$(SRC) $(DEPS) -o 02_sample_from_cdf_beta/$(OUTPUT) + $(CC) $(OPTIMIZED) $(DEBUG) 03_ci_beta/$(SRC) $(DEPS) -o 03_ci_beta/$(OUTPUT) + $(CC) $(OPTIMIZED) $(DEBUG) 04_nuclear_war/$(SRC) $(DEPS) -o 04_nuclear_war/$(OUTPUT) + $(CC) $(OPTIMIZED) $(DEBUG) 05_burn_10kg_fat/$(SRC) $(DEPS) -o 05_burn_10kg_fat/$(OUTPUT) + $(CC) $(OPTIMIZED) $(DEBUG) 06_nuclear_recovery/$(SRC) $(DEPS) -o 06_nuclear_recovery/$(OUTPUT) + $(CC) $(OPTIMIZED) $(DEBUG) 07_algebra/$(SRC) $(DEPS) -o 07_algebra/$(OUTPUT) + $(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) -format: $(SRC) - $(FORMATTER) $(SRC) +format-all: + $(FORMATTER) 00_example_template/$(SRC) + $(FORMATTER) 01_sample_from_cdf/$(SRC) + $(FORMATTER) 02_sample_from_cdf_beta/$(SRC) + $(FORMATTER) 03_ci_beta/$(SRC) + $(FORMATTER) 04_nuclear_war/$(SRC) + $(FORMATTER) 05_burn_10kg_fat/$(SRC) + $(FORMATTER) 06_nuclear_recovery/$(SRC) + $(FORMATTER) 07_algebra/$(SRC) + $(FORMATTER) 08_algebra_and_conversion/$(SRC) + $(FORMATTER) 09_ergonomic_algebra/$(SRC) + $(FORMATTER) 10_twitter_thread_example/$(SRC) -run: $(SRC) $(OUTPUT) - ./$(OUTPUT) && echo +run-all: + 00_example_template/$(OUTPUT) + 01_sample_from_cdf/$(OUTPUT) + 02_sample_from_cdf_beta/$(OUTPUT) + 03_ci_beta/$(OUTPUT) + 04_nuclear_war/$(OUTPUT) + 05_burn_10kg_fat/$(OUTPUT) + 06_nuclear_recovery/$(OUTPUT) + 07_algebra/$(OUTPUT) + 08_algebra_and_conversion/$(OUTPUT) + 09_ergonomic_algebra/$(OUTPUT) + 10_twitter_thread_example/$(OUTPUT) -time-linux: +## make one DIR=06_nuclear_recovery +one: $(DIR)/$(SRC) + $(CC) $(OPTIMIZED) $(DEBUG) $(DIR)/$(SRC) $(DEPS) -o $(DIR)/$(OUTPUT) + +## make format-one DIR=06_nuclear_recovery +format-one: $(DIR)/$(SRC) + $(FORMATTER) $(DIR)/$(SRC) + +## make run-one DIR=06_nuclear_recovery +run-one: $(DIR)/$(OUTPUT) + $(DIR)/$(OUTPUT) && echo + +## make time-linux-one DIR=06_nuclear_recovery +time-linux-one: $(DIR)/$(OUTPUT) @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 + @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 -## Profiling - -profile-linux: +## e.g., make profile-linux-one DIR=06_nuclear_recovery +profile-linux-one: 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) + $(CC) $(OPTIMIZED) $(DEBUG) $(DIR)/$(SRC) $(DEPS) -o $(DIR)/$(OUTPUT) + # $(CC) $(SRC) $(DEPS) -o $(OUTPUT) + sudo perf record $(DIR)/$(OUTPUT) sudo perf report rm perf.data