AUTH's THMMY "Parallel and distributed systems" course assignments.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Makefile 10 KiB

il y a 3 jours
il y a 1 semaine
il y a 3 jours
il y a 1 semaine
il y a 1 semaine
il y a 3 jours
il y a 3 jours
il y a 1 semaine
il y a 1 semaine
il y a 3 jours
il y a 1 semaine
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. #
  2. # PDS homework_1 Makefile
  3. #
  4. # Copyright (C) 2024 Christos Choutouridis <christos@choutouridis.net>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Lesser General Public License as
  8. # published by the Free Software Foundation, either version 3
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # ============== Project settings ==============
  20. # Project's name
  21. PROJECT := PDS_homework_1
  22. # Excecutable's name
  23. TARGET := knnsearch
  24. # Source directories list(space seperated). Makefile-relative path, UNDER current directory.
  25. SRC_DIR_LIST := src gtest
  26. # Include directories list(space seperated). Makefile-relative path.
  27. INC_DIR_LIST := inc \
  28. src \
  29. /usr/include/hdf5/serial/ \
  30. gtest \
  31. # Libs/MATLAB/R2019b/include/ \
  32. # Exclude files list(space seperated). Filenames only.
  33. # EXC_FILE_LIST := bad.cpp old.cpp
  34. # Build directories
  35. BUILD_DIR := bin
  36. OBJ_DIR := $(BUILD_DIR)/obj
  37. DEP_DIR := $(BUILD_DIR)/.dep
  38. # ========== Compiler settings ==========
  39. # Compiler flags for debug and release
  40. DEB_CFLAGS := -DDEBUG -g3 -Wall -Wextra -std=c11
  41. REL_CFLAGS := -Wall -Wextra -O3 -std=c11
  42. DEB_CXXFLAGS := -DDEBUG -g3 -Wall -Wextra -std=c++17
  43. REL_CXXFLAGS := -Wall -Wextra -O3 -std=c++17
  44. # Pre-defines
  45. # PRE_DEFS := MYCAB=1729 SUPER_MODE
  46. PRE_DEFS :=
  47. # ============== Linker settings ==============
  48. # Linker flags (example: -pthread -lm)
  49. LDFLAGS := -pthread -lopenblas \
  50. -L/usr/lib/x86_64-linux-gnu/hdf5/serial -lhdf5
  51. # -LLibs/MATLAB/R2019b/bin/ -lmat -lmx -Wl,-rpath,Libs/MATLAB/R2019b/bin/ \
  52. # Map output file
  53. MAP_FILE := output.map
  54. MAP_FLAG := -Xlinker -Map=$(BUILD_DIR)/$(MAP_FILE)
  55. # ============== Docker settings ==============
  56. # We need:
  57. # - Bind the entire project directory(the dir that icludes all the code) as volume.
  58. # - In docker instance, change to working directory(where the makefile is).
  59. DOCKER_VOL_DIR := ${PWD}
  60. DOCKER_WRK_DIR :=
  61. DOCKER_RUN := docker run --rm
  62. DOCKER_FLAGS := -v $(DOCKER_VOL_DIR):/usr/src/$(PROJECT) -w /usr/src/$(PROJECT)/$(DOCKER_WRK_DIR)
  63. # docker invoke mechanism (edit with care)
  64. # note:
  65. # Here, `DOCKER` variable is empty. Rules can assign `DOCKER := DOCKER_CMD` when docker
  66. # functionality is needed.
  67. DOCKER_CMD = $(DOCKER_RUN) $(DOCKER_FLAGS) $(IMAGE)
  68. DOCKER :=
  69. # ============== Tool selection ==============
  70. # compiler and compiler flags.
  71. CSIZE := size
  72. CFLAGS := $(DEB_CFLAGS)
  73. CXXFLAGS := $(DEB_CXXFLAGS)
  74. CXX := g++
  75. CC := gcc
  76. #
  77. # =========== Main body and Patterns ===========
  78. #
  79. #ifeq ($(OS), Windows_NT)
  80. # TARGET := $(TARGET).exe
  81. #endif
  82. INC := $(foreach dir,$(INC_DIR_LIST),-I$(dir))
  83. DEF := $(foreach def,$(PRE_DEFS),-D$(def))
  84. EXC := $(foreach fil,$(EXC_FILE_LIST), \
  85. $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/$(fil))) \
  86. )
  87. # source files. object and dependencies list
  88. # recursive search into current and source directories
  89. SRC := $(wildcard *.cpp)
  90. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/*.cpp))
  91. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/**/*.cpp))
  92. SRC := $(filter-out $(EXC),$(SRC))
  93. #SRC := $(abspath $(SRC))
  94. OBJ := $(foreach file,$(SRC:%.cpp=%.o),$(OBJ_DIR)/$(file))
  95. DEP := $(foreach file,$(SRC:%.cpp=%.d),$(DEP_DIR)/$(file))
  96. # Make Dependencies pattern.
  97. # This little trick enables recompilation only when dependencies change
  98. # and it does so for changes both in source AND header files ;)
  99. #
  100. # It is based on Tom Tromey's method.
  101. #
  102. # Invoke cpp to create makefile rules with dependencies for each source file
  103. $(DEP_DIR)/%.d: %.c
  104. @mkdir -p $(@D)
  105. @$(DOCKER) $(CC) -E $(CFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)/$(<:.c=.o) -MF $@ $<
  106. # c file objects depent on .c AND dependency files, which have an empty recipe
  107. $(OBJ_DIR)/%.o: %.c $(DEP_DIR)/%.d
  108. @mkdir -p $(@D)
  109. $(DOCKER) $(CC) -c $(CFLAGS) $(INC) $(DEF) -o $@ $<
  110. $(DEP_DIR)/%.d: %.cpp
  111. @mkdir -p $(@D)
  112. @$(DOCKER) $(CXX) -E $(CXXFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)/$(<:.cpp=.o) -MF $@ $<
  113. # cpp file objects depent on .cpp AND dependency files, which have an empty recipe
  114. $(OBJ_DIR)/%.o: %.cpp $(DEP_DIR)/%.d
  115. @mkdir -p $(@D)
  116. $(DOCKER) $(CXX) -c $(CXXFLAGS) $(INC) $(DEF) -o $@ $<
  117. # empty recipe for dependency files. This prevents make errors
  118. $(DEP):
  119. # now include all dependencies
  120. # After all they are makefile dependency rules ;)
  121. include $(wildcard $(DEP))
  122. # main target rule
  123. $(BUILD_DIR)/$(TARGET): $(OBJ)
  124. @mkdir -p $(@D)
  125. @echo Linking to target: $(TARGET)
  126. @echo $(DOCKER) $(CXX) '$$(OBJ)' $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET)
  127. @$(DOCKER) $(CXX) $(OBJ) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET)
  128. @echo
  129. @echo Print size information
  130. @$(CSIZE) $(@D)/$(TARGET)
  131. @echo Done
  132. .PHONY: clean
  133. clean:
  134. @echo Cleaning build directories
  135. @rm -rf $(OBJ_DIR)
  136. @rm -rf $(DEP_DIR)
  137. @rm -rf $(BUILD_DIR)
  138. #
  139. # ================ Local build rules =================
  140. # example:
  141. # make debug
  142. debug: CFLAGS := $(DEB_CFLAGS)
  143. debug: $(BUILD_DIR)/$(TARGET)
  144. release: CFLAGS := $(REL_CFLAGS)
  145. release: $(BUILD_DIR)/$(TARGET)
  146. all: release
  147. hpc-results/post:
  148. $(CXX) $(CFLAGS) -o $@ hpc-results/main.cpp
  149. hpc-clean:
  150. rm hpc-results/post
  151. #
  152. # ================ Local (and/or) via docker build rules =================
  153. #
  154. # examples:
  155. # make IMAGE=hpcimage v0
  156. # make IMAGE=hpcimage v1_cilk
  157. #
  158. local_v0: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=0
  159. local_v0: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=0
  160. local_v0: TARGET := local_v0
  161. local_v0: $(BUILD_DIR)/$(TARGET)
  162. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  163. local_v1: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=1
  164. local_v1: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=1
  165. local_v1: TARGET := local_v1
  166. local_v1: $(BUILD_DIR)/$(TARGET)
  167. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  168. local_v1_omp: CFLAGS := $(DEB_CFLAGS) -fopenmp -DCODE_VERSION=1 -DOMP
  169. local_v1_omp: CXXFLAGS := $(DEB_CXXFLAGS) -fopenmp -DCODE_VERSION=1 -DOMP
  170. local_v1_omp: LDFLAGS += -fopenmp
  171. local_v1_omp: TARGET := local_v1_omp
  172. local_v1_omp: $(BUILD_DIR)/$(TARGET)
  173. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  174. local_v1_pth: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=1 -DPTHREADS
  175. local_v1_pth: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=1 -DPTHREADS
  176. local_v1_pth: TARGET := local_v1_pth
  177. local_v1_pth: $(BUILD_DIR)/$(TARGET)
  178. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  179. v0: DOCKER := $(DOCKER_CMD)
  180. v0: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=0
  181. v0: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=0
  182. v0: TARGET := knnsearch_v0
  183. v0: $(BUILD_DIR)/$(TARGET)
  184. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  185. v1_cilk: DOCKER := $(DOCKER_CMD)
  186. v1_cilk: CXX := /usr/local/OpenCilk-9.0.1-Linux/bin/clang++
  187. v1_cilk: CFLAGS := $(REL_CFLAGS) -fcilkplus -DCODE_VERSION=1 -DCILK
  188. v1_cilk: CXXFLAGS := $(REL_CXXFLAGS) -fcilkplus -DCODE_VERSION=1 -DCILK
  189. v1_cilk: LDFLAGS += -fcilkplus
  190. v1_cilk: TARGET := knnsearch_v1_cilk
  191. v1_cilk: $(BUILD_DIR)/$(TARGET)
  192. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  193. v1_omp: DOCKER := $(DOCKER_CMD)
  194. v1_omp: CFLAGS := $(REL_CFLAGS) -fopenmp -DCODE_VERSION=1 -DOMP
  195. v1_omp: CXXFLAGS := $(REL_CXXFLAGS) -fopenmp -DCODE_VERSION=1 -DOMP
  196. v1_omp: LDFLAGS += -fopenmp
  197. v1_omp: TARGET := knnsearch_v1_omp
  198. v1_omp: $(BUILD_DIR)/$(TARGET)
  199. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  200. v1_pth: DOCKER := $(DOCKER_CMD)
  201. v1_pth: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=1 -DPTHREADS
  202. v1_pth: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=1 -DPTHREADS
  203. v1_pth: TARGET := knnsearch_v1_pth
  204. v1_pth: $(BUILD_DIR)/$(TARGET)
  205. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  206. v1: DOCKER := $(DOCKER_CMD)
  207. v1: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=1
  208. v1: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=1
  209. v1: TARGET := knnsearch_v1
  210. v1: $(BUILD_DIR)/$(TARGET)
  211. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  212. tests: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=0 -DTESTING
  213. tests: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=0 -DTESTING
  214. tests: TARGET := tests
  215. tests: $(BUILD_DIR)/$(TARGET)
  216. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  217. tests_rel: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=0 -DTESTING
  218. tests_rel: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=0 -DTESTING
  219. tests_rel: TARGET := tests
  220. tests_rel: $(BUILD_DIR)/$(TARGET)
  221. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  222. #
  223. # ========= Inside CSAL Image build rules ===========
  224. #
  225. # 1) first jump into image (make sure you are in the directory where Makefile is):
  226. # > docker run -it -v ${PWD}:/usr/src/exercise_1 -w /usr/src/exercise_1/ hpcimage
  227. # 2) Clean binaries first **important**
  228. # > make clean
  229. # 3) for v4 cilk for example:
  230. # > make csal_v4_cilk
  231. # 4) run executables from `bin/`. Examples:
  232. # > ./bin/tcount_ompv3 -i mtx/NACA0015.mtx --timing -r 3 -o /dev/null
  233. # > ./bin/tcount_pthv4 -i mtx/com_Youtube.mtx --timing --dynamic --print_count
  234. csal_v0: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=0
  235. csal_v0: TARGET := knnsearch_v0
  236. csal_v0: $(BUILD_DIR)/$(TARGET)
  237. csal_v1_cilk: CXX := /usr/local/OpenCilk-9.0.1-Linux/bin/clang++
  238. csal_v1_cilk: CFLAGS := $(REL_CFLAGS) -fcilkplus -DCODE_VERSION=1 -DCILK
  239. csal_v1_cilk: CXXFLAGS := $(REL_CXXFLAGS) -fcilkplus -DCODE_VERSION=1 -DCILK
  240. csal_v1_cilk: LDFLAGS += -fcilkplus
  241. csal_v1_cilk: TARGET := knnsearch_cilkv1
  242. csal_v1_cilk: $(BUILD_DIR)/$(TARGET)
  243. csal_v1_omp: CFLAGS := $(REL_CFLAGS) -fopenmp -DCODE_VERSION=1 -DOMP
  244. csal_v1_omp: CXXFLAGS := $(REL_CXXFLAGS) -fopenmp -DCODE_VERSION=1 -DOMP
  245. csal_v1_omp: LDFLAGS += -fopenmp
  246. csal_v1_omp: TARGET := knnsearch_ompv1
  247. csal_v1_omp: $(BUILD_DIR)/$(TARGET)
  248. csal_v1: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=1
  249. csal_v1: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=1
  250. csal_v1: TARGET := knnsearch_v1
  251. csal_v1: $(BUILD_DIR)/$(TARGET)
  252. #
  253. # ======== Run from container =========
  254. #
  255. # examples:
  256. #
  257. # make IMAGE=hpcimage EXEC=knnsearch_v1 run
  258. # make IMAGE=hpcimage EXEC=knnsearch_v1 run
  259. #
  260. run:
  261. $(DOCKER) ./out/$(EXEC)