AUTH's THMMY "Parallel and distributed systems" course assignments.
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.
 
 
 
 
 
 

222 line
6.7 KiB

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