-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.example
121 lines (114 loc) · 3.63 KB
/
Makefile.example
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
# Example Makefile for NanoFASE model. Usage:
# `make` Compile the model with maximum debugging and minimal optimisations
# `make release` Compile the model with -O3 optimisations
# `make fast` Compile the model with -Ofast optimisations
# `make clean` Clean compilation files
# What compiler to use? gfortran recommended
FC = gfortran
# Flags for debug (main) build. Caution using -O0 due to this issue: https://stackoverflow.com/questions/44385909/adding-to-an-array-of-characters-in-fortran
DEBUG_FLAGS = -Og -pg -g -Wall
# Flags for release build
RELEASE_FLAGS = -O3 -pg -g
# Fast flags - use with caution. The -march flag might result in the compiled model only working on your computer
FAST_FLAGS = -Ofast -march=native -mtune=native
# Flags common to both builds
COMMON_FLAGS = -ffpe-trap=zero,invalid,overflow,underflow -fcheck=all
# Default to debug flags
FLAGS = ${DEBUG_FLAGS} ${COMMON_FLAGS}
# Executable file name and path
EXEC_FILE = nanofase
BUILD_DIR = build
# NetCDF config, assuming you have the nf-config utility installed
NETCDF = `nf-config --fflags --flibs`
# The following variables generate a unique compilation metadata file to be placed in EXEC_PATH,
# which includes the current Git commit, branch and compilation time
GIT_HASH = `git rev-parse HEAD`
COMPILE_TIME = `date -u +'%Y-%m-%d %H:%M:%S UTC'`
GIT_RELEASE = `git describe --tags`
COMP_META = $(COMPILE_TIME) $(GIT_HASH) $(GIT_RELEASE)
# Should we be compiling with auto parallelisation? Depending on your setup, this might actually slow things down
AUTOPARALLEL = 0
N_THREADS = 4
ifeq ($(AUTOPARALLEL), 1)
COMMON_FLAGS += -floop-parallelize-all -ftree-parallelize-loops=${N_THREADS}
endif
# Objects to generate, in dependency order
OBJECTS_ = ErrorInstance.o \
Result.o \
ErrorHandler.o \
ErrorCriteria.o \
mo_types.o \
mo_netcdf.o \
datetime_module.o \
sparskit.o \
Spoof.o \
mod_strptime.o \
VersionModule.o \
DefaultsModule.o \
GlobalsModule.o \
UtilModule.o \
LoggerModule.o \
DataInputModule.o \
AbstractBiotaModule.o \
BiotaSoilModule.o \
BiotaWaterModule.o \
AbstractReactorModule.o \
ReactorModule.o \
FineSedimentModule.o \
AbstractBedSedimentLayerModule.o \
BedSedimentLayerModule.o \
AbstractBedSedimentModule.o \
BedSedimentModule.o \
DiffuseSourceModule.o \
PointSourceModule.o \
FlowModule.o \
WaterBodyModule.o \
ReachModule.o \
RiverReachModule.o \
EstuaryReachModule.o \
AbstractSoilLayerModule.o \
SoilLayerModule.o \
AbstractSoilProfileModule.o \
SoilProfileModule.o \
CropModule.o \
AbstractGridCellModule.o \
GridCellModule.o \
AbstractEnvironmentModule.o \
EnvironmentModule.o \
NetCDFOutputModule.o \
NetCDFAggregatedOutputModule.o \
DataOutputModule.o \
CheckpointModule.o \
main.o
# Add the build dir to each object name
OBJECTS = $(addprefix build/, $(OBJECTS_))
# Where to look for the source files
VPATH = vendor/feh/src \
vendor/mo_netcdf/src \
vendor/datetime-fortran/src \
vendor/spoof/src \
src \
src/Data \
src/Logger \
src/Biota \
src/Reactor \
src/BedSedimentLayer \
src/BedSediment \
src/Source \
src/WaterBody \
src/Soil \
src/GridCell \
src/Environment
# Write the model version (from git) to file
MODEL_VERSION := $(shell sed -i "s/\".*\"/\"${GIT_RELEASE}\"/g" src/VersionModule.f90)
$(EXEC_FILE): $(OBJECTS)
$(FC) $(FLAGS) -o $(BUILD_DIR)/$@ $^ $(NETCDF)
echo $(COMP_META) > $(BUILD_DIR)/comp_meta
$(BUILD_DIR)/%.o: %.f90
$(FC) -c $< -o $@ -J$(BUILD_DIR) $(FLAGS) $(NETCDF)
release: FLAGS = ${RELEASE_FLAGS} ${COMMON_FLAGS}
release: $(EXEC_FILE)
fast: FLAGS = ${FAST_FLAGS} ${COMMON_FLAGS}
fast: $(EXEC_FILE)
clean:
rm -f $(BUILD_DIR)/*.mod $(BUILD_DIR)/*.o $(BUILD_DIR)/$(EXEC_FILE) $(BUILD_DIR)/comp_meta