forked from TUM-I5/SWE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
160 lines (133 loc) · 5.78 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
cmake_minimum_required(VERSION 3.13)
project(SWE LANGUAGES CXX)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
option(ENABLE_CUDA "Enable CUDA-accelerated SWE_Blocks" OFF)
option(ENABLE_NETCDF "Enable Output using NetCDF" ON)
option(ENABLE_OPENMP "Enable shared-memory parallelization of intra-block iterations using OpenMP" ON)
option(ENABLE_VECTORIZATION "Enable auto-vectorization of the block iteration on the CPU (only supported solvers), and in Release Mode." OFF)
option(ENABLE_VECTORIZATION_VERBOSE "Enable verbose auto-vectorization reporting." OFF)
option(ENABLE_TEAMPI "Enable use of TeaMPI replication" OFF)
#todo: adapt these to supported solvers
set(SOLVER_STRINGS "rusanov" "augRie" "fwave" "hlle")
#Path to teaMPI lib
set(TEAMPI_PATH "/dss/dsshome1/lxc09/ga84nus2/Bachelorarbeit/teaMPI/lib")
#Path to ULFM
set(ULFM_PATH "/opt")
set(SOLVER "augRie" CACHE STRING "Default Riemann solver")
set_property(CACHE SOLVER PROPERTY STRINGS ${SOLVER_STRINGS})
if (ENABLE_CUDA)
enable_language(CUDA)
endif()
if( NOT SOLVER IN_LIST SOLVER_STRINGS)
message(FATAL_ERROR "solver must be one of ${SOLVER_STRINGS}")
endif()
message(STATUS "Using riemann solver ${SOLVER}")
find_package(NetCDF)
find_package(OpenMP)
find_package(MPI)
find_library(TEAMPI_LIBRARY NAMES tmpi PATHS ${TEAMPI_PATH})
add_executable(swe-single-node)
add_library(swe)
message(STATUS "MPI_LIB ${MPI_CXX_INCLUDE_DIRS}")
if(SOLVER STREQUAL "augRie")
target_compile_definitions(swe PUBLIC SOLVER_AUGRIE)
elseif(SOLVER STREQUAL "hlle")
target_compile_definitions(swe PUBLIC SOLVER_HLLE)
elseif(SOLVER STREQUAL "fwave")
target_compile_definitions(swe PUBLIC SOLVER_FWAVE)
elseif(SOLVER STREQUAL "rusanov")
target_compile_definitions(swe PUBLIC SOLVER_RUSANOV)
endif()
add_subdirectory(src/blocks)
add_subdirectory(src/blocks/rusanov)
add_subdirectory(src/scenarios)
add_subdirectory(src/tools)
add_subdirectory(src/writer)
add_subdirectory(src/reader)
if (ENABLE_CUDA)
target_compile_definitions(swe PUBLIC CUDA)
add_subdirectory(src/blocks/cuda)
endif()
target_sources(swe-single-node
PRIVATE
src/examples/swe_simple.cpp
)
target_link_libraries(swe-single-node PUBLIC swe)
if (MPI_FOUND)
add_executable(swe-mpi)
target_sources(swe-mpi
PRIVATE
src/examples/swe_mpi.cpp
)
if(ENABLE_TEAMPI)
if(NOT TEAMPI_LIBRARY)
message(FATAL_ERROR "teaMPI is enabled bit teaMPI Library was not found")
endif()
message(STATUS "Enabled TeaMPI")
target_compile_definitions(swe-mpi PRIVATE TEAMPI)
target_include_directories(swe-mpi PRIVATE ${TEAMPI_PATH})
target_sources(swe-mpi PRIVATE ${TEAMPI_PATH}/teaMPI.h)
message(STATUS "Linking to ${TEAMPI_LIBRARY}")
target_link_libraries(swe-mpi PUBLIC ${TEAMPI_LIBRARY})
endif()
target_link_libraries(swe-mpi PUBLIC swe)
target_link_libraries(swe-mpi PRIVATE ${MPI_CXX_LIBRARIES})
target_include_directories(swe-mpi PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(swe-mpi PRIVATE ${MPI_CXX_INCLUDE_DIRS})
endif()
if (OpenMP_FOUND AND ENABLE_OPENMP)
target_compile_definitions(swe PUBLIC LOOP_OPENMP)
target_link_libraries(swe PRIVATE OpenMP::OpenMP_CXX)
message(STATUS "OpenMP supported loop parallelization is enabled.")
else()
message(STATUS "OpenMP loop parallelization is disabled.")
endif()
if (OpenMP_FOUND AND ENABLE_VECTORIZATION)
#target_compile_definitions(swe PUBLIC $<$<CONFIG:Release>:VECTORIZE NDEBUG>)
target_compile_definitions(swe PUBLIC VECTORIZE NDEBUG)
target_link_libraries(swe PRIVATE OpenMP::OpenMP_CXX)
target_compile_options(swe PRIVATE
$<$<CXX_COMPILER_ID:Clang>: -march=native -fno-math-errno>
$<$<CXX_COMPILER_ID:AppleClang>: -march=native -fno-math-errno>
$<$<CXX_COMPILER_ID:Intel>: -xHost>
$<$<CXX_COMPILER_ID:GNU>: -march=native -ffast-math -fassociative-math>
)
if(ENABLE_VECTORIZATION_VERBOSE)
target_compile_options(swe PRIVATE
$<$<CXX_COMPILER_ID:AppleClang>: -Rpass-analysis=loop-vectorize>
$<$<CXX_COMPILER_ID:Clang>: -Rpass-analysis=loop-vectorize>
$<$<CXX_COMPILER_ID:Intel>: -qopt-report-phase=vec -qopt-report=2>
$<$<CXX_COMPILER_ID:GNU>: -ftree-vectorizer-verbose=4 -fopt-info-all-vec>
)
endif()
message(STATUS "OpenMP vectorization is enabled (Only for Release Mode).")
elseif(OpenMP_NOTFOUND AND ENABLE_VECTORIZATION)
message(FATAL_ERROR "OpenMP is required to use Vectorization.")
else()
message(STATUS "OpenMP vectorization is disabled.")
endif()
target_include_directories(swe PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(swe-single-node PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
if (ENABLE_NETCDF AND NETCDF_FOUND)
message(STATUS "Enabled NetCDF writer")
message(${NETCDF_INCLUDE_DIRS})
target_compile_definitions(swe PRIVATE WRITENETCDF)
target_include_directories(swe PRIVATE ${NETCDF_INCLUDE_DIRS})
target_link_libraries(swe PRIVATE ${NETCDF_LIBRARIES})
target_include_directories(swe-mpi PRIVATE ${NETCDF_INCLUDE_DIRS})
else ()
message(WARNING "Enabled VTK IO (Slow, fall-back, as NetCDF is unavailable)")
endif()
# Warnings
target_compile_options(swe PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:-Wall -Wextra -Wno-unused-parameter -g -pedantic>
$<$<COMPILE_LANGUAGE:CUDA>:-g>
)
#target_compile_options(swe PUBLIC <$<$ >:-g>) # -Wextra -pedantic)
#C++ Standard
set_property(TARGET swe PROPERTY CXX_STANDARD 11)
set_property(TARGET swe PROPERTY CUDA_STANDARD 11)
set_property(TARGET swe-mpi PROPERTY CXX_STANDARD 11)
set_property(TARGET swe-single-node PROPERTY CXX_STANDARD 11)
# Export compiler commands for use in YouCompleteMe
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)