From 2096b363bd0acd05589dcb109616f7b8d6eeee19 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Fri, 11 Aug 2023 14:01:12 +0200 Subject: [PATCH] start adding model about probability of recovery after nuclear war. --- examples/10_nuclear_recovery/example.c | 28 ++++++++++++++ examples/10_nuclear_recovery/makefile | 53 ++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 examples/10_nuclear_recovery/example.c create mode 100644 examples/10_nuclear_recovery/makefile diff --git a/examples/10_nuclear_recovery/example.c b/examples/10_nuclear_recovery/example.c new file mode 100644 index 0000000..88a4746 --- /dev/null +++ b/examples/10_nuclear_recovery/example.c @@ -0,0 +1,28 @@ +#include "../../squiggle.h" +#include +#include +#include +#include + +double laplace(double successes, double trials){ + return (successes + 1)/(trials + 2); +} + +double yearly_probability_nuclear_apocalypse(double year, uint64_t* seed) +{ + double successes = 0; + double failures = (year - 1960); + +} + + +int main() +{ + // set randomness seed + uint64_t* seed = malloc(sizeof(uint64_t)); + *seed = 1000; // xorshift can't start with 0 + + int n = 1000 * 1000; + + free(seed); +} diff --git a/examples/10_nuclear_recovery/makefile b/examples/10_nuclear_recovery/makefile new file mode 100644 index 0000000..ef385f7 --- /dev/null +++ b/examples/10_nuclear_recovery/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