forked from Slaedr/FVENS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
310 lines (280 loc) · 11.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
cmake_minimum_required(VERSION 3.0)
# EIGEN3_ROOT needs to be set to the path of the Eigen top-level directory.
# PETSC_DIR and PETSC_ARCH need to be set.
# BLASTED_DIR may be set to the root of the BLASTed linear algebra library.
# BLASTED_BIN_DIR may be set to the root of the BLASTed build directory.
# Pass -DBOOST_ROOT=<path-to-Boost-root-directory> if Boost is not present in a default directory
# Pass -DWITH_BLASTED=1 to compile with BLASTed preconditioning support
# Pass -DNOOMP=1 to compile without OpenMP
# Pass -DSSE=1 to compile with SSE 4.2 instructions; ignored when compiling for KNC.
# Pass -DAVX=1 to compile with AVX instructions.
# Pass -DAVX_2=1 to compile with AVX 2.0 instructions.
# PASS -DZEN=1 to compiler for AMD Zen with AVX 2.0.
# Pass -DSKYLAKE=1 to compile with AVX-512 instructions for Xeon Skylake CPUs.
# Pass -DKNL=1 to compile for Xeon Phi Knights Landing.
# Pass -DMICKNC=1 to compile for Xeon Phi Knights Corner.
# Pass -DPROFILE=1 for profiling.
# Pass -DSLURM=1 for running the automated tests on a system managed by SLURM
# Pass -DNOTAGS=1 to NOT generate tags for navigating code, otherwise, exuberent-ctags is needed.
project (fvens)
# detect C++ compiler
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CXX_COMPILER_GNUCLANG TRUE)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
set(CXX_COMPILER_GNU TRUE)
message(STATUS "GNU C++ compiler detected")
else()
set(CXX_COMPILER_CLANG TRUE)
message(STATUS "Clang C++ compiler detected")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
set(CXX_COMPILER_INTEL TRUE)
message(STATUS "Intel C++ compiler detected")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Cray")
set(CXX_COMPILER_CRAY TRUE)
message(STATUS "Cray C++ compiler detected")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "PGI")
set(CXX_COMPILER_PGI TRUE)
message(STATUS "PGI C++ compiler detected")
else()
message(SEND_ERROR "Could not identify compiler!")
endif()
# Basic options
if(CXX_COMPILER_GNUCLANG OR CXX_COMPILER_INTEL)
set (CMAKE_CXX_FLAGS "-std=c++14 -Wall -Werror")
set (CMAKE_CXX_FLAGS_DEBUG "-g")
set (CMAKE_CXX_FLAGS_RELEASE "-O3")
elseif(CXX_COMPILER_PGI)
set (CMAKE_CXX_FLAGS "-std=c++14")
set (CMAKE_CXX_FLAGS_DEBUG "-g")
set (CMAKE_CXX_FLAGS_RELEASE "-O2")
elseif(CXX_COMPILER_CRAY)
set (CMAKE_CXX_FLAGS "-h std=c++14 -h error_on_warning")
set (CMAKE_CXX_FLAGS_DEBUG "-g -O1")
set (CMAKE_CXX_FLAGS_RELEASE "-O2")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -UDEBUG -DNDEBUG")
# Disable C - this should cause C compilation to fail
set(CMAKE_C_FLAGS "-std=c++14")
# to compile with OpenMP
if(NOOMP)
if(CXX_COMPILER_GNUCLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas")
endif()
if(CXX_COMPILER_PGI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nomp")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nomp")
endif()
if(CXX_COMPILER_CRAY)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -hnoomp")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -hnoomp")
endif()
message(STATUS "Compiling without OpenMP")
else()
if(CXX_COMPILER_GNUCLANG)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
message(STATUS "Compiling with OpenMP for GNU")
elseif(CXX_COMPILER_INTEL)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -qopenmp")
message(STATUS "Compiling with OpenMP for Intel")
elseif(CXX_COMPILER_CRAY)
message(STATUS "Compiling with OpenMP for Cray")
elseif(CXX_COMPILER_PGI)
message(STATUS "Compiling with OpenMP for PGI")
else()
message(SEND_ERROR "Don't know OpenMP flag for this compiler!")
endif()
endif()
# set verbosity options
if(CXX_COMPILER_GNU)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopt-info-inline-vec-optimized-missed=optimizations.info")
elseif(CXX_COMPILER_CLANG)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Rpass=inline,vectorize")
elseif(CXX_COMPILER_INTEL)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -qopt-report=2")
elseif(CXX_COMPILER_CRAY)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -hlist=a -hreport=fisv")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1")
endif()
# Architecture to target
if(MICKNC)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmic")
message(STATUS "Compiling for KNC")
if(NOT CXX_COMPILER_INTEL)
message(SEND_ERROR "Need to use Intel compiler for Xeon Phi!")
endif()
else()
# Select hardware-specific optimizations
if(AVX)
if(CXX_COMPILER_GNUCLANG OR CXX_COMPILER_INTEL)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mavx")
elseif(CXX_COMPILER_PGI)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -tp=sandybridge")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
message(STATUS "Compiling with AVX")
endif()
elseif(AVX_2)
if(CXX_COMPILER_INTEL)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -xcore-avx2")
elseif(CXX_COMPILER_GNUCLANG)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mavx2")
elseif(CXX_COMPILER_PGI)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -tp=haswell")
elseif(CXX_COMPILER_CRAY)
message(STATUS "Architecture options for Cray are to be set by the compiler wrapper.")
add_definitions(-DEIGEN_VECTORIZE_AVX2 -DEIGEN_VECTORIZE_FMA)
else()
message(SEND_ERROR "Don't know/require option for this compiler!")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
message(STATUS "Compiling with AVX-2")
endif()
elseif(ZEN)
if(CXX_COMPILER_INTEL)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -xcore-avx2")
elseif(CXX_COMPILER_GNUCLANG)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=znver1")
elseif(CXX_COMPILER_PGI)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -tp=zen")
add_definitions(-DEIGEN_VECTORIZE_AVX2 -DEIGEN_VECTORIZE_FMA)
elseif(CXX_COMPILER_CRAY)
message(STATUS "Architecture options for Cray are to be set by the compiler wrapper.")
# But we need to tell Eigen something
add_definitions(-DEIGEN_VECTORIZE_AVX2 -DEIGEN_VECTORIZE_FMA)
else()
message(SEND_ERROR "Don't know option for this compiler!")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
message(STATUS "Compiling with AVX 2.0 for AMD Zen")
endif()
elseif(SKYLAKE)
if(CXX_COMPILER_INTEL)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -xcore-avx512")
elseif(CXX_COMPILER_GNUCLANG)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=skylake-avx512")
elseif(CXX_COMPILER_PGI)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -tp=skylake")
add_definitions(-DEIGEN_VECTORIZE_AVX512 -DEIGEN_VECTORIZE_FMA)
elseif(CXX_COMPILER_CRAY)
message(STATUS "Architecture options for Cray are to be set by the compiler wrapper.")
add_definitions(-DEIGEN_VECTORIZE_AVX512 -DEIGEN_VECTORIZE_FMA)
else()
message(SEND_ERROR "Don't know/require option for this compiler!")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
message(STATUS "Compiling with AVX-512 for Skylake")
endif()
elseif(KNL)
if(CXX_COMPILER_INTEL)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -xmic-avx512")
elseif(CXX_COMPILER_GNUCLANG)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=knl")
elseif(CXX_COMPILER_PGI)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -tp=knl")
add_definitions(-DEIGEN_VECTORIZE_AVX512 -DEIGEN_VECTORIZE_FMA)
elseif(CXX_COMPILER_CRAY)
message(STATUS "Architecture options for Cray are to be set by the compiler wrapper.")
add_definitions(-DEIGEN_VECTORIZE_AVX512 -DEIGEN_VECTORIZE_FMA)
else()
message(SEND_ERROR "Don't know/require option for this compiler!")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
message(STATUS "Compiling with AVX-512 for KNL")
endif()
else()
if(CXX_COMPILER_GNUCLANG OR CXX_COMPILER_INTEL)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -msse4.2")
elseif(CXX_COMPILER_PGI)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -tp=x64,nehalem")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
message(STATUS "Compiling with SSE4")
endif()
endif()
endif()
# profiling
if(PROFILE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg -g")
endif()
# Boost
find_package(Boost 1.60 REQUIRED COMPONENTS program_options)
include_directories(${Boost_INCLUDE_DIRS})
message(STATUS "Found Boost libraries at ${Boost_LIBRARIES}")
# Eigen
find_path(EIGEN3_INCLUDE_DIR signature_of_eigen3_matrix_library
PATHS ENV EIGEN3_ROOT DOC "Eigen3 include directory")
if(${EIGEN3_INCLUDE_DIR} STREQUAL "EIGEN3_INCLUDE_DIR-NOTFOUND")
message(SEND_ERROR "Eigen3 not found!")
endif()
include_directories(${EIGEN3_INCLUDE_DIR})
message(STATUS "Found Eigen 3 at ${EIGEN3_INCLUDE_DIR}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEIGEN_DONT_PARALLELIZE")
# BLASTed
if(WITH_BLASTED)
find_path(BLASTED_INCLUDE_DIR blasted_petsc.h PATHS ENV BLASTED_DIR PATH_SUFFIXES include
DOC "Include directory of BLASTed library")
if(${BLASTED_INCLUDE_DIR} STREQUAL "BLASTED_INCLUDE_DIR-NOTFOUND")
message(SEND_ERROR "BLASTed requested, but header not found!")
endif()
include_directories(${BLASTED_INCLUDE_DIR})
find_library(BLASTED_LIB blasted_petsc PATHS ENV BLASTED_BIN_DIR PATH_SUFFIXES lib
DOC "Location of BLASTed library")
if(${BLASTED_LIB} STREQUAL "BLASTED_LIB-NOTFOUND")
message(SEND_ERROR "BLASTed requested, but library not found!")
endif()
message(STATUS "Building with BLASTed: ${BLASTED_INCLUDE_DIR}, ${BLASTED_LIB}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BLASTED=1")
endif()
# MPI
find_package(MPI REQUIRED)
include_directories(${MPI_C_INCLUDE_PATH} ${MPI_CXX_INCLUDE_PATH})
# PETSc
# If PETSc variables were not passed to CMake, set them from environment variables
if(NOT DEFINED PETSC_DIR)
set(PETSC_DIR $ENV{PETSC_DIR} CACHE PATH "PETSc install directory")
endif()
if(NOT DEFINED PETSC_ARCH)
set(PETSC_ARCH $ENV{PETSC_ARCH} CACHE STRING "PETSc architecture to use")
endif()
find_library(PETSC_LIB NAMES petsc PATHS ${PETSC_DIR}/${PETSC_ARCH}/lib
DOC "Location of PETSc library")
if(${PETSC_LIB} STREQUAL "PETSC_LIB-NOTFOUND")
message(SEND_ERROR "PETSc library not found!")
endif()
include_directories(${PETSC_DIR}/include ${PETSC_DIR}/${PETSC_ARCH}/include)
message(STATUS "Building with PETSc found at ${PETSC_LIB}/${PETSC_ARCH}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWITH_PETSC=1")
# ---------------------------------------------------------------------------- #
string(TOLOWER ${CMAKE_BUILD_TYPE} LCASE_CMAKE_BUILD_TYPE)
if(LCASE_CMAKE_BUILD_TYPE MATCHES "debug")
message(STATUS "Debug build")
endif()
if(LCASE_CMAKE_BUILD_TYPE MATCHES "release")
message(STATUS "Release build")
endif()
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
include_directories(${CMAKE_SOURCE_DIR}/src)
# libraries to be compiled
add_subdirectory(src)
# Tags
if(NOT NOTAGS)
find_program(CTAGS_PATH ctags)
if(CTAGS_PATH)
message(STATUS "Found ctags: ${CTAGS_PATH}")
else()
message(STATUS "ctags not found! Tags cannot be generated.")
endif(CTAGS_PATH)
set_source_files_properties(tags PROPERTIES GENERATED true)
add_custom_target ( tags
COMMAND ctags -R --c++-kinds=+pf --extra=+q .
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
# Tests
enable_testing()
add_subdirectory(tests)
# Benchmarking
add_subdirectory(benchmarking)