-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Option.cmake
402 lines (366 loc) · 16.1 KB
/
Option.cmake
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
395
396
397
398
399
400
401
402
include_directories(${ROOT})
include_directories(Include)
include_directories(Include/metis)
include_directories(Include/fmt/include)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Debug Release RelWithDebInfo MinSizeRel")
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
set(BUILD_PACKAGE "" CACHE STRING "DEB OR RPM")
option(BUILD_DLL_EXAMPLE "Build dynamic linked library examples." OFF)
option(BUILD_MULTITHREAD "Build with multi-threaded support via TBB." OFF)
option(BUILD_SHARED "Build all libraries as shared ones." OFF)
option(USE_SUPERLUMT "Use multi-threaded SuperLU. Note the performance may not be better than the sequential version." OFF)
option(USE_VTK "Enable visualisation via VTK. Note external VTK libraries need to be compiled in advance." OFF)
option(USE_HDF5 "Enable recording results in HDF5 format." ON)
option(USE_AVX "Enable AVX support." OFF)
option(USE_AVX2 "Enable AVX2 support." ON)
option(USE_AVX512 "Enable AVX512 support." OFF)
option(USE_MKL "Use Intel MKL instead of OpenBLAS." OFF)
option(USE_MIMALLOC "Use mimalloc instead of default memory allocator." OFF)
option(USE_SYS_LIB "Use libraries installed on the system instead of the bundled ones." OFF)
if (USE_MKL)
option(USE_INTEL_OPENMP "Use Intel OpenMP implementation on Linux and macOS" ON)
option(LINK_DYNAMIC_MKL "Link dynamic Intel MKL libraries." ON)
option(USE_MPI "Enable MPI based global solvers." OFF)
if (USE_MPI)
option(USE_INTEL_MPI "Use Intel MPI implementation on Linux and macOS." ON)
if (NOT USE_INTEL_MPI)
set(MPI_INC "OpenMPI include path." CACHE PATH "")
set(MPI_LIB "OpenMPI lib path." CACHE PATH "")
endif ()
endif ()
else ()
set(USE_MPI OFF CACHE BOOL "" FORCE)
set(CUSTOM_OPENBLAS "" CACHE PATH "The path that contains the custom OpenBLAS library. If not set, the bundled OpenBLAS will be used.")
endif ()
set(COMPILER_IDENTIFIER "unknown")
set(SP_EXTERNAL_LIB_PATH "unknown")
if (CMAKE_SYSTEM_NAME MATCHES "Windows") # WINDOWS PLATFORM
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") # GNU GCC COMPILER
set(COMPILER_IDENTIFIER "gcc-win")
set(SP_EXTERNAL_LIB_PATH "win")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") # MSVC COMPILER
set(COMPILER_IDENTIFIER "vs")
set(SP_EXTERNAL_LIB_PATH "vs")
add_compile_definitions(_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
if (FORTRAN_STATUS)
set(BUILD_SHARED OFF CACHE BOOL "" FORCE)
endif ()
option(USE_CUDA "Enable GPU based global solvers via CUDA." OFF)
endif ()
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux") # LINUX PLATFORM
set(SP_EXTERNAL_LIB_PATH "linux")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") # GNU GCC COMPILER
set(COMPILER_IDENTIFIER "gcc-linux")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM") # Intel COMPILER icpx
set(COMPILER_IDENTIFIER "clang-linux")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel") # Intel COMPILER Classic icc
set(COMPILER_IDENTIFIER "gcc-linux")
message(STATUS "Classic Intel compiler icc has incomplete CPP20 support, if it fails to compile please use another compiler.")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Clang COMPILER
set(COMPILER_IDENTIFIER "clang-linux")
endif ()
option(USE_CUDA "Enable GPU based global solvers via CUDA." OFF)
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") # MAC PLATFORM
set(SP_EXTERNAL_LIB_PATH "mac")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") # GNU GCC COMPILER
set(COMPILER_IDENTIFIER "gcc-mac")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(COMPILER_IDENTIFIER "clang-mac")
link_directories(/usr/local/opt/libomp/lib/)
message(STATUS "On macOS, make sure llvm and libomp are installed.")
message(STATUS "brew install llvm libomp")
endif ()
endif ()
if (COMPILER_IDENTIFIER MATCHES "unknown")
message(FATAL_ERROR "Cannot identify the compiler available, please use GCC or MSVC or Intel.")
endif ()
if (USE_MKL AND USE_CUDA)
option(USE_MAGMA "Enable GPU based global solvers via MAGMA." OFF)
endif ()
if (NOT CUSTOM_OPENBLAS STREQUAL "")
link_directories(${CUSTOM_OPENBLAS})
elseif(USE_SYS_LIB)
find_package(OpenBLAS REQUIRED)
endif ()
if (NOT USE_SYS_LIB)
link_directories(Libs/${SP_EXTERNAL_LIB_PATH})
endif ()
if (USE_SUPERLUMT)
message(WARNING "Current SuperLU MT library may contain bugs. Disabling it.")
set(USE_SUPERLUMT OFF CACHE BOOL "" FORCE)
# add_compile_definitions(SUANPAN_SUPERLUMT)
endif ()
if (FORTRAN_STATUS AND CMAKE_Fortran_COMPILER_ID MATCHES "Intel" AND NOT USE_MKL)
message(FATAL_ERROR "Since Intel compilers are used, why not enabling MKL?")
endif()
if (USE_MKL)
set(MKLROOT "" CACHE PATH "MKL library path which contains /include and /lib folders.")
find_file(MKL_HEADER NAMES mkl.h PATHS ${MKLROOT}/include)
if (MKL_HEADER MATCHES "MKL_HEADER-NOTFOUND")
message(FATAL_ERROR "The <mkl.h> is not found under the path: ${MKLROOT}/include.")
endif ()
add_compile_definitions(SUANPAN_MKL)
# add_compile_definitions(ARMA_USE_MKL_ALLOC)
include_directories(${MKLROOT}/include)
if (EXISTS ${MKLROOT}/lib/intel64)
link_directories(${MKLROOT}/lib/intel64)
else (EXISTS ${MKLROOT}/lib/intel64)
link_directories(${MKLROOT}/lib)
endif ()
if (USE_MPI)
add_compile_definitions(SUANPAN_MPI)
if (USE_INTEL_MPI)
add_compile_definitions(MPICH_SKIP_MPICXX)
include_directories(${MKLROOT}/../../mpi/latest/include)
link_directories(${MKLROOT}/../../mpi/latest/lib/release)
elseif (MPI_INC STREQUAL "" OR MPI_LIB STREQUAL "")
message(FATAL_ERROR "Please specify the MPI_INC and MPI_LIB paths.")
else ()
include_directories(${MPI_INC})
link_directories(${MPI_LIB})
endif ()
endif ()
if (COMPILER_IDENTIFIER MATCHES "IntelLLVM")
set(USE_INTEL_OPENMP ON CACHE BOOL "" FORCE)
endif ()
if (USE_INTEL_OPENMP OR COMPILER_IDENTIFIER MATCHES "vs")
if (MKLROOT MATCHES "(oneapi|oneAPI)")
if (COMPILER_IDENTIFIER MATCHES "linux")
find_library(IOMPPATH iomp5 PATHS
${MKLROOT}/../../compiler/latest/linux/compiler/lib/intel64_lin
${MKLROOT}/../../compiler/latest/lib
REQUIRED
)
get_filename_component(IOMPPATH ${IOMPPATH} DIRECTORY)
link_directories(${IOMPPATH})
elseif (COMPILER_IDENTIFIER MATCHES "(win|vs)")
find_library(IOMPPATH libiomp5md PATHS
${MKLROOT}/../../compiler/latest/windows/compiler/lib/intel64_win
${MKLROOT}/../../compiler/latest/lib
REQUIRED
)
get_filename_component(IOMPPATH ${IOMPPATH} DIRECTORY)
link_directories(${IOMPPATH})
endif ()
else ()
message(FATAL_ERROR "Intel Parallel Studio is not supported, please install Intel oneAPI toolkits.")
endif ()
endif ()
endif ()
if (USE_CUDA)
if (POLICY CMP0146)
cmake_policy(SET CMP0146 OLD)
endif ()
find_package(CUDA)
if (NOT CUDA_FOUND)
set(CUDA_PATH "" CACHE PATH "CUDA library path which contains /include folder.")
find_package(CUDA PATHS ${CUDA_PATH})
if (NOT CUDA_FOUND)
message(FATAL_ERROR "CUDA library is not found, please indicate its path.")
endif ()
endif ()
add_compile_definitions(SUANPAN_CUDA)
include_directories(${CUDA_INCLUDE_DIRS})
link_libraries(${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDA_cusolver_LIBRARY} ${CUDA_cusparse_LIBRARY})
if (CUDA_VERSION VERSION_GREATER_EQUAL "12.3")
if (COMPILER_IDENTIFIER MATCHES "vs")
add_compile_options(/wd4996)
endif ()
endif ()
endif ()
if (USE_MAGMA)
set(MAGMAROOT "" CACHE PATH "Magma library path which contains /include and /lib folders.")
find_file(MAGMA_HEADER NAMES magma.h PATHS ${MAGMAROOT}/include)
if (MAGMA_HEADER MATCHES "MAGMA_HEADER-NOTFOUND")
message(FATAL_ERROR "The <magma.h> is not found under the path: ${MAGMAROOT}/include.")
endif ()
include_directories(${MAGMAROOT}/include)
link_directories(${MAGMAROOT}/lib)
link_libraries(magma magma_sparse)
add_compile_definitions(SUANPAN_MAGMA)
endif ()
set(HAVE_VTK FALSE CACHE INTERNAL "")
if (USE_VTK)
if (VTK_PATH MATCHES "")
find_package(VTK)
else ()
find_package(VTK PATHS ${VTK_PATH})
endif ()
if (VTK_FOUND)
add_compile_definitions(SUANPAN_VTK)
set(HAVE_VTK TRUE CACHE INTERNAL "")
else ()
set(VTK_PATH "" CACHE PATH "VTK library path which contains /include folder.")
find_package(VTK PATHS ${VTK_PATH})
if (NOT VTK_FOUND)
message(FATAL_ERROR "VTK library is not found, please indicate its path.")
endif ()
endif ()
endif ()
if (USE_HDF5)
add_compile_definitions(SUANPAN_HDF5)
if (HAVE_VTK)
string(REGEX REPLACE "/lib6?4?/cmake/vtk" "/include/vtk" VTK_INCLUDE ${VTK_DIR}) # on linux
string(REGEX REPLACE "\\\\lib6?4?\\\\cmake\\\\vtk" "\\\\include\\\\vtk" VTK_INCLUDE ${VTK_INCLUDE}) # on windows
include_directories(${VTK_INCLUDE}/vtkhdf5)
include_directories(${VTK_INCLUDE}/vtkhdf5/src)
include_directories(${VTK_INCLUDE}/vtkhdf5/hl/src)
find_file(HDF5_HEADER NAMES hdf5.h PATHS ${VTK_INCLUDE}/vtkhdf5/src)
if (HDF5_HEADER MATCHES "HDF5_HEADER-NOTFOUND")
message(FATAL_ERROR "The <hdf5.h> is not found in the include directories.")
else()
message(STATUS "Found HDF5 header: ${HDF5_HEADER}")
endif ()
else ()
if (USE_SYS_LIB)
find_package(HDF5 REQUIRED COMPONENTS C HL)
include_directories(${HDF5_INCLUDE_DIRS})
link_libraries(${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
else ()
include_directories(Include/hdf5)
include_directories(Include/hdf5-${SP_EXTERNAL_LIB_PATH})
if (COMPILER_IDENTIFIER MATCHES "vs")
link_libraries(libhdf5_hl libhdf5 shlwapi)
else ()
link_libraries(hdf5_hl hdf5)
endif ()
endif ()
endif ()
else ()
add_compile_definitions(ARMA_DONT_USE_HDF5)
endif ()
if (USE_MIMALLOC)
message(STATUS "USING MIMALLOC LIBRARY")
include(FetchContent)
FetchContent_Declare(mimalloc
GIT_REPOSITORY https://github.com/microsoft/mimalloc
GIT_TAG v2.1.2)
FetchContent_MakeAvailable(mimalloc)
endif ()
if (BUILD_MULTITHREAD)
message(STATUS "USING TBB LIBRARY")
add_compile_definitions(SUANPAN_MT)
if (USE_SYS_LIB)
find_package(TBB REQUIRED)
include_directories(${TBB_INCLUDE_DIRS})
link_libraries(TBB::tbb TBB::tbbmalloc TBB::tbbmalloc_proxy)
else ()
if (COMPILER_IDENTIFIER MATCHES "gcc-win")
link_libraries(tbb12)
else ()
link_libraries(tbb)
endif ()
option(USE_TBB_ALLOC "Use tbb memory allocator. Enable if no other allocators will be used." OFF)
if (USE_TBB_ALLOC)
# for armadillo to use tbb allocator
add_compile_definitions(ARMA_USE_TBB_ALLOC)
include_directories(Include/oneapi) # because armadillo assumes oneapi be in the include path
link_libraries(tbbmalloc tbbmalloc_proxy)
endif ()
endif ()
endif ()
if (BUILD_SHARED)
message(STATUS "BUILD SHARED LIBRARY")
set(LIBRARY_TYPE SHARED)
else ()
message(STATUS "BUILD STATIC LIBRARY")
set(LIBRARY_TYPE STATIC)
endif ()
if (USE_AVX512)
add_compile_definitions(SUANPAN_AVX512)
elseif (USE_AVX2)
add_compile_definitions(SUANPAN_AVX2)
elseif (USE_AVX)
add_compile_definitions(SUANPAN_AVX)
endif ()
if (COMPILER_IDENTIFIER MATCHES "vs")
unset(TEST_COVERAGE CACHE)
link_directories(Libs/win)
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP /openmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /openmp /EHsc")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /nowarn /MP /Qopenmp /Qparallel /fpp /names:lowercase /assume:underscore /libs:dll /threads")
if (USE_AVX512)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX512")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX512")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /arch:AVX2")
elseif (USE_AVX2)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /arch:AVX2")
elseif (USE_AVX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} /arch:AVX")
endif ()
else ()
if (BUILD_SHARED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fPIC")
endif ()
link_libraries(dl pthread gfortran)
find_library(HAS_QUADMATH quadmath)
if (HAS_QUADMATH)
link_libraries(quadmath)
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
link_libraries(stdc++)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffp-model=precise -fexceptions -fiopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffp-model=precise -fexceptions -fiopenmp")
elseif (COMPILER_IDENTIFIER MATCHES "clang-mac")
include_directories("/usr/local/include" "/usr/local/opt/llvm/include")
link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib")
link_libraries(omp)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions -Xpreprocessor -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -Xpreprocessor -fopenmp")
else ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -fopenmp")
endif ()
if (USE_AVX512)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512f")
elseif (USE_AVX2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2")
elseif (USE_AVX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx")
endif ()
option(TEST_COVERAGE "TEST CODE COVERAGE USING GCOV" OFF)
if (TEST_COVERAGE AND COMPILER_IDENTIFIER MATCHES "gcc") # only report coverage with gcc
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
link_libraries(gcov)
endif ()
if (CMAKE_BUILD_TYPE MATCHES "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
option(USE_ASAN "USE ADDRESS SANITIZER" OFF)
if (USE_ASAN)
message(STATUS "Using the address sanitizer with flags: -fsanitize=address,leak,undefined")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,leak,undefined")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,leak,undefined")
endif ()
endif ()
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -w -fallow-argument-mismatch")
if (CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fpp -qopenmp")
if (USE_AVX512)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -arch AVX2")
elseif (USE_AVX2)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -arch AVX2")
elseif (USE_AVX)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -arch AVX")
endif ()
else ()
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -cpp -fopenmp")
if (USE_AVX512)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -mavx512f")
elseif (USE_AVX2)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -mavx2")
elseif (USE_AVX)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -mavx")
endif ()
endif ()
endif ()