ready for parralization

This commit is contained in:
2025-09-12 22:58:52 +02:00
parent cb825aec40
commit 320436ce98
14 changed files with 920 additions and 294 deletions
+37 -3
View File
@@ -1,7 +1,9 @@
# Compiler and flags
CC := g++
CXXFLAGS := -std=c++14 -Wall -Iinclude
CXXFLAGS := -std=c++14 -Wall -Iinclude -O3 -march=native -fopenmp
LDFLAGS := -fopenmp
# Directories
SRC_DIR := src
@@ -20,19 +22,50 @@ SRCS := $(shell find $(SRC_DIR) -name '*.cpp')
# === Convert src/foo/bar.cpp → obj/foo/bar.o ===
OBJS := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRCS))
# === OpenMP runtime configuration (override-able) ===
OMP_PROC_BIND ?= close # close|spread|master
OMP_PLACES ?= cores # cores|threads|sockets
OMP_MAX_LEVELS ?= 1 # 1 = no nested teams; set 2+ to allow nesting
OMP_THREADS ?= 16 # e.g. "16" or "8,4" for nested (outer,inner)
OMP_DYNAMIC ?= true # true/false: let runtime adjust threads
OMP_DISPLAY_ENV ?= FALSE # TRUE to print runtime config at startup
# === Default Target ===
all: $(TARGET)
# === Linking final executable ===
$(TARGET): $(OBJS)
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -o $@ $^
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
# === Compiling source files to object files ===
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c $< -o $@
# === Run with OpenMP env set only for the run ===
.PHONY: run
run: $(TARGET)
OMP_PROC_BIND=$(OMP_PROC_BIND) \
OMP_PLACES=$(OMP_PLACES) \
OMP_MAX_ACTIVE_LEVELS=$(OMP_MAX_LEVELS) \
OMP_NUM_THREADS="$(OMP_THREADS)" \
OMP_DYNAMIC=$(OMP_DYNAMIC) \
OMP_DISPLAY_ENV=$(OMP_DISPLAY_ENV) \
./$(TARGET)
# Handy presets
.PHONY: run-single
run-single: ## Single-level parallel (good default)
$(MAKE) run OMP_MAX_LEVELS=1 OMP_THREADS=16 OMP_PROC_BIND=close OMP_PLACES=cores
.PHONY: run-nested
run-nested: ## Two-level nested (outer,inner), adjust to your cores
$(MAKE) run OMP_MAX_LEVELS=2 OMP_THREADS="4,8" OMP_PROC_BIND=close OMP_PLACES=cores
# Clean up
.PHONY: clean
clean:
@@ -43,4 +76,5 @@ clean:
info:
@echo "Source files: $(SRCS)"
@echo "Object files: $(OBJS)"
@echo "CXXFLAGS: $(CXXFLAGS)"
@echo "CXXFLAGS: $(CXXFLAGS)"
@echo "LDFLAGS: $(LDFLAGS)"