kmp_stub.c

Go to the documentation of this file.
00001 /*
00002  * kmp_stub.c -- stub versions of user-callable OpenMP RT functions.
00003  * $Revision: 42150 $
00004  * $Date: 2013-03-15 15:40:38 -0500 (Fri, 15 Mar 2013) $
00005  */
00006 
00007 /* <copyright>
00008     Copyright (c) 1997-2013 Intel Corporation.  All Rights Reserved.
00009 
00010     Redistribution and use in source and binary forms, with or without
00011     modification, are permitted provided that the following conditions
00012     are met:
00013 
00014       * Redistributions of source code must retain the above copyright
00015         notice, this list of conditions and the following disclaimer.
00016       * Redistributions in binary form must reproduce the above copyright
00017         notice, this list of conditions and the following disclaimer in the
00018         documentation and/or other materials provided with the distribution.
00019       * Neither the name of Intel Corporation nor the names of its
00020         contributors may be used to endorse or promote products derived
00021         from this software without specific prior written permission.
00022 
00023     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027     HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 
00035 
00036 ------------------------------------------------------------------------
00037 
00038     Portions of this software are protected under the following patents:
00039         U.S. Patent 5,812,852
00040         U.S. Patent 6,792,599
00041         U.S. Patent 7,069,556
00042         U.S. Patent 7,328,433
00043         U.S. Patent 7,500,242
00044 
00045 </copyright> */
00046 
00047 #include "kmp_stub.h"
00048 
00049 #include <stdlib.h>
00050 #include <limits.h>
00051 #include <errno.h>
00052 
00053 #include "kmp_os.h"             // KMP_OS_*
00054 
00055 #if KMP_OS_WINDOWS
00056     #include <windows.h>
00057 #else
00058     #include <sys/time.h>
00059 #endif
00060 
00061 #include "kmp.h"                // KMP_DEFAULT_STKSIZE
00062 #include "kmp_version.h"
00063 
00064 #include "omp.h"                // Function renamings.
00065 
00066 
00067 static double frequency = 0.0;
00068 
00069 // Helper functions.
00070 static size_t __kmps_init() {
00071     static int    initialized = 0;
00072     static size_t dummy = 0;
00073     if ( ! initialized ) {
00074 
00075         // TODO: Analyze KMP_VERSION environment variable, print __kmp_version_copyright and
00076         // __kmp_version_build_time.
00077         // WARNING: Do not use "fprintf( stderr, ... )" because it will cause unresolved "__iob"
00078         // symbol (see C70080). We need to extract __kmp_printf() stuff from kmp_runtime.c and use
00079         // it.
00080 
00081         // Trick with dummy variable forces linker to keep __kmp_version_copyright and
00082         // __kmp_version_build_time strings in executable file (in case of static linkage).
00083         // When KMP_VERSION analyze is implemented, dummy variable should be deleted, function
00084         // should return void.
00085         dummy = __kmp_version_copyright - __kmp_version_build_time;
00086 
00087         #if KMP_OS_WINDOWS
00088             LARGE_INTEGER freq;
00089             BOOL status = QueryPerformanceFrequency( & freq );
00090             if ( status ) {
00091                 frequency = double( freq.QuadPart );
00092             }; // if
00093         #endif
00094 
00095         initialized = 1;
00096     }; // if
00097     return dummy;
00098 }; // __kmps_init
00099 
00100 #define i __kmps_init();
00101 
00102 /* set API functions */
00103 void omp_set_num_threads( omp_int_t num_threads ) { i; }
00104 void omp_set_dynamic( omp_int_t dynamic )         { i; __kmps_set_dynamic( dynamic ); }
00105 void omp_set_nested( omp_int_t nested )           { i; __kmps_set_nested( nested );   }
00106 #if OMP_30_ENABLED
00107     void omp_set_max_active_levels( omp_int_t max_active_levels ) { i; }
00108     void omp_set_schedule( omp_sched_t kind, omp_int_t modifier ) { i; __kmps_set_schedule( (kmp_sched_t)kind, modifier ); }
00109     int omp_get_ancestor_thread_num( omp_int_t level ) { i; return ( level ) ? ( -1 ) : ( 0 ); }
00110     int omp_get_team_size( omp_int_t level ) { i; return ( level ) ? ( -1 ) : ( 1 ); }
00111     int kmpc_set_affinity_mask_proc( int proc, void **mask ) { i; return -1; }
00112     int kmpc_unset_affinity_mask_proc( int proc, void **mask ) { i; return -1; }
00113     int kmpc_get_affinity_mask_proc( int proc, void **mask ) { i; return -1; }
00114 #endif // OMP_30_ENABLED
00115 
00116 /* kmp API functions */
00117 void kmp_set_stacksize( omp_int_t arg )   { i; __kmps_set_stacksize( arg ); }
00118 void kmp_set_stacksize_s( size_t arg )    { i; __kmps_set_stacksize( arg ); }
00119 void kmp_set_blocktime( omp_int_t arg )   { i; __kmps_set_blocktime( arg ); }
00120 void kmp_set_library( omp_int_t arg )     { i; __kmps_set_library( arg ); }
00121 void kmp_set_defaults( char const * str ) { i; }
00122 
00123 /* KMP memory management functions. */
00124 void * kmp_malloc( size_t size )                 { i; return malloc( size ); }
00125 void * kmp_calloc( size_t nelem, size_t elsize ) { i; return calloc( nelem, elsize ); }
00126 void * kmp_realloc( void *ptr, size_t size )     { i; return realloc( ptr, size ); }
00127 void   kmp_free( void * ptr )                    { i; free( ptr ); }
00128 
00129 static int __kmps_blocktime = INT_MAX;
00130 
00131 void __kmps_set_blocktime( int arg ) {
00132     i;
00133     __kmps_blocktime = arg;
00134 } // __kmps_set_blocktime
00135 
00136 int __kmps_get_blocktime( void ) {
00137     i;
00138     return __kmps_blocktime;
00139 } // __kmps_get_blocktime
00140 
00141 static int __kmps_dynamic = 0;
00142 
00143 void __kmps_set_dynamic( int arg ) {
00144     i;
00145     __kmps_dynamic = arg;
00146 } // __kmps_set_dynamic
00147 
00148 int __kmps_get_dynamic( void ) {
00149     i;
00150     return __kmps_dynamic;
00151 } // __kmps_get_dynamic
00152 
00153 static int __kmps_library = 1000;
00154 
00155 void __kmps_set_library( int arg ) {
00156     i;
00157     __kmps_library = arg;
00158 } // __kmps_set_library
00159 
00160 int __kmps_get_library( void ) {
00161     i;
00162     return __kmps_library;
00163 } // __kmps_get_library
00164 
00165 static int __kmps_nested = 0;
00166 
00167 void __kmps_set_nested( int arg ) {
00168     i;
00169     __kmps_nested = arg;
00170 } // __kmps_set_nested
00171 
00172 int __kmps_get_nested( void ) {
00173     i;
00174     return __kmps_nested;
00175 } // __kmps_get_nested
00176 
00177 static size_t __kmps_stacksize = KMP_DEFAULT_STKSIZE;
00178 
00179 void __kmps_set_stacksize( int arg ) {
00180     i;
00181     __kmps_stacksize = arg;
00182 } // __kmps_set_stacksize
00183 
00184 int __kmps_get_stacksize( void ) {
00185     i;
00186     return __kmps_stacksize;
00187 } // __kmps_get_stacksize
00188 
00189 #if OMP_30_ENABLED
00190 
00191 static kmp_sched_t __kmps_sched_kind     = kmp_sched_default;
00192 static int         __kmps_sched_modifier = 0;
00193 
00194     void __kmps_set_schedule( kmp_sched_t kind, int modifier ) {
00195         i;
00196         __kmps_sched_kind     = kind;
00197         __kmps_sched_modifier = modifier;
00198     } // __kmps_set_schedule
00199 
00200     void __kmps_get_schedule( kmp_sched_t *kind, int *modifier ) {
00201         i;
00202         *kind     = __kmps_sched_kind;
00203         *modifier = __kmps_sched_modifier;
00204     } // __kmps_get_schedule
00205 
00206 #endif // OMP_30_ENABLED
00207 
00208 #if OMP_40_ENABLED
00209 
00210 static kmp_proc_bind_t __kmps_proc_bind = proc_bind_false;
00211 
00212 void __kmps_set_proc_bind( kmp_proc_bind_t arg ) {
00213     i;
00214     __kmps_proc_bind = arg;
00215 } // __kmps_set_proc_bind
00216 
00217 kmp_proc_bind_t __kmps_get_proc_bind( void ) {
00218     i;
00219     return __kmps_proc_bind;
00220 } // __kmps_get_proc_bind
00221 
00222 #endif /* OMP_40_ENABLED */
00223 
00224 double __kmps_get_wtime( void ) {
00225     // Elapsed wall clock time (in second) from "sometime in the past".
00226     double wtime = 0.0;
00227     i;
00228     #if KMP_OS_WINDOWS
00229         if ( frequency > 0.0 ) {
00230             LARGE_INTEGER now;
00231             BOOL status = QueryPerformanceCounter( & now );
00232             if ( status ) {
00233                 wtime = double( now.QuadPart ) / frequency;
00234             }; // if
00235         }; // if
00236     #else
00237         // gettimeofday() returns seconds and microseconds sinse the Epoch.
00238         struct timeval  tval;
00239         int             rc;
00240         rc = gettimeofday( & tval, NULL );
00241         if ( rc == 0 ) {
00242             wtime = (double)( tval.tv_sec ) + 1.0E-06 * (double)( tval.tv_usec );
00243         } else {
00244             // TODO: Assert or abort here.
00245         }; // if
00246     #endif
00247     return wtime;
00248 }; // __kmps_get_wtime
00249 
00250 double __kmps_get_wtick( void ) {
00251     // Number of seconds between successive clock ticks.
00252     double wtick = 0.0;
00253     i;
00254     #if KMP_OS_WINDOWS
00255         {
00256             DWORD increment;
00257             DWORD adjustment;
00258             BOOL  disabled;
00259             BOOL  rc;
00260             rc = GetSystemTimeAdjustment( & adjustment, & increment, & disabled );
00261             if ( rc ) {
00262                 wtick = 1.0E-07 * (double)( disabled ? increment : adjustment );
00263             } else {
00264                 // TODO: Assert or abort here.
00265                 wtick = 1.0E-03;
00266             }; // if
00267         }
00268     #else
00269         // TODO: gettimeofday() returns in microseconds, but what the precision?
00270         wtick = 1.0E-06;
00271     #endif
00272     return wtick;
00273 }; // __kmps_get_wtick
00274 
00275 
00276 /*
00277     These functions are exported from libraries, but not declared in omp,h and omp_lib.f:
00278 
00279         // omalyshe: eight entries below removed from the library (2011-11-22)
00280         kmpc_get_banner
00281         kmpc_get_poolmode
00282         kmpc_get_poolsize
00283         kmpc_get_poolstat
00284         kmpc_poolprint
00285         kmpc_print_banner
00286         kmpc_set_poolmode
00287         kmpc_set_poolsize
00288 
00289         kmpc_set_affinity
00290         kmp_threadprivate_insert
00291         kmp_threadprivate_insert_private_data
00292         VT_getthid
00293         vtgthid
00294 
00295     The list is collected on lin_32.
00296 
00297 */
00298 
00299 // end of file //
00300 

Generated on 25 Aug 2013 for libomp_oss by  doxygen 1.6.1