-
Notifications
You must be signed in to change notification settings - Fork 54
/
CMakeLists.txt
251 lines (221 loc) · 9.19 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.5)
### Choose CMAKE Type
if(NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE RELEASE CACHE STRING
"Choose the type of build, options are: None Debug Release."
FORCE)
endif()
### Set compiler flags
if("$ENV{SYST}" STREQUAL "CARTESIUS")
set(CMAKE_Fortran_COMPILER "mpiifort")
set(CMAKE_Fortran_FLAGS "-cpp -r8 -ftz" CACHE STRING "")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3" CACHE STRING "")
set(CMAKE_Fortran_FLAGS_DEBUG "-traceback -fpe1 -O0 -g -check all" CACHE STRING "")
elseif("$ENV{SYST}" STREQUAL "localpc_ifort")
set(CMAKE_Fortran_COMPILER "mpif90")
set(CMAKE_Fortran_FLAGS "-cpp -r8 -ftz" CACHE STRING "")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3" CACHE STRING "")
set(CMAKE_Fortran_FLAGS_DEBUG "-traceback -fpe1 -O0 -g -check all" CACHE STRING "")
elseif("$ENV{SYST}" STREQUAL "HYDRA")
set(CMAKE_Fortran_COMPILER "mpiifort")
set(CMAKE_Fortran_FLAGS "-cpp -r8 -ftz" CACHE STRING "")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3" CACHE STRING "")
set(CMAKE_Fortran_FLAGS_DEBUG "-traceback -fpe1 -O0 -g -check all" CACHE STRING "")
elseif("$ENV{SYST}" STREQUAL "FEDORA")
set(CMAKE_Fortran_COMPILER "mpif90")
set(CMAKE_Fortran_FLAGS "-cpp -fdefault-real-8 -fdefault-double-8 -march=native -malign-double -ffree-line-length-none -I /usr/lib64/gfortran/modules/mpich/ -std=gnu -Werror=implicit-interface" CACHE STRING "")
set (CMAKE_Fortran_FLAGS_RELEASE "-funroll-all-loops -fno-f2c -O3" CACHE STRING "")
set (CMAKE_Fortran_FLAGS_DEBUG "-finit-real=nan -fbounds-check -fbacktrace -fno-f2c -O0 -g -ffpe-trap=invalid,zero,overflow" CACHE STRING "")
set (CMAKE_Fortran_FLAGS_DEV "-fbounds-check -fbacktrace -fno-f2c -O3 -g -ffpe-trap=invalid,zero,overflow" CACHE STRING "")
elseif("$ENV{SYST}" STREQUAL "lisa-intel")
set(CMAKE_Fortran_COMPILER "mpiifort")
set(CMAKE_Fortran_FLAGS "-cpp -r8 -ftz" CACHE STRING "")
set(CMAKE_Fortran_FLAGS_RELEASE "-g -traceback -O3 -xHost" CACHE STRING "")
set(CMAKE_Fortran_FLAGS_DEBUG "-traceback -fpe1 -O0 -g -check all" CACHE STRING "")
elseif("$ENV{SYST}" STREQUAL "gnu-fast")
set(CMAKE_Fortran_COMPILER "mpif90")
set(CMAKE_Fortran_FLAGS "-cpp -W -Wall -fdefault-real-8 -fdefault-double-8 -march=native -ffree-line-length-none -std=gnu -Werror=implicit-interface" CACHE STRING "")
set (CMAKE_Fortran_FLAGS_RELEASE "-funroll-all-loops -fno-f2c -Ofast -g -fbacktrace" CACHE STRING "")
set (CMAKE_Fortran_FLAGS_DEBUG "-finit-real=nan -fbounds-check -fbacktrace -fno-f2c -O0 -g -ffpe-trap=invalid,zero,overflow" CACHE STRING "")
elseif("$ENV{SYST}" STREQUAL "FX-Fujitsu")
set(CMAKE_Fortran_COMPILER "mpifrtpx")
set(CMAKE_Fortran_FLAGS "-Cpp -CcdRR8 -g -Koptmsg=2" CACHE STRING "")
set (CMAKE_Fortran_FLAGS_RELEASE "-Kfast -x 128" CACHE STRING "")
set (CMAKE_Fortran_FLAGS_DEBUG "-Haefosux -O0" CACHE STRING "")
# Fujitsu fortran compiler
# -CcdRR8 default real is 64 bit, like gnu -fdefault-real-8
# -Ad (-CcR4R8) is like gnu -freal-4-real-8 ALL reals are 64 bit
# -Kfast optimization and SVE vectorization
# -Haefosux checking: s-subscript range, u-undefinied values
# a-argument mismatches, e-shape conformance
# f-simultaneousOPEN and I/O recursive calls
# o-overlapping dummy arguments and extend undefined
# x-module, submodule, common, and pointer undefined
# -x <n> inlines functions if the size increases by at most n bytes
# 128 gives good speedup
# -Koptmsg=2 prints a lot of optimization information
#
elseif("$ENV{SYST}" STREQUAL "NO_OVERRIDES")
# don't set any compilation flags here, allows setting them outside CMake
else()
set(CMAKE_Fortran_COMPILER "mpif90")
set(CMAKE_Fortran_FLAGS "-cpp -fimplicit-none -fdefault-real-8 -fdefault-double-8 -march=native -ffree-line-length-none -std=gnu -Werror=implicit-interface" CACHE STRING "")
set (CMAKE_Fortran_FLAGS_RELEASE "-funroll-all-loops -fno-f2c -O3" CACHE STRING "")
set (CMAKE_Fortran_FLAGS_DEBUG "-finit-real=nan -fbounds-check -fbacktrace -fno-f2c -O0 -g -ffpe-trap=invalid,zero,overflow" CACHE STRING "")
endif()
# On compiler options
# June 2020: added -std=legacy to gfortran for compatibility with gfortran 10, which introduced stricter type checking
# the old FFT code from Netlib/FFTPACK does not compile with gfortran 10 without this flag.
# March 2021: fixed interfaces and removed -std=legacy
# For GCC based compilers:
# * -march=native : compile for the current CPU, allows use of modern AVX etc.
# * -malign-double : align stuff on 64-bit boundaries. Only for x86, e.g. not available on M1 macs.
# * -finit-real-nan : makes the code slower, moved them to debug
## Project parameters
PROJECT(DALES Fortran)
set(VERSION_MAJOR "4")
set(VERSION_MINOR "4")
set(VERSION_PATCH "2")
# use nf-config to find paths to netcdf. Broken on Fedora due to module path missing.
execute_process(COMMAND nf-config --prefix OUTPUT_VARIABLE NFCONFIG_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND nf-config --includedir OUTPUT_VARIABLE NFCONFIG_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
# execute_process(COMMAND nf-config --flibs OUTPUT_VARIABLE NFCONFIG_FORTRAN_LIB OUTPUT_STRIP_TRAILING_WHITESPACE)
# not used at the moment - not just a path but several compiler flags
### If necessary, resort to BASH-methods to find netcdf-directory
#execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/findnetcdf OUTPUT_VARIABLE ADDMODULEPATH)
### Find NetCDF files
FIND_PATH(NETCDF_INCLUDE_DIR netcdf.mod NETCDF.mod
PATHS
${NFCONFIG_INCLUDE_DIR}
$ENV{SARA_NETCDF_INCLUDE}
$ENV{SURFSARA_NETCDF_INCLUDE}
$ENV{NETCDF_INCLUDE}
${ADDMODULEPATH}/include
/usr/include
$ENV{HOME}/include
/usr/lib64/gfortran/modules
DOC "NetCDF include directory (must contain netcdf.mod)"
)
FIND_LIBRARY(NETCDF_C_LIB netcdf
PATHS
$ENV{SARA_NETCDF_LIB}
$ENV{SURFSARA_NETCDF_LIB}
$ENV{NETCDF_LIB}
${ADDMODULEPATH}/lib
${ADDMODULEPATH}/lib64
/usr/lib
/usr/lib64
$ENV{HOME}/lib
$ENV{HOME}/lib64
DOC "NetCDF C library"
)
FIND_LIBRARY(NETCDF_FORTRAN_LIB netcdff
PATHS
${NFCONFIG_PREFIX}/lib
$ENV{SARA_NETCDF_LIB}
$ENV{SURFSARA_NETCDF_LIB}
$ENV{NETCDF_LIB}
${ADDMODULEPATH}/lib
${ADDMODULEPATH}/lib64
/usr/lib
/usr/lib64
$ENV{HOME}/lib
$ENV{HOME}/lib64
DOC "NetCDF Fortran library"
)
# libHYPRE.a for static library
FIND_LIBRARY(HYPRE_LIB HYPRE_core HYPRE
PATHS
$ENV{HYPRE_LIB}
${ADDMODULEPATH}/lib
${ADDMODULEPATH}/lib64
/usr/lib
/usr/lib64
$ENV{HOME}/lib
$ENV{HOME}/lib64
DOC "Iterative solver library"
)
FIND_PATH(FFTW_INCLUDE_DIR fftw3.f03
PATHS
$ENV{FFTW_INCLUDE_DIR}
/usr/include
DOC "FFTW include files (fftw3.f03)"
)
#libfftw3.a for static library
FIND_LIBRARY(FFTW_LIB fftw3
PATHS
$ENV{FFTW_LIB}
/usr/lib
/usr/lib64
DOC "FFTW static library"
)
FIND_LIBRARY(FFTWF_LIB fftw3f
PATHS
$ENV{FFTW_LIB}
/usr/lib
/usr/lib64
DOC "FFTW single precision library"
)
if(NETCDF_INCLUDE_DIR)
include_directories(${NETCDF_INCLUDE_DIR})
else(NETCDF_INCLUDE_DIR)
MESSAGE(STATUS "WARNING: No NETCDF bindings are found.")
endif(NETCDF_INCLUDE_DIR)
if(FFTW_INCLUDE_DIR)
include_directories(${FFTW_INCLUDE_DIR})
else(FFTW_INCLUDE_DIR)
MESSAGE(STATUS "WARNING: No FFTW3 bindings are found (fftw3.f03).")
endif(FFTW_INCLUDE_DIR)
if(NETCDF_C_LIB)
set(NETCDF_LIBS ${NETCDF_C_LIB})
else(NETCDF_C_LIB)
MESSAGE(STATUS "WARNING: No NETCDF C bindings are found - may be OK.")
endif(NETCDF_C_LIB)
if(NETCDF_FORTRAN_LIB)
set(NETCDF_LIBS ${NETCDF_LIBS} ${NETCDF_FORTRAN_LIB})
else(NETCDF_FORTRAN_LIB)
MESSAGE(STATUS "WARNING: No Fortran NETCDF bindings are found.")
endif(NETCDF_FORTRAN_LIB)
### Iterative solver (HYPRE)
OPTION(USE_HYPRE "Also build iterative solver (optional, needs HYPRE)" OFF)
### FFTW based poisson solver (FFTW)
OPTION(USE_FFTW "Also build FFTW based poisson solver (optional, needs FFTW3)" OFF)
### Documentation
INCLUDE(FindDoxygen)
if(DOXYGEN)
ADD_SUBDIRECTORY(utils/doc)
else()
MESSAGE(STATUS "WARNING: Doxygen not found - Reference manual will not be created")
endif()
### Set case
if(NOT CASE)
set (CASE standard CACHE STRING
"Set the case."
FORCE)
endif()
### Add case specific file
FILE(GLOB usrfile "${CMAKE_CURRENT_SOURCE_DIR}/cases/${CASE}/moduser.f90")
if(usrfile STREQUAL "")
set(usrfile "${CMAKE_CURRENT_SOURCE_DIR}/cases/standard/moduser.f90")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${usrfile} ${CMAKE_CURRENT_SOURCE_DIR}/src/moduser.f90)
MESSAGE(STATUS "Case " ${CASE} " uses " ${usrfile})
#optional compilation flags
set(opt_flags "")
if(USE_HYPRE)
# Build the iterative Poisson solver
list(APPEND OPTIONAL_LIBS ${HYPRE_LIB})
set(opt_flags "${opt_flags} -DUSE_HYPRE")
endif(USE_HYPRE)
if(USE_FFTW)
# Build the FFTW-based Poisson solver
list(APPEND OPTIONAL_LIBS ${FFTW_LIB} ${FFTWF_LIB})
set(opt_flags "${opt_flags} -DUSE_FFTW")
endif(USE_FFTW)
### Precision
set(POIS_PRECISION 64 CACHE STRING "Precision for poisson solver (default 64 bit) [32,64]")
set(FIELD_PRECISION 64 CACHE STRING "Precision for fields in modfields.f90 (default 64 bit) [32, 64]")
# Append all flags
set(opt_flags "${opt_flags} -DPOIS_PRECISION=${POIS_PRECISION} -DFIELD_PRECISION=${FIELD_PRECISION}")
string(APPEND CMAKE_Fortran_FLAGS "${opt_flags}")
ADD_SUBDIRECTORY(src)