-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
238 lines (196 loc) · 6.77 KB
/
Makefile
File metadata and controls
238 lines (196 loc) · 6.77 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
SRC_DIR := src
LIB_DIR := include
BUILD_DIR := build
TMP_DIR := tmp
PROGRAM := minqp
PROBLEMS := problems
BENCHMARKS := benchmarks
SCRIPTS := scripts
ALGLIB_VERSION := 4.06.0
ALGLIB_ZIP := alglib-$(ALGLIB_VERSION).cpp.gpl.zip
ALGLIB_URL := https://www.alglib.net/translator/re/$(ALGLIB_ZIP)
#
# Parameters to pass to the makefile
#
# Condition numbers (relative to norm2) of the matrix Q to use
COND_Q := 1.01 1.05 2.50 5.50 10.00 20.00
# Problem dimensions
N := 50 100 200 500 750 1000 1200 1500
# Linear constraints count
K := 10 25 50 75 100 150 200 250 300 350 400 500 600
# Number of problems to generate for each N,K,cond2(Q) combination
COUNT := 2
# Barrier reduction parameter
SIGMA := 0.2
# Solvers to study
SOLVERS := ipm-newton ipm-prediction ipm-prediction-normal
# Reference solver for comparisons
REFERENCE_SOLVER := alglib-ipm
# Cores to use for problems/benchmarks generation
CORES := $(MAKE_JOBS)
CORES := $(if $(CORES),$(CORES),2)
PROBLEMS_PARAMETERS = --cores $(CORES) --prob-dims $(N) --constraints $(K) --matrix-conds $(COND_Q) --count $(COUNT)
BENCHMARKS_PARAMETERS = --cores $(CORES) --sigma $(SIGMA) --solvers $(REFERENCE_SOLVER) --solvers $(SOLVERS)
CHARTS_PARAMETERS = --cores $(CORES)
#
# OS-specific parameters
#
ifeq ($(OS),Windows_NT)
SHELL := powershell.exe
CXX := cl
OBJ_EXT := obj
# MSVC flags
QP_DIR := $(LIB_DIR)\qp
CXXFLAGS := /nologo /std:c++20 /O2 /EHsc /I$(LIB_DIR) /I$(QP_DIR)
PROJECT_FLAGS := /fp:fast
# ALGLIB flags (assume windows is running on Intel)
ALGLIB_FLAGS := /DAE_OS=AE_WINDOWS /W3 /arch:AVX2 /DAE_CPU=AE_INTEL
ALGLIB_DIR := $(LIB_DIR)\alglib
TARGET := $(PROGRAM).exe
else
# Linux and macOS
CXX := g++
OBJ_EXT := o
QP_DIR := $(LIB_DIR)/qp
CXXFLAGS := -std=c++20 -O3 -I$(LIB_DIR) -I$(QP_DIR) -D_GLIBCXX_USE_CXX11_ABI=0 -MMD -MP
PROJECT_FLAGS := -fstack-protector -ffast-math
ALGLIB_FLAGS := -DAE_OS=AE_POSIX
ALGLIB_DIR := $(LIB_DIR)/alglib
# Check it is Intel/AMD architecture
ARCH := $(shell uname -m)
ifneq (,$(filter x86_64 AMD64 i386 i486 i586 i686,$(ARCH)))
CXXFLAGS += -mavx2 -mfma
ALGLIB_FLAGS += -DAE_CPU=AE_INTEL
endif
TARGET := $(PROGRAM)
endif
#
# Project files
#
SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.$(OBJ_EXT),$(SRC_FILES))
DEP_FILES := $(OBJ_FILES:.$(OBJ_EXT)=.d)
ALGLIB_SRC := $(wildcard $(ALGLIB_DIR)/*.cpp)
ALGLIB_OBJ := $(patsubst $(ALGLIB_DIR)/%.cpp,$(BUILD_DIR)/alglib/%.$(OBJ_EXT),$(ALGLIB_SRC))
#
# Build Targets
#
.PHONY: all clean_problems clean_benchmarks clean benchmarks_python_requirements_check
all: $(TARGET)
$(TARGET): $(OBJ_FILES) $(ALGLIB_OBJ)
ifeq ($(OS),Windows_NT)
$(CXX) /Fe$(TARGET) $^
else
$(CXX) $(CXXFLAGS) $(PROJECT_FLAGS) -o $@ $^
endif
#
# Compile rules
#
# Generate output directories
$(BUILD_DIR):
ifeq ($(OS),Windows_NT)
@mkdir ".\$(BUILD_DIR)" -Force | Out-Null
@mkdir ".\$(BUILD_DIR)\alglib" -Force | Out-Null
else
@mkdir -p $(BUILD_DIR) $(BUILD_DIR)/alglib
endif
# Project files
$(BUILD_DIR)/%.$(OBJ_EXT): $(SRC_DIR)/%.cpp | $(BUILD_DIR)
ifeq ($(OS),Windows_NT)
@$(CXX) $(CXXFLAGS) $(PROJECT_FLAGS) /c $< /Fo$@
else
$(CXX) $(CXXFLAGS) $(PROJECT_FLAGS) -c $< -o $@
endif
# Alglib library files
$(BUILD_DIR)/alglib/%.$(OBJ_EXT): $(ALGLIB_DIR)/%.cpp | $(BUILD_DIR)
ifeq ($(OS),Windows_NT)
@$(CXX) $(CXXFLAGS) $(ALGLIB_FLAGS) /c $< /Fo$@
else
$(CXX) $(CXXFLAGS) $(ALGLIB_FLAGS) -c $< -o $@
endif
# Include generated dependencies (not on Windows, as it doesn't generate them)
ifneq ($(OS),Windows_NT)
-include $(DEP_FILES)
endif
#
# Download and extract ALGLIB library
#
$(ALGLIB_DIR):
ifeq ($(OS),Windows_NT)
@mkdir ".\$(TMP_DIR)" -Force | Out-Null
@Write-Output "Downloading ALGLIB $(ALGLIB_VERSION)..."
@Invoke-WebRequest -OutFile ".\$(TMP_DIR)\$(ALGLIB_ZIP)" -Uri "$(ALGLIB_URL)"
@Expand-Archive -LiteralPath ".\$(TMP_DIR)\$(ALGLIB_ZIP)" -DestinationPath ".\$(TMP_DIR)" -Force
@Write-Output "Library downloaded and extracted"
@Move-Item -Path ".\$(TMP_DIR)\alglib-cpp\src" -Destination ".\$(ALGLIB_DIR)"
@Remove-Item ".\$(TMP_DIR)" -Recurse -Force
@Write-Output "Now you can compile the whole project with 'make'"
else
@mkdir -p $(TMP_DIR)
@echo Downloading ALGLIB $(ALGLIB_VERSION)...
@curl -s -o $(TMP_DIR)/$(ALGLIB_ZIP) $(ALGLIB_URL)
@unzip -q $(TMP_DIR)/$(ALGLIB_ZIP) -d $(TMP_DIR)
@echo Library downloaded and extracted
@mv $(TMP_DIR)/alglib-cpp/src $(ALGLIB_DIR)
@rm -rf $(TMP_DIR)
@echo "Now you can compile the whole project with 'make'"
endif
#
# Generate and solve problems
#
GEN_PROBLEMS = generate_problems.py
GEN_BENCHMARKS = generate_benchmarks.py
GEN_CHARTS = generate_charts.py
GEN_PROBLEMS_HELPER = benchmark_problems.py
GEN_BENCHMARKS_HELPER = benchmark_status.py
# Python scripts dependencies
$(SCRIPTS)/$(GEN_PROBLEMS): $(SCRIPTS)/$(GEN_PROBLEMS_HELPER)
$(SCRIPTS)/$(GEN_BENCHMARKS): $(SCRIPTS)/$(GEN_BENCHMARKS_HELPER) $(SCRIPTS)/$(GEN_PROBLEMS_HELPER)
$(SCRIPTS)/$(GEN_CHARTS): $(SCRIPTS)/$(GEN_BENCHMARKS)
$(PROBLEMS): $(SCRIPTS)/$(GEN_PROBLEMS)
ifeq ($(OS),Windows_NT)
@python ".\$(SCRIPTS)\$(GEN_PROBLEMS)" --minqp=".\$(TARGET)" $(PROBLEMS_PARAMETERS)
else
@python3 $(SCRIPTS)/$(GEN_PROBLEMS) --minqp="./$(TARGET)" $(PROBLEMS_PARAMETERS)
endif
# Python modules checker
benchmarks_python_requirements_check: $(SCRIPTS)/$(GEN_CHARTS)
ifeq ($(OS),Windows_NT)
@python -c "import numpy, pandas, matplotlib, rich" *> $$null; if ($$LASTEXITCODE -ne 0) { Write-Host "Missing python dependencies: run 'pip install -r scripts/requirements.txt'"; exit 1 }
else
@python3 -c "import numpy, pandas, matplotlib, rich" >/dev/null 2>&1 \
|| (echo "Missing python dependencies: 'pip install -r $(SCRIPTS)/requirements.txt'"; exit 1)
endif
$(BENCHMARKS): all $(PROBLEMS) benchmarks_python_requirements_check
ifeq ($(OS),Windows_NT)
@python ".\$(SCRIPTS)\$(GEN_BENCHMARKS)" --minqp=".\$(TARGET)" $(BENCHMARKS_PARAMETERS)
@python ".\$(SCRIPTS)\$(GEN_CHARTS)" $(CHARTS_PARAMETERS)
else
@python3 $(SCRIPTS)/$(GEN_BENCHMARKS) --minqp="./$(TARGET)" $(BENCHMARKS_PARAMETERS)
@python3 $(SCRIPTS)/$(GEN_CHARTS) $(CHARTS_PARAMETERS)
endif
#
# Clean builds, problems and benchmarks
#
clean_benchmarks:
ifeq ($(OS),Windows_NT)
@if (Test-Path ".\$(BENCHMARKS)") { Remove-Item ".\$(BENCHMARKS)" -Recurse -Force; }
else
@rm -rf $(BENCHMARKS)
endif
clean_problems: clean_benchmarks
ifeq ($(OS),Windows_NT)
@if (Test-Path ".\$(PROBLEMS)") { Remove-Item ".\$(PROBLEMS)" -Recurse -Force; }
else
@rm -rf $(PROBLEMS)
endif
clean: clean_problems
ifeq ($(OS),Windows_NT)
@if (Test-Path ".\$(BUILD_DIR)") { Remove-Item ".\$(BUILD_DIR)" -Recurse -Force; }
@if (Test-Path ".\$(TARGET)") { Remove-Item ".\$(TARGET)" -Force; }
else
@find $(BUILD_DIR) -maxdepth 1 -type f -name "*.o" -delete
@rm -f $(TARGET)
endif
docs:
@doxygen