forked from ecmwf-ifs/ecrad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
261 lines (216 loc) · 8.06 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
# ecRad Makefile - read the README file before editing
#############################
### --- CONFIGURATION --- ###
#############################
# Use the nf-config utility, if available, to set the NETCDF_INCLUDE
# and NETCDF_LIB flags
HAVE_NFCONFIG := $(shell nf-config --version 2> /dev/null)
ifdef HAVE_NFCONFIG
$(info *** Using nf-config to obtain NetCDF flags)
NETCDF_INCLUDE = $(shell nf-config --fflags)
NETCDF_LIB = $(shell nf-config --flibs)
ifeq ($(shell nf-config --has-nc4),yes)
NETCDF4 = 1
endif
else
$(info *** nf-config not found)
endif
# make can be invoked using "make PROFILE=<prof>" in which case your
# local configuration parameters will be obtained from
# Makefile_include.<prof>
ifndef PROFILE
$(info *** No "PROFILE" variable provided, assuming "gfortran")
PROFILE = gfortran
endif
# Include a platform-specific makefile that defines FC, FCFLAGS and
# LIBS
include Makefile_include.$(PROFILE)
# Check for presence of the NETCDF_INCLUDE and NETCDF_LIB flags
ifndef NETCDF_INCLUDE
$(info *** You may need to set NETCDF_INCLUDE manually)
endif
ifndef NETCDF_LIB
$(info *** You may need to set NETCDF_LIB manually)
endif
# Add single-precision flag if SINGLE_PRECISION=1 was given on the
# "make" command line
ifdef SINGLE_PRECISION
CPPFLAGS += -DPARKIND1_SINGLE
endif
# Flags to test optimized code, to be described in a paper. These include
# - Optimized two-stream kernels
# - Optimized expm and other matrix kernels used by SPARTACUS
# - Batching of cloudy layers to improve vectorization in TripleClouds and SPARTACUS
# - Aerosol optimizations
# - declare number of g-points (inner dimension) at compile time, beneficial when NG is small
# - other things
# do make PROFILE=gfortran SINGLE_PRECISION=1 ..
# .. OPTIM_CODE=2 NG_SW=32 NG_LW=32 (for full optimizations when using 32-term ECCKD models)
# .. OPTIM_CODE=1 (refactored solvers but original two-stream and matrix exponential kernels)
ifdef NG_SW
CPPFLAGS += -DNG_SW=$(NG_SW)
endif
ifdef NG_LW
CPPFLAGS += -DNG_LW=$(NG_LW)
endif
ifdef OPTIM_CODE
# CPPFLAGS += -DOPTIM_CODE
CPPFLAGS += -DOPTIM_CODE=$(OPTIM_CODE)
endif
# ------------- NEW FOR ECRAD+RRTMGP--------------
# BLAS library: requisite for RRTMGP-NN
ifeq ($(BLASLIB),blis)
BLAS_INCLUDE = -I$(BLAS_DIR)/include/blis
LIBS_BLAS = $(BLAS_DIR)/lib/libblis.a -lm -lpthread
else ifeq ($(BLASLIB),blis-amd)
BLAS_INCLUDE = -I$(BLAS_DIR)/include
LIBS_BLAS = $(BLAS_DIR)/lib/libblis-mt.a -lm -lpthread
else ifeq ($(BLASLIB),openblas)
LIBS_BLAS = -lopenblas
else ifeq ($(BLASLIB),mkl)
#BLAS_INCLUDE += -I${MKLROOT}/include
BLAS_INCLUDE = -I"${MKLROOT}/include"
#LIBS_BLAS = -L${MKLROOT}/lib/intel64 -lpthread -lm -ldl
LIBS_BLAS = -L${MKLROOT}/lib/intel64 -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl
endif
# Use the General Purpose Timing Library (GPTL)?
ifeq ($(GPTL_TIMING),1)
CPPFLAGS += -DUSE_TIMING
TIMING_INCLUDE = -I$(TIME_DIR)/include
LDFLAGS += -L$(TIME_DIR)/lib -Wl,-rpath=$(TIME_DIR)/lib
LIBS_TIMING = -lgptl # -rdynamic
# Use GPTL with PAPI enabled to estimate computational intensity
else ifeq ($(GPTL_TIMING),2) # only tested to work with gcc, other compilers probably need different flags
# GPTL + PAPI
CPPFLAGS += -DUSE_TIMING -DUSE_PAPI
TIMING_INCLUDE = -I$(TIME_DIR)/include
LDFLAGS += -L$(TIME_DIR)/lib -Wl,-rpath=$(TIME_DIR)/lib
LIBS_TIMING = -lpthread -lgptl -rdynamic -lpapi
# LIBS_TIMING += -lgptl -lpapi
endif
# If PRINT_ENTRAPMENT_DATA=1 was given on the "make" command line
# then the SPARTACUS shortwave solver will write data to fort.101 and
# fort.102
ifdef PRINT_ENTRAPMENT_DATA
CPPFLAGS += -DPRINT_ENTRAPMENT_DATA
endif
# For backwards compatibility we allow the following as well
ifdef PRINT_ENCROACHMENT_DATA
CPPFLAGS += -DPRINT_ENTRAPMENT_DATA
endif
# Allow the capability to write NetCDF4/HDF5 files, provided the code
# is compiled against the NetCDF4 library
ifdef NETCDF4
$(info *** Building with NetCDF4/HDF5 support)
CPPFLAGS += -DNC_NETCDF4
endif
# Consolidate flags
export FC
export FCFLAGS = $(WARNFLAGS) $(BASICFLAGS) $(CPPFLAGS) -I../include \
$(OPTFLAGS) $(DEBUGFLAGS) $(BLAS_INCLUDE) $(NETCDF_INCLUDE) $(TIMING_INCLUDE) $(OMPFLAG)
export LIBS = $(LDFLAGS) -L../lib -lradiation -lutilities \
-lifsrrtm -lifsaux -lrrtmgp -lneural -lstdc++ $(FCLIBS) $(LIBS_BLAS) $(NETCDF_LIB) $(LIBS_TIMING) $(OMPFLAG)
# Do we include Dr Hook from ECMWF's fiat library?
ifdef FIATDIR
# Prepend location of yomhook.mod module file from fiat library, so
# that it is found in preference to the dummy one in ecRad
FCFLAGS := -I$(FIATDIR)/module/fiat $(FCFLAGS)
# Append fiat library (usually shared: libfiat.so)
LIBS += -L$(FIATDIR)/lib -Wl,-rpath,$(FIATDIR)/lib -lfiat
else
# Dummy Dr Hook library
LIBS += -ldrhook
endif
#############################
### --- BUILD TARGETS --- ###
#############################
all: build
help:
@echo "Usage:"
@echo " make PROFILE=<prof>"
@echo "where <prof> is one of gfortran, pgi, intel or cray (see Makefile_include.<prof>)"
@echo "Other possible arguments are:"
@echo " DEBUG=1 Compile with debug settings on and optimizations off"
@echo " SINGLE_PRECISION=1 Compile with single precision"
@echo " OPTIM_CODE=2 Compile with fully optimized version of TripleClouds, SPARTACUS and aerosol optics code
@echo " NG_SW=32 NG_LW=32 Compile with explicit spectral dimension to allow compiler to optimize short loops, in this case for 32-term ECCKD models
@echo " FIATDIR=/my/path Compile with Dr Hook, specifying the directory containing lib/libfiat.so and module/fiat/yomhook.mod"
@echo " test Run test cases in test directory"
@echo " clean Remove all compiled files"
ifndef FIATDIR
build: directories libifsaux libdummydrhook libutilities libifsrrtm librrtmgp \
libradiation driver ifsdriver symlinks
libradiation libutilities: libdummydrhook
else
# Note that if we are using Dr Hook from the fiat library we don't
# want to create mod/yomhook.mod as this can sometimes be found before
# the one in the fiat directory leading to an error at link stage
build: directories libifsaux libutilities libifsrrtm librrtmgp libradiation \
driver ifsdriver symlinks
endif
# git cannot store empty directories so they may need to be created
directories: mod lib
mod:
mkdir -p mod
lib:
mkdir -p lib
deps: clean-deps
cd ifsaux && $(MAKE) deps
cd ifsrrtm && $(MAKE) deps
cd ifs && $(MAKE) deps
clean-deps:
rm -f include/*.intfb.h
libifs: libradiation
cd ifs && $(MAKE)
libifsaux:
cd ifsaux && $(MAKE)
libdummydrhook: libifsaux
cd drhook && $(MAKE) dummy
libutilities: libifsaux
cd utilities && $(MAKE)
libifsrrtm: libifsaux
cd ifsrrtm && $(MAKE)
librrtmgp:
cd rrtmgp-nn && $(MAKE)
libradiation: libifsrrtm libutilities libifsaux
cd radiation && $(MAKE)
driver: libifsaux libifsrrtm librrtmgp libutilities libradiation
cd driver && $(MAKE) driver
ifsdriver: libifsaux libifsrrtm librrtmgp libutilities libradiation libifs
cd driver && $(MAKE) ifs_driver
test_programs: driver
cd driver && $(MAKE) test_programs
symlinks: clean-symlinks
cd practical && ln -s ../bin/ecrad
cd practical && ln -s ../data
test: test_ifs test_i3rc test_ckdmip
test_ifs: driver
cd test/ifs && $(MAKE) test
test_i3rc: driver
cd test/i3rc && $(MAKE) test
test_ckdmip:
cd test/ckdmip && $(MAKE) test
clean: clean-tests clean-toplevel clean-utilities clean-mods clean-symlinks
clean-tests:
cd test/ifs && $(MAKE) clean
cd test/i3rc && $(MAKE) clean
cd test/ckdmip && $(MAKE) clean
clean-toplevel:
cd rrtmgp-nn && $(MAKE) clean
cd radiation && $(MAKE) clean
cd driver && $(MAKE) clean
clean-utilities:
cd ifsaux && $(MAKE) clean
cd utilities && $(MAKE) clean
cd ifsrrtm && $(MAKE) clean
cd drhook && $(MAKE) clean
cd ifs && $(MAKE) clean
clean-mods:
rm -f mod/*.mod mod/*__genmod.f90 ifsaux/*.mod ifsaux/*__genmod.f90
clean-symlinks:
rm -f practical/ecrad practical/data
clean-autosaves:
rm -f *~ .gitignore~ */*~ */*/*~
.PHONY: all build help deps clean-deps libifsaux libdummydrhook libutilities libifsrrtm librrtmgp \
libradiation driver symlinks clean clean-toplevel test test_ifs ifsdriver \
test_i3rc clean-tests clean-utilities clean-mods clean-symlinks