-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
330 lines (273 loc) · 7.52 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
ARCH ?= gcc
# -----------------------------------------------------------------------------
# Environment
# -----------------------------------------------------------------------------
#
# Default GCC environment
#
ifeq ($(ARCH), gcc)
CC = gcc
MPICC = mpicc
CFLAGS = -Wall -Wextra -Wpedantic -std=gnu99
LDFLAGS = -lm
MPICFLAGS = $(CFLAGS)
MPILDFLAGS = $(LDFLAGS)
OPENMP_FLAG = -fopenmp
ifneq (,$(DEBUG))
CFLAGS += -g -DDEBUG
MPICFLAGS += -g -DDEBUG
LDFLAGS += -g
MPILDFLAGS += -g
else
CFLAGS += -Ofast
MPICFLAGS += -Ofast
endif
endif
#
# Solaris environment
#
ifeq ($(ARCH), solaris)
CC = cc
MPICC = mpicc
CFLAGS = -m64 -fast
MPICFLAGS = -m64 -fast
LDFLAGS = -m64 -lm -fast
MPILDFLAGS = -m64 -fast
OPENMP = -xopenmp
endif
#
# SGI environment
#
ifeq ($(ARCH), irix)
CC = c99
MPICC = c99
CFLAGS = -64 -Ofast
MPICFLAGS = -64 -Ofast
LDFLAGS = -64 -lm -Ofast
MPILDFLAGS = -64 -lm -Ofast -lmpi
OPENMP = -mp
endif
#
# IA-64 (Itanium) environment
#
ifeq ($(ARCH), ia64)
CC = opencc
MPICC = mpicc
CFLAGS = -std=gnu99 -Ofast
MPICFLAGS = -std=gnu99 -Ofast
LDFLAGS = -lm -Ofast
MPILDFLAGS = -lm -Ofast
OPENMP = -mp
endif
# -----------------------------------------------------------------------------
# Build config
# -----------------------------------------------------------------------------
#
# Simulation parameters
#
gridlength=128
threads=4
#
# Environment
#
SHELL := /bin/bash
HOSTNAME = $(shell hostname)
ARCHNAME = $(shell uname -s)_$(shell uname -m)
TESTDIR = test
TESTDIR_PERF = perf-test
TESTDIR_PERF_OUT = perf-test-out/$(HOSTNAME)
SCRIPTDIR = helper-scripts
MPIRUN = mpirun
SRCDIR = src
ifneq (,$(DESTDIR))
OBJDIR = $(DESTDIR)/$(ARCHNAME)/obj
BINDIR = $(DESTDIR)/$(ARCHNAME)/bin
OUTDIR = $(DESTDIR)/$(ARCHNAME)/output
else
OBJDIR = $(ARCHNAME)/obj
BINDIR = $(ARCHNAME)/bin
OUTDIR = $(ARCHNAME)/output
endif
OBJ =
BIN =
DATA =
OBJ_TESTS =
BIN_TESTS =
# -----------------------------------------------------------------------------
# Macros
# -----------------------------------------------------------------------------
# Macro to create linking target
# $(1) Target bin, $(2) Sources, $(3) Extra LDFLAGS, $(4) Output data
define DEF_BIN
OBJ += $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(2))
BIN += $(1)
$(1): $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(2))
$(CC) $$^ $(LDFLAGS) $(3) -o $$@
DATA += $(4)
$(4): $(1)
$$< -n $(gridlength) -o $$@
endef
# Macro to create linking target using MPI
# $(1) Target bin, $(2) Sources, $(3) Extra LDFLAGS, $(4) Output data
define DEF_BIN_MPI
OBJ += $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(2))
BIN += $(1)
$(1): $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(2))
$(MPICC) $$^ $(MPILDFLAGS) $(3) -o $$@
DATA += $(4)
$(4): $(1)
$(MPIRUN) -n $(threads) $$< -n $(gridlength) -o $$@
endef
# Macro to create linking target
# $(1) Target bin, $(2) Sources, $(3) Extra LDFLAGS
define DEF_TEST
OBJ_TESTS += $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(2))
BIN_TESTS += $(1)
$(1): $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(2))
$(CC) $$^ $(LDFLAGS) -lcunit $(3) -o $$@
endef
# -----------------------------------------------------------------------------
# Targets
# -----------------------------------------------------------------------------
#
# Meta
#
all: $(OBJDIR) $(BINDIR) bin
#
# Serial reference version
#
yee_SRC = $(SRCDIR)/yee.c \
$(SRCDIR)/yee_common.c
$(eval $(call DEF_BIN, $(BINDIR)/yee, $(yee_SRC),, $(OUTDIR)/yee.tsv))
# Additional output for the reference version
#DATA += $(OUTDIR)/yee0.tsv
#$(OUTDIR)/yee0.tsv: $(BINDIR)/yee
# $< -n $(gridlength) -o $@
#
# POSIX threads (blocked)
#
yee_block_pthr_SRC = $(SRCDIR)/yee_block_pthr.c \
$(SRCDIR)/yee_common.c
EXTRA_LDFLAGS = -pthread
$(eval $(call DEF_BIN, $(BINDIR)/yee_block_pthr, $(yee_block_pthr_SRC), $(EXTRA_LDFLAGS), $(OUTDIR)/yee_block_pthr.tsv))
#
# POSIX threads (stride: 1)
#
yee_stride1_pthr_SRC = $(SRCDIR)/yee_stride1_pthr.c \
$(SRCDIR)/yee_common.c
EXTRA_LDFLAGS = -pthread
$(eval $(call DEF_BIN, $(BINDIR)/yee_stride1_pthr, $(yee_stride1_pthr_SRC), $(EXTRA_LDFLAGS), $(OUTDIR)/yee_stride1_pthr.tsv))
#
# OpenMP (naive implementation, slow)
#
yee_naive_omp_SRC = $(SRCDIR)/yee_naive_omp.c \
$(SRCDIR)/yee_common.c
EXTRA_LDFLAGS = $(OPENMP_FLAG)
$(eval $(call DEF_BIN, $(BINDIR)/yee_naive_omp, $(yee_naive_omp_SRC), $(EXTRA_LDFLAGS), $(OUTDIR)/yee_naive_omp.tsv))
#
# OpenMP (blocked version)
#
yee_block_omp_SRC = $(SRCDIR)/yee_block_omp.c \
$(SRCDIR)/yee_common.c
EXTRA_LDFLAGS = $(OPENMP_FLAG)
$(eval $(call DEF_BIN, $(BINDIR)/yee_block_omp, $(yee_block_omp_SRC), $(EXTRA_LDFLAGS), $(OUTDIR)/yee_block_omp.tsv))
#
# OpenMP (stride: 1)
#
yee_stride1_omp_SRC = $(SRCDIR)/yee_stride1_omp.c \
$(SRCDIR)/yee_common.c
EXTRA_LDFLAGS = $(OPENMP_FLAG)
$(eval $(call DEF_BIN, $(BINDIR)/yee_stride1_omp, $(yee_stride1_omp_SRC), $(EXTRA_LDFLAGS), $(OUTDIR)/yee_stride1_omp.tsv))
#
# MPI (blocking send/recieve)
#
yee_blocking_mpi_SRC = $(SRCDIR)/yee_blocking_mpi.c \
$(SRCDIR)/yee_common.c \
$(SRCDIR)/yee_common_mpi.c
$(eval $(call DEF_BIN_MPI, $(BINDIR)/yee_blocking_mpi, $(yee_blocking_mpi_SRC),, $(OUTDIR)/yee_blocking_mpi.tsv))
#
# MPI (Non-blocking)
#
yee_nonblock_mpi_SRC = $(SRCDIR)/yee_nonblock_mpi.c \
$(SRCDIR)/yee_common.c \
$(SRCDIR)/yee_common_mpi.c
$(eval $(call DEF_BIN_MPI, $(BINDIR)/yee_nonblock_mpi, $(yee_nonblock_mpi_SRC),, $(OUTDIR)/yee_nonblock_mpi.tsv))
#
# Tests
#
unittests_SRC = $(SRCDIR)/yee_common_tests.c \
$(SRCDIR)/yee_common.c
$(eval $(call DEF_TEST, $(BINDIR)/unit_tests, $(unittests_SRC)))
GNUPLOT = $(DATA:.tsv=.plt)
PNG = $(GNUPLOT:.plt=.png)
.PHONY: clean
.PRECIOUS: $(tests_DATA)
# -----------------------------------------------------------------------------
# Rules
# -----------------------------------------------------------------------------
#
# Meta targets
#
bin: $(BIN)
test: $(BIN_TESTS)
./$<
test-integration: all
bindir=$(BINDIR) $(TESTDIR)/integration-tests.sh
data: all $(OUTDIR) $(DATA)
plot: data $(PNG)
indent:
indent -kr --no-tabs $(SRCDIR)/*.c
indent -kr --no-tabs $(SRCDIR)/*.h
tags:
ctags -R src
#
# Compilation
#
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%_omp.o: $(SRCDIR)/%_omp.c
$(CC) $(CFLAGS) -c $< $(OPENMP_FLAG) -o $@
$(OBJDIR)/%_mpi.o: $(SRCDIR)/%_mpi.c
$(MPICC) $(MPICFLAGS) -c $< -o $@
#
# Generate plots
#
$(GNUPLOT): $(SRCDIR)/template.gnuplot
sed 's:file:$(@:.plt=):g' $< > $@
%.png: %.plt %.tsv
gnuplot $<
#
# Performance testing
#
test-scaling-compute: all
./$(TESTDIR_PERF)/test_scaling.sh -n 8 -N 256 -s 4
#test-scaling: test-scaling-compute
test-scaling:
python3 $(SCRIPTDIR)/gather_data.py $(TESTDIR_PERF_OUT)/test_scaling_*.tsv \
> $(TESTDIR_PERF_OUT)/test_scaling.tsv
cp $(TESTDIR_PERF)/test_scaling.plt $(TESTDIR_PERF_OUT)
pushd $(TESTDIR_PERF_OUT) && \
gnuplot test_scaling.plt
test-perf-compute: all
#./$(TESTDIR_PERF)/test_perf.sh -n 4 -N 1000 -s 2 -t 50
./$(TESTDIR_PERF)/test_perf.sh -n 4 -N 1000 -s 4 -t 1
#test-perf: test-perf-compute
test-perf:
python3 $(SCRIPTDIR)/gather_data.py $(TESTDIR_PERF_OUT)/test_perf_4_*.tsv \
> $(TESTDIR_PERF_OUT)/test_perf_4.tsv
cp $(TESTDIR_PERF)/test_perf_4.plt $(TESTDIR_PERF_OUT)
cp $(TESTDIR_PERF)/test_perf_8.plt $(TESTDIR_PERF_OUT)
pushd $(TESTDIR_PERF_OUT) && \
gnuplot test_perf_4.plt
#
# Environment
#
$(BINDIR) $(OBJDIR) $(OUTDIR):
mkdir -p $@
clean:
$(RM) $(BIN) $(BIN_TESTS) $(OBJ) $(OBJ_TESTS) \
$(DATA) $(PNG) $(GNUPLOT) $(unittests_BIN) $(unittests_OBJ)
[ -d $(OBJDIR) ] && rmdir $(OBJDIR)
[ -d $(BINDIR) ] && rmdir $(BINDIR)
[ -d $(OUTDIR) ] && rmdir $(OUTDIR)
[ -d $(ARCHNAME) ] && rmdir $(ARCHNAME)