-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
85 lines (66 loc) · 2.2 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
MPICC = mpicc
CC = gcc -std=c99
BUILD_DIR := build
SRC_DIR := src
# Colors
#GREEN = \033[1;32m
#RED = \033[1;31m
#NC = \033[0m
GREEN =
RED =
NC =
# Directories
LIBRARIES_SRC := $(shell find $(SRC_DIR)/data $(SRC_DIR)/processes -name '*.c')
LIBRARIES_SRC := $(LIBRARIES_SRC:%=$(BUILD_DIR)/%.o)
MPI_SRC := $(SRC_DIR)/main.c
MPI_SRC := $(MPI_SRC:%=$(BUILD_DIR)/%.o)
# Every folder in ./src will need to be passed to GCC so that it can find header files
INC_DIRS := $(shell find $(SRC_DIR) -type d)
# Add a prefix to INC_DIRS. So moduleA would become -ImoduleA. GCC understands this -I flag
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CFLAGS := $(INC_FLAGS) -O3 -g
MPI_FLAGS := --mca opal_warn_on_missing_libcuda 0 -hostfile hostfile
# If the first argument is "run_mpi"...
ifeq (run_mpi,$(firstword $(MAKECMDGOALS)))
# use the rest as arguments for "run_mpi"
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
$(eval $(RUN_ARGS):;@:)
else ifeq (debug_mpi,$(firstword $(MAKECMDGOALS)))
# use the rest as arguments for "debug_mpi"
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
$(eval $(RUN_ARGS):;@:)
endif
pre_build:
@echo
@echo "$(GREEN)Building MPI binary ...$(NC)"
@echo
build_mpi: pre_build $(MPI_SRC) $(LIBRARIES_SRC)
@echo
@$(MPICC) $(CFLAGS) -o $(BUILD_DIR)/mpi_main.out $(MPI_SRC) $(LIBRARIES_SRC) -lpthread -lm
@echo "$(GREEN)Build finished successfully!$(NC)"
@echo
$(BUILD_DIR)/%.c.o: %.c
@echo " Building" $@ "..."
@mkdir -p $(dir $@)
@$(MPICC) $(CFLAGS) -c $< -o $@
%.c:
run_mpi:
@mpirun $(MPI_FLAGS) $(BUILD_DIR)/mpi_main.out $(RUN_ARGS)
debug_mpi:
@mpirun $(MPI_FLAGS) valgrind $(BUILD_DIR)/mpi_main.out $(RUN_ARGS)
create_datafile:
@mkdir -p datasets
@echo
@echo "$(GREEN)Creating data file with d=20 n=8388608 path=./datasets/data.bin$(NC)"
@$(CC) -o $(BUILD_DIR)/create_sample_points.out $(SRC_DIR)/tools/create_sample_points.c
@$(BUILD_DIR)/create_sample_points.out 20 8388608 ./datasets/data.bin
@echo
.PHONY: clean
clean:
@echo
@echo "$(RED)Clearing build directory...$(NC)"
@rm -rf $(BUILD_DIR)/*
@echo "$(GREEN)All done!$(NC)"
@echo