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