time-to-botec/C-optimized/makefile

64 lines
1.4 KiB
Makefile
Raw Normal View History

2023-05-29 21:17:07 +00:00
# Interface:
# make
# make build
# make format
# make run
# Compiler
2023-05-29 22:48:25 +00:00
CC=gcc
2023-05-29 21:17:07 +00:00
# CC=tcc # <= faster compilation
# Main file
SRC=samples.c
2023-05-29 21:50:00 +00:00
OUTPUT=out/samples
2023-05-29 21:17:07 +00:00
## Dependencies
# Has no dependencies
2023-05-29 21:59:17 +00:00
MATH=-lm
2023-05-29 21:17:07 +00:00
## Flags
DEBUG= #'-g'
STANDARD=-std=c99
WARNINGS=-Wall
OPTIMIZED=-O3 #-O3 actually gives better performance than -Ofast, at least for this version
OPENMP=-fopenmp
2023-05-29 21:59:17 +00:00
2023-05-29 21:17:07 +00:00
## Formatter
STYLE_BLUEPRINT=webkit
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
## make build
build: $(SRC)
2023-05-29 21:59:17 +00:00
$(CC) $(OPTIMIZED) $(DEBUG) $(SRC) $(OPENMP) $(MATH) -o $(OUTPUT)
2023-05-29 21:17:07 +00:00
#fast: Has been removed, compilation of "build" is very fast and it outputs optimized code by default
format: $(SRC)
$(FORMATTER) $(SRC)
run: $(SRC) $(OUTPUT)
2023-05-29 23:04:21 +00:00
OMP_NUM_THREADS=4 ./$(OUTPUT)
2023-05-29 22:48:25 +00:00
test: $(SRC) $(OUTPUT)
OMP_NUM_THREADS=1 ./$(OUTPUT)
echo ""
OMP_NUM_THREADS=2 ./$(OUTPUT)
echo ""
OMP_NUM_THREADS=4 ./$(OUTPUT)
2023-05-29 21:17:07 +00:00
# echo "Increasing stack size limit, because we are dealing with 1M samples"
# # ulimit: increase stack size limit
# # -Ss: the soft limit. If you set the hard limit, you then can't raise it
# # 256000: around 250Mbs, if I'm reading it correctly.
# # Then run the program
# ulimit -Ss 256000 && ./$(OUTPUT)
2023-05-29 21:50:00 +00:00
linux-install:
2023-05-29 21:47:52 +00:00
sudo apt-get install libomp-dev
2023-05-29 21:17:07 +00:00
# Old:
# Link libraries, for good measure
# LD_LIBRARY_PATH=/usr/local/lib
# export LD_LIBRARY_PATH