A triangle counting assignment for A.U.TH Parallel and distributed systems class.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. # ========= Inside CSAL Image build rules ===========
  194. #
  195. # 1) first jump into image (make sure you are in the directory where Makefile is):
  196. # > docker run -it -v ${PWD}:/usr/src/exercise_1 -w /usr/src/exercise_1/ hpcimage
  197. # 2) Clean binaries first **important**
  198. # > make clean
  199. # 3) for v4 cilk for example:
  200. # > make csal_v4_cilk
  201. # 4) run executables from `out/`
  202. csal_v3: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=3
  203. csal_v3: TARGET := tcount_v3
  204. csal_v3: $(BUILD_DIR)/$(TARGET)
  205. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  206. csal_v3_cilk: CXX := /usr/local/OpenCilk-9.0.1-Linux/bin/clang++
  207. csal_v3_cilk: CFLAGS := $(REL_CFLAGS) -fcilkplus -DCODE_VERSION=3 -DCILK
  208. csal_v3_cilk: LDFLAGS += -fcilkplus
  209. csal_v3_cilk: TARGET := tcount_cilkv3
  210. csal_v3_cilk: $(BUILD_DIR)/$(TARGET)
  211. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  212. csal_v3_omp: CFLAGS := $(REL_CFLAGS) -fopenmp -DCODE_VERSION=3 -DOMP
  213. csal_v3_omp: LDFLAGS += -fopenmp
  214. csal_v3_omp: TARGET := tcount_ompv3
  215. csal_v3_omp: $(BUILD_DIR)/$(TARGET)
  216. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  217. csal_v4: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=4
  218. csal_v4: TARGET := tcount_v4
  219. csal_v4: $(BUILD_DIR)/$(TARGET)
  220. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  221. csal_v4_cilk: CXX := /usr/local/OpenCilk-9.0.1-Linux/bin/clang++
  222. csal_v4_cilk: CFLAGS := $(REL_CFLAGS) -fcilkplus -DCODE_VERSION=V4 -DCILK
  223. csal_v4_cilk: LDFLAGS += -fcilkplus
  224. csal_v4_cilk: TARGET := tcount_cilkv4
  225. csal_v4_cilk: $(BUILD_DIR)/$(TARGET)
  226. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  227. csal_v4_omp: CFLAGS := $(REL_CFLAGS) -fopenmp -DCODE_VERSION=4 -DOMP
  228. csal_v4_omp: LDFLAGS += -fopenmp
  229. csal_v4_omp: TARGET := tcount_ompv4
  230. csal_v4_omp: $(BUILD_DIR)/$(TARGET)
  231. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  232. csal_v4_pthreads: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=4 -DTHREADS
  233. csal_v4_pthreads: TARGET := tcount_pthv4
  234. csal_v4_pthreads: $(BUILD_DIR)/$(TARGET)
  235. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  236. #
  237. # ================ hpc build rules =================
  238. #
  239. hpc_v3_ser: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=3
  240. hpc_v3_ser: TARGET := hpc_v3
  241. hpc_v3_ser: $(BUILD_DIR)/$(TARGET)
  242. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  243. hpc_v3_omp: CFLAGS := $(REL_CFLAGS) -fopenmp -DCODE_VERSION=3 -DOMP
  244. hpc_v3_omp: LDFLAGS += -fopenmp
  245. hpc_v3_omp: TARGET := hpc_ompv3
  246. hpc_v3_omp: $(BUILD_DIR)/$(TARGET)
  247. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  248. hpc_v3_cilk: CXX := clang++
  249. hpc_v3_cilk: CFLAGS := $(REL_CFLAGS) -fcilkplus -DCODE_VERSION=3 -DCILK
  250. hpc_v3_cilk: LDFLAGS += -fcilkplus
  251. hpc_v3_cilk: TARGET := hpc_cilkv3
  252. hpc_v3_cilk: $(BUILD_DIR)/$(TARGET)
  253. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  254. hpc_v4_ser: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=4
  255. hpc_v4_ser: TARGET := hpc_v4
  256. hpc_v4_ser: $(BUILD_DIR)/$(TARGET)
  257. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  258. hpc_v4_omp: CFLAGS := $(REL_CFLAGS) -fopenmp -DCODE_VERSION=4 -DOMP
  259. hpc_v4_omp: LDFLAGS += -fopenmp
  260. hpc_v4_omp: TARGET := hpc_ompv4
  261. hpc_v4_omp: $(BUILD_DIR)/$(TARGET)
  262. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  263. hpc_v4_cilk: CXX := clang++
  264. hpc_v4_cilk: CFLAGS := $(REL_CFLAGS) -fcilkplus -DCODE_VERSION=4 -DCILK
  265. hpc_v4_cilk: LDFLAGS += -fcilkplus
  266. hpc_v4_cilk: TARGET := hpc_cilkv4
  267. hpc_v4_cilk: $(BUILD_DIR)/$(TARGET)
  268. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)
  269. hpc_v4_pth: CFLAGS := $(REL_CFLAGS) -DCODE_VERSION=4 -DTHREADS
  270. hpc_v4_pth: TARGET := hpc_pthv4
  271. hpc_v4_pth: $(BUILD_DIR)/$(TARGET)
  272. cp $(BUILD_DIR)/$(TARGET) out/$(TARGET)