reorg: move all examples using squiggle_more to one makefile

This commit is contained in:
NunoSempere 2023-11-19 14:47:19 +00:00
parent 3f9027a530
commit b0f711e9a6
29 changed files with 101 additions and 41 deletions

Binary file not shown.

View File

@ -0,0 +1,16 @@
#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.

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

Binary file not shown.

View File

@ -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>

Binary file not shown.

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -1,58 +1,102 @@
# Interface: # Interface:
# make # make all
# make build # make format-all
# make format # make run-all
# make run # 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 # Compiler
CC=gcc # required for nested functions CC=gcc
# CC=tcc # <= faster compilation # CC=tcc # <= faster compilation
# Main file # Main file
SRC=example.c ../../squiggle.c ../../squiggle_more.c SRC=example.c
OUTPUT=./example OUTPUT=example
## Dependencies ## Dependencies
OPENMP=-fopenmp SQUIGGLE=../../squiggle.c
SQUIGGLE_MORE=../../squiggle_more.c
MATH=-lm MATH=-lm
DEPENDENCIES=$(MATH) $(OPENMP) OPENMP=-fopenmp
# OPENMP=-fopenmp DEPS=$(SQUIGGLE) $(SQUIGGLE_MORE) $(MATH) $(OPENMP)
## Flags ## Flags
DEBUG= #'-g' DEBUG= #'-g'
STANDARD=-std=c99 ## gnu99 allows for nested functions. STANDARD=-std=c99
EXTENSIONS= #-fnested-functions
WARNINGS=-Wall WARNINGS=-Wall
OPTIMIZED=-O3#-Ofast OPTIMIZED=-O3 #-Ofast
CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
## Formatter ## Formatter
STYLE_BLUEPRINT=webkit STYLE_BLUEPRINT=webkit
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT) FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
## make build ## make all
build: $(SRC) all:
# gcc -std=gnu99 example.c -lm -o example $(CC) $(OPTIMIZED) $(DEBUG) 00_example_template/$(SRC) $(DEPS) -o 00_example_template/$(OUTPUT)
$(CC) $(CFLAGS) $(SRC) $(DEPENDENCIES) -o $(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) format-all:
$(FORMATTER) $(SRC) $(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) run-all:
./$(OUTPUT) && echo 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 "Requires /bin/time, found on GNU/Linux systems" && echo
@echo "Running 100x and taking avg time $(DIR)/$(OUTPUT)"
@echo "Running 100x and taking avg time $(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 $(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 ## e.g., make profile-linux-one DIR=06_nuclear_recovery
profile-linux-one:
profile-linux:
echo "Requires perf, which depends on the kernel version, and might be in linux-tools package or similar" echo "Requires perf, which depends on the kernel version, and might be in linux-tools package or similar"
echo "Must be run as sudo" echo "Must be run as sudo"
$(CC) $(SRC) $(MATH) -o $(OUTPUT) $(CC) $(OPTIMIZED) $(DEBUG) $(DIR)/$(SRC) $(DEPS) -o $(DIR)/$(OUTPUT)
sudo perf record ./$(OUTPUT) # $(CC) $(SRC) $(DEPS) -o $(OUTPUT)
sudo perf record $(DIR)/$(OUTPUT)
sudo perf report sudo perf report
rm perf.data rm perf.data