-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
266 lines (231 loc) · 9.74 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
cmake_minimum_required (VERSION 3.14.0)
project(advectionHPCtester Fortran )
enable_language (Fortran)
set(CMAKE_Fortran_FLAGS "-g")
#execute_process(COMMAND bash "${PROJECT_SOURCE_DIR}/advection/src_algorithms/prepgpu.sh"
# WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/advection/src_algorithms/" )
option(ENABLE_GPU "Configure for NVIDIA GPU" OFF)
if(ENABLE_GPU)
find_library(LIBNVTOOLSEXT nvToolsExt PATHS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
message(STATUS "Building with GPU support")
enable_language (CUDA)
find_library(LIBNVTOOLSEXT nvToolsExt PATHS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
find_library(LIBPNETCDF libpnetcdf PATHS "/usr/lib/x86_64-linux-gnu")
set(optsgpu -DCUDACODE -DTIMERSCUDA )
else()
message(STATUS "Building without GPU support")
set(optsgpu -DNOCUDACODE )
endif()
option(ENABLE_MPI "Configure for MPI parallelization" ON)
if(ENABLE_MPI)
find_package(MPI REQUIRED COMPONENTS Fortran)
include_directories(${MPI_Fortran_INCLUDE_PATH})
message(STATUS "Building with MPI")
if(ENABLE_GPU)
set(optsmpi -DPUREMPI -DMPI90 )
else()
set(optsmpi -DPUREMPI -DMPI90 -DTIMERSMPI )
endif()
message (STATUS ${MPI_Fortran_INCLUDE_PATH})
include_directories(${MPI_Fortran_INCLUDE_PATH})
else()
message(STATUS "Building without MPI")
if(ENABLE_GPU)
else()
set(optsmpi -DTIMERSCPU )
endif()
endif()
option(ENABLE_PNETCDF "Configure PNETCDF output" OFF)
if(ENABLE_PNETCDF)
message(STATUS "Building with PNETCDF support")
set(optspnet -DPNETCDF -lpnetcdf -I$ENV{PNETCDF_INCLUDE} -L$ENV{PNETCDF_LIB} )
TARGET_LINK_LIBRARIES(advection common)
else()
message(STATUS "Building without PNETCDF support")
set(optspnet )
endif()
option(ENABLE_TESTING "Compute solution norms" ON)
if(ENABLE_TESTING)
message(STATUS "Building with TESTING of the solutions ")
set(optstest -DTESTING )
else()
message(STATUS "Building without TESTING support")
set(optstest "")
endif()
option(ENABLE_FAST "Optimize - ON, Debug - OFF" ON)
if(ENABLE_FAST)
# message(STATUS ${CMAKE_Fortran_COMPILER_ID})
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(optims -Ofast -cpp )
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(optims -O3 -xHost -unroll-aggressive -qopt-prefetch -align commons )
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "NVHPC" OR CMAKE_Fortran_COMPILER_ID MATCHES "PGI")
set(optims -O2 -Mpreprocess )
endif()
else()
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(optims -ffree-form -fimplicit-none -cpp )
set(debugs -g -fbounds-check -fbacktrace -ffpe-trap=invalid,zero,overflow -finit-real=snan )
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(optims -O1 )
set(debugs -g -traceback -check bounds -ftrapuv -init=snan -implicitnone -fpe0 -ftz )
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "NVHPC" OR CMAKE_Fortran_COMPILER_ID MATCHES "PGI")
set(optims -O1 -Mpreprocess )
set(debugs -C traceback -Mbounds -Mchkfpstk -Kieee -Mlist -Mpreprocess )
endif()
endif()
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${debugs}")
set(CMAKE_Fortran_FLAGS_TMP "${optims} ${optsmpi} ${optsgpu} ${optpnet} ${optstest}")
if(ENABLE_GPU)
set(CMAKE_Fortran_FLAGS_TMP "${CMAKE_Fortran_FLAGS_TMP} -cuda")
endif()
foreach(arg ${CMAKE_Fortran_FLAGS_TMP})
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${arg}")
endforeach(arg ${CMAKE_Fortran_FLAGS_TMP})
message(STATUS "Compiling with flags: ${CMAKE_Fortran_FLAGS} ")
set(commondir "${PROJECT_SOURCE_DIR}/include/common")
set(advectiondir "${PROJECT_SOURCE_DIR}/include/advection")
set(common_sources_to_preprocess ${common_sources_to_preprocess}
mpi_parallel.f90
eulag_datafields_modular.f90
diagnostics.f90
diagutils.f90
eulag_moist_datafields.f90
scratch_datafields_modular.f90
geometry_datafields_modular.f90
geometry.f90
filters.f90
)
set(advection_alg_sources_to_preprocess ${advection_alg_sources_to_preprocess}
upwind3d-gpubc.f90
antidiff3d-gauge-gpubc.f90
antidiff3d-standard-gpubc.f90
mpdata3d-rho-gauge-gpubc.f90
velprd_driver.f90
module_velprd.f90
)
set(advection_drv_sources_to_preprocess ${advection_drv_sources_to_preprocess}
advec.f90
advection_CEtimestep_twostep_GPUBC.f90
)
set(advection_tst_sources_to_preprocess ${advection_tst_sources_to_preprocess}
advection_test_setup.f90
)
foreach( file_i ${common_sources_to_preprocess})
execute_process(COMMAND cp ${file_i} ${file_i}.pp.f90
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/common )
endforeach( file_i )
foreach( file_i ${advection_alg_sources_to_preprocess})
execute_process(COMMAND cp ${file_i} ${file_i}.pp.f90
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/advection/src_algorithms )
endforeach( file_i )
foreach( file_i ${advection_drv_sources_to_preprocess})
execute_process(COMMAND cp ${file_i} ${file_i}.pp.f90
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/advection/src_drivers )
endforeach( file_i )
foreach( file_i ${advection_tst_sources_to_preprocess})
execute_process(COMMAND cp ${file_i} ${file_i}.pp.f90
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/advection/src_testdata )
endforeach( file_i )
add_library(commontmp INTERFACE )
add_library(advectiontmp INTERFACE )
set(localdir "${PROJECT_SOURCE_DIR}/common")
foreach( file_i ${common_sources_to_preprocess})
message (STATUS "inside loop:${localdir}/${file_i}")
add_custom_target( ${file_i}.target
COMMAND gcc-13 -E -P ${optsgpu} ${optsmpi} -cpp ${localdir}/${file_i}
| sed -e "s/\&/\&\\n/g" -e "s/\;/\;\\n/g" -e "s/>>>/>>>\\n/g" -e "/^$/d" > "${localdir}/${file_i}.pp.f90"
DEPENDS ${localdir}/${file_i}
COMMENT "Preprocessing ${PROJECT_SOURCE_DIR}/common/${file_i} to ${localdir}/${file_i}.pp.f90"
VERBATIM
)
add_dependencies (commontmp ${file_i}.target)
endforeach( file_i )
set(localdir "${PROJECT_SOURCE_DIR}/advection/src_algorithms")
foreach( file_i ${advection_alg_sources_to_preprocess})
message (STATUS "inside loop:${localdir}/${file_i}")
add_custom_target( ${file_i}.target
COMMAND gcc-13 -E -P ${optsgpu} ${optsmpi} -cpp ${localdir}/${file_i}
| sed -e "s/\&/\&\\n/g" -e "s/\;/\;\\n/g" -e "s/>>>/>>>\\n/g" -e "/^$/d" > "${localdir}/${file_i}.pp.f90"
DEPENDS ${localdir}/${file_i}
COMMENT "Preprocessing ${PROJECT_SOURCE_DIR}/common/${file_i} to ${localdir}/${file_i}.pp.f90"
VERBATIM
)
add_dependencies (advectiontmp ${file_i}.target)
endforeach( file_i )
set(localdir "${PROJECT_SOURCE_DIR}/advection/src_drivers")
foreach( file_i ${advection_drv_sources_to_preprocess})
message (STATUS "inside loop:${localdir}/${file_i}")
add_custom_target( ${file_i}.target
COMMAND gcc-13 -E -P ${optsgpu} ${optsmpi} -cpp ${localdir}/${file_i}
| sed -e "s/\&/\&\\n/g" -e "s/\;/\;\\n/g" -e "s/>>>/>>>\\n/g" -e "/^$/d" > "${localdir}/${file_i}.pp.f90"
DEPENDS ${localdir}/${file_i}
COMMENT "Preprocessing ${PROJECT_SOURCE_DIR}/common/${file_i} to ${localdir}/${file_i}.pp.f90"
VERBATIM
)
add_dependencies (advectiontmp ${file_i}.target)
endforeach( file_i )
set(localdir "${PROJECT_SOURCE_DIR}/advection/src_testdata")
foreach( file_i ${advection_tst_sources_to_preprocess})
message (STATUS "inside loop:${localdir}/${file_i}")
add_custom_target( ${file_i}.target
COMMAND gcc-13 -E -P ${optsmpi} ${optsgpu} -cpp ${localdir}/${file_i}
| sed -e "s/\&/\&\\n/g" -e "s/\;/\;\\n/g" -e "s/>>>/>>>\\n/g" -e "/^$/d" > "${localdir}/${file_i}.pp.f90"
DEPENDS ${localdir}/${file_i}
COMMENT "Preprocessing ${PROJECT_SOURCE_DIR}/common/${file_i} to ${localdir}/${file_i}.pp.f90"
VERBATIM
)
add_dependencies (advectiontmp ${file_i}.target)
endforeach( file_i )
set(advection_sources ${advection_sources}
advection/src_algorithms/mpdata3d-rho-gauge-gpubc.f90.pp.f90
advection/src_algorithms/mpdataoperators.inc
advection/src_algorithms/antidiff3d-gauge-gpubc.f90.pp.f90
advection/src_algorithms/module_velprd.f90.pp.f90
advection/src_algorithms/upwind3d-gpubc.f90.pp.f90
advection/src_algorithms/antidiff3d-standard-gpubc.f90.pp.f90
advection/src_algorithms/velprd_driver.f90.pp.f90
advection/src_drivers/advec.f90.pp.f90
advection/src_drivers/advection_CEtimestep_twostep_GPUBC.f90.pp.f90
advection/src_testdata/advection_test_setup.f90.pp.f90
)
set(common_sources ${common_sources}
common/precisions.f90
common/eulag_datafields_modular.f90.pp.f90
common/argsparser
common/bconditions.f90
common/diagutils.f90.pp.f90
common/diagnostics.f90.pp.f90
common/epsilons.f90
common/eulag_lib_parameters.f90
common/eulag_moist_datafields.f90.pp.f90
common/filters.f90.pp.f90
common/geometry.f90.pp.f90
common/mpi_parallel.f90.pp.f90
common/noise.f90
common/geometry_datafields_modular.f90.pp.f90
common/scratch_datafields_modular.f90.pp.f90
common/argsparser/argsparser.f90)
add_library(common STATIC ${common_sources})
add_library(advection STATIC ${advection_sources})
add_dependencies(common commontmp )
add_dependencies(advection common advectiontmp commontmp )
set_target_properties(common PROPERTIES Fortran_MODULE_DIRECTORY ${commondir})
set_target_properties(advection PROPERTIES Fortran_MODULE_DIRECTORY ${advectiondir})
include_directories(${commondir} ${advectiondir}) # ${solverdir} ${diffusiondir})
link_libraries(${MPI_Fortran_LIBRARIES} common advection)
if(ENABLE_GPU)
add_link_options( -cuda -lnvToolsExt)
set(execname_single advectiontest.gpu)
#set(execname_fullset tladvectiontest.gpu)
else()
set(execname_single advectiontest.cpu)
set(execname_fullset tladvectiontest.cpu)
endif()
add_executable(${execname_single} "advection/src_testapps/advection_dwarf_test_modular.f90")
add_dependencies(${execname_single} common advection )
set_property(TARGET ${execname_single} PROPERTY LINKER_LANGUAGE Fortran)