# Compiler and flags CC := g++ CXXFLAGS := -std=c++14 -Wall -Iinclude -O3 -march=native -fopenmp LDFLAGS := -fopenmp # Directories SRC_DIR := src INC_DIR := include OBJ_DIR := obj BIN_DIR := bin # # === Executable Name === TARGET := $(BIN_DIR)/abc_lab # === Find all .cpp files recursively in src/ === 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 $@ $^ $(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: rm -rf $(OBJ_DIR) $(BIN_DIR) # Optional: print debug info .PHONY: info info: @echo "Source files: $(SRCS)" @echo "Object files: $(OBJS)" @echo "CXXFLAGS: $(CXXFLAGS)" @echo "LDFLAGS: $(LDFLAGS)"