-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
118 lines (106 loc) · 4.29 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
#
# nvortexVc
#
PROJECT (nvortexVc)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo")
IF (NOT CMAKE_BUILD_TYPE)
SET (CMAKE_BUILD_TYPE "Release")
ENDIF ()
SET (CMAKE_BUILD_TYPE "Release" CACHE STRING "Select which configuration to build")
SET (USE_OMP FALSE CACHE BOOL "Use OpenMP multithreading")
SET (USE_MPI FALSE CACHE BOOL "Use MPI distributed-memory multitasking")
SET (USE_VC FALSE CACHE BOOL "Use Vc for vector arithmetic")
SET (CMAKE_VERBOSE_MAKEFILE on)
SET (CMAKE_EXPORT_COMPILE_COMMANDS on)
IF( NOT CMAKE_BUILD_TYPE )
SET( CMAKE_BUILD_TYPE "Release" )
ENDIF()
# split on compiler family
IF( CMAKE_COMPILER_IS_GNUCXX )
ADD_COMPILE_OPTIONS( -Wall -Wformat -std=c++14 )
IF( CMAKE_BUILD_TYPE STREQUAL "Debug" )
# Debug already includes -O0 -g
ADD_COMPILE_OPTIONS( -ggdb3 )
ELSEIF( CMAKE_BUILD_TYPE STREQUAL "Release" )
# Release already includes -O3
ADD_COMPILE_OPTIONS( -march=native -ffast-math -Ofast -flto )
ELSEIF( CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
# RelDbg already includes -O2 -g
ADD_COMPILE_OPTIONS( -march=native -Ofast -ggdb3 )
ENDIF()
ELSEIF( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
ADD_COMPILE_OPTIONS( -Wall -Wformat -std=c++14 )
# The Cray compiler reports as Clang to most versions of CMake
EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} --version
COMMAND grep -c Cray
OUTPUT_VARIABLE INTERNAL_HAVE_CRAY_COMPILER
OUTPUT_STRIP_TRAILING_WHITESPACE)
IF (INTERNAL_HAVE_CRAY_COMPILER) #not actually Clang
# cray compiler misidentifies as Clang and needs this instead
ADD_COMPILE_OPTIONS( -fsave-loopmark -floopmark-style=interspersed )
ELSE()
# real clang needs this - OR NOT?!?
#ADD_COMPILE_OPTIONS( -stdlib=libc++ )
ENDIF()
IF( CMAKE_BUILD_TYPE STREQUAL "Debug" )
# Debug already includes -O0 -g
ADD_COMPILE_OPTIONS( -ggdb )
ELSEIF( CMAKE_BUILD_TYPE STREQUAL "Release" )
# Release already includes -O3
#ADD_COMPILE_OPTIONS( -march=native -Ofast -flto -funroll-loops -fvectorize )
#ADD_COMPILE_OPTIONS( -march=native -Ofast -flto )
ADD_COMPILE_OPTIONS( -march=native -Ofast )
ELSEIF( CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
# RelDbg already includes -O2 -g
ADD_COMPILE_OPTIONS( -march=native -Ofast -ggdb )
ENDIF()
ELSEIF( MSVC )
# needs work
ADD_COMPILE_OPTIONS( /Ox )
ENDIF()
IF( NOT USE_OMP )
# silence the warnings
# this line must appear BEFORE defining the executables
ADD_COMPILE_OPTIONS( -Wno-unknown-pragmas )
ENDIF()
# if you have headers in src, tell cmake here
#INCLUDE_DIRECTORIES( "src" )
# build these two bins
ADD_EXECUTABLE( "nvortex2d.bin" "src/nvortex2d.cpp" )
ADD_EXECUTABLE( "nvortex3d.bin" "src/nvortex3d.cpp" )
ADD_EXECUTABLE( "ngrav3d.bin" "src/ngrav3d.cpp" )
# OpenMP for multithreading
IF( USE_OMP )
# many ways to do this?
# https://cmake.org/cmake/help/latest/module/FindOpenMP.html
# https://cliutils.gitlab.io/modern-cmake/chapters/packages/OpenMP.html
# https://stackoverflow.com/questions/17633513/cmake-cannot-find-openmp#28792611
FIND_PACKAGE( OpenMP REQUIRED )
TARGET_LINK_LIBRARIES( "nvortex2d.bin" PUBLIC OpenMP::OpenMP_CXX)
TARGET_LINK_LIBRARIES( "nvortex3d.bin" PUBLIC OpenMP::OpenMP_CXX)
TARGET_LINK_LIBRARIES( "ngrav3d.bin" PUBLIC OpenMP::OpenMP_CXX)
ADD_COMPILE_OPTIONS( ${OpenMP_CXX_FLAGS} )
ENDIF() # OpenMP for multithreading
# Vc for explicit vectorization
IF( USE_VC )
FIND_PACKAGE( Vc REQUIRED )
ADD_DEFINITIONS(-DUSE_VC)
INCLUDE_DIRECTORIES( ${Vc_INCLUDE_DIR} )
# these lines must appear AFTER defining the executables
TARGET_LINK_LIBRARIES( "nvortex2d.bin" PUBLIC ${Vc_LIBRARIES} )
TARGET_LINK_LIBRARIES( "nvortex3d.bin" PUBLIC ${Vc_LIBRARIES} )
TARGET_LINK_LIBRARIES( "ngrav3d.bin" PUBLIC ${Vc_LIBRARIES} )
ENDIF() # Vc for explicit vectorization
# more adds for MPI
IF (USE_MPI)
FIND_PACKAGE(MPI REQUIRED)
# mpi is a library and does not set a compile-time variable
ADD_DEFINITIONS(-DUSE_MPI)
# this is for openmpi
ADD_DEFINITIONS(-DOMPI_SKIP_MPICXX)
# add the mpi library
TARGET_LINK_LIBRARIES( "nvortex2d.bin" PRIVATE MPI::MPI_C )
TARGET_LINK_LIBRARIES( "nvortex3d.bin" PRIVATE MPI::MPI_C )
TARGET_LINK_LIBRARIES( "ngrav3d.bin" PRIVATE MPI::MPI_C )
ENDIF() # MPI for distributed memory parallelism