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