time-to-botec/C-optimized/makefile

53 lines
1.2 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
2023-05-29 23:55:57 +00:00
SRC_ONE_THREAD=./samples-one-thread.c
OUTPUT_ONE_THREAD=out/samples-one-thread
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 23:55:57 +00:00
$(CC) $(OPTIMIZED) $(DEBUG) $(SRC_ONE_THREAD) $(OPENMP) $(MATH) -o $(OUTPUT_ONE_THREAD)
2023-05-29 21:17:07 +00:00
format: $(SRC)
$(FORMATTER) $(SRC)
run: $(SRC) $(OUTPUT)
2023-05-30 00:05:18 +00:00
OMP_NUM_THREADS=1 ./$(OUTPUT) && echo
2023-05-29 23:55:57 +00:00
./$(OUTPUT_ONE_THREAD)
2023-05-29 22:48:25 +00:00
2023-05-29 23:40:03 +00:00
time:
OMP_NUM_THREADS=1 /bin/time -f "Time: %es" ./$(OUTPUT) && echo
OMP_NUM_THREADS=2 /bin/time -f "Time: %es" ./$(OUTPUT) && echo
OMP_NUM_THREADS=4 /bin/time -f "Time: %es" ./$(OUTPUT) && echo
2023-05-29 23:55:57 +00:00
/bin/time -f "Time: %es" ./$(OUTPUT_ONE_THREAD) && echo
2023-05-29 21:17:07 +00:00
2023-05-29 21:50:00 +00:00
linux-install:
2023-05-29 21:47:52 +00:00
sudo apt-get install libomp-dev