Makefile 15.3 KB
Newer Older
Volker Springel's avatar
Volker Springel committed
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
#/*******************************************************************************
# * \copyright   This file is part of the GADGET4 N-body/SPH code developed
# * \copyright   by Volker Springel. Copyright (C) 2014, 2015 by Volker Springel
# * \copyright   (volker.springel@h-its.org) and all contributing authors.
# *******************************************************************************/
#
# You might be looking for the compile-time Makefile options of the
# code if you are familiar with Gadget2...
#
# They have moved to a separate file.
#
# To build the code, do the following:
#
#  (1) Copy the file "Template-Config.sh"  to  "Config.sh"
#
#        cp Template-Config.sh Config.sh
#
#  (2) Edit "Config.sh" as needed for your application
#
#  (3) Run "make"
#
#
#  New compile-time options should be added to the
#  file "Template-Config.sh" only. Usually, they should be added
#  there in the disabled/default version.
#
#  "Config.sh" should not be checked in to the repository.
#
#  Note: It is possible to override the default name of the
#  Config.sh file, if desired, as well as the name of the
#  executable. For example:
#
#   make CONFIG=MyNewConf.sh EXEC=Gadget4_new
#
#-----------------------------------------------------------------
#
# You might also be looking for the target system SYSTYPE option
#
# It has also moved to a separate file.
#
# To build the code, do the following:
#
# (A) set the SYSTYPE variable in your .bashrc (or similar file):
#
#        e.g. export SYSTYPE=Magny
# or
#
# (B) set SYSTYPE in Makefile.systype
#     This file has priority over your shell variable:
#
#    (1) Copy the file "Template-Makefile.systype"  to  "Makefile.systype"
#
#        cp Template-Makefile.systype Makefile.systype
#
#    (2) Uncomment your system in  "Makefile.systype".
#
# For the chosen system type, an if-clause should be defined below,
# loading short definitions of library path names and/or compiler
# names and options from the buildsystem/ directory. A new system
# type should also be added to Template-Makefile.systype
#


ifdef DIR
EXEC = $(DIR)/Gadget4
CONFIG = $(DIR)/Config.sh
BUILD_DIR = $(DIR)/build
else
EXEC   = Gadget4
CONFIG   = Config.sh
BUILD_DIR = build
endif


SRC_DIR = src

###################
#determine SYSTYPE#
###################
ifdef SYSTYPE
SYSTYPE := "$(SYSTYPE)"
-include Makefile.systype
else
include Makefile.systype
endif




$(info Build configuration:)
$(info SYSTYPE: $(SYSTYPE))
$(info CONFIG: $(CONFIG))
$(info EXEC: $(EXEC))
$(info )


PYTHON   = /usr/bin/python

RESULT     := $(shell CONFIG=$(CONFIG) PYTHON=$(PYTHON) BUILD_DIR=$(BUILD_DIR) SRC_DIR=$(SRC_DIR) CURDIR=$(CURDIR) make -f buildsystem/Makefile.config)
$(info $(RESULT))
CONFIGVARS := $(shell cat $(BUILD_DIR)/gadgetconfig.h)

RESULT     := $(shell SRC_DIR=$(SRC_DIR) BUILD_DIR=$(BUILD_DIR) ./buildsystem/git_version.sh)

##########################
#define available Systems#
##########################
ifeq ($(SYSTYPE),"Generic-gcc")
include buildsystem/Makefile.gen.libs
include buildsystem/Makefile.comp.gcc
endif
ifeq ($(SYSTYPE),"Generic-intel")
include buildsystem/Makefile.comp.gcc-paranoia
include buildsystem/Makefile.gen.libs
endif

ifeq ($(SYSTYPE),"SuperMUC-NG")
include buildsystem/Makefile.comp.supermuc-ng
include buildsystem/Makefile.path.supermuc-ng
endif

ifeq ($(SYSTYPE),"SuperMUC-NG-OpenMPI")
include buildsystem/Makefile.comp.supermuc-ng-openmpi
include buildsystem/Makefile.path.supermuc-ng
endif

ifeq ($(SYSTYPE),"SuperMUC-NG-GCC")
include buildsystem/Makefile.comp.supermuc-ng-gcc
include buildsystem/Makefile.path.supermuc-ng-gcc
endif

