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 8.6 KiB

il y a 1 semaine
il y a 1 semaine
il y a 1 semaine
il y a 1 semaine
il y a 1 semaine
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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
  26. # Include directories list(space seperated). Makefile-relative path.
  27. INC_DIR_LIST := inc \
  28. src
  29. # Exclude files list(space seperated). Filenames only.
  30. # EXC_FILE_LIST := bad.cpp old.cpp
  31. # Build directories
  32. BUILD_DIR := bin
  33. OBJ_DIR := $(BUILD_DIR)/obj
  34. DEP_DIR := $(BUILD_DIR)/.dep
  35. # ========== Compiler settings ==========
  36. # Compiler flags for debug and release
  37. DEB_CFLAGS := -DDEBUG -g3 -Wall -Wextra -std=c11
  38. REL_CFLAGS := -Wall -Wextra -O3 -std=c11
  39. DEB_CXXFLAGS := -DDEBUG -g3 -Wall -Wextra -std=c++17
  40. REL_CXXFLAGS := -Wall -Wextra -O3 -std=c++17
  41. # Pre-defines
  42. # PRE_DEFS := MYCAB=1729 SUPER_MODE
  43. PRE_DEFS :=
  44. # ============== Linker settings ==============
  45. # Linker flags (example: -pthread -lm)
  46. LDFLAGS := -pthread -lopenblas
  47. # Map output file
  48. MAP_FILE := output.map
  49. MAP_FLAG := -Xlinker -Map=$(BUILD_DIR)/$(MAP_FILE)
  50. # ============== Docker settings ==============
  51. # We need:
  52. # - Bind the entire project directory(the dir that icludes all the code) as volume.
  53. # - In docker instance, change to working directory(where the makefile is).
  54. DOCKER_VOL_DIR := ${PWD}
  55. DOCKER_WRK_DIR :=
  56. DOCKER_RUN := docker run --rm
  57. DOCKER_FLAGS := -v $(DOCKER_VOL_DIR):/usr/src/$(PROJECT) -w /usr/src/$(PROJECT)/$(DOCKER_WRK_DIR)
  58. # docker invoke mechanism (edit with care)
  59. # note:
  60. # Here, `DOCKER` variable is empty. Rules can assign `DOCKER := DOCKER_CMD` when docker
  61. # functionality is needed.
  62. DOCKER_CMD = $(DOCKER_RUN) $(DOCKER_FLAGS) $(IMAGE)
  63. DOCKER :=
  64. # ============== Tool selection ==============
  65. # compiler and compiler flags.
  66. CSIZE := size
  67. CFLAGS := $(DEB_CFLAGS)
  68. CXXFLAGS := $(DEB_CXXFLAGS)
  69. CXX := g++
  70. #
  71. # =========== Main body and Patterns ===========
  72. #
  73. #ifeq ($(OS), Windows_NT)
  74. # TARGET := $(TARGET).exe
  75. #endif
  76. INC := $(foreach dir,$(INC_DIR_LIST),-I$(dir))
  77. DEF := $(foreach def,$(PRE_DEFS),-D$(def))
  78. EXC := $(foreach fil,$(EXC_FILE_LIST), \
  79. $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/$(fil))) \
  80. )
  81. # source files. object and dependencies list
  82. # recursive search into current and source directories
  83. SRC := $(wildcard *.cpp)
  84. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/*.cpp))
  85. SRC += $(foreach dir,$(SRC_DIR_LIST),$(wildcard $(dir)/**/*.cpp))
  86. SRC := $(filter-out $(EXC),$(SRC))
  87. #SRC := $(abspath $(SRC))
  88. OBJ := $(foreach file,$(SRC:%.cpp=%.o),$(OBJ_DIR)/$(file))
  89. DEP := $(foreach file,$(SRC:%.cpp=%.d),$(DEP_DIR)/$(file))
  90. # Make Dependencies pattern.
  91. # This little trick enables recompilation only when dependencies change
  92. # and it does so for changes both in source AND header files ;)
  93. #
  94. # It is based on Tom Tromey's method.
  95. #
  96. # Invoke cpp to create makefile rules with dependencies for each source file
  97. $(DEP_DIR)/%.d: %.c
  98. @mkdir -p $(@D)
  99. @$(DOCKER) $(CC) -E $(CFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)/$(<:.c=.o) -MF $@ $<
  100. # c file objects depent on .c AND dependency files, which have an empty recipe
  101. $(OBJ_DIR)/%.o: %.c $(DEP_DIR)/%.d
  102. @mkdir -p $(@D)
  103. $(DOCKER) $(CC) -c $(CFLAGS) $(INC) $(DEF) -o $@ $<
  104. $(DEP_DIR)/%.d: %.cpp
  105. @mkdir -p $(@D)
  106. @$(DOCKER) $(CXX) -E $(CXXFLAGS) $(INC) $(DEF) -MM -MT $(OBJ_DIR)/$(<:.cpp=.o) -MF $@ $<
  107. # cpp file objects depent on .cpp AND dependency files, which have an empty recipe
  108. $(OBJ_DIR)/%.o: %.cpp $(DEP_DIR)/%.d
  109. @mkdir -p $(@D)
  110. $(DOCKER) $(CXX) -c $(CXXFLAGS) $(INC) $(DEF) -o $@ $<
  111. # empty recipe for dependency files. This prevents make errors
  112. $(DEP):
  113. # now include all dependencies
  114. # After all they are makefile dependency rules ;)
  115. include $(wildcard $(DEP))
  116. # main target rule
  117. $(BUILD_DIR)/$(TARGET): $(OBJ)
  118. @mkdir -p $(@D)
  119. @echo Linking to target: $(TARGET)
  120. @echo $(DOCKER) $(CXX) '$$(OBJ)' $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET)
  121. @$(DOCKER) $(CXX) $(OBJ) $(LDFLAGS) $(MAP_FLAG) -o $(@D)/$(TARGET)
  122. @echo
  123. @echo Print size information
  124. @$(CSIZE) $(@D)/$(TARGET)
  125. @echo Done
  126. .PHONY: clean
  127. clean:
  128. @echo Cleaning build directories
  129. @rm -rf $(OBJ_DIR)
  130. @rm -rf $(DEP_DIR)
  131. @rm -rf $(BUILD_DIR)
  132. #
  133. # ================ Local build rules =================
  134. # example:
  135. # make debug
  136. debug: CFLAGS := $(DEB_CFLAGS)
  137. debug: $(BUILD_DIR)/$(TARGET)
  138. release: CFLAGS := $(REL_CFLAGS)
  139. release: $(BUILD_DIR)/$(TARGET)
  140. all: release
  141. hpc-results/post:
  142. $(CXX) $(CFLAGS) -o $@ hpc-results/main.cpp
  143. hpc-clean:
  144. rm hpc-results/post
  145. #
  146. # ================ Local via docker build rules =================
  147. #
  148. # examples:
  149. # make IMAGE=hpcimage v0
  150. # make IMAGE=hpcimage v1_cilk
  151. #
  152. local_v0: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=0
  153. local_v0: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=0
  154. local_v0: TARGET := local_v0
  155. local_v0: $(BUILD_DIR)/$(TARGET)
  156. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  157. local_v1: CFLAGS := $(DEB_CFLAGS) -DCODE_VERSION=4
  158. local_v1: CXXFLAGS := $(DEB_CXXFLAGS) -DCODE_VERSION=4
  159. local_v1: TARGET := local_v1
  160. local_v1: $(BUILD_DIR)/$(TARGET)
  161. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  162. v0: DOCKER := $(DOCKER_CMD)
  163. v0: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=0
  164. v0: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=0
  165. v0: TARGET := knnsearch_v0
  166. v0: $(BUILD_DIR)/$(TARGET)
  167. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  168. v1_cilk: DOCKER := $(DOCKER_CMD)
  169. v1_cilk: CXX := /usr/local/OpenCilk-9.0.1-Linux/bin/clang++
  170. v1_cilk: CFLAGS := $(REL_CFLAGS) -fcilkplus -DCODE_VERSION=1 -DCILK
  171. v1_cilk: CXXFLAGS := $(REL_CXXFLAGS) -fcilkplus -DCODE_VERSION=1 -DCILK
  172. v1_cilk: LDFLAGS += -fcilkplus
  173. v1_cilk: TARGET := knnsearch_cilkv1
  174. v1_cilk: $(BUILD_DIR)/$(TARGET)
  175. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  176. v1_omp: DOCKER := $(DOCKER_CMD)
  177. v1_omp: CFLAGS := $(REL_CFLAGS) -fopenmp -DCODE_VERSION=1 -DOMP
  178. v1_omp: CXXFLAGS := $(REL_CXXFLAGS) -fopenmp -DCODE_VERSION=1 -DOMP
  179. v1_omp: LDFLAGS += -fopenmp
  180. v1_omp: TARGET := knnsearch_ompv1
  181. v1_omp: $(BUILD_DIR)/$(TARGET)
  182. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  183. v1: DOCKER := $(DOCKER_CMD)
  184. v1: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=1
  185. v1: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=1
  186. v1: TARGET := knnsearch_v1
  187. v1: $(BUILD_DIR)/$(TARGET)
  188. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  189. #
  190. # ========= Inside CSAL Image build rules ===========
  191. #
  192. # 1) first jump into image (make sure you are in the directory where Makefile is):
  193. # > docker run -it -v ${PWD}:/usr/src/exercise_1 -w /usr/src/exercise_1/ hpcimage
  194. # 2) Clean binaries first **important**
  195. # > make clean
  196. # 3) for v4 cilk for example:
  197. # > make csal_v4_cilk
  198. # 4) run executables from `bin/`. Examples:
  199. # > ./bin/tcount_ompv3 -i mtx/NACA0015.mtx --timing -r 3 -o /dev/null
  200. # > ./bin/tcount_pthv4 -i mtx/com_Youtube.mtx --timing --dynamic --print_count
  201. csal_v0: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=0
  202. csal_v0: TARGET := knnsearch_v0
  203. csal_v0: $(BUILD_DIR)/$(TARGET)
  204. csal_v1_cilk: CXX := /usr/local/OpenCilk-9.0.1-Linux/bin/clang++
  205. csal_v1_cilk: CFLAGS := $(REL_CFLAGS) -fcilkplus -DCODE_VERSION=1 -DCILK
  206. csal_v1_cilk: CXXFLAGS := $(REL_CXXFLAGS) -fcilkplus -DCODE_VERSION=1 -DCILK
  207. csal_v1_cilk: LDFLAGS += -fcilkplus
  208. csal_v1_cilk: TARGET := knnsearch_cilkv1
  209. csal_v1_cilk: $(BUILD_DIR)/$(TARGET)
  210. csal_v1_omp: CFLAGS := $(REL_CFLAGS) -fopenmp -DCODE_VERSION=1 -DOMP
  211. csal_v1_omp: CXXFLAGS := $(REL_CXXFLAGS) -fopenmp -DCODE_VERSION=1 -DOMP
  212. csal_v1_omp: LDFLAGS += -fopenmp
  213. csal_v1_omp: TARGET := knnsearch_ompv1
  214. csal_v1_omp: $(BUILD_DIR)/$(TARGET)
  215. csal_v1: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=1
  216. csal_v1: CXXFLAGS := $(REL_CXXFLAGS) -DCODE_VERSION=1
  217. csal_v1: TARGET := knnsearch_v1
  218. csal_v1: $(BUILD_DIR)/$(TARGET)
  219. #
  220. # ======== Run from container =========
  221. #
  222. # examples:
  223. #
  224. # make IMAGE=hpcimage EXEC=knnsearch_v1 run
  225. # make IMAGE=hpcimage EXEC=knnsearch_cilkv1 run
  226. #
  227. run: DOCKER := $(DOCKER_CMD)
  228. run:
  229. $(DOCKER) ./out/$(EXEC)