GEOSX
coreComponents
LvArray
src
Macros.hpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020, Lawrence Livermore National Security, LLC and LvArray contributors.
3
* All rights reserved.
4
* See the LICENSE file for details.
5
* SPDX-License-Identifier: (BSD-3-Clause)
6
*/
7
13
#pragma once
14
15
// Source includes
16
#include "LvArrayConfig.hpp"
17
#include "
system.hpp
"
18
19
// System includes
20
#include <fstream>
21
#include <sstream>
22
#include <iostream>
23
#include <type_traits>
24
25
#if defined(LVARRAY_USE_CUDA)
26
#include <cassert>
27
#endif
28
33
#define STRINGIZE_NX( A ) #A
34
39
#define STRINGIZE( A ) STRINGIZE_NX( A )
40
45
#define LVARRAY_UNUSED_ARG( X )
46
51
#define LVARRAY_UNUSED_VARIABLE( X ) ( ( void ) X )
52
57
#define LVARRAY_DEBUG_VAR( X ) LVARRAY_UNUSED_VARIABLE( X )
58
60
#define LOCATION __FILE__ ":" STRINGIZE( __LINE__ )
61
66
#define TYPEOFPTR( X ) std::remove_pointer_t< decltype( X ) >
67
72
#define TYPEOFREF( X ) std::remove_reference_t< decltype( X ) >
73
77
#define LVARRAY_LOG( ... ) std::cout << __VA_ARGS__ << std::endl
78
82
#define LVARRAY_LOG_VAR( ... ) LVARRAY_LOG( STRINGIZE( __VA_ARGS__ ) << " = " << __VA_ARGS__ )
83
94
#if defined(__CUDA_ARCH__)
95
#if !defined(NDEBUG)
96
#define LVARRAY_ERROR_IF( EXP, MSG ) assert( !(EXP) )
97
#else
98
#define LVARRAY_ERROR_IF( EXP, MSG ) if( EXP ) asm ( "trap;" )
99
#endif
100
#else
101
#define LVARRAY_ERROR_IF( EXP, MSG ) \
102
do \
103
{ \
104
if( EXP ) \
105
{ \
106
std::ostringstream __oss; \
107
__oss << "***** ERROR\n"; \
108
__oss << "***** LOCATION: " LOCATION "\n"; \
109
__oss << "***** Controlling expression (should be false): " STRINGIZE( EXP ) "\n"; \
110
__oss << MSG << "\n"; \
111
__oss << LvArray::system::stackTrace( true ); \
112
std::cout << __oss.str() << std::endl; \
113
LvArray::system::callErrorHandler(); \
114
} \
115
} while( false )
116
#endif
117
122
#define LVARRAY_ERROR( MSG ) LVARRAY_ERROR_IF( true, MSG )
123
135
#if !defined(NDEBUG)
136
#define LVARRAY_ASSERT_MSG( EXP, MSG ) LVARRAY_ERROR_IF( !(EXP), MSG )
137
#else
138
#define LVARRAY_ASSERT_MSG( EXP, MSG ) ((void) 0)
139
#endif
140
142
#define LVARRAY_ASSERT( EXP ) LVARRAY_ASSERT_MSG( EXP, "" )
143
149
#define LVARRAY_WARNING_IF( EXP, MSG ) \
150
do \
151
{ \
152
if( EXP ) \
153
{ \
154
std::ostringstream __oss; \
155
__oss << "***** WARNING\n"; \
156
__oss << "***** LOCATION: " LOCATION "\n"; \
157
__oss << "***** Controlling expression (should be false): " STRINGIZE( EXP ) "\n"; \
158
__oss << MSG; \
159
std::cout << __oss.str() << std::endl; \
160
} \
161
} while( false )
162
167
#define LVARRAY_WARNING( MSG ) LVARRAY_WARNING_IF( true, MSG )
168
174
#define LVARRAY_INFO_IF( EXP, MSG ) \
175
do \
176
{ \
177
if( EXP ) \
178
{ \
179
std::ostringstream __oss; \
180
__oss << "***** INFO\n"; \
181
__oss << "***** LOCATION: " LOCATION "\n"; \
182
__oss << "***** Controlling expression: " STRINGIZE( EXP ) "\n"; \
183
__oss << MSG; \
184
std::cout << __oss.str() << std::endl; \
185
} \
186
} while( false )
187
192
#define LVARRAY_INFO( msg ) LVARRAY_INFO_IF( true, msg )
193
202
#define LVARRAY_ERROR_IF_OP_MSG( lhs, OP, NOP, rhs, msg ) \
203
LVARRAY_ERROR_IF( lhs OP rhs, \
204
msg << "\n" << \
205
"Expected " << #lhs << " " << #NOP << " " << #rhs << "\n" << \
206
" " << #lhs << " = " << lhs << "\n" << \
207
" " << #rhs << " = " << rhs << "\n" )
208
215
#define LVARRAY_ERROR_IF_EQ_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_OP_MSG( lhs, ==, !=, rhs, msg )
216
222
#define LVARRAY_ERROR_IF_EQ( lhs, rhs ) LVARRAY_ERROR_IF_EQ_MSG( lhs, rhs, "" )
223
230
#define LVARRAY_ERROR_IF_NE_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_OP_MSG( lhs, !=, ==, rhs, msg )
231
237
#define LVARRAY_ERROR_IF_NE( lhs, rhs ) LVARRAY_ERROR_IF_NE_MSG( lhs, rhs, "" )
238
245
#define LVARRAY_ERROR_IF_GT_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_OP_MSG( lhs, >, <=, rhs, msg )
246
252
#define LVARRAY_ERROR_IF_GT( lhs, rhs ) LVARRAY_ERROR_IF_GT_MSG( lhs, rhs, "" )
253
260
#define LVARRAY_ERROR_IF_GE_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_OP_MSG( lhs, >=, <, rhs, msg )
261
267
#define LVARRAY_ERROR_IF_GE( lhs, rhs ) LVARRAY_ERROR_IF_GE_MSG( lhs, rhs, "" )
268
275
#define LVARRAY_ERROR_IF_LT_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_OP_MSG( lhs, <, >=, rhs, msg )
276
282
#define LVARRAY_ERROR_IF_LT( lhs, rhs ) LVARRAY_ERROR_IF_LT_MSG( lhs, rhs, "" )
283
290
#define LVARRAY_ERROR_IF_LE_MSG( lhs, rhs, msg ) LVARRAY_ERROR_IF_OP_MSG( lhs, <=, >, rhs, msg )
291
297
#define LVARRAY_ERROR_IF_LE( lhs, rhs ) LVARRAY_ERROR_IF_GE_MSG( lhs, rhs, "" )
298
306
#define LVARRAY_ASSERT_OP_MSG( lhs, OP, rhs, msg ) \
307
LVARRAY_ASSERT_MSG( lhs OP rhs, \
308
msg << "\n" << \
309
" " << #lhs << " = " << lhs << "\n" << \
310
" " << #rhs << " = " << rhs << "\n" )
311
318
#define LVARRAY_ASSERT_EQ_MSG( lhs, rhs, msg ) LVARRAY_ASSERT_OP_MSG( lhs, ==, rhs, msg )
319
325
#define LVARRAY_ASSERT_EQ( lhs, rhs ) LVARRAY_ASSERT_EQ_MSG( lhs, rhs, "" )
326
333
#define LVARRAY_ASSERT_NE_MSG( lhs, rhs, msg ) LVARRAY_ASSERT_OP_MSG( lhs, !=, rhs, msg )
334
340
#define LVARRAY_ASSERT_NE( lhs, rhs ) LVARRAY_ASSERT_NE_MSG( lhs, rhs, "" )
341
348
#define LVARRAY_ASSERT_GT_MSG( lhs, rhs, msg ) LVARRAY_ASSERT_OP_MSG( lhs, >, rhs, msg )
349
355
#define LVARRAY_ASSERT_GT( lhs, rhs ) LVARRAY_ASSERT_GT_MSG( lhs, rhs, "" )
356
363
#define LVARRAY_ASSERT_GE_MSG( lhs, rhs, msg ) LVARRAY_ASSERT_OP_MSG( lhs, >=, rhs, msg )
364
370
#define LVARRAY_ASSERT_GE( lhs, rhs ) LVARRAY_ASSERT_GE_MSG( lhs, rhs, "" )
371
372
#if defined(LVARRAY_USE_CUDA) && defined(__CUDACC__)
373
#define LVARRAY_HOST_DEVICE __host__ __device__
375
377
#define LVARRAY_DEVICE __device__
378
386
#define DISABLE_HD_WARNING _Pragma("hd_warning_disable")
387
#else
388
#define LVARRAY_HOST_DEVICE
390
392
#define LVARRAY_DEVICE
393
401
#define DISABLE_HD_WARNING
402
#endif
403
404
405
#if defined(__clang__)
406
#define LVARRAY_RESTRICT __restrict__
407
#define LVARRAY_RESTRICT_REF __restrict__
408
#define LVARRAY_INTEL_CONSTEXPR constexpr
409
#elif defined(__GNUC__)
410
#if defined(__INTEL_COMPILER)
411
#define LVARRAY_RESTRICT __restrict__
412
#define LVARRAY_RESTRICT_REF __restrict__
413
#define LVARRAY_INTEL_CONSTEXPR
414
#else
415
#define LVARRAY_RESTRICT __restrict__
416
#define LVARRAY_RESTRICT_REF __restrict__
417
#define LVARRAY_INTEL_CONSTEXPR constexpr
418
#endif
419
#endif
420
421
#if !defined(LVARRAY_BOUNDS_CHECK)
422
425
#define CONSTEXPR_WITHOUT_BOUNDS_CHECK constexpr
426
#else
427
430
#define CONSTEXPR_WITHOUT_BOUNDS_CHECK
431
#endif
432
433
#if defined(NDEBUG)
434
437
#define CONSTEXPR_WITH_NDEBUG constexpr
438
#else
439
442
#define CONSTEXPR_WITH_NDEBUG
443
#endif
444
445
#if !defined(LVARRAY_BOUNDS_CHECK)
446
449
#define CONSTEXPR_WITHOUT_BOUNDS_CHECK constexpr
450
#else
451
454
#define CONSTEXPR_WITHOUT_BOUNDS_CHECK
455
#endif
456
457
#if defined(NDEBUG)
458
461
#define CONSTEXPR_WITH_NDEBUG constexpr
462
#else
463
466
#define CONSTEXPR_WITH_NDEBUG
467
#endif
system.hpp
Contains functions that interact with the system or runtime environment.
Generated by
1.8.13