ifeq ($(SYSTYPE), "Generic-gcc-single")
include buildsystem/Makefile.comp.gcc
Volker Springel's avatar
Volker Springel committed
134
include buildsystem/Makefile.gen.libs
Volker Springel's avatar
Volker Springel committed
135
136
137
138
endif

ifeq ($(SYSTYPE), "Generic-intel-single")
include buildsystem/Makefile.comp.gcc-paranoia
Volker Springel's avatar
Volker Springel committed
139
include buildsystem/Makefile.gen.libs
Volker Springel's avatar
Volker Springel committed
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
endif

ifeq ($(SYSTYPE),"Darwin")
include buildsystem/Makefile.comp.gcc
include buildsystem/Makefile.path.macports
endif

ifeq ($(SYSTYPE),"Magny")
include buildsystem/Makefile.comp.gcc
include buildsystem/Makefile.path.magny
endif

ifeq ($(SYSTYPE),"Freya")
include buildsystem/Makefile.comp.freya
include buildsystem/Makefile.path.freya
endif

#module load  gcc/7.2    gsl/2.2  hdf5-serial/gcc/1.8.18   fftw/gcc/3.3.6   
ifeq ($(SYSTYPE),"FreyaOpenMPI")
include buildsystem/Makefile.comp.freyaopenmpi
include buildsystem/Makefile.path.freya
endif


ifeq ($(SYSTYPE),"Cobra")
include buildsystem/Makefile.comp.cobra
include buildsystem/Makefile.path.cobra
endif

ifeq ($(SYSTYPE),"RavenOpenMPI")
include buildsystem/Makefile.comp.ravenopenmpi
include buildsystem/Makefile.path.cobra
endif

ifeq ($(SYSTYPE),"CobraOpenMPI")
include buildsystem/Makefile.comp.cobraopenmpi
include buildsystem/Makefile.path.cobra
endif

ifeq ($(SYSTYPE),"Haswell")
include buildsystem/Makefile.comp.gcc
include buildsystem/Makefile.path.haswell
endif

ifeq ($(SYSTYPE),"gcc-paranoia")
include buildsystem/Makefile.comp.gcc-paranoia
include buildsystem/Makefile.path.mpa_desktop
endif


ifeq ($(SYSTYPE),"libs")
include buildsystem/makefile.comp.gcc
include buildsystem/Makefile.path.libs
endif

ifeq ($(SYSTYPE),"hydra")
include buildsystem/Makefile.comp.gcc
include buildsystem/Makefile.path.hydra
endif

ifeq ($(SYSTYPE),"bwforcluster")
include buildsystem/Makefile.comp.gcc
include buildsystem/Makefile.path.bwforcluster
endif


ifndef LINKER
LINKER = $(CPP)
endif

##########################################
#determine the needed object/header files#
##########################################
SUBDIRS += .


SUBDIRS += main
OBJS    += main/begrun.o main/init.o main/main.o main/run.o
INCL    += main/main.h main/simulation.h


SUBDIRS += data
OBJS    += data/mymalloc.o data/allvars.o data/test_symtensors.o
INCL    += data/allvars.h data/dtypes.h data/mymalloc.h data/idstorage.h data/symtensors.h \
           data/intposconvert.h data/constants.h data/simparticles.h \
           data/macros.h data/particle_data.h data/sph_particle_data.h \
           data/lightcone_particle_data.h data/lightcone_massmap_data.h data/lcparticles.h data/mmparticles.h


SUBDIRS += domain
OBJS    += domain/domain.o domain/domain_balance.o domain/domain_box.o \
           domain/domain_exchange.o domain/domain_toplevel.o
INCL    += domain/domain.h


SUBDIRS += io
OBJS    += io/hdf5_util.o io/snap_io.o io/parameters.o \
           io/restart.o io/io.o io/test_io_bandwidth.o
INCL    += io/io.h io/hdf5_util.h io/snap_io.h io/parameters.h \
	         io/restart.h io/io_streamcount.h io/test_io_bandwidth.h


SUBDIRS += logs
OBJS    += logs/logs.o
INCL    += logs/logs.h logs/timer.h

SUBDIRS += gitversion
INCL    += gitversion/version.h


