-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
76 lines (57 loc) · 2.42 KB
/
Copy pathMakefile
File metadata and controls
76 lines (57 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
CC := cc
CFLAGS := -Wall -Wextra -g
LDLIBS := -lm
PRINT ?= 0 # Can be 0 (no print) 1 (standard) 2 (verbose)
NUM_NEIGHBORS ?= 20
SINGLE_LM_ENV_FLAGS := -DPRINT=${PRINT}
MULTI_LM_ENV_FLAGS := -DPRINT=${PRINT} -DNUM_NEIGHBORS=${NUM_NEIGHBORS}
# ---------------------------------------------------------
# OPERATING SYSTEM
# ---------------------------------------------------------
UNAME_S := $(shell uname -s)
# Default to Linux/Cluster flags (Standard GCC)
OMP_FLAGS := -fopenmp
# If macOS is detected, overwrite with Apple Clang flags
ifeq ($(UNAME_S),Darwin)
# Force Homebrew path for Apple Silicon
OMP_FLAGS := -Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include -L/opt/homebrew/opt/libomp/lib -lomp
endif
# ---------------------------------------------------------
# SOURCE FILES
# ---------------------------------------------------------
# List of files tat should become an executable
MAIN_SRCS := src/main.c src/omp_test.c src/scale_out.c
ALL_SRCS := $(wildcard src/*.c)
# Filter out mains
SHARED_SRCS := $(filter-out $(MAIN_SRCS), $(ALL_SRCS))
# ---------------------------------------------------------
# TARGETS
# ---------------------------------------------------------
.PHONY: all clean help
all: main
# Standard: optimized O3
main: src/main.c $(SHARED_SRCS)
$(CC) $(CFLAGS) $(SINGLE_LM_ENV_FLAGS) -g -fno-omit-frame-pointer -DNDEBUG -O3 $^ -o $@ $(LDLIBS)
# Non optimized O0 for debugging
main_no_opt: src/main.c $(SHARED_SRCS)
$(CC) $(CFLAGS) $(SINGLE_LM_ENV_FLAGS) -g -fno-omit-frame-pointer -O0 $^ -o $@ $(LDLIBS)
# Multi-lm using OMP
scale-out: src/scale_out.c $(SHARED_SRCS)
$(CC) $(CFLAGS) $(MULTI_LM_ENV_FLAGS) $(OMP_FLAGS) -g -fno-omit-frame-pointer -DNDEBUG -O3 $^ -o $@ $(LDLIBS)
# ---------------------------------------------------------
# GCC Build Rule (To fix the 256-thread limit on macOS from kmp)
# Requires: brew install gcc
# ---------------------------------------------------------
GCC_BIN ?= gcc-15
scale-out-gcc: src/scale_out.c $(SHARED_SRCS)
$(GCC_BIN) $(CFLAGS) $(MULTI_LM_ENV_FLAGS) -fopenmp -g -fno-omit-frame-pointer -DNDEBUG -O3 $^ -o $@ $(LDLIBS)
clean:
rm -f main main_opt scale-out scale-out-gcc *.o *~
rm -rf *.dSYM
help:
@echo "Detected OS: $(UNAME_S)"
@echo "OMP Flags: $(OMP_FLAGS)"
@echo ""
@echo "Targets:"
@echo " make scale-out : Compiles src/scale_out.c for the current OS"
@echo " make scale-out-gcc : Compiles src/scale_out.c for the current OS using gcc explicitly"