-
Notifications
You must be signed in to change notification settings - Fork 20
/
CMakeLists.txt
395 lines (360 loc) · 14 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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
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.
# ADOLC_DIR should be set if needed.
# 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 -DSLURMTESTTHREADS=<n> to use <n> threads for multi-threaded tests; defaults to 4
# 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 -Wfloat-conversion -Werror")
set (CMAKE_CXX_FLAGS_DEBUG "-g")
set (CMAKE_CXX_FLAGS_RELEASE "-O3")
if(CXX_COMPILER_GNUCLANG)
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
else()
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1")
endif()
elseif(CXX_COMPILER_PGI)
set (CMAKE_CXX_FLAGS "-std=c++14")
set (CMAKE_CXX_FLAGS_DEBUG "-g -O1")
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)
add_definitions(-DEIGEN_VECTORIZE_AVX512)
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)
message(STATUS "Building with profiling options")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
if(CXX_COMPILER_GNUCLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
elseif(CXX_COMPILER_INTEL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -shared-intel -debug inline-debug-info -parallel-source-info=2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -shared-intel -debug inline-debug-info -parallel-source-info=2")
endif()
endif()
# Boost
find_package(Boost 1.57 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 "Found 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})
# Gmsh
# if(NOT DEFINED GMSH_DIR)
# set(GMSH_DIR $ENV{GMSH_DIR} CACHE PATH "Gmsh library directory")
# endif()
find_library(GMSH_LIB NAMES gmsh PATHS ${GMSH_DIR} ENV GMSH_DIR PATH_SUFFIXES lib
DOC "Location of Gmsh library file")
if(${GMSH_LIB} STREQUAL "GMSH_LIB-NOTFOUND")
message(SEND_ERROR "Gmsh library not found!")
endif()
include_directories(${GMSH_DIR}/include)
message(STATUS "Found Gmsh library at ${GMSH_LIB}")
# 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}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWITH_PETSC=1")
# Scotch
if(NOT DEFINED SCOTCH_DIR)
set(SCOTCH_DIR $ENV{SCOTCH_DIR} CACHE PATH "Scotch install directory")
endif()
find_library(SCOTCH_LIB NAMES scotch PATHS ${SCOTCH_DIR}/lib DOC "Scotch library")
if(${SCOTCH_LIB} STREQUAL "SCOTCH_LIB-NOTFOUND")
message(SEND_ERROR "Scotch not found!")
else()
message(STATUS "Building with Scotch found at ${SCOTCH_LIB}")
endif()
find_library(SCOTCH_ERR_LIB NAMES scotcherr PATHS ${SCOTCH_DIR}/lib DOC "Scotch error library")
if(${SCOTCH_ERR_LIB} STREQUAL "SCOTCH_ERR_LIB-NOTFOUND")
message(SEND_ERROR "Scotch error lib not found!")
else()
message(STATUS "Building with Scotch error lib found at ${SCOTCH_ERR_LIB}")
endif()
# ADOLC
if(WITH_ADOLC)
if(NOT DEFINED ADOLC_DIR)
set(ADOLC_DIR $ENV{ADOLC_DIR} CACHE PATH "ADOL-C install directory")
endif()
find_library(ADOLC_LIB NAMES adolc PATHS ${ADOLC_DIR}/lib64)
if(${ADOLC_LIB} STREQUAL "ADOLC_LIB-NOTFOUND")
message(SEND_ERROR "ADOL-C library not found!")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_ADOLC=1")
include_directories(${ADOLC_DIR}/include)
message(STATUS "Building with ADOL-C found at ${ADOLC_LIB}")
endif()
endif()
# ---------------------------------------------------------------------------- #
# For test execution
if(SLURM)
set(SEQEXEC "srun")
set(SEQTASKS "-n 1")
set(MPIEXEC "srun")
if(SLURMTESTTHREADS)
set(THREADOPTS "--cpus-per-task=${SLURMTESTTHREADS}")
else()
set(THREADOPTS "--cpus-per-task=4")
endif()
else(SLURM)
set(SEQEXEC "")
set(SEQTASKS "")
set(MPIEXEC "mpirun")
set(THREADOPTS "")
endif(SLURM)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting default build type of debug")
set(CMAKE_BUILD_TYPE "Debug")
endif()
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)
# Non-automated test cases
add_subdirectory(testcases)
# Performance testing
add_subdirectory(perftest)