Compare commits
No commits in common. "1521030421af2e8734ff6721881f348e2f0f9bb9" and "a543bd5b942c7899a93967527b79e616c5217bbc" have entirely different histories.
1521030421
...
a543bd5b94
|
@ -1,4 +1,4 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
53
examples/00_example_template/makefile
Normal file
53
examples/00_example_template/makefile
Normal file
|
@ -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
|
|
@ -1,4 +1,4 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
53
examples/01_one_sample/makefile
Normal file
53
examples/01_one_sample/makefile
Normal file
|
@ -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
|
|
@ -1,4 +1,4 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
Binary file not shown.
|
@ -1,4 +1,4 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -15,7 +15,6 @@ int main()
|
||||||
|
|
||||||
int n_dists = 4;
|
int n_dists = 4;
|
||||||
|
|
||||||
// These are nested functions. They will not compile without gcc.
|
|
||||||
double sample_0(uint64_t * seed) { return 0; }
|
double sample_0(uint64_t * seed) { return 0; }
|
||||||
double sample_1(uint64_t * seed) { return 1; }
|
double sample_1(uint64_t * seed) { return 1; }
|
||||||
double sample_few(uint64_t * seed) { return sample_to(1, 3, seed); }
|
double sample_few(uint64_t * seed) { return sample_to(1, 3, seed); }
|
57
examples/03_gcc_nested_function/makefile
Normal file
57
examples/03_gcc_nested_function/makefile
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
CC=gcc # required for nested functions
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../squiggle.c
|
||||||
|
OUTPUT=example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
MATH=-lm
|
||||||
|
DEPENDENCIES=$(MATH)
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=gnu99 ## allows for nested functions.
|
||||||
|
EXTENSIONS= #-fnested-functions
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3#-Ofast
|
||||||
|
CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
./$(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
|
BIN
examples/04_sample_from_cdf_simple/example
Executable file
BIN
examples/04_sample_from_cdf_simple/example
Executable file
Binary file not shown.
|
@ -1,5 +1,5 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include "../../../squiggle_more.h"
|
#include "../../squiggle_more.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
58
examples/04_sample_from_cdf_simple/makefile
Normal file
58
examples/04_sample_from_cdf_simple/makefile
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
CC=gcc # required for nested functions
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../squiggle.c ../../squiggle_more.c
|
||||||
|
OUTPUT=./example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
OPENMP=-fopenmp
|
||||||
|
MATH=-lm
|
||||||
|
DEPENDENCIES=$(MATH) $(OPENMP)
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=c99 ## gnu99 allows for nested functions.
|
||||||
|
EXTENSIONS= #-fnested-functions
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3#-Ofast
|
||||||
|
CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
./$(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
|
BIN
examples/05_sample_from_cdf_beta/example
Executable file
BIN
examples/05_sample_from_cdf_beta/example
Executable file
Binary file not shown.
|
@ -1,5 +1,5 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include "../../../squiggle_more.h"
|
#include "../../squiggle_more.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
58
examples/05_sample_from_cdf_beta/makefile
Normal file
58
examples/05_sample_from_cdf_beta/makefile
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
# CC=gcc # required for nested functions
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../squiggle.c ../../squiggle_more.c
|
||||||
|
OUTPUT=./example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
MATH=-lm
|
||||||
|
DEPENDENCIES=$(MATH)
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
VERBOSE=#-v
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=c99 ## gnu99 allows for nested functions.
|
||||||
|
EXTENSIONS= #-fnested-functions
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3#-Ofast
|
||||||
|
CFLAGS=$(VERBOSE) $(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
./$(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
|
|
@ -1,4 +1,4 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
53
examples/06_gamma_beta/makefile
Normal file
53
examples/06_gamma_beta/makefile
Normal file
|
@ -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
|
BIN
examples/07_ci_beta/example
Executable file
BIN
examples/07_ci_beta/example
Executable file
Binary file not shown.
|
@ -1,5 +1,5 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include "../../../squiggle_more.h"
|
#include "../../squiggle_more.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
58
examples/07_ci_beta/makefile
Normal file
58
examples/07_ci_beta/makefile
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
CC=gcc # required for nested functions
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../squiggle.c ../../squiggle_more.c
|
||||||
|
OUTPUT=./example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
OPENMP=-fopenmp
|
||||||
|
MATH=-lm
|
||||||
|
DEPENDENCIES=$(MATH) $(OPENMP)
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=c99 ## gnu99 allows for nested functions.
|
||||||
|
EXTENSIONS= #-fnested-functions
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3#-Ofast
|
||||||
|
CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
./$(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
|
BIN
examples/08_nuclear_war/example
Executable file
BIN
examples/08_nuclear_war/example
Executable file
Binary file not shown.
|
@ -1,5 +1,5 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include "../../../squiggle_more.h"
|
#include "../../squiggle_more.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
53
examples/08_nuclear_war/makefile
Normal file
53
examples/08_nuclear_war/makefile
Normal file
|
@ -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 ../../squiggle_more.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
|
BIN
examples/09_burn_10kg_fat/example
Executable file
BIN
examples/09_burn_10kg_fat/example
Executable file
Binary file not shown.
|
@ -1,5 +1,5 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include "../../../squiggle_more.h"
|
#include "../../squiggle_more.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
57
examples/09_burn_10kg_fat/makefile
Normal file
57
examples/09_burn_10kg_fat/makefile
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
CC=gcc # required for nested functions
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../squiggle.c ../../squiggle_more.c
|
||||||
|
OUTPUT=./example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
MATH=-lm
|
||||||
|
DEPENDENCIES=$(MATH)
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=c99 ## gnu99 allows for nested functions.
|
||||||
|
EXTENSIONS= #-fnested-functions
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3#-Ofast
|
||||||
|
CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
./$(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
|
BIN
examples/10_nuclear_recovery/example
Executable file
BIN
examples/10_nuclear_recovery/example
Executable file
Binary file not shown.
|
@ -1,5 +1,5 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include "../../../squiggle_more.h"
|
#include "../../squiggle_more.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
57
examples/10_nuclear_recovery/makefile
Normal file
57
examples/10_nuclear_recovery/makefile
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
CC=gcc # required for nested functions
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../squiggle.c ../../squiggle_more.c
|
||||||
|
OUTPUT=./example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
MATH=-lm
|
||||||
|
DEPENDENCIES=$(MATH)
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=c99 ## gnu99 allows for nested functions.
|
||||||
|
EXTENSIONS= #-fnested-functions
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3#-Ofast
|
||||||
|
CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
./$(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
|
BIN
examples/11_algebra/example
Executable file
BIN
examples/11_algebra/example
Executable file
Binary file not shown.
|
@ -1,5 +1,5 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include "../../../squiggle_more.h"
|
#include "../../squiggle_more.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
57
examples/11_algebra/makefile
Normal file
57
examples/11_algebra/makefile
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
CC=gcc # required for nested functions
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../squiggle.c ../../squiggle_more.c
|
||||||
|
OUTPUT=./example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
MATH=-lm
|
||||||
|
DEPENDENCIES=$(MATH)
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=c99 ## gnu99 allows for nested functions.
|
||||||
|
EXTENSIONS= #-fnested-functions
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3#-Ofast
|
||||||
|
CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
./$(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
|
BIN
examples/12_algebra_and_conversion/example
Executable file
BIN
examples/12_algebra_and_conversion/example
Executable file
Binary file not shown.
|
@ -1,5 +1,5 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include "../../../squiggle_more.h"
|
#include "../../squiggle_more.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
57
examples/12_algebra_and_conversion/makefile
Normal file
57
examples/12_algebra_and_conversion/makefile
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
CC=gcc # required for nested functions
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../squiggle.c ../../squiggle_more.c
|
||||||
|
OUTPUT=./example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
MATH=-lm
|
||||||
|
DEPENDENCIES=$(MATH)
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=c99 ## gnu99 allows for nested functions.
|
||||||
|
EXTENSIONS= #-fnested-functions
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3#-Ofast
|
||||||
|
CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
./$(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
|
BIN
examples/13_ergonomic_algebra/example
Executable file
BIN
examples/13_ergonomic_algebra/example
Executable file
Binary file not shown.
|
@ -1,5 +1,5 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include "../../../squiggle_more.h"
|
#include "../../squiggle_more.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
57
examples/13_ergonomic_algebra/makefile
Normal file
57
examples/13_ergonomic_algebra/makefile
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
CC=gcc # required for nested functions
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../squiggle.c ../../squiggle_more.c
|
||||||
|
OUTPUT=./example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
MATH=-lm
|
||||||
|
DEPENDENCIES=$(MATH)
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=c99 ## gnu99 allows for nested functions.
|
||||||
|
EXTENSIONS= #-fnested-functions
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3#-Ofast
|
||||||
|
CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
./$(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
|
BIN
examples/14_twitter_thread_example/example
Executable file
BIN
examples/14_twitter_thread_example/example
Executable file
Binary file not shown.
|
@ -1,5 +1,5 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include "../../../squiggle_more.h"
|
#include "../../squiggle_more.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
57
examples/14_twitter_thread_example/makefile
Normal file
57
examples/14_twitter_thread_example/makefile
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
CC=gcc # required for nested functions
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../squiggle.c ../../squiggle_more.c
|
||||||
|
OUTPUT=./example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
MATH=-lm
|
||||||
|
DEPENDENCIES=$(MATH)
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=c99 ## gnu99 allows for nested functions.
|
||||||
|
EXTENSIONS= #-fnested-functions
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3#-Ofast
|
||||||
|
CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
./$(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
|
53
examples/15_plotting-scratchpad/src/makefile
Normal file
53
examples/15_plotting-scratchpad/src/makefile
Normal file
|
@ -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)
|
||||||
|
./$(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
|
|
@ -1,4 +1,4 @@
|
||||||
#include "../../../squiggle.h"
|
#include "../../squiggle.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
53
examples/16_100_lognormal_samples/makefile
Normal file
53
examples/16_100_lognormal_samples/makefile
Normal file
|
@ -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
|
|
@ -1,85 +0,0 @@
|
||||||
# Interface:
|
|
||||||
# make all
|
|
||||||
# make format-all
|
|
||||||
# make run-all
|
|
||||||
# make one DIR=01_one_sample
|
|
||||||
# make format-one DIR=01_one_sample
|
|
||||||
# make run-one DIR=01_one_sample
|
|
||||||
# make time-linux-one DIR=01_one_sample
|
|
||||||
# make profile-one DIR=01_one_sample
|
|
||||||
|
|
||||||
# Compiler
|
|
||||||
CC=gcc
|
|
||||||
# CC=tcc # <= faster compilation
|
|
||||||
|
|
||||||
# Main file
|
|
||||||
SRC=example.c
|
|
||||||
OUTPUT=example
|
|
||||||
|
|
||||||
## Dependencies
|
|
||||||
SQUIGGLE=../../squiggle.c
|
|
||||||
MATH=-lm
|
|
||||||
DEPS=$(SQUIGGLE) $(MATH)
|
|
||||||
|
|
||||||
## Flags
|
|
||||||
DEBUG= #'-g'
|
|
||||||
STANDARD=-std=c99
|
|
||||||
WARNINGS=-Wall
|
|
||||||
OPTIMIZED=-O3 #-Ofast
|
|
||||||
|
|
||||||
## Formatter
|
|
||||||
STYLE_BLUEPRINT=webkit
|
|
||||||
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
|
|
||||||
|
|
||||||
## make all
|
|
||||||
all:
|
|
||||||
$(CC) $(OPTIMIZED) $(DEBUG) 00_example_template/$(SRC) $(DEPS) -o 00_example_template/$(OUTPUT)
|
|
||||||
$(CC) $(OPTIMIZED) $(DEBUG) 01_one_sample/$(SRC) $(DEPS) -o 01_one_sample/$(OUTPUT)
|
|
||||||
$(CC) $(OPTIMIZED) $(DEBUG) 02_time_to_botec/$(SRC) $(DEPS) -o 02_time_to_botec/$(OUTPUT)
|
|
||||||
$(CC) $(OPTIMIZED) $(DEBUG) 03_gcc_nested_function/$(SRC) $(DEPS) -o 03_gcc_nested_function/$(OUTPUT)
|
|
||||||
$(CC) $(OPTIMIZED) $(DEBUG) 04_gamma_beta/$(SRC) $(DEPS) -o 04_gamma_beta/$(OUTPUT)
|
|
||||||
$(CC) $(OPTIMIZED) $(DEBUG) 05_hundred_lognormals/$(SRC) $(DEPS) -o 05_hundred_lognormals/$(OUTPUT)
|
|
||||||
|
|
||||||
format-all:
|
|
||||||
$(FORMATTER) 00_example_template/$(SRC)
|
|
||||||
$(FORMATTER) 01_one_sample/$(SRC)
|
|
||||||
$(FORMATTER) 02_time_to_botec/$(SRC)
|
|
||||||
$(FORMATTER) 03_gcc_nested_function/$(SRC)
|
|
||||||
$(FORMATTER) 04_gamma_beta/$(SRC)
|
|
||||||
$(FORMATTER) 05_hundred_lognormals/$(SRC)
|
|
||||||
|
|
||||||
run-all:
|
|
||||||
00_example_template/$(OUTPUT)
|
|
||||||
01_one_sample/$(OUTPUT)
|
|
||||||
02_time_to_botec/$(OUTPUT)
|
|
||||||
03_gcc_nested_function/$(OUTPUT)
|
|
||||||
04_gamma_beta/$(OUTPUT)
|
|
||||||
05_hundred_lognormals/$(OUTPUT)
|
|
||||||
|
|
||||||
## make one DIR=01_one_sample
|
|
||||||
one: $(DIR)/$(SRC)
|
|
||||||
$(CC) $(OPTIMIZED) $(DEBUG) $(DIR)/$(SRC) $(DEPS) -o $(DIR)/$(OUTPUT)
|
|
||||||
|
|
||||||
## make format-one DIR=01_one_sample
|
|
||||||
format-one: $(DIR)/$(SRC)
|
|
||||||
$(FORMATTER) $(DIR)/$(SRC)
|
|
||||||
|
|
||||||
## make run-one DIR=01_one_sample
|
|
||||||
run-one: $(DIR)/$(OUTPUT)
|
|
||||||
$(DIR)/$(OUTPUT) && echo
|
|
||||||
|
|
||||||
## make time-linux-one DIR=01_one_sample
|
|
||||||
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
|
|
||||||
|
|
||||||
## e.g., make profile-linux-one DIR=01_one_sample
|
|
||||||
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) $(OPTIMIZED) $(DEBUG) $(DIR)/$(SRC) $(DEPS) -o $(DIR)/$(OUTPUT)
|
|
||||||
# $(CC) $(SRC) $(DEPS) -o $(OUTPUT)
|
|
||||||
sudo perf record $(DIR)/$(OUTPUT)
|
|
||||||
sudo perf report
|
|
||||||
rm perf.data
|
|
Binary file not shown.
|
@ -1,16 +0,0 @@
|
||||||
#include "../../../squiggle.h"
|
|
||||||
#include "../../../squiggle_more.h"
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
// set randomness seed
|
|
||||||
uint64_t* seed = malloc(sizeof(uint64_t));
|
|
||||||
*seed = 1000; // xorshift can't start with 0
|
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
free(seed);
|
|
||||||
}
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,30 +0,0 @@
|
||||||
#include "../../../squiggle.h"
|
|
||||||
#include "../../../squiggle_more.h"
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
// Estimate functions
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
// set randomness seed
|
|
||||||
// uint64_t* seed = malloc(sizeof(uint64_t));
|
|
||||||
// *seed = 1000; // xorshift can't start with 0
|
|
||||||
// ^ not necessary, because parallel_sampler takes care of the seed.
|
|
||||||
|
|
||||||
int n_samples = 1000 * 1000 * 1000;
|
|
||||||
int n_threads = 16;
|
|
||||||
double sampler(uint64_t* seed){
|
|
||||||
return sample_lognormal(0, 10, seed);
|
|
||||||
}
|
|
||||||
double* results = malloc(n_samples * sizeof(double));
|
|
||||||
|
|
||||||
parallel_sampler(sampler, results, n_threads, n_samples);
|
|
||||||
double avg = array_sum(results, n_samples)/n_samples;
|
|
||||||
printf("Average of 1B lognormal(0,10): %f", avg);
|
|
||||||
|
|
||||||
free(results);
|
|
||||||
|
|
||||||
// free(seed);
|
|
||||||
// ^ not necessary, because parallel_sampler takes care of the seed.
|
|
||||||
}
|
|
Binary file not shown.
|
@ -1,29 +0,0 @@
|
||||||
#include "../../../squiggle.h"
|
|
||||||
#include "../../../squiggle_more.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
double p_a = 0.8;
|
|
||||||
double p_b = 0.5;
|
|
||||||
double p_c = p_a * p_b;
|
|
||||||
|
|
||||||
double sample_0(uint64_t* seed){ return 0; }
|
|
||||||
double sample_1(uint64_t* seed) { return 1; }
|
|
||||||
double sample_few(uint64_t* seed) { return sample_to(1, 3, seed); }
|
|
||||||
double sample_many(uint64_t* seed) { return sample_to(2, 10, seed); }
|
|
||||||
|
|
||||||
int n_dists = 4;
|
|
||||||
double weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 };
|
|
||||||
double (*samplers[])(uint64_t*) = { sample_0, sample_1, sample_few, sample_many };
|
|
||||||
double sampler_result(uint64_t* seed) {
|
|
||||||
return sample_mixture(samplers, weights, n_dists, seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
int n_samples = 1000 * 1000, n_threads = 16;
|
|
||||||
double* results = malloc(n_samples * sizeof(double));
|
|
||||||
parallel_sampler(sampler_result, results, n_threads, n_samples);
|
|
||||||
printf("Avg: %f", array_sum(results, n_samples)/n_samples);
|
|
||||||
free(results);
|
|
||||||
}
|
|
|
@ -1,108 +0,0 @@
|
||||||
# Interface:
|
|
||||||
# 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
|
|
||||||
# CC=tcc # <= faster compilation
|
|
||||||
|
|
||||||
# Main file
|
|
||||||
SRC=example.c
|
|
||||||
OUTPUT=example
|
|
||||||
|
|
||||||
## Dependencies
|
|
||||||
SQUIGGLE=../../squiggle.c
|
|
||||||
SQUIGGLE_MORE=../../squiggle_more.c
|
|
||||||
MATH=-lm
|
|
||||||
OPENMP=-fopenmp
|
|
||||||
DEPS=$(SQUIGGLE) $(SQUIGGLE_MORE) $(MATH) $(OPENMP)
|
|
||||||
|
|
||||||
## Flags
|
|
||||||
DEBUG= #'-g'
|
|
||||||
STANDARD=-std=c99
|
|
||||||
WARNINGS=-Wall
|
|
||||||
OPTIMIZED=-O3 #-Ofast
|
|
||||||
|
|
||||||
## Formatter
|
|
||||||
STYLE_BLUEPRINT=webkit
|
|
||||||
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
|
|
||||||
|
|
||||||
## 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)
|
|
||||||
$(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)
|
|
||||||
$(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)
|
|
||||||
$(FORMATTER) 11_billion_lognormals_paralell/$(SRC)
|
|
||||||
$(FORMATTER) 12_time_to_botec_parallel/$(SRC)
|
|
||||||
|
|
||||||
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)
|
|
||||||
11_billion_lognormals_paralell/$(OUTPUT)
|
|
||||||
12_time_to_botec_parallel/$(OUTPUT)
|
|
||||||
|
|
||||||
## 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 $(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: |" | sed 's|$$|ms|' && echo
|
|
||||||
|
|
||||||
## 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) $(OPTIMIZED) $(DEBUG) $(DIR)/$(SRC) $(DEPS) -o $(DIR)/$(OUTPUT)
|
|
||||||
# $(CC) $(SRC) $(DEPS) -o $(OUTPUT)
|
|
||||||
sudo perf record $(DIR)/$(OUTPUT)
|
|
||||||
sudo perf report
|
|
||||||
rm perf.data
|
|
36
makefile
36
makefile
|
@ -5,12 +5,40 @@ STYLE_BLUEPRINT=webkit
|
||||||
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
|
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
|
||||||
|
|
||||||
build-examples:
|
build-examples:
|
||||||
cd examples/core && make all
|
cd examples/01_one_sample && make && echo
|
||||||
cd examples/more && make all
|
cd examples/02_many_samples_time_to_botec && make && echo
|
||||||
|
cd examples/03_gcc_nested_function && make && echo
|
||||||
|
cd examples/04_sample_from_cdf_simple && make && echo
|
||||||
|
cd examples/05_sample_from_cdf_beta && make && echo
|
||||||
|
cd examples/06_gamma_beta && make && echo
|
||||||
|
cd examples/07_ci_beta && make && echo
|
||||||
|
cd examples/08_nuclear_war && make && echo
|
||||||
|
cd examples/09_burn_10kg_fat && make && echo
|
||||||
|
cd examples/10_nuclear_recovery && make && echo
|
||||||
|
cd examples/11_algebra && make && echo
|
||||||
|
cd examples/12_algebra_and_conversion && make && echo
|
||||||
|
cd examples/13_ergonomic_algebra && make && echo
|
||||||
|
cd examples/14_twitter_thread_example && make && echo
|
||||||
|
cd examples/15_plotting-scratchpad && make && echo
|
||||||
|
cd examples/16_100_lognormal_samples && make && echo
|
||||||
|
|
||||||
format-examples:
|
format-examples:
|
||||||
cd examples/core && make format-all
|
cd examples/01_one_sample && make format && echo
|
||||||
cd examples/more && make format-all
|
cd examples/02_many_samples_time_to_botec && make format && echo
|
||||||
|
cd examples/03_gcc_nested_function && make format && echo
|
||||||
|
cd examples/04_sample_from_cdf_simple && make format && echo
|
||||||
|
cd examples/05_sample_from_cdf_beta && make format && echo
|
||||||
|
cd examples/06_gamma_beta && make format && echo
|
||||||
|
cd examples/07_ci_beta && make format && echo
|
||||||
|
cd examples/08_nuclear_war && make format && echo
|
||||||
|
cd examples/09_burn_10kg_fat && make format && echo
|
||||||
|
cd examples/10_nuclear_recovery && make format && echo
|
||||||
|
cd examples/11_algebra && make format && echo
|
||||||
|
cd examples/12_algebra_and_conversion && make format && echo
|
||||||
|
cd examples/13_ergonomic_algebra && make format && echo
|
||||||
|
cd examples/14_twitter_thread_example && make format && echo
|
||||||
|
cd examples/15_plotting-scratchpad && make format && echo
|
||||||
|
cd examples/16_100_lognormal_samples && make format && echo
|
||||||
|
|
||||||
format: squiggle.c squiggle.h
|
format: squiggle.c squiggle.h
|
||||||
$(FORMATTER) squiggle.c
|
$(FORMATTER) squiggle.c
|
||||||
|
|
|
@ -7,20 +7,20 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "squiggle.h"
|
#include "squiggle.h"
|
||||||
|
|
||||||
/* Math constants */
|
// math constants
|
||||||
#define PI 3.14159265358979323846 // M_PI in gcc gnu99
|
#define PI 3.14159265358979323846 // M_PI in gcc gnu99
|
||||||
#define NORMAL90CONFIDENCE 1.6448536269514727
|
#define NORMAL90CONFIDENCE 1.6448536269514727
|
||||||
|
|
||||||
/* Some error niceties */
|
// Some error niceties; these won't be used until later
|
||||||
// These won't be used until later
|
|
||||||
#define MAX_ERROR_LENGTH 500
|
#define MAX_ERROR_LENGTH 500
|
||||||
#define EXIT_ON_ERROR 0
|
#define EXIT_ON_ERROR 0
|
||||||
#define PROCESS_ERROR(error_msg) process_error(error_msg, EXIT_ON_ERROR, __FILE__, __LINE__)
|
#define PROCESS_ERROR(error_msg) process_error(error_msg, EXIT_ON_ERROR, __FILE__, __LINE__)
|
||||||
|
|
||||||
/* Get confidence intervals, given a sampler */
|
// Get confidence intervals, given a sampler
|
||||||
// Not in core yet because I'm not sure how much I like the struct
|
// Not in core yet because I'm not sure how much I like the struct
|
||||||
// and the built-in 100k samples
|
// and the built-in 100k samples
|
||||||
// to do: add n to function parameters and document
|
// to do: add n to function parameters and document
|
||||||
|
|
||||||
typedef struct ci_t {
|
typedef struct ci_t {
|
||||||
float low;
|
float low;
|
||||||
float high;
|
float high;
|
||||||
|
@ -58,10 +58,7 @@ ci get_90_confidence_interval(double (*sampler)(uint64_t*), uint64_t* seed)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scaffolding to handle errors */
|
// ## Sample from an arbitrary cdf
|
||||||
// We are building towards sample from an arbitrary cdf
|
|
||||||
// and that operation might fail
|
|
||||||
// so we build some scaffolding here
|
|
||||||
struct box {
|
struct box {
|
||||||
int empty;
|
int empty;
|
||||||
double content;
|
double content;
|
||||||
|
@ -81,10 +78,14 @@ struct box process_error(const char* error_msg, int should_exit, char* file, int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Invert an arbitrary cdf at a point */
|
// Inverse cdf at point
|
||||||
// Version #1:
|
// Two versions of this function:
|
||||||
// - input: (cdf: double => double, p)
|
// - raw, dealing with cdfs that return doubles
|
||||||
// - output: Box(number|error)
|
// - input: cdf: double => double, p
|
||||||
|
// - output: Box(number|error)
|
||||||
|
// - box, dealing with cdfs that return a box.
|
||||||
|
// - input: cdf: double => Box(number|error), p
|
||||||
|
// - output: Box(number|error)
|
||||||
struct box inverse_cdf_double(double cdf(double), double p)
|
struct box inverse_cdf_double(double cdf(double), double p)
|
||||||
{
|
{
|
||||||
// given a cdf: [-Inf, Inf] => [0,1]
|
// given a cdf: [-Inf, Inf] => [0,1]
|
||||||
|
@ -148,9 +149,6 @@ struct box inverse_cdf_double(double cdf(double), double p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version #2:
|
|
||||||
// - input: (cdf: double => Box(number|error), p)
|
|
||||||
// - output: Box(number|error)
|
|
||||||
struct box inverse_cdf_box(struct box cdf_box(double), double p)
|
struct box inverse_cdf_box(struct box cdf_box(double), double p)
|
||||||
{
|
{
|
||||||
// given a cdf: [-Inf, Inf] => Box([0,1])
|
// given a cdf: [-Inf, Inf] => Box([0,1])
|
||||||
|
@ -227,9 +225,7 @@ struct box inverse_cdf_box(struct box cdf_box(double), double p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sample from an arbitrary cdf */
|
// Sampler based on inverse cdf and randomness function
|
||||||
// Before: invert an arbitrary cdf at a point
|
|
||||||
// Now: from an arbitrary cdf, get a sample
|
|
||||||
struct box sampler_cdf_box(struct box cdf(double), uint64_t* seed)
|
struct box sampler_cdf_box(struct box cdf(double), uint64_t* seed)
|
||||||
{
|
{
|
||||||
double p = sample_unit_uniform(seed);
|
double p = sample_unit_uniform(seed);
|
||||||
|
@ -242,18 +238,22 @@ struct box sampler_cdf_double(double cdf(double), uint64_t* seed)
|
||||||
struct box result = inverse_cdf_double(cdf, p);
|
struct box result = inverse_cdf_double(cdf, p);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
double sampler_cdf_danger(struct box cdf(double), uint64_t* seed)
|
|
||||||
|
/* Could also define other variations, e.g.,
|
||||||
|
double sampler_danger(struct box cdf(double), uint64_t* seed)
|
||||||
{
|
{
|
||||||
double p = sample_unit_uniform(seed);
|
double p = sample_unit_uniform(seed);
|
||||||
struct box result = inverse_cdf_box(cdf, p);
|
struct box result = inverse_cdf_box(cdf, p);
|
||||||
if(result.empty){
|
if(result.empty){
|
||||||
exit(1);
|
exit(1);
|
||||||
}else{
|
}else{
|
||||||
return result.content;
|
return result.content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// # Small algebra manipulations
|
||||||
|
|
||||||
/* Algebra manipulations */
|
|
||||||
// here I discover named structs,
|
// here I discover named structs,
|
||||||
// which mean that I don't have to be typing
|
// which mean that I don't have to be typing
|
||||||
// struct blah all the time.
|
// struct blah all the time.
|
||||||
|
@ -304,8 +304,9 @@ ci convert_lognormal_params_to_ci(lognormal_params y)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parallel sampler */
|
// Paralellism
|
||||||
void parallel_sampler(double (*sampler)(uint64_t* seed), double* results, int n_threads, int n_samples){
|
/*
|
||||||
|
void paralellize(float (*sampler)(uint64_t* seed), float* results, int n_threads, int n_samples){
|
||||||
if((n_samples % n_threads) != 0){
|
if((n_samples % n_threads) != 0){
|
||||||
fprintf(stderr, "Number of samples isn't divisible by number of threads, aborting\n");
|
fprintf(stderr, "Number of samples isn't divisible by number of threads, aborting\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -335,3 +336,4 @@ void parallel_sampler(double (*sampler)(uint64_t* seed), double* results, int n_
|
||||||
}
|
}
|
||||||
free(seeds);
|
free(seeds);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
|
@ -46,6 +46,4 @@ lognormal_params algebra_product_lognormals(lognormal_params a, lognormal_params
|
||||||
lognormal_params convert_ci_to_lognormal_params(ci x);
|
lognormal_params convert_ci_to_lognormal_params(ci x);
|
||||||
ci convert_lognormal_params_to_ci(lognormal_params y);
|
ci convert_lognormal_params_to_ci(lognormal_params y);
|
||||||
|
|
||||||
void parallel_sampler(double (*sampler)(uint64_t* seed), double* results, int n_threads, int n_samples);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user