SUBDIRS += mpi_utils
OBJS    += mpi_utils/hypercube_allgatherv.o mpi_utils/mpi_types.o mpi_utils/mpi_vars.o mpi_utils/sums_and_minmax.o \
           mpi_utils/sizelimited_sendrecv.o mpi_utils/myalltoall.o mpi_utils/allreduce_sparse_double_sum.o mpi_utils/healthtest.o \
           mpi_utils/allreduce_debugcheck.o mpi_utils/shared_mem_handler.o 
INCL    += mpi_utils/mpi_utils.h mpi_utils/generic_comm.h mpi_utils/shared_mem_handler.h


SUBDIRS += pm
OBJS    += pm/pm_nonperiodic.o pm/pm_periodic.o \
           pm/pm_mpi_fft.o
INCL    += pm/pm.h pm/pm_mpi_fft.h pm/pm_periodic.h pm/pm_nonperiodic.h


SUBDIRS += vectorclass
OBJS    += vectorclass/instrset_detect.o
INCL    +=


SUBDIRS += sort
OBJS    += sort/peano.o
INCL    += sort/peano.h sort/cxxsort.h sort/parallel_sort.h


SUBDIRS += sph
OBJS    += sph/density.o sph/hydra.o sph/init_entropy.o sph/artificial_viscosity.o
INCL    += sph/kernel.h sph/sph.h

SUBDIRS += system
OBJS    += system/pinning.o system/system.o
INCL    += system/system.h system/pinning.h


SUBDIRS += time_integration
OBJS    += time_integration/driftfac.o time_integration/kicks.o \
           time_integration/predict.o time_integration/timestep.o \
           time_integration/timestep_treebased.o
INCL    += time_integration/timestep.h time_integration/driftfac.h


SUBDIRS += gravity
OBJS    += gravity/gravity.o gravity/ewald.o gravity/ewald_test.o \
           gravity/grav_forcetest.o \
           gravity/grav_direct.o gravity/second_order_ics.o
INCL    += gravity/ewald.h gravity/ewaldtensors.h gravity/grav_forcetest.h


SUBDIRS += tree
OBJS    += tree/tree.o
INCL    += tree/tree.h


SUBDIRS += gravtree
OBJS    += gravtree/gravtree_build.o gravtree/gravtree.o gravtree/gwalk.o
INCL    += gravtree/gravtree.h  gravtree/gwalk.h  


SUBDIRS += ngbtree
OBJS    += ngbtree/ngbtree_build.o 
INCL    += ngbtree/ngbtree.h


ifeq (COOLING,$(findstring COOLING,$(CONFIGVARS)))
OBJS    += cooling_sfr/cooling.o cooling_sfr/sfr_eos.o cooling_sfr/starformation.o
INCL    += cooling_sfr/cooling.h
SUBDIRS += cooling_sfr
endif


ifeq (FOF,$(findstring FOF,$(CONFIGVARS)))
OBJS    += fof/fof.o fof/fof_findgroups.o fof/fof_nearest.o fof/fof_io.o fof/foftree_build.o
INCL    += fof/fof.h  fof/fof_io.h  fof/foftree.h
SUBDIRS += fof
endif


ifeq (SUBFIND,$(findstring SUBFIND,$(CONFIGVARS)))
OBJS	+= subfind/subfind.o subfind/subfind_treepotential.o \
           subfind/subfind_processing.o subfind/subfind_density.o subfind/subfind_distribute.o subfind/subfind_findlinkngb.o \
           subfind/subfind_nearesttwo.o subfind/subfind_properties.o subfind/subfind_unbind.o subfind/subfind_history.o \
           subfind/subfind_so.o subfind/subfind_readid_io.o subfind/subfind_orphanids.o subfind/subfind_excursionset.o 
INCL	+= subfind/subfind.h subfind/subfind_readid_io.h
SUBDIRS += subfind
endif


ifeq (FMM,$(findstring FMM,$(CONFIGVARS)))
SUBDIRS += fmm
OBJS    += fmm/fmm.o
INCL    += fmm/fmm.h
endif


ifeq (MERGERTREE,$(findstring MERGERTREE,$(CONFIGVARS)))
OBJS    += mergertree/descendant.o mergertree/io_descendant.o mergertree/io_progenitors.o \
           mergertree/postproc_descendants.o mergertree/io_readsnap.o mergertree/halotrees.o \
           mergertree/io_halotrees.o mergertree/io_treelinks.o mergertree/io_readtrees_mbound.o \
           mergertree/rearrange.o
