-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
341 lines (309 loc) · 14.2 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
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
# Minimum required Version
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
# Generates a 'compile_commands.json' file containing the exact compiler calls for all translation units of the project in machine-readable form.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CUDA_ARCHITECTURES 70 80)
# Since GNU Compiler is always available, look first for mpiifort which is usually linked with intel
find_program(CMAKE_Fortran_COMPILER NAMES $ENV{FC} mpiifort mpif90 PATHS ENV PATH NO_DEFAULT_PATH)
find_program(CMAKE_CXX_COMPILER NAMES $ENV{FC} mpicxx PATHS ENV PATH NO_DEFAULT_PATH)
# Project name and languages (C or CXX must be activated to findLAPACK from MKL)
project(TITAN Fortran CXX)
# Defining options
option(DEBUG "Enable debugging" OFF)
option(PREP "Enable Instrumentation" OFF)
find_package(MPI)
# Source files
set(SOURCE_TITAN source/main.F90
source/AtomTypes.F90
source/Lattice.F90
source/create_files.F90
source/check_files.F90
source/sort_all_files.F90
source/mod_greenfunction.F90
source/mod_hamiltonian.F90
source/mod_distributions.F90
source/dtdksub.F90
source/mod_U_matrix.F90
source/mod_initial_expectation.F90
source/mod_expectation.F90
source/mod_System.F90
source/mod_polyBasis.F90
source/mod_BrillouinZone.F90
source/mod_SOC.F90
source/mod_magnet.F90
source/mod_LDOS.F90
source/mod_coupling.F90
source/ElectricField.F90
source/mod_io.F90
source/mod_logging.F90
source/coupling.F90
source/jij_energy.F90
source/mod_TCM.F90
source/createFolder.F90
source/eintshechi.F90
source/eintshe.F90
source/calculate_chi.F90
source/calculate_all.F90
source/calculate_dc_limit.F90
source/mod_fermi_surface.F90
source/mod_Atom_variables.F90
source/mod_rotation_matrices.F90
source/mod_check_stop.F90
source/mod_band_structure.F90
source/mod_kind.F90
source/mod_constants.F90
source/mod_parameters.F90
source/mod_mpi_pars.F90
source/mod_tools.F90
source/mod_input.F90
source/mod_dnsqe.F90
source/mod_chkder.F90
source/mod_progress.F90
source/mod_sumrule.F90
source/EnergyIntegration.F90
source/TightBinding.F90
source/mod_self_consistency.F90
source/mod_susceptibilities.F90
source/mod_alpha.F90
source/mod_beff.F90
source/mod_torques.F90
source/mod_disturbances.F90
source/mod_prefactors.F90
source/adaptiveMesh.F90
source/setLoops.F90
source/TorqueTorqueResponse.F90
source/TorqueSpinResponse.F90
source/mod_superconductivity.F90
source/mod_time_propagator.F90
source/mod_cuda.F90
source/mod_nvtx.F90
source/mod_dft.F90
)
# Setting instrumentation of the code when -DPREP=on
set(INSTRUMENT)
if(PREP)
set(CMAKE_Fortran_COMPILER scorep-mpif90)
set(CMAKE_CXX_COMPILER scorep-nvcc)
set(INSTRUMENT _inst)
message("Instrumentation on")
message("Don't forget to export the line: export SCOREP_WRAPPER_INSTRUMENTER_FLAGS='--thread=omp'")
endif()
# Getting the COMPILER when not given
if(NOT COMPILER)
set(COMPILER ${CMAKE_Fortran_COMPILER_ID})
message("Setting COMPILER=${COMPILER}")
endif()
# Changing $COMPILER variable to lowercase for comparison later
string(TOLOWER ${COMPILER} COMPILER)
# Checking preparation/instrumentalization flag
if(NOT PREP)
set(PREP OFF)
endif()
# Adding debugging suffix when present
if(DEBUG)
set(DEBUGSUFFIX _debug)
message("DEBUG on")
else()
set(DEBUGSUFFIX)
endif()
# Adding compiler suffix:
# INTEL
if(COMPILER MATCHES intel)
set(CMAKE_Fortran_COMPILER mpiifort)
set(COMPILERSUFFIX _intel)
message("Using Intel Compiler")
endif()
# GNU
if(COMPILER MATCHES gfortran OR COMPILER MATCHES gcc OR COMPILER MATCHES gfort OR COMPILER MATCHES gnu)
set(COMPILER gnu)
set(CMAKE_Fortran_COMPILER mpif90)
set(COMPILERSUFFIX _gnu)
message("Using GNU Compiler")
endif()
# NVIDIA
if(COMPILER MATCHES pgi OR COMPILER MATCHES nv OR COMPILER MATCHES nvidia)
set(COMPILER nv)
set(COMPILERSUFFIX _nv)
message("Using NVIDIA Compiler")
set(CMAKE_CXX_COMPILER nvcc)
set(SOURCE_TITAN_CPP ${SOURCE_TITAN_CPP} source/diagonalize_gpu.cpp
)
endif()
# Setting coverage suffix
set(COVSUFFIX)
if(COV AND COMPILER MATCHES gnu)
set(COVSUFFIX _cov)
endif(COV AND COMPILER MATCHES gnu)
# Adding other suffixes when present
if(SUFFIX)
set(SUFFIX _${SUFFIX})
else()
set(SUFFIX)
endif()
######################################## EXECUTABLE ########################################
# Defining executable name
set(TITAN_EXE titan${DEBUGSUFFIX}${COMPILERSUFFIX}${INSTRUMENT}${COVSUFFIX}${SUFFIX}.exe)
# Add an executable to the project using the specified source files
add_executable(${TITAN_EXE} ${SOURCE_TITAN} ${SOURCE_TITAN_CPP})
# Set (main) language
set_property(TARGET ${TITAN_EXE} PROPERTY LINKER_LANGUAGE Fortran)
# Set location for binary
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
######################################## LIBRARIES ########################################
# Add libraries
find_package(LAPACK REQUIRED)
find_package(OpenMP)
target_link_libraries(${TITAN_EXE} MPI::MPI_Fortran LAPACK::LAPACK OpenMP::OpenMP_Fortran)
# Getting GIT version
execute_process(COMMAND git describe --abbrev=8 --dirty --always OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
if(PREP)
#target_link_libraries(${TITAN_EXE} --thread=omp)
target_compile_options(${TITAN_EXE} PRIVATE -D_OLDMPI )
endif(PREP)
#target_compile_options(${TITAN_EXE} PRIVATE -D_OLDMPI )
# Setting coverage flags (only for GNU compiler)
if(COV)
if(COMPILER MATCHES gnu)
message("Coverage on")
target_link_libraries(${TITAN_EXE} -coverage -fprofile-abs-path)
target_compile_options(${TITAN_EXE} PRIVATE -coverage -fprofile-abs-path)
else(COMPILER MATCHES gnu)
message("WARNING: Coverage not activated! Please use -DCOMPILER=gnu")
endif(COMPILER MATCHES gnu)
endif(COV)
# Setting DEBUG definition
if(DEBUG)
target_compile_definitions(${TITAN_EXE} PRIVATE DEBUG)
endif(DEBUG)
######################################## COMPILATION FLAGS ########################################
if(COMPILER MATCHES intel) # INTEL:
if(NOT DEBUG)
target_compile_options(${TITAN_EXE} PRIVATE -no-wrap-margin
-fpp
-DVERSION="${GIT_VERSION}"
-g
-qopt-zmm-usage=high
-align array64byte
-march=core-avx2
-O3
)
else(NOT DEBUG)
target_compile_options(${TITAN_EXE} PRIVATE -C
-CB
-check uninit
-debug all
-warn all
-e18
-ftrapuv
-traceback
-fpp
-fpe0
-DVERSION="${GIT_VERSION}"
-g
-O0
)
endif(NOT DEBUG)
elseif(COMPILER MATCHES gnu) # GFORTRAN:
if(NOT DEBUG)
target_compile_options(${TITAN_EXE} PRIVATE -cpp
-DVERSION="${GIT_VERSION}"
-fallow-argument-mismatch
-ffree-form
-ffree-line-length-0
-g
-O3
-march=native
)
else(NOT DEBUG)
target_compile_options(${TITAN_EXE} PRIVATE -C
-Wall
-Wextra
-Wconversion
-Wline-truncation
-Wcharacter-truncation
-Wsurprising
-Waliasing
-Wunused-parameter
-Wno-maybe-uninitialized
-fwhole-file
-fimplicit-none
-fallow-argument-mismatch
-fbacktrace
-ffree-form
-ffree-line-length-0
-fcheck=all
#-ffpe-trap=zero,overflow,underflow
-finit-real=nan
-ftrapv
-cpp
-DVERSION="${GIT_VERSION}"
-g
-O0
)
endif(NOT DEBUG)
elseif(COMPILER MATCHES nv) # NVIDIA:
enable_language(CUDA)
# set_property(TARGET ${TITAN_EXE} PROPERTY CUDA_ARCHITECTURES 70-real 80-real)
# set_target_properties(${TITAN_EXE} PROPERTIES CUDA_ARCHITECTURES "35;50;72")
# message("CUDA_ARCHITECTURES ${CUDA_ARCHITECTURES}")
# message("CMAKE_CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES}")
target_compile_definitions(${TITAN_EXE} PRIVATE _GPU )
find_package(CUDAToolkit REQUIRED)
find_package(OpenACC REQUIRED)
# set_target_properties(${TITAN_EXE} PROPERTIES CUDA_ARCHITECTURES "70;80")
# set_property(TARGET ${TITAN_EXE} PROPERTY CUDA_ARCHITECTURES 7.0 8.0)
# set(CMAKE_CUDA_ARCH 7 8)
# set(CMAKE_CUDA_CODE 7 8)
# SET(CMAKE_CUDA_ARCHITECTURES "70;80")
target_link_libraries(${TITAN_EXE} CUDA::cusolver CUDA::cudart CUDA::nvToolsExt OpenACC::OpenACC_Fortran)
set_target_properties(${TITAN_EXE} PROPERTIES LINK_FLAGS "-Mcuda -gpu=cc70,cc80")
if(NOT DEBUG)
string(CONCAT FORTRAN_FLAGS "-cpp "
"-DVERSION=\\\"${GIT_VERSION}\\\" "
"-lineinfo "
"-O3 "
# "-lm "
"-fast "
"-gpu=cc70,cc80 "
"-Minfo=accel "
"-Mcuda "
"-g "
)
set_source_files_properties(${SOURCE_TITAN} PROPERTIES COMPILE_FLAGS ${FORTRAN_FLAGS} )
string(CONCAT CXX_FLAGS "-lineinfo "
"--gpu-architecture=sm_80 "
"-g "
)
set_source_files_properties(${SOURCE_TITAN_CPP} PROPERTIES COMPILE_FLAGS ${CXX_FLAGS} )
else(NOT DEBUG)
string(CONCAT FORTRAN_FLAGS "-cpp "
"-DVERSION=\\\"${GIT_VERSION}\\\" "
"-lineinfo "
"-g "
"-Mcuda "
"-Mdclchk " # instructs the compiler to require that all program variables be declared
"-Minform=inform " # instructs the compiler to display all error messages (inform, warn, severe and fatal).
"-Mchkptr " # instructs the compiler to check for pointers that are dereferenced while initialized to NULL (Fortran only).
"-Mchkstk " # instructs the compiler to check the stack for available space in the prologue of a function and before the start of a parallel region.
"-traceback "
"-Ktrap=fp,unf " # fp, unf is equivalent to inv,divz,ovf, unf correspond to the processor’s exception mask bits: invalid operation, divide-by-zero, overflow, and underflow, respectively.
"-gpu=cc70,cc80 "
"-Minfo=accel "
"-acc "
"-O0 "
)
set_source_files_properties(${SOURCE_TITAN} PROPERTIES COMPILE_FLAGS ${FORTRAN_FLAGS})
string(CONCAT CXX_FLAGS "-g "
"--gpu-architecture=sm_80 "
"-G "
)
set_source_files_properties(${SOURCE_TITAN_CPP} PROPERTIES COMPILE_FLAGS ${CXX_FLAGS} )
endif(NOT DEBUG)
endif(COMPILER MATCHES intel)
# unset(DEBUG CACHE)
# unset(DEBUGSUFFIX CACHE)
# unset(PREP CACHE)
# unset(SUFFIX CACHE)
# unset(COMPILER CACHE)