Intel® OpenMP* Runtime Library
 All Classes Functions Variables Typedefs Enumerations Enumerator Modules Pages
kmp_itt.c
1 #if USE_ITT_BUILD
2 /*
3  * kmp_itt.c -- ITT Notify interface.
4  */
5 
6 /* <copyright>
7  Copyright (c) 1997-2015 Intel Corporation. All Rights Reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15  * Redistributions in binary form must reproduce the above copyright
16  notice, this list of conditions and the following disclaimer in the
17  documentation and/or other materials provided with the distribution.
18  * Neither the name of Intel Corporation nor the names of its
19  contributors may be used to endorse or promote products derived
20  from this software without specific prior written permission.
21 
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 </copyright> */
35 
36 #include "kmp_itt.h"
37 
38 #if KMP_DEBUG
39  #include "kmp_itt.inl"
40 #endif
41 
42 
43 #if USE_ITT_NOTIFY
44 
45  kmp_int32 __kmp_barrier_domain_count;
46  kmp_int32 __kmp_region_domain_count;
47  __itt_domain* __kmp_itt_barrier_domains[KMP_MAX_FRAME_DOMAINS];
48  __itt_domain* __kmp_itt_region_domains[KMP_MAX_FRAME_DOMAINS];
49  __itt_domain* __kmp_itt_imbalance_domains[KMP_MAX_FRAME_DOMAINS];
50  kmp_int32 __kmp_itt_region_team_size[KMP_MAX_FRAME_DOMAINS];
51  __itt_domain * metadata_domain = NULL;
52 
53  #include "kmp_version.h"
54  #include "kmp_i18n.h"
55  #include "kmp_str.h"
56 
57  KMP_BUILD_ASSERT( sizeof( kmp_itt_mark_t ) == sizeof( __itt_mark_type ) );
58 
59  /*
60  Previously used warnings:
61 
62  KMP_WARNING( IttAllNotifDisabled );
63  KMP_WARNING( IttObjNotifDisabled );
64  KMP_WARNING( IttMarkNotifDisabled );
65  KMP_WARNING( IttUnloadLibFailed, libittnotify );
66  */
67 
68 
69  kmp_int32 __kmp_itt_prepare_delay = 0;
70  kmp_bootstrap_lock_t __kmp_itt_debug_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER( __kmp_itt_debug_lock );
71 
72 #endif // USE_ITT_NOTIFY
73 
74 void __kmp_itt_initialize() {
75 
76  // ITTNotify library is loaded and initialized at first call to any ittnotify function,
77  // so we do not need to explicitly load it any more.
78  // Jusr report OMP RTL version to ITTNotify.
79 
80  #if USE_ITT_NOTIFY
81  // Report OpenMP RTL version.
82  kmp_str_buf_t buf;
83  __itt_mark_type version;
84  __kmp_str_buf_init( & buf );
85  __kmp_str_buf_print(
86  & buf,
87  "OMP RTL Version %d.%d.%d",
88  __kmp_version_major,
89  __kmp_version_minor,
90  __kmp_version_build
91  );
92  if ( __itt_api_version_ptr != NULL ) {
93  __kmp_str_buf_print( & buf, ":%s", __itt_api_version() );
94  }; // if
95  version = __itt_mark_create( buf.str );
96  __itt_mark( version, NULL );
97  __kmp_str_buf_free( & buf );
98  #endif
99 
100 } // __kmp_itt_initialize
101 
102 
103 void __kmp_itt_destroy() {
104  #if USE_ITT_NOTIFY
105  __kmp_itt_fini_ittlib();
106  #endif
107 } // __kmp_itt_destroy
108 
109 
110 extern "C"
111 void
112 __itt_error_handler(
113  __itt_error_code err,
114  va_list args
115 ) {
116 
117  switch ( err ) {
118  case __itt_error_no_module : {
119  char const * library = va_arg( args, char const * );
120  #if KMP_OS_WINDOWS
121  int sys_err = va_arg( args, int );
122  __kmp_msg( kmp_ms_warning, KMP_MSG( IttLoadLibFailed, library ), KMP_SYSERRCODE( sys_err ), __kmp_msg_null );
123  #else
124  char const * sys_err = va_arg( args, char const * );
125  __kmp_msg( kmp_ms_warning, KMP_MSG( IttLoadLibFailed, library ), KMP_SYSERRMESG( sys_err ), __kmp_msg_null );
126  #endif
127  } break;
128  case __itt_error_no_symbol : {
129  char const * library = va_arg( args, char const * );
130  char const * symbol = va_arg( args, char const * );
131  KMP_WARNING( IttLookupFailed, symbol, library );
132  } break;
133  case __itt_error_unknown_group : {
134  char const * var = va_arg( args, char const * );
135  char const * group = va_arg( args, char const * );
136  KMP_WARNING( IttUnknownGroup, var, group );
137  } break;
138  case __itt_error_env_too_long : {
139  char const * var = va_arg( args, char const * );
140  size_t act_len = va_arg( args, size_t );
141  size_t max_len = va_arg( args, size_t );
142  KMP_WARNING( IttEnvVarTooLong, var, (unsigned long) act_len, (unsigned long) max_len );
143  } break;
144  case __itt_error_cant_read_env : {
145  char const * var = va_arg( args, char const * );
146  int sys_err = va_arg( args, int );
147  __kmp_msg( kmp_ms_warning, KMP_MSG( CantGetEnvVar, var ), KMP_ERR( sys_err ), __kmp_msg_null );
148  } break;
149  case __itt_error_system : {
150  char const * func = va_arg( args, char const * );
151  int sys_err = va_arg( args, int );
152  __kmp_msg( kmp_ms_warning, KMP_MSG( IttFunctionError, func ), KMP_SYSERRCODE( sys_err ), __kmp_msg_null );
153  } break;
154  default : {
155  KMP_WARNING( IttUnknownError, err );
156  };
157  }; // switch
158 
159 } // __itt_error_handler
160 
161 #endif /* USE_ITT_BUILD */