A triangle counting assignment for A.U.TH Parallel and distributed systems class.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

276 Zeilen
8.5 KiB

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