INCL    += mergertree/mergertree.h mergertree/io_descendant.h mergertree/io_progenitors.h \
           mergertree/io_readsnap.h mergertree/io_treelinks.h mergertree/io_halotrees.h \
           mergertree/io_readtrees_mbound.h
SUBDIRS += mergertree
endif


ifeq (LIGHTCONE,$(findstring LIGHTCONE,$(CONFIGVARS)))
SUBDIRS += lightcone
OBJS    += lightcone/lightcone.o lightcone/lightcone_particle_io.o lightcone/lightcone_massmap_io.o      
INCL    += lightcone/lightcone.h lightcone/lightcone_particle_io.h lightcone/lightcone_massmap_io.h 
endif


ifeq (LIGHTCONE_MASSMAPS,$(findstring LIGHTCONE_MASSMAPS,$(CONFIGVARS)))
MAPS_LIBS += -lchealpix -lcfitsio #-lcurl
endif

ifeq (LIGHTCONE_PARTICLES,$(findstring LIGHTCONE_PARTICLES,$(CONFIGVARS)))
MAPS_LIBS += -lchealpix -lcfitsio #-lcurl
endif


ifeq (NGENIC,$(findstring NGENIC,$(CONFIGVARS)))
OBJS    += ngenic/ngenic.o ngenic/power.o ngenic/grid.o
INCL    += ngenic/ngenic.h
SUBDIRS += ngenic
endif


ifeq (DEBUG_MD5,$(findstring DEBUG_MD5,$(CONFIGVARS)))
SUBDIRS += debug_md5
OBJS    += debug_md5/calc_checksum.o debug_md5/Md5.o
INCL    += debug_md5/Md5.h
endif


################################
#determine the needed libraries#
################################

# we only need fftw if PMGRID is turned on
ifeq (PMGRID, $(findstring PMGRID, $(CONFIGVARS)))
ifeq (DOUBLEPRECISION_FFTW,$(findstring DOUBLEPRECISION_FFTW,$(CONFIGVARS)))  # test for double precision libraries
FFTW_LIBS += -lfftw3
else
FFTW_LIBS += -lfftw3f
endif
else
ifeq (NGENIC, $(findstring NGENIC, $(CONFIGVARS)))
ifeq (DOUBLEPRECISION_FFTW,$(findstring DOUBLEPRECISION_FFTW,$(CONFIGVARS)))  # test for double precision libraries
FFTW_LIBS += -lfftw3
else
FFTW_LIBS += -lfftw3f
endif
else

endif
endif

ifeq (FORCETEST, $(findstring FORCETEST, $(CONFIGVARS)))
FFTW_LIBS += -lfftw3
endif


HWLOC_LIBS  += -lhwloc

ifneq (IMPOSE_PINNING,$(findstring IMPOSE_PINNING,$(CONFIGVARS)))
HWLOC_INCL =
HWLOC_LIBS =
endif

ifneq (VTUNE_INSTRUMENT,$(findstring VTUNE_INSTRUMENT,$(CONFIGVARS)))
VTUNE_INCL =
VTUNE_LIBS =
endif

GSL_LIBS   += -lgsl -lgslcblas
HDF5_LIBS  += -lhdf5 -lz
MATH_LIBS  = -lm

MAKEFILES = $(MAKEFILE_LIST) buildsystem/Makefile.config

##########################
#combine compiler options#
##########################

CFLAGS = $(OPTIMIZE) $(OPT) $(HDF5_INCL) $(GSL_INCL) $(FFTW_INCL) $(HWLOC_INCL) $(VTUNE_INCL) $(MAPS_INCL) -I$(BUILD_DIR) -I$(SRC_DIR)

LIBS = $(MATH_LIBS) $(HDF5_LIBS) $(GSL_LIBS) $(FFTW_LIBS) $(HWLOC_LIBS) $(VTUNE_LIBS) $(TEST_LIBS) $(MAPS_LIBS)


SUBDIRS := $(addprefix $(BUILD_DIR)/,$(SUBDIRS))
OBJS := $(addprefix $(BUILD_DIR)/,$(OBJS)) $(BUILD_DIR)/compile_time_info.o $(BUILD_DIR)/compile_time_info_hdf5.o $(BUILD_DIR)/version.o
INCL := $(addprefix $(SRC_DIR)/,$(INCL)) $(BUILD_DIR)/gadgetconfig.h


