-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
263 lines (240 loc) · 9.08 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
252
253
254
255
256
257
258
259
260
261
262
263
cmake_minimum_required(VERSION 3.16)
if (DEFINED ENV{HDF5_ROOT})
message(NOTICE "HDF5 found")
set(HDF5_ROOT $ENV{HDF5_ROOT})
endif()
if (DEFINED ENV{I_MPI_ROOT})
message(NOTICE "Intel MPI found")
set(I_MPI_ROOT $ENV{I_MPI_ROOT})
endif()
option(hdf5 "Use HDF5" ON)
option(intel "Use Intel compiler" ON)
if (${hdf5} STREQUAL "ON")
set(CMAKE_Fortran_COMPILER "${HDF5_ROOT}/bin/h5pfc")
else()
if (${intel} STREQUAL "ON")
set(CMAKE_Fortran_COMPILER "${I_MPI_ROOT}/bin/mpif90")
endif()
endif()
message(NOTICE "Compiler: ${CMAKE_Fortran_COMPILER}")
project(tristan-v2 VERSION 2.9
DESCRIPTION "Relativistic cartesian particle-in-cell code"
LANGUAGES Fortran)
find_package(MPI REQUIRED COMPONENTS Fortran)
if (${hdf5} STREQUAL "ON")
find_package(HDF5 REQUIRED COMPONENTS Fortran)
endif()
set(DEBUG "OFF" CACHE BOOL "Debug mode")
add_compile_definitions(STR_MAX=280)
add_compile_definitions(TINYXYZ=1e-6)
add_compile_definitions(TINYREAL=1e-3)
add_compile_definitions(TINYFLD=1e-8)
add_compile_definitions(TINYWEI=1e-6)
add_compile_definitions(M_PI=3.141592653589793)
add_compile_definitions(VEC_LEN=16)
# -- optimizations --
set(vectorization "None" CACHE STRING "Vectorization level (None, avx2, avx512)")
if (${DEBUG} STREQUAL "ON") # debug
set(CMAKE_BUILD_TYPE CACHE STRING "Debug")
add_compile_definitions(DEBUG)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g -O0")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wall -Wextra -Wconversion -pedantic -Wno-compare-reals -Wno-unused-dummy-argument")
if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # gnu
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fcheck=all -fimplicit-none -fbacktrace -ffpe-trap=invalid,zero,overflow,underflow,denormal")
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -traceback -fpe0 -check all -check noarg_temp_created")
else()
message(FATAL_ERROR "Compiler not supported")
endif()
else() # nodebug
set(CMAKE_BUILD_TYPE CACHE STRING "Release")
add_compile_definitions(NDEBUG)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Ofast -O3 -DSoA")
if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fwhole-program -mavx2 -fopt-info-vec -fopt-info-vec-missed -ftree-vectorizer-verbose=5 -ffree-line-length-512")
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ipo -qopenmp-simd -qopt-report=3 -qopt-streaming-stores auto")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -diag-disable 10397 -diag-disable 10346 -diag-disable 8100 -diag-disable 6178")
else()
message(FATAL_ERROR "Compiler not supported")
endif()
# vectorization
if (${vectorization} STREQUAL "avx2")
if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -mavx2")
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -xCORE-AVX2")
endif()
elseif (${vectorization} STREQUAL "avx512")
if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -mavx512f")
elseif (CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -xCORE-AVX512 -qopt-zmm-usage:high")
endif()
elseif (${vectorization} STREQUAL "None")
# do nothing
else()
message(FATAL_ERROR "Vectorization level not supported")
endif()
endif()
# -- options --
# architecture
option(mpi08 "Use MPI08" ON)
option(mpinonblock "Use non-blocking MPI" OFF)
option(lowmem "Use low memory mode" OFF)
option(ifport "Use ifport" OFF)
# optimizations
option(dwn "Use particle downsampling" OFF)
option(slb "Use static load balancing" OFF)
option(alb "Use adaptive load balancing" OFF)
option(payload "Use particle payloads" OFF)
# output
option(serialoutput "Output in serial" OFF)
option(usroutput "Enable custom user data outputting" OFF)
# physics
option(extfields "Use external fields" OFF)
option(absorb "Use absorbing boundary conditions" OFF)
option(vay "Use Vay current deposition" OFF)
option(blinne "Use Blinne field solvers" OFF)
option(emit "Enable photon emission" OFF)
set(precision "single" CACHE STRING "Precision of the code (single or double)")
set(nghosts "2" CACHE STRING "Number of ghost cells (default 2)")
set(radiation "OFF" CACHE STRING "Radiation drag (or OFF)")
# -- additional configs for each option --
if (${mpi08} STREQUAL "ON")
add_compile_definitions(MPI08)
endif()
if (${mpinonblock} STREQUAL "ON")
add_compile_definitions(MPINONBLOCK)
endif()
if (${lowmem} STREQUAL "ON")
add_compile_definitions(LOWMEM)
endif()
if (${ifport} STREQUAL "ON")
add_compile_definitions(IFPORT)
endif()
if (${dwn} STREQUAL "ON")
add_compile_definitions(DOWNSAMPLING)
endif()
if (${slb} STREQUAL "ON")
add_compile_definitions(SLB)
endif()
if (${alb} STREQUAL "ON")
add_compile_definitions(ALB)
endif()
if (${payload} STREQUAL "ON")
add_compile_definitions(PRTLPAYLOADS)
endif()
if (${serialoutput} STREQUAL "ON")
add_compile_definitions(SERIALOUTPUT)
endif()
if (${usroutput} STREQUAL "ON")
add_compile_definitions(USROUTPUT)
endif()
if (${extfields} STREQUAL "ON")
add_compile_definitions(EXTERNALFIELDS)
endif()
if (${absorb} STREQUAL "ON")
add_compile_definitions(ABSORB)
endif()
if (${vay} STREQUAL "ON")
add_compile_definitions(VAY)
endif()
if (${blinne} STREQUAL "ON")
add_compile_definitions(BLINNE)
endif()
if (${emit} STREQUAL "ON")
add_compile_definitions(EMIT)
endif()
if (${precision} STREQUAL "single")
add_compile_definitions(default_h5_real=H5T_NATIVE_REAL)
else()
add_compile_definitions(DPREC)
add_compile_definitions(default_h5_real=H5T_NATIVE_DOUBLE)
if (${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fdefault-real-8")
elseif (${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -r8")
endif()
endif()
add_compile_definitions(NGHOST=${nghosts})
if (${radiation} MATCHES "sync")
add_compile_definitions(SYNCHROTRON)
add_compile_definitions(RADIATION)
endif()
if (${radiation} MATCHES "ic")
add_compile_definitions(INVERSECOMPTON)
add_compile_definitions(RADIATION)
endif()
# select the dimension
set (dim "None" CACHE STRING "dimension")
if (dim STREQUAL "1")
add_compile_definitions(oneD)
elseif (dim STREQUAL "2")
add_compile_definitions(twoD)
elseif (dim STREQUAL "3")
add_compile_definitions(threeD)
else()
message(FATAL_ERROR "Please specify dimension (1,2,3) with `-D dim=<DIM>`")
endif()
# if userfile not defined
# list all files in user directory
set(user "" CACHE STRING "userfile")
set(unit "" CACHE STRING "unitfile")
if(user STREQUAL "" AND unit STREQUAL "")
file(GLOB userfiles ${CMAKE_CURRENT_SOURCE_DIR}/../user/*.F90)
file(GLOB unitfiles ${CMAKE_CURRENT_SOURCE_DIR}/../unit/*.F90)
message(STATUS "Please specify userfile or unitfile with `-D user=<USERFILE>` or `-D unit=<UNITFILE>`:")
message(STATUS "userfiles:")
foreach(userfile ${userfiles})
get_filename_component(userfile ${userfile} NAME)
string(REGEX REPLACE ".F90$" "" userfile ${userfile})
message(STATUS ": ${userfile}")
endforeach()
message(STATUS "unitfiles:")
foreach(unitfile ${unitfiles})
get_filename_component(unitfile ${unitfile} NAME)
string(REGEX REPLACE ".F90$" "" unitfile ${unitfile})
message(STATUS ": ${unitfile}")
endforeach()
message(FATAL_ERROR "userfile or unitfile not defined")
endif()
if (NOT user STREQUAL "")
set(userfile "${CMAKE_CURRENT_SOURCE_DIR}/user/${user}.F90")
else()
set(userfile "${CMAKE_CURRENT_SOURCE_DIR}/unit/${unit}.F90")
endif()
add_subdirectory(src)
# -- report --
get_directory_property(Defs COMPILE_DEFINITIONS)
string(REPLACE ";" " " Defs "${Defs}")
message(NOTICE "==========================================================")
message(NOTICE "Tristan v2 has been configured with the following options:")
message(NOTICE "")
message(NOTICE "SETUP:")
message(NOTICE " Userfile: ${userfile}")
message(NOTICE " Dim: ${dim}D")
message(NOTICE " ghost zones: ${nghosts}")
message(NOTICE " Load balancing: SLB=${slb} ALB=${alb}")
message(NOTICE " Particle downsampling: ${dwn}")
message(NOTICE " Particle pusher: Vay=${vay}")
message(NOTICE " Particle payloads: ${payload}")
message(NOTICE "")
message(NOTICE "PHYSICS:")
message(NOTICE " External fields: ${extfields}")
message(NOTICE " Absorbing boundaries: ${absorb}")
message(NOTICE " Cooling: ${radiation}")
message(NOTICE " Photon emission: ${emit}")
message(NOTICE "")
message(NOTICE "TECHNICAL:")
message(NOTICE " Float precision: ${precision}")
message(NOTICE " Debug mode: ${DEBUG}")
message(NOTICE " Low memory mode: ${lowmem}")
message(NOTICE " Output: HDF5=${hdf5} (serial=${serialoutput})")
message(NOTICE " User output: ${usroutput}")
message(NOTICE " MPI version: MPI08=${mpi08}")
message(NOTICE " IFPORT mkdir: ${ifport}")
message(NOTICE "..........................................................")
message(NOTICE "Compilation command: ${CMAKE_Fortran_COMPILER} ${CMAKE_Fortran_FLAGS}")
message(NOTICE "Definitions: ${Defs}")
message(NOTICE "==========================================================")