Intel® OpenMP* Runtime Library
 All Classes Functions Variables Typedefs Enumerations Enumerator Modules Pages
kmp_debug.h
1 /*
2  * kmp_debug.h -- debug / assertion code for Assure library
3  */
4 
5 /* <copyright>
6  Copyright (c) 1997-2015 Intel Corporation. All Rights Reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions
10  are met:
11 
12  * Redistributions of source code must retain the above copyright
13  notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15  notice, this list of conditions and the following disclaimer in the
16  documentation and/or other materials provided with the distribution.
17  * Neither the name of Intel Corporation nor the names of its
18  contributors may be used to endorse or promote products derived
19  from this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 </copyright> */
34 
35 #ifndef KMP_DEBUG_H
36 #define KMP_DEBUG_H
37 
38 #include <stdarg.h>
39 
40 #ifdef __cplusplus
41  extern "C" {
42 #endif // __cplusplus
43 
44 // -------------------------------------------------------------------------------------------------
45 // Build-time assertion.
46 // -------------------------------------------------------------------------------------------------
47 
48 /*
49  Build-time assertion can do compile-time checking of data structure sizes, etc. This works by
50  declaring a negative-length array if the conditional expression evaluates to false. In that
51  case, the compiler issues a syntax error and stops the compilation. If the expression is
52  true, we get an extraneous static single character array in the scope of the macro.
53 
54  Usage:
55 
56  KMP_BUILD_ASSERT( sizeof( some_t ) <= 32 );
57  KMP_BUILD_ASSERT( offsetof( some_t, field ) % 8 == 0 );
58 
59  Do not use _KMP_BUILD_ASSERT and __KMP_BUILD_ASSERT directly, it is working guts.
60 */
61 
62 #define __KMP_BUILD_ASSERT( expr, suffix ) static char __kmp_build_check_##suffix[ (expr) ? 1 : -1 ]
63 #define _KMP_BUILD_ASSERT( expr, suffix ) __KMP_BUILD_ASSERT( (expr), suffix )
64 #define KMP_BUILD_ASSERT( expr ) _KMP_BUILD_ASSERT( (expr), __LINE__ )
65 
66 // -------------------------------------------------------------------------------------------------
67 // Run-time assertions.
68 // -------------------------------------------------------------------------------------------------
69 
70 extern void __kmp_dump_debug_buffer( void );
71 
72 #ifdef KMP_USE_ASSERT
73  extern int __kmp_debug_assert( char const * expr, char const * file, int line );
74  #ifdef KMP_DEBUG
75  #define KMP_ASSERT( cond ) ( (cond) ? 0 : __kmp_debug_assert( #cond, __FILE__, __LINE__ ) )
76  #define KMP_ASSERT2( cond, msg ) ( (cond) ? 0 : __kmp_debug_assert( (msg), __FILE__, __LINE__ ) )
77  #define KMP_DEBUG_ASSERT( cond ) KMP_ASSERT( cond )
78  #define KMP_DEBUG_ASSERT2( cond, msg ) KMP_ASSERT2( cond, msg )
79  #else
80  // Do not expose condition in release build. Use "assertion failure".
81  #define KMP_ASSERT( cond ) ( (cond) ? 0 : __kmp_debug_assert( "assertion failure", __FILE__, __LINE__ ) )
82  #define KMP_ASSERT2( cond, msg ) KMP_ASSERT( cond )
83  #define KMP_DEBUG_ASSERT( cond ) 0
84  #define KMP_DEBUG_ASSERT2( cond, msg ) 0
85  #endif // KMP_DEBUG
86 #else
87  #define KMP_ASSERT( cond ) 0
88  #define KMP_ASSERT2( cond, msg ) 0
89  #define KMP_DEBUG_ASSERT( cond ) 0
90  #define KMP_DEBUG_ASSERT2( cond, msg ) 0
91 #endif // KMP_USE_ASSERT
92 
93 #ifdef KMP_DEBUG
94  extern void __kmp_debug_printf_stdout( char const * format, ... );
95 #endif
96 extern void __kmp_debug_printf( char const * format, ... );
97 
98 #ifdef KMP_DEBUG
99 
100  extern int kmp_a_debug;
101  extern int kmp_b_debug;
102  extern int kmp_c_debug;
103  extern int kmp_d_debug;
104  extern int kmp_e_debug;
105  extern int kmp_f_debug;
106  extern int kmp_diag;
107 
108  #define KA_TRACE(d,x) if (kmp_a_debug >= d) { __kmp_debug_printf x ; }
109  #define KB_TRACE(d,x) if (kmp_b_debug >= d) { __kmp_debug_printf x ; }
110  #define KC_TRACE(d,x) if (kmp_c_debug >= d) { __kmp_debug_printf x ; }
111  #define KD_TRACE(d,x) if (kmp_d_debug >= d) { __kmp_debug_printf x ; }
112  #define KE_TRACE(d,x) if (kmp_e_debug >= d) { __kmp_debug_printf x ; }
113  #define KF_TRACE(d,x) if (kmp_f_debug >= d) { __kmp_debug_printf x ; }
114  #define K_DIAG(d,x) {if (kmp_diag == d) { __kmp_debug_printf_stdout x ; } }
115 
116  #define KA_DUMP(d,x) if (kmp_a_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
117  #define KB_DUMP(d,x) if (kmp_b_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
118  #define KC_DUMP(d,x) if (kmp_c_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
119  #define KD_DUMP(d,x) if (kmp_d_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
120  #define KE_DUMP(d,x) if (kmp_e_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
121  #define KF_DUMP(d,x) if (kmp_f_debug >= d) { int ks; __kmp_disable(&ks); (x) ; __kmp_enable(ks); }
122 
123 #else
124 
125  #define KA_TRACE(d,x) /* nothing to do */
126  #define KB_TRACE(d,x) /* nothing to do */
127  #define KC_TRACE(d,x) /* nothing to do */
128  #define KD_TRACE(d,x) /* nothing to do */
129  #define KE_TRACE(d,x) /* nothing to do */
130  #define KF_TRACE(d,x) /* nothing to do */
131  #define K_DIAG(d,x) {}/* nothing to do */
132 
133  #define KA_DUMP(d,x) /* nothing to do */
134  #define KB_DUMP(d,x) /* nothing to do */
135  #define KC_DUMP(d,x) /* nothing to do */
136  #define KD_DUMP(d,x) /* nothing to do */
137  #define KE_DUMP(d,x) /* nothing to do */
138  #define KF_DUMP(d,x) /* nothing to do */
139 
140 #endif // KMP_DEBUG
141 
142 #ifdef __cplusplus
143  } // extern "C"
144 #endif // __cplusplus
145 
146 #endif /* KMP_DEBUG_H */