Intel® OpenMP* Runtime Library
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups Pages
kmp_stub.c
1 /*
2  * kmp_stub.c -- stub versions of user-callable OpenMP RT functions.
3  * $Revision: 42150 $
4  * $Date: 2013-03-15 15:40:38 -0500 (Fri, 15 Mar 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 #include "kmp_stub.h"
38 
39 #include <stdlib.h>
40 #include <limits.h>
41 #include <errno.h>
42 
43 #include "kmp_os.h" // KMP_OS_*
44 
45 #if KMP_OS_WINDOWS
46  #include <windows.h>
47 #else
48  #include <sys/time.h>
49 #endif
50 
51 #include "kmp.h" // KMP_DEFAULT_STKSIZE
52 #include "kmp_version.h"
53 
54 #include "omp.h" // Function renamings.
55 
56 
57 static double frequency = 0.0;
58 
59 // Helper functions.
60 static size_t __kmps_init() {
61  static int initialized = 0;
62  static size_t dummy = 0;
63  if ( ! initialized ) {
64 
65  // TODO: Analyze KMP_VERSION environment variable, print __kmp_version_copyright and
66  // __kmp_version_build_time.
67  // WARNING: Do not use "fprintf( stderr, ... )" because it will cause unresolved "__iob"
68  // symbol (see C70080). We need to extract __kmp_printf() stuff from kmp_runtime.c and use
69  // it.
70 
71  // Trick with dummy variable forces linker to keep __kmp_version_copyright and
72  // __kmp_version_build_time strings in executable file (in case of static linkage).
73  // When KMP_VERSION analyze is implemented, dummy variable should be deleted, function
74  // should return void.
75  dummy = __kmp_version_copyright - __kmp_version_build_time;
76 
77  #if KMP_OS_WINDOWS
78  LARGE_INTEGER freq;
79  BOOL status = QueryPerformanceFrequency( & freq );
80  if ( status ) {
81  frequency = double( freq.QuadPart );
82  }; // if
83  #endif
84 
85  initialized = 1;
86  }; // if
87  return dummy;
88 }; // __kmps_init
89 
90 #define i __kmps_init();
91 
92 /* set API functions */
93 void omp_set_num_threads( omp_int_t num_threads ) { i; }
94 void omp_set_dynamic( omp_int_t dynamic ) { i; __kmps_set_dynamic( dynamic ); }
95 void omp_set_nested( omp_int_t nested ) { i; __kmps_set_nested( nested ); }
96 #if OMP_30_ENABLED
97  void omp_set_max_active_levels( omp_int_t max_active_levels ) { i; }
98  void omp_set_schedule( omp_sched_t kind, omp_int_t modifier ) { i; __kmps_set_schedule( (kmp_sched_t)kind, modifier ); }
99  int omp_get_ancestor_thread_num( omp_int_t level ) { i; return ( level ) ? ( -1 ) : ( 0 ); }
100  int omp_get_team_size( omp_int_t level ) { i; return ( level ) ? ( -1 ) : ( 1 ); }
101  int kmpc_set_affinity_mask_proc( int proc, void **mask ) { i; return -1; }
102  int kmpc_unset_affinity_mask_proc( int proc, void **mask ) { i; return -1; }
103  int kmpc_get_affinity_mask_proc( int proc, void **mask ) { i; return -1; }
104 #endif // OMP_30_ENABLED
105 
106 /* kmp API functions */
107 void kmp_set_stacksize( omp_int_t arg ) { i; __kmps_set_stacksize( arg ); }
108 void kmp_set_stacksize_s( size_t arg ) { i; __kmps_set_stacksize( arg ); }
109 void kmp_set_blocktime( omp_int_t arg ) { i; __kmps_set_blocktime( arg ); }
110 void kmp_set_library( omp_int_t arg ) { i; __kmps_set_library( arg ); }
111 void kmp_set_defaults( char const * str ) { i; }
112 
113 /* KMP memory management functions. */
114 void * kmp_malloc( size_t size ) { i; return malloc( size ); }
115 void * kmp_calloc( size_t nelem, size_t elsize ) { i; return calloc( nelem, elsize ); }
116 void * kmp_realloc( void *ptr, size_t size ) { i; return realloc( ptr, size ); }
117 void kmp_free( void * ptr ) { i; free( ptr ); }
118 
119 static int __kmps_blocktime = INT_MAX;
120 
121 void __kmps_set_blocktime( int arg ) {
122  i;
123  __kmps_blocktime = arg;
124 } // __kmps_set_blocktime
125 
126 int __kmps_get_blocktime( void ) {
127  i;
128  return __kmps_blocktime;
129 } // __kmps_get_blocktime
130 
131 static int __kmps_dynamic = 0;
132 
133 void __kmps_set_dynamic( int arg ) {
134  i;
135  __kmps_dynamic = arg;
136 } // __kmps_set_dynamic
137 
138 int __kmps_get_dynamic( void ) {
139  i;
140  return __kmps_dynamic;
141 } // __kmps_get_dynamic
142 
143 static int __kmps_library = 1000;
144 
145 void __kmps_set_library( int arg ) {
146  i;
147  __kmps_library = arg;
148 } // __kmps_set_library
149 
150 int __kmps_get_library( void ) {
151  i;
152  return __kmps_library;
153 } // __kmps_get_library
154 
155 static int __kmps_nested = 0;
156 
157 void __kmps_set_nested( int arg ) {
158  i;
159  __kmps_nested = arg;
160 } // __kmps_set_nested
161 
162 int __kmps_get_nested( void ) {
163  i;
164  return __kmps_nested;
165 } // __kmps_get_nested
166 
167 static size_t __kmps_stacksize = KMP_DEFAULT_STKSIZE;
168 
169 void __kmps_set_stacksize( int arg ) {
170  i;
171  __kmps_stacksize = arg;
172 } // __kmps_set_stacksize
173 
174 int __kmps_get_stacksize( void ) {
175  i;
176  return __kmps_stacksize;
177 } // __kmps_get_stacksize
178 
179 #if OMP_30_ENABLED
180 
181 static kmp_sched_t __kmps_sched_kind = kmp_sched_default;
182 static int __kmps_sched_modifier = 0;
183 
184  void __kmps_set_schedule( kmp_sched_t kind, int modifier ) {
185  i;
186  __kmps_sched_kind = kind;
187  __kmps_sched_modifier = modifier;
188  } // __kmps_set_schedule
189 
190  void __kmps_get_schedule( kmp_sched_t *kind, int *modifier ) {
191  i;
192  *kind = __kmps_sched_kind;
193  *modifier = __kmps_sched_modifier;
194  } // __kmps_get_schedule
195 
196 #endif // OMP_30_ENABLED
197 
198 #if OMP_40_ENABLED
199 
200 static kmp_proc_bind_t __kmps_proc_bind = proc_bind_false;
201 
202 void __kmps_set_proc_bind( kmp_proc_bind_t arg ) {
203  i;
204  __kmps_proc_bind = arg;
205 } // __kmps_set_proc_bind
206 
207 kmp_proc_bind_t __kmps_get_proc_bind( void ) {
208  i;
209  return __kmps_proc_bind;
210 } // __kmps_get_proc_bind
211 
212 #endif /* OMP_40_ENABLED */
213 
214 double __kmps_get_wtime( void ) {
215  // Elapsed wall clock time (in second) from "sometime in the past".
216  double wtime = 0.0;
217  i;
218  #if KMP_OS_WINDOWS
219  if ( frequency > 0.0 ) {
220  LARGE_INTEGER now;
221  BOOL status = QueryPerformanceCounter( & now );
222  if ( status ) {
223  wtime = double( now.QuadPart ) / frequency;
224  }; // if
225  }; // if
226  #else
227  // gettimeofday() returns seconds and microseconds sinse the Epoch.
228  struct timeval tval;
229  int rc;
230  rc = gettimeofday( & tval, NULL );
231  if ( rc == 0 ) {
232  wtime = (double)( tval.tv_sec ) + 1.0E-06 * (double)( tval.tv_usec );
233  } else {
234  // TODO: Assert or abort here.
235  }; // if
236  #endif
237  return wtime;
238 }; // __kmps_get_wtime
239 
240 double __kmps_get_wtick( void ) {
241  // Number of seconds between successive clock ticks.
242  double wtick = 0.0;
243  i;
244  #if KMP_OS_WINDOWS
245  {
246  DWORD increment;
247  DWORD adjustment;
248  BOOL disabled;
249  BOOL rc;
250  rc = GetSystemTimeAdjustment( & adjustment, & increment, & disabled );
251  if ( rc ) {
252  wtick = 1.0E-07 * (double)( disabled ? increment : adjustment );
253  } else {
254  // TODO: Assert or abort here.
255  wtick = 1.0E-03;
256  }; // if
257  }
258  #else
259  // TODO: gettimeofday() returns in microseconds, but what the precision?
260  wtick = 1.0E-06;
261  #endif
262  return wtick;
263 }; // __kmps_get_wtick
264 
265 
266 /*
267  These functions are exported from libraries, but not declared in omp,h and omp_lib.f:
268 
269  // omalyshe: eight entries below removed from the library (2011-11-22)
270  kmpc_get_banner
271  kmpc_get_poolmode
272  kmpc_get_poolsize
273  kmpc_get_poolstat
274  kmpc_poolprint
275  kmpc_print_banner
276  kmpc_set_poolmode
277  kmpc_set_poolsize
278 
279  kmpc_set_affinity
280  kmp_threadprivate_insert
281  kmp_threadprivate_insert_private_data
282  VT_getthid
283  vtgthid
284 
285  The list is collected on lin_32.
286 
287 */
288 
289 // end of file //
290