/
code_config.hpp
135 lines (118 loc) · 4.15 KB
/
code_config.hpp
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
/*!
* \file code_config.hpp
* \brief Header file for collecting common macros, definitions and type configurations.
* \author T. Albring, P. Gomes, J. Blühdorn
* \version 7.4.0 "Blackbird"
*
* SU2 Project Website: https://su2code.github.io
*
* The SU2 Project is maintained by the SU2 Foundation
* (http://su2foundation.org)
*
* Copyright 2012-2022, SU2 Contributors (cf. AUTHORS.md)
*
* SU2 is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* SU2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <type_traits>
#if defined(_MSC_VER)
#define FORCEINLINE __forceinline
#elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
#define FORCEINLINE inline __attribute__((always_inline))
#else
#define FORCEINLINE inline
#endif
#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
#define NEVERINLINE inline __attribute__((noinline))
#else
#define NEVERINLINE inline
#endif
#if defined(__INTEL_COMPILER)
/*--- Disable warnings related to inline attributes. ---*/
#pragma warning disable 2196
#pragma warning disable 3415
/*--- Disable warnings related to overloaded virtual. ---*/
#pragma warning disable 654
#pragma warning disable 1125
#if defined(CODI_FORWARD_TYPE) || defined(CODI_REVERSE_TYPE)
#pragma warning disable 1875
#endif
#endif
/*--- Convenience SFINAE typedef to conditionally
* enable/disable function template overloads. ---*/
template<bool condition>
using su2enable_if = typename std::enable_if<condition,bool>::type;
/*--- Compile-time type selection. ---*/
template<bool B, class T, class F> struct su2conditional { using type = T; };
template<class T, class F> struct su2conditional<false, T, F> { using type = F; };
template<bool B, class T, class F>
using su2conditional_t = typename su2conditional<B,T,F>::type;
/*! \brief Static cast "In" to "Out", in debug builds a dynamic cast is used. */
template<class Out, class In>
FORCEINLINE Out su2staticcast_p(In ptr) {
static_assert(std::is_pointer<In>::value, "This expects a pointer");
#ifndef NDEBUG
return static_cast<Out>(ptr);
#else
return dynamic_cast<Out>(ptr);
#endif
}
/*--- Detect compilation with OpenMP. ---*/
#if defined(_OPENMP)
#define HAVE_OMP
#endif
/*--- Depending on the datatype defined during the configuration,
* include the correct definition, and create the main typedef. ---*/
#if defined(CODI_REVERSE_TYPE) // reverse mode AD
#include "codi.hpp"
#include "codi/tools/dataStore.hpp"
#if defined(HAVE_OMP)
using su2double = codi::RealReverseIndexParallel;
#else
#if defined(CODI_INDEX_TAPE)
using su2double = codi::RealReverseIndex;
//#elif defined(CODI_PRIMAL_TAPE)
//using su2double = codi::RealReversePrimal;
//#elif defined(CODI_PRIMAL_INDEX_TAPE)
//using su2double = codi::RealReversePrimalIndex;
#else
using su2double = codi::RealReverse;
#endif
#endif
#elif defined(CODI_FORWARD_TYPE) // forward mode AD
#include "codi.hpp"
using su2double = codi::RealForward;
#else // primal / direct / no AD
using su2double = double;
#endif
/*--- This type can be used for (rare) compatibility cases or for
* computations that are intended to be (always) passive. ---*/
using passivedouble = double;
/*--- Define a type for potentially lower precision operations. ---*/
#ifdef USE_MIXED_PRECISION
using su2mixedfloat = float;
#else
using su2mixedfloat = passivedouble;
#endif
/*--- Detect if OpDiLib has to be used. ---*/
#if defined(HAVE_OMP) && defined(CODI_REVERSE_TYPE)
#ifndef __INTEL_COMPILER
#define HAVE_OPDI
#else
#warning Hybrid parallel reverse mode AD cannot be used with Intel compilers.
#endif
#if (_OPENMP >= 201811 && !defined(FORCE_OPDI_MACRO_BACKEND)) || defined(FORCE_OPDI_OMPT_BACKEND)
#define HAVE_OMPT
#endif
#endif