TO_CHECK := $(addsuffix .check, $(OBJS) $(patsubst $(SRC_DIR)%, $(BUILD_DIR)%, $(INCL)) )
TO_CHECK +=  $(BUILD_DIR)/Makefile.check
CONFIG_CHECK = $(BUILD_DIR)/$(notdir $(CONFIG)).check
DOCS_CHECK = $(BUILD_DIR)/config.check  $(BUILD_DIR)/param.check


################
#create subdirs#
################
RESULT := $(shell mkdir -p $(SUBDIRS)  )

###########################################
#create info file for command line options#
###########################################
RESULT := $(shell echo 'static const char *compiler_flags="$(CPP) $(CFLAGS)";' > $(BUILD_DIR)/compiler-command-line-args.h )

#############
#build rules#
#############

all: check_docs check build

build: $(EXEC)

$(EXEC): $(OBJS)
	$(LINKER) $(OPTIMIZE) $(OBJS) $(LIBS) -o $(EXEC)

clean:
	rm -f $(OBJS) $(EXEC)
	rm -f $(BUILD_DIR)/compile_time_info.cc $(BUILD_DIR)/compile_time_info_hdf5.cc $(BUILD_DIR)/gadgetconfig.h
	rm -f $(TO_CHECK) $(CONFIG_CHECK)
	rm -f $(BUILD_DIR)/version.cc

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp $(INCL) $(MAKEFILES)
	$(CPP) $(CFLAGS) -c $< -o $@

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cc $(INCL) $(MAKEFILES)
	$(CPP) $(CFLAGS) -c $< -o $@

$(BUILD_DIR)/compile_time_info.o: $(BUILD_DIR)/compile_time_info.cc $(MAKEFILES)
	$(CPP) $(CFLAGS) -c $< -o $@

$(BUILD_DIR)/compile_time_info_hdf5.o: $(BUILD_DIR)/compile_time_info_hdf5.cc $(MAKEFILES)
	$(CPP) $(CFLAGS) -c $< -o $@


check: $(CONFIG_CHECK)

check_docs: $(DOCS_CHECK)

$(CONFIG_CHECK): $(TO_CHECK) $(CONFIG) buildsystem/check.py
	@$(PYTHON) buildsystem/check.py 2 $(CONFIG) $(CONFIG_CHECK) defines_extra $(TO_CHECK)

$(BUILD_DIR)/%.o.check: $(SRC_DIR)/%.cpp Template-Config.sh defines_extra buildsystem/check.py
	@$(PYTHON) buildsystem/check.py 1 $< $@ Template-Config.sh defines_extra

$(BUILD_DIR)/%.o.check: $(SRC_DIR)/%.cc Template-Config.sh defines_extra buildsystem/check.py
	@$(PYTHON) buildsystem/check.py 1 $< $@ Template-Config.sh defines_extra

$(BUILD_DIR)/%.h.check: $(SRC_DIR)/%.h Template-Config.sh defines_extra buildsystem/check.py
	@$(PYTHON) buildsystem/check.py 1 $< $@ Template-Config.sh defines_extra

$(BUILD_DIR)/%.o.check: $(BUILD_DIR)/%.cc Template-Config.sh defines_extra buildsystem/check.py
	@$(PYTHON) buildsystem/check.py 1 $< $@ Template-Config.sh defines_extra

$(BUILD_DIR)/%.h.check: $(BUILD_DIR)/%.h Template-Config.sh defines_extra buildsystem/check.py
	@$(PYTHON) buildsystem/check.py 1 $< $@ Template-Config.sh defines_extra

$(BUILD_DIR)/Makefile.check: Makefile Template-Config.sh defines_extra buildsystem/check.py
	@$(PYTHON) buildsystem/check.py 3 $< $@ Template-Config.sh defines_extra

$(BUILD_DIR)/config.check: documentation/04_config-options.md Template-Config.sh buildsystem/check.py
	@$(PYTHON) buildsystem/check.py 4 Template-Config.sh $@  $<

$(BUILD_DIR)/param.check: documentation/05_parameterfile.md $(SRC_DIR)/io/parameters.cc buildsystem/check.py
	@$(PYTHON) buildsystem/check.py 5 $(SRC_DIR)/data/allvars.cc $@  $<

.PHONY = all check build clean