[Openmp-commits] [openmp] r302929 - Clang-format and whitespace cleanup of source code
Jonathan Peyton via Openmp-commits
openmp-commits at lists.llvm.org
Fri May 12 11:01:35 PDT 2017
Modified: openmp/trunk/runtime/src/kmp_runtime.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_runtime.cpp?rev=302929&r1=302928&r2=302929&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_runtime.cpp (original)
+++ openmp/trunk/runtime/src/kmp_runtime.cpp Fri May 12 13:01:32 2017
@@ -14,18 +14,18 @@
#include "kmp.h"
+#include "kmp_affinity.h"
#include "kmp_atomic.h"
-#include "kmp_wrapper_getpid.h"
#include "kmp_environment.h"
-#include "kmp_itt.h"
-#include "kmp_str.h"
-#include "kmp_settings.h"
+#include "kmp_error.h"
#include "kmp_i18n.h"
#include "kmp_io.h"
-#include "kmp_error.h"
+#include "kmp_itt.h"
+#include "kmp_settings.h"
#include "kmp_stats.h"
+#include "kmp_str.h"
#include "kmp_wait_release.h"
-#include "kmp_affinity.h"
+#include "kmp_wrapper_getpid.h"
#if OMPT_SUPPORT
#include "ompt-specific.h"
@@ -41,494 +41,499 @@
#include "tsan_annotations.h"
#if defined(KMP_GOMP_COMPAT)
-char const __kmp_version_alt_comp[] = KMP_VERSION_PREFIX "alternative compiler support: yes";
+char const __kmp_version_alt_comp[] =
+ KMP_VERSION_PREFIX "alternative compiler support: yes";
#endif /* defined(KMP_GOMP_COMPAT) */
char const __kmp_version_omp_api[] = KMP_VERSION_PREFIX "API version: "
#if OMP_50_ENABLED
- "5.0 (201611)";
+ "5.0 (201611)";
#elif OMP_45_ENABLED
- "4.5 (201511)";
+ "4.5 (201511)";
#elif OMP_40_ENABLED
- "4.0 (201307)";
+ "4.0 (201307)";
#else
- "3.1 (201107)";
+ "3.1 (201107)";
#endif
#ifdef KMP_DEBUG
-char const __kmp_version_lock[] = KMP_VERSION_PREFIX "lock type: run time selectable";
+char const __kmp_version_lock[] =
+ KMP_VERSION_PREFIX "lock type: run time selectable";
#endif /* KMP_DEBUG */
-#define KMP_MIN( x, y ) ( (x) < (y) ? (x) : (y) )
+#define KMP_MIN(x, y) ((x) < (y) ? (x) : (y))
/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
kmp_info_t __kmp_monitor;
-/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
-
/* Forward declarations */
-void __kmp_cleanup( void );
+void __kmp_cleanup(void);
-static void __kmp_initialize_info( kmp_info_t *, kmp_team_t *, int tid, int gtid );
-static void __kmp_initialize_team( kmp_team_t * team, int new_nproc, kmp_internal_control_t * new_icvs, ident_t * loc );
+static void __kmp_initialize_info(kmp_info_t *, kmp_team_t *, int tid,
+ int gtid);
+static void __kmp_initialize_team(kmp_team_t *team, int new_nproc,
+ kmp_internal_control_t *new_icvs,
+ ident_t *loc);
#if OMP_40_ENABLED && KMP_AFFINITY_SUPPORTED
-static void __kmp_partition_places( kmp_team_t *team, int update_master_only=0 );
+static void __kmp_partition_places(kmp_team_t *team,
+ int update_master_only = 0);
#endif
-static void __kmp_do_serial_initialize( void );
-void __kmp_fork_barrier( int gtid, int tid );
-void __kmp_join_barrier( int gtid );
-void __kmp_setup_icv_copy( kmp_team_t *team, int new_nproc, kmp_internal_control_t * new_icvs, ident_t *loc );
+static void __kmp_do_serial_initialize(void);
+void __kmp_fork_barrier(int gtid, int tid);
+void __kmp_join_barrier(int gtid);
+void __kmp_setup_icv_copy(kmp_team_t *team, int new_nproc,
+ kmp_internal_control_t *new_icvs, ident_t *loc);
#ifdef USE_LOAD_BALANCE
-static int __kmp_load_balance_nproc( kmp_root_t * root, int set_nproc );
+static int __kmp_load_balance_nproc(kmp_root_t *root, int set_nproc);
#endif
static int __kmp_expand_threads(int nWish, int nNeed);
#if KMP_OS_WINDOWS
-static int __kmp_unregister_root_other_thread( int gtid );
+static int __kmp_unregister_root_other_thread(int gtid);
#endif
-static void __kmp_unregister_library( void ); // called by __kmp_internal_end()
-static void __kmp_reap_thread( kmp_info_t * thread, int is_root );
+static void __kmp_unregister_library(void); // called by __kmp_internal_end()
+static void __kmp_reap_thread(kmp_info_t *thread, int is_root);
static kmp_info_t *__kmp_thread_pool_insert_pt = NULL;
-/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
-
/* Calculate the identifier of the current thread */
-/* fast (and somewhat portable) way to get unique */
-/* identifier of executing thread. */
-/* returns KMP_GTID_DNE if we haven't been assigned a gtid */
-
-int
-__kmp_get_global_thread_id( )
-{
- int i;
- kmp_info_t **other_threads;
- size_t stack_data;
- char *stack_addr;
- size_t stack_size;
- char *stack_base;
-
- KA_TRACE( 1000, ( "*** __kmp_get_global_thread_id: entering, nproc=%d all_nproc=%d\n",
- __kmp_nth, __kmp_all_nth ));
-
- /* JPH - to handle the case where __kmpc_end(0) is called immediately prior to a
- parallel region, made it return KMP_GTID_DNE to force serial_initialize by
- caller. Had to handle KMP_GTID_DNE at all call-sites, or else guarantee
- __kmp_init_gtid for this to work. */
+/* fast (and somewhat portable) way to get unique identifier of executing
+ thread. Returns KMP_GTID_DNE if we haven't been assigned a gtid. */
- if ( !TCR_4(__kmp_init_gtid) ) return KMP_GTID_DNE;
+int __kmp_get_global_thread_id() {
+ int i;
+ kmp_info_t **other_threads;
+ size_t stack_data;
+ char *stack_addr;
+ size_t stack_size;
+ char *stack_base;
+
+ KA_TRACE(
+ 1000,
+ ("*** __kmp_get_global_thread_id: entering, nproc=%d all_nproc=%d\n",
+ __kmp_nth, __kmp_all_nth));
+
+ /* JPH - to handle the case where __kmpc_end(0) is called immediately prior to
+ a parallel region, made it return KMP_GTID_DNE to force serial_initialize
+ by caller. Had to handle KMP_GTID_DNE at all call-sites, or else guarantee
+ __kmp_init_gtid for this to work. */
+
+ if (!TCR_4(__kmp_init_gtid))
+ return KMP_GTID_DNE;
#ifdef KMP_TDATA_GTID
- if ( TCR_4(__kmp_gtid_mode) >= 3) {
- KA_TRACE( 1000, ( "*** __kmp_get_global_thread_id: using TDATA\n" ));
- return __kmp_gtid;
- }
-#endif
- if ( TCR_4(__kmp_gtid_mode) >= 2) {
- KA_TRACE( 1000, ( "*** __kmp_get_global_thread_id: using keyed TLS\n" ));
- return __kmp_gtid_get_specific();
- }
- KA_TRACE( 1000, ( "*** __kmp_get_global_thread_id: using internal alg.\n" ));
-
- stack_addr = (char*) & stack_data;
- other_threads = __kmp_threads;
-
- /*
- ATT: The code below is a source of potential bugs due to unsynchronized access to
- __kmp_threads array. For example:
- 1. Current thread loads other_threads[i] to thr and checks it, it is non-NULL.
- 2. Current thread is suspended by OS.
- 3. Another thread unregisters and finishes (debug versions of free() may fill memory
- with something like 0xEF).
- 4. Current thread is resumed.
- 5. Current thread reads junk from *thr.
- TODO: Fix it.
- --ln
- */
-
- for( i = 0 ; i < __kmp_threads_capacity ; i++ ) {
-
- kmp_info_t *thr = (kmp_info_t *)TCR_SYNC_PTR(other_threads[i]);
- if( !thr ) continue;
-
- stack_size = (size_t)TCR_PTR(thr->th.th_info.ds.ds_stacksize);
- stack_base = (char *)TCR_PTR(thr->th.th_info.ds.ds_stackbase);
-
- /* stack grows down -- search through all of the active threads */
-
- if( stack_addr <= stack_base ) {
- size_t stack_diff = stack_base - stack_addr;
-
- if( stack_diff <= stack_size ) {
- /* The only way we can be closer than the allocated */
- /* stack size is if we are running on this thread. */
- KMP_DEBUG_ASSERT( __kmp_gtid_get_specific() == i );
- return i;
- }
- }
- }
+ if (TCR_4(__kmp_gtid_mode) >= 3) {
+ KA_TRACE(1000, ("*** __kmp_get_global_thread_id: using TDATA\n"));
+ return __kmp_gtid;
+ }
+#endif
+ if (TCR_4(__kmp_gtid_mode) >= 2) {
+ KA_TRACE(1000, ("*** __kmp_get_global_thread_id: using keyed TLS\n"));
+ return __kmp_gtid_get_specific();
+ }
+ KA_TRACE(1000, ("*** __kmp_get_global_thread_id: using internal alg.\n"));
+
+ stack_addr = (char *)&stack_data;
+ other_threads = __kmp_threads;
+
+ /* ATT: The code below is a source of potential bugs due to unsynchronized
+ access to __kmp_threads array. For example:
+ 1. Current thread loads other_threads[i] to thr and checks it, it is
+ non-NULL.
+ 2. Current thread is suspended by OS.
+ 3. Another thread unregisters and finishes (debug versions of free()
+ may fill memory with something like 0xEF).
+ 4. Current thread is resumed.
+ 5. Current thread reads junk from *thr.
+ TODO: Fix it. --ln */
+
+ for (i = 0; i < __kmp_threads_capacity; i++) {
+
+ kmp_info_t *thr = (kmp_info_t *)TCR_SYNC_PTR(other_threads[i]);
+ if (!thr)
+ continue;
+
+ stack_size = (size_t)TCR_PTR(thr->th.th_info.ds.ds_stacksize);
+ stack_base = (char *)TCR_PTR(thr->th.th_info.ds.ds_stackbase);
+
+ /* stack grows down -- search through all of the active threads */
+
+ if (stack_addr <= stack_base) {
+ size_t stack_diff = stack_base - stack_addr;
+
+ if (stack_diff <= stack_size) {
+ /* The only way we can be closer than the allocated */
+ /* stack size is if we are running on this thread. */
+ KMP_DEBUG_ASSERT(__kmp_gtid_get_specific() == i);
+ return i;
+ }
+ }
+ }
+
+ /* get specific to try and determine our gtid */
+ KA_TRACE(1000,
+ ("*** __kmp_get_global_thread_id: internal alg. failed to find "
+ "thread, using TLS\n"));
+ i = __kmp_gtid_get_specific();
- /* get specific to try and determine our gtid */
- KA_TRACE( 1000, ( "*** __kmp_get_global_thread_id: internal alg. failed to find "
- "thread, using TLS\n" ));
- i = __kmp_gtid_get_specific();
-
- /*fprintf( stderr, "=== %d\n", i ); */ /* GROO */
-
- /* if we havn't been assigned a gtid, then return code */
- if( i<0 ) return i;
-
- /* dynamically updated stack window for uber threads to avoid get_specific call */
- if( ! TCR_4(other_threads[i]->th.th_info.ds.ds_stackgrow) ) {
- KMP_FATAL( StackOverflow, i );
- }
-
- stack_base = (char *) other_threads[i]->th.th_info.ds.ds_stackbase;
- if( stack_addr > stack_base ) {
- TCW_PTR(other_threads[i]->th.th_info.ds.ds_stackbase, stack_addr);
- TCW_PTR(other_threads[i]->th.th_info.ds.ds_stacksize,
- other_threads[i]->th.th_info.ds.ds_stacksize + stack_addr - stack_base);
- } else {
- TCW_PTR(other_threads[i]->th.th_info.ds.ds_stacksize, stack_base - stack_addr);
- }
+ /*fprintf( stderr, "=== %d\n", i ); */ /* GROO */
- /* Reprint stack bounds for ubermaster since they have been refined */
- if ( __kmp_storage_map ) {
- char *stack_end = (char *) other_threads[i]->th.th_info.ds.ds_stackbase;
- char *stack_beg = stack_end - other_threads[i]->th.th_info.ds.ds_stacksize;
- __kmp_print_storage_map_gtid( i, stack_beg, stack_end,
- other_threads[i]->th.th_info.ds.ds_stacksize,
- "th_%d stack (refinement)", i );
- }
+ /* if we havn't been assigned a gtid, then return code */
+ if (i < 0)
return i;
-}
-int
-__kmp_get_global_thread_id_reg( )
-{
- int gtid;
-
- if ( !__kmp_init_serial ) {
- gtid = KMP_GTID_DNE;
- } else
+ /* dynamically updated stack window for uber threads to avoid get_specific
+ call */
+ if (!TCR_4(other_threads[i]->th.th_info.ds.ds_stackgrow)) {
+ KMP_FATAL(StackOverflow, i);
+ }
+
+ stack_base = (char *)other_threads[i]->th.th_info.ds.ds_stackbase;
+ if (stack_addr > stack_base) {
+ TCW_PTR(other_threads[i]->th.th_info.ds.ds_stackbase, stack_addr);
+ TCW_PTR(other_threads[i]->th.th_info.ds.ds_stacksize,
+ other_threads[i]->th.th_info.ds.ds_stacksize + stack_addr -
+ stack_base);
+ } else {
+ TCW_PTR(other_threads[i]->th.th_info.ds.ds_stacksize,
+ stack_base - stack_addr);
+ }
+
+ /* Reprint stack bounds for ubermaster since they have been refined */
+ if (__kmp_storage_map) {
+ char *stack_end = (char *)other_threads[i]->th.th_info.ds.ds_stackbase;
+ char *stack_beg = stack_end - other_threads[i]->th.th_info.ds.ds_stacksize;
+ __kmp_print_storage_map_gtid(i, stack_beg, stack_end,
+ other_threads[i]->th.th_info.ds.ds_stacksize,
+ "th_%d stack (refinement)", i);
+ }
+ return i;
+}
+
+int __kmp_get_global_thread_id_reg() {
+ int gtid;
+
+ if (!__kmp_init_serial) {
+ gtid = KMP_GTID_DNE;
+ } else
#ifdef KMP_TDATA_GTID
- if ( TCR_4(__kmp_gtid_mode) >= 3 ) {
- KA_TRACE( 1000, ( "*** __kmp_get_global_thread_id_reg: using TDATA\n" ));
- gtid = __kmp_gtid;
- } else
-#endif
- if ( TCR_4(__kmp_gtid_mode) >= 2 ) {
- KA_TRACE( 1000, ( "*** __kmp_get_global_thread_id_reg: using keyed TLS\n" ));
- gtid = __kmp_gtid_get_specific();
+ if (TCR_4(__kmp_gtid_mode) >= 3) {
+ KA_TRACE(1000, ("*** __kmp_get_global_thread_id_reg: using TDATA\n"));
+ gtid = __kmp_gtid;
+ } else
+#endif
+ if (TCR_4(__kmp_gtid_mode) >= 2) {
+ KA_TRACE(1000, ("*** __kmp_get_global_thread_id_reg: using keyed TLS\n"));
+ gtid = __kmp_gtid_get_specific();
+ } else {
+ KA_TRACE(1000,
+ ("*** __kmp_get_global_thread_id_reg: using internal alg.\n"));
+ gtid = __kmp_get_global_thread_id();
+ }
+
+ /* we must be a new uber master sibling thread */
+ if (gtid == KMP_GTID_DNE) {
+ KA_TRACE(10,
+ ("__kmp_get_global_thread_id_reg: Encountered new root thread. "
+ "Registering a new gtid.\n"));
+ __kmp_acquire_bootstrap_lock(&__kmp_initz_lock);
+ if (!__kmp_init_serial) {
+ __kmp_do_serial_initialize();
+ gtid = __kmp_gtid_get_specific();
} else {
- KA_TRACE( 1000, ( "*** __kmp_get_global_thread_id_reg: using internal alg.\n" ));
- gtid = __kmp_get_global_thread_id();
- }
-
- /* we must be a new uber master sibling thread */
- if( gtid == KMP_GTID_DNE ) {
- KA_TRACE( 10, ( "__kmp_get_global_thread_id_reg: Encountered new root thread. "
- "Registering a new gtid.\n" ));
- __kmp_acquire_bootstrap_lock( &__kmp_initz_lock );
- if( !__kmp_init_serial ) {
- __kmp_do_serial_initialize();
- gtid = __kmp_gtid_get_specific();
- } else {
- gtid = __kmp_register_root(FALSE);
- }
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
- /*__kmp_printf( "+++ %d\n", gtid ); */ /* GROO */
+ gtid = __kmp_register_root(FALSE);
}
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
+ /*__kmp_printf( "+++ %d\n", gtid ); */ /* GROO */
+ }
- KMP_DEBUG_ASSERT( gtid >=0 );
+ KMP_DEBUG_ASSERT(gtid >= 0);
- return gtid;
+ return gtid;
}
/* caller must hold forkjoin_lock */
-void
-__kmp_check_stack_overlap( kmp_info_t *th )
-{
- int f;
- char *stack_beg = NULL;
- char *stack_end = NULL;
- int gtid;
-
- KA_TRACE(10,("__kmp_check_stack_overlap: called\n"));
- if ( __kmp_storage_map ) {
- stack_end = (char *) th->th.th_info.ds.ds_stackbase;
- stack_beg = stack_end - th->th.th_info.ds.ds_stacksize;
-
- gtid = __kmp_gtid_from_thread( th );
-
- if (gtid == KMP_GTID_MONITOR) {
- __kmp_print_storage_map_gtid( gtid, stack_beg, stack_end, th->th.th_info.ds.ds_stacksize,
- "th_%s stack (%s)", "mon",
- ( th->th.th_info.ds.ds_stackgrow ) ? "initial" : "actual" );
- } else {
- __kmp_print_storage_map_gtid( gtid, stack_beg, stack_end, th->th.th_info.ds.ds_stacksize,
- "th_%d stack (%s)", gtid,
- ( th->th.th_info.ds.ds_stackgrow ) ? "initial" : "actual" );
- }
- }
-
- /* No point in checking ubermaster threads since they use refinement and cannot overlap */
- gtid = __kmp_gtid_from_thread( th );
- if ( __kmp_env_checks == TRUE && !KMP_UBER_GTID(gtid))
- {
- KA_TRACE(10,("__kmp_check_stack_overlap: performing extensive checking\n"));
- if ( stack_beg == NULL ) {
- stack_end = (char *) th->th.th_info.ds.ds_stackbase;
- stack_beg = stack_end - th->th.th_info.ds.ds_stacksize;
- }
-
- for( f=0 ; f < __kmp_threads_capacity ; f++ ) {
- kmp_info_t *f_th = (kmp_info_t *)TCR_SYNC_PTR(__kmp_threads[f]);
+void __kmp_check_stack_overlap(kmp_info_t *th) {
+ int f;
+ char *stack_beg = NULL;
+ char *stack_end = NULL;
+ int gtid;
+
+ KA_TRACE(10, ("__kmp_check_stack_overlap: called\n"));
+ if (__kmp_storage_map) {
+ stack_end = (char *)th->th.th_info.ds.ds_stackbase;
+ stack_beg = stack_end - th->th.th_info.ds.ds_stacksize;
+
+ gtid = __kmp_gtid_from_thread(th);
+
+ if (gtid == KMP_GTID_MONITOR) {
+ __kmp_print_storage_map_gtid(
+ gtid, stack_beg, stack_end, th->th.th_info.ds.ds_stacksize,
+ "th_%s stack (%s)", "mon",
+ (th->th.th_info.ds.ds_stackgrow) ? "initial" : "actual");
+ } else {
+ __kmp_print_storage_map_gtid(
+ gtid, stack_beg, stack_end, th->th.th_info.ds.ds_stacksize,
+ "th_%d stack (%s)", gtid,
+ (th->th.th_info.ds.ds_stackgrow) ? "initial" : "actual");
+ }
+ }
+
+ /* No point in checking ubermaster threads since they use refinement and
+ * cannot overlap */
+ gtid = __kmp_gtid_from_thread(th);
+ if (__kmp_env_checks == TRUE && !KMP_UBER_GTID(gtid)) {
+ KA_TRACE(10,
+ ("__kmp_check_stack_overlap: performing extensive checking\n"));
+ if (stack_beg == NULL) {
+ stack_end = (char *)th->th.th_info.ds.ds_stackbase;
+ stack_beg = stack_end - th->th.th_info.ds.ds_stacksize;
+ }
+
+ for (f = 0; f < __kmp_threads_capacity; f++) {
+ kmp_info_t *f_th = (kmp_info_t *)TCR_SYNC_PTR(__kmp_threads[f]);
+
+ if (f_th && f_th != th) {
+ char *other_stack_end =
+ (char *)TCR_PTR(f_th->th.th_info.ds.ds_stackbase);
+ char *other_stack_beg =
+ other_stack_end - (size_t)TCR_PTR(f_th->th.th_info.ds.ds_stacksize);
+ if ((stack_beg > other_stack_beg && stack_beg < other_stack_end) ||
+ (stack_end > other_stack_beg && stack_end < other_stack_end)) {
- if( f_th && f_th != th ) {
- char *other_stack_end = (char *)TCR_PTR(f_th->th.th_info.ds.ds_stackbase);
- char *other_stack_beg = other_stack_end -
- (size_t)TCR_PTR(f_th->th.th_info.ds.ds_stacksize);
- if((stack_beg > other_stack_beg && stack_beg < other_stack_end) ||
- (stack_end > other_stack_beg && stack_end < other_stack_end)) {
-
- /* Print the other stack values before the abort */
- if ( __kmp_storage_map )
- __kmp_print_storage_map_gtid( -1, other_stack_beg, other_stack_end,
- (size_t)TCR_PTR(f_th->th.th_info.ds.ds_stacksize),
- "th_%d stack (overlapped)",
- __kmp_gtid_from_thread( f_th ) );
+ /* Print the other stack values before the abort */
+ if (__kmp_storage_map)
+ __kmp_print_storage_map_gtid(
+ -1, other_stack_beg, other_stack_end,
+ (size_t)TCR_PTR(f_th->th.th_info.ds.ds_stacksize),
+ "th_%d stack (overlapped)", __kmp_gtid_from_thread(f_th));
- __kmp_msg( kmp_ms_fatal, KMP_MSG( StackOverlap ), KMP_HNT( ChangeStackLimit ), __kmp_msg_null );
- }
- }
+ __kmp_msg(kmp_ms_fatal, KMP_MSG(StackOverlap),
+ KMP_HNT(ChangeStackLimit), __kmp_msg_null);
}
+ }
}
- KA_TRACE(10,("__kmp_check_stack_overlap: returning\n"));
+ }
+ KA_TRACE(10, ("__kmp_check_stack_overlap: returning\n"));
}
-
-/* ------------------------------------------------------------------------ */
-
/* ------------------------------------------------------------------------ */
-void
-__kmp_infinite_loop( void )
-{
- static int done = FALSE;
-
- while (! done) {
- KMP_YIELD( 1 );
- }
-}
-
-#define MAX_MESSAGE 512
-
-void
-__kmp_print_storage_map_gtid( int gtid, void *p1, void *p2, size_t size, char const *format, ...) {
- char buffer[MAX_MESSAGE];
- va_list ap;
+void __kmp_infinite_loop(void) {
+ static int done = FALSE;
- va_start( ap, format);
- KMP_SNPRINTF( buffer, sizeof(buffer), "OMP storage map: %p %p%8lu %s\n", p1, p2, (unsigned long) size, format );
- __kmp_acquire_bootstrap_lock( & __kmp_stdio_lock );
- __kmp_vprintf( kmp_err, buffer, ap );
+ while (!done) {
+ KMP_YIELD(1);
+ }
+}
+
+#define MAX_MESSAGE 512
+
+void __kmp_print_storage_map_gtid(int gtid, void *p1, void *p2, size_t size,
+ char const *format, ...) {
+ char buffer[MAX_MESSAGE];
+ va_list ap;
+
+ va_start(ap, format);
+ KMP_SNPRINTF(buffer, sizeof(buffer), "OMP storage map: %p %p%8lu %s\n", p1,
+ p2, (unsigned long)size, format);
+ __kmp_acquire_bootstrap_lock(&__kmp_stdio_lock);
+ __kmp_vprintf(kmp_err, buffer, ap);
#if KMP_PRINT_DATA_PLACEMENT
- int node;
- if(gtid >= 0) {
- if(p1 <= p2 && (char*)p2 - (char*)p1 == size) {
- if( __kmp_storage_map_verbose ) {
- node = __kmp_get_host_node(p1);
- if(node < 0) /* doesn't work, so don't try this next time */
- __kmp_storage_map_verbose = FALSE;
- else {
- char *last;
- int lastNode;
- int localProc = __kmp_get_cpu_from_gtid(gtid);
-
- const int page_size = KMP_GET_PAGE_SIZE();
-
- p1 = (void *)( (size_t)p1 & ~((size_t)page_size - 1) );
- p2 = (void *)( ((size_t) p2 - 1) & ~((size_t)page_size - 1) );
- if(localProc >= 0)
- __kmp_printf_no_lock(" GTID %d localNode %d\n", gtid, localProc>>1);
- else
- __kmp_printf_no_lock(" GTID %d\n", gtid);
-# if KMP_USE_PRCTL
-/* The more elaborate format is disabled for now because of the prctl hanging bug. */
- do {
- last = p1;
- lastNode = node;
- /* This loop collates adjacent pages with the same host node. */
- do {
- (char*)p1 += page_size;
- } while(p1 <= p2 && (node = __kmp_get_host_node(p1)) == lastNode);
- __kmp_printf_no_lock(" %p-%p memNode %d\n", last,
- (char*)p1 - 1, lastNode);
- } while(p1 <= p2);
-# else
- __kmp_printf_no_lock(" %p-%p memNode %d\n", p1,
- (char*)p1 + (page_size - 1), __kmp_get_host_node(p1));
- if(p1 < p2) {
- __kmp_printf_no_lock(" %p-%p memNode %d\n", p2,
- (char*)p2 + (page_size - 1), __kmp_get_host_node(p2));
- }
-# endif
- }
- }
- } else
- __kmp_printf_no_lock(" %s\n", KMP_I18N_STR( StorageMapWarning ) );
- }
+ int node;
+ if (gtid >= 0) {
+ if (p1 <= p2 && (char *)p2 - (char *)p1 == size) {
+ if (__kmp_storage_map_verbose) {
+ node = __kmp_get_host_node(p1);
+ if (node < 0) /* doesn't work, so don't try this next time */
+ __kmp_storage_map_verbose = FALSE;
+ else {
+ char *last;
+ int lastNode;
+ int localProc = __kmp_get_cpu_from_gtid(gtid);
+
+ const int page_size = KMP_GET_PAGE_SIZE();
+
+ p1 = (void *)((size_t)p1 & ~((size_t)page_size - 1));
+ p2 = (void *)(((size_t)p2 - 1) & ~((size_t)page_size - 1));
+ if (localProc >= 0)
+ __kmp_printf_no_lock(" GTID %d localNode %d\n", gtid,
+ localProc >> 1);
+ else
+ __kmp_printf_no_lock(" GTID %d\n", gtid);
+#if KMP_USE_PRCTL
+ /* The more elaborate format is disabled for now because of the prctl
+ * hanging bug. */
+ do {
+ last = p1;
+ lastNode = node;
+ /* This loop collates adjacent pages with the same host node. */
+ do {
+ (char *)p1 += page_size;
+ } while (p1 <= p2 && (node = __kmp_get_host_node(p1)) == lastNode);
+ __kmp_printf_no_lock(" %p-%p memNode %d\n", last, (char *)p1 - 1,
+ lastNode);
+ } while (p1 <= p2);
+#else
+ __kmp_printf_no_lock(" %p-%p memNode %d\n", p1,
+ (char *)p1 + (page_size - 1),
+ __kmp_get_host_node(p1));
+ if (p1 < p2) {
+ __kmp_printf_no_lock(" %p-%p memNode %d\n", p2,
+ (char *)p2 + (page_size - 1),
+ __kmp_get_host_node(p2));
+ }
+#endif
+ }
+ }
+ } else
+ __kmp_printf_no_lock(" %s\n", KMP_I18N_STR(StorageMapWarning));
+ }
#endif /* KMP_PRINT_DATA_PLACEMENT */
- __kmp_release_bootstrap_lock( & __kmp_stdio_lock );
+ __kmp_release_bootstrap_lock(&__kmp_stdio_lock);
}
-void
-__kmp_warn( char const * format, ... )
-{
- char buffer[MAX_MESSAGE];
- va_list ap;
+void __kmp_warn(char const *format, ...) {
+ char buffer[MAX_MESSAGE];
+ va_list ap;
- if ( __kmp_generate_warnings == kmp_warnings_off ) {
- return;
- }
+ if (__kmp_generate_warnings == kmp_warnings_off) {
+ return;
+ }
- va_start( ap, format );
+ va_start(ap, format);
- KMP_SNPRINTF( buffer, sizeof(buffer) , "OMP warning: %s\n", format );
- __kmp_acquire_bootstrap_lock( & __kmp_stdio_lock );
- __kmp_vprintf( kmp_err, buffer, ap );
- __kmp_release_bootstrap_lock( & __kmp_stdio_lock );
+ KMP_SNPRINTF(buffer, sizeof(buffer), "OMP warning: %s\n", format);
+ __kmp_acquire_bootstrap_lock(&__kmp_stdio_lock);
+ __kmp_vprintf(kmp_err, buffer, ap);
+ __kmp_release_bootstrap_lock(&__kmp_stdio_lock);
- va_end( ap );
+ va_end(ap);
}
-void
-__kmp_abort_process()
-{
+void __kmp_abort_process() {
+ // Later threads may stall here, but that's ok because abort() will kill them.
+ __kmp_acquire_bootstrap_lock(&__kmp_exit_lock);
- // Later threads may stall here, but that's ok because abort() will kill them.
- __kmp_acquire_bootstrap_lock( & __kmp_exit_lock );
+ if (__kmp_debug_buf) {
+ __kmp_dump_debug_buffer();
+ }; // if
- if ( __kmp_debug_buf ) {
- __kmp_dump_debug_buffer();
- }; // if
+ if (KMP_OS_WINDOWS) {
+ // Let other threads know of abnormal termination and prevent deadlock
+ // if abort happened during library initialization or shutdown
+ __kmp_global.g.g_abort = SIGABRT;
- if ( KMP_OS_WINDOWS ) {
- // Let other threads know of abnormal termination and prevent deadlock
- // if abort happened during library initialization or shutdown
- __kmp_global.g.g_abort = SIGABRT;
-
- /*
- On Windows* OS by default abort() causes pop-up error box, which stalls nightly testing.
- Unfortunately, we cannot reliably suppress pop-up error boxes. _set_abort_behavior()
- works well, but this function is not available in VS7 (this is not problem for DLL, but
- it is a problem for static OpenMP RTL). SetErrorMode (and so, timelimit utility) does
- not help, at least in some versions of MS C RTL.
-
- It seems following sequence is the only way to simulate abort() and avoid pop-up error
- box.
- */
- raise( SIGABRT );
- _exit( 3 ); // Just in case, if signal ignored, exit anyway.
- } else {
- abort();
- }; // if
+ /* On Windows* OS by default abort() causes pop-up error box, which stalls
+ nightly testing. Unfortunately, we cannot reliably suppress pop-up error
+ boxes. _set_abort_behavior() works well, but this function is not
+ available in VS7 (this is not problem for DLL, but it is a problem for
+ static OpenMP RTL). SetErrorMode (and so, timelimit utility) does not
+ help, at least in some versions of MS C RTL.
- __kmp_infinite_loop();
- __kmp_release_bootstrap_lock( & __kmp_exit_lock );
+ It seems following sequence is the only way to simulate abort() and
+ avoid pop-up error box. */
+ raise(SIGABRT);
+ _exit(3); // Just in case, if signal ignored, exit anyway.
+ } else {
+ abort();
+ }; // if
+
+ __kmp_infinite_loop();
+ __kmp_release_bootstrap_lock(&__kmp_exit_lock);
} // __kmp_abort_process
-void
-__kmp_abort_thread( void )
-{
- // TODO: Eliminate g_abort global variable and this function.
- // In case of abort just call abort(), it will kill all the threads.
- __kmp_infinite_loop();
+void __kmp_abort_thread(void) {
+ // TODO: Eliminate g_abort global variable and this function.
+ // In case of abort just call abort(), it will kill all the threads.
+ __kmp_infinite_loop();
} // __kmp_abort_thread
-/* ------------------------------------------------------------------------ */
-
-/*
- * Print out the storage map for the major kmp_info_t thread data structures
- * that are allocated together.
- */
-
-static void
-__kmp_print_thread_storage_map( kmp_info_t *thr, int gtid )
-{
- __kmp_print_storage_map_gtid( gtid, thr, thr + 1, sizeof(kmp_info_t), "th_%d", gtid );
-
- __kmp_print_storage_map_gtid( gtid, &thr->th.th_info, &thr->th.th_team, sizeof(kmp_desc_t),
- "th_%d.th_info", gtid );
-
- __kmp_print_storage_map_gtid( gtid, &thr->th.th_local, &thr->th.th_pri_head, sizeof(kmp_local_t),
- "th_%d.th_local", gtid );
-
- __kmp_print_storage_map_gtid( gtid, &thr->th.th_bar[0], &thr->th.th_bar[bs_last_barrier],
- sizeof(kmp_balign_t) * bs_last_barrier, "th_%d.th_bar", gtid );
-
- __kmp_print_storage_map_gtid( gtid, &thr->th.th_bar[bs_plain_barrier],
- &thr->th.th_bar[bs_plain_barrier+1],
- sizeof(kmp_balign_t), "th_%d.th_bar[plain]", gtid);
-
- __kmp_print_storage_map_gtid( gtid, &thr->th.th_bar[bs_forkjoin_barrier],
- &thr->th.th_bar[bs_forkjoin_barrier+1],
- sizeof(kmp_balign_t), "th_%d.th_bar[forkjoin]", gtid);
-
- #if KMP_FAST_REDUCTION_BARRIER
- __kmp_print_storage_map_gtid( gtid, &thr->th.th_bar[bs_reduction_barrier],
- &thr->th.th_bar[bs_reduction_barrier+1],
- sizeof(kmp_balign_t), "th_%d.th_bar[reduction]", gtid);
- #endif // KMP_FAST_REDUCTION_BARRIER
-}
-
-/*
- * Print out the storage map for the major kmp_team_t team data structures
- * that are allocated together.
- */
-
-static void
-__kmp_print_team_storage_map( const char *header, kmp_team_t *team, int team_id, int num_thr )
-{
- int num_disp_buff = team->t.t_max_nproc > 1 ? __kmp_dispatch_num_buffers : 2;
- __kmp_print_storage_map_gtid( -1, team, team + 1, sizeof(kmp_team_t), "%s_%d",
- header, team_id );
-
- __kmp_print_storage_map_gtid( -1, &team->t.t_bar[0], &team->t.t_bar[bs_last_barrier],
- sizeof(kmp_balign_team_t) * bs_last_barrier, "%s_%d.t_bar", header, team_id );
-
-
- __kmp_print_storage_map_gtid( -1, &team->t.t_bar[bs_plain_barrier], &team->t.t_bar[bs_plain_barrier+1],
- sizeof(kmp_balign_team_t), "%s_%d.t_bar[plain]", header, team_id );
-
- __kmp_print_storage_map_gtid( -1, &team->t.t_bar[bs_forkjoin_barrier], &team->t.t_bar[bs_forkjoin_barrier+1],
- sizeof(kmp_balign_team_t), "%s_%d.t_bar[forkjoin]", header, team_id );
+/* Print out the storage map for the major kmp_info_t thread data structures
+ that are allocated together. */
- #if KMP_FAST_REDUCTION_BARRIER
- __kmp_print_storage_map_gtid( -1, &team->t.t_bar[bs_reduction_barrier], &team->t.t_bar[bs_reduction_barrier+1],
- sizeof(kmp_balign_team_t), "%s_%d.t_bar[reduction]", header, team_id );
- #endif // KMP_FAST_REDUCTION_BARRIER
-
- __kmp_print_storage_map_gtid( -1, &team->t.t_dispatch[0], &team->t.t_dispatch[num_thr],
- sizeof(kmp_disp_t) * num_thr, "%s_%d.t_dispatch", header, team_id );
-
- __kmp_print_storage_map_gtid( -1, &team->t.t_threads[0], &team->t.t_threads[num_thr],
- sizeof(kmp_info_t *) * num_thr, "%s_%d.t_threads", header, team_id );
-
- __kmp_print_storage_map_gtid( -1, &team->t.t_disp_buffer[0], &team->t.t_disp_buffer[num_disp_buff],
- sizeof(dispatch_shared_info_t) * num_disp_buff, "%s_%d.t_disp_buffer",
- header, team_id );
+static void __kmp_print_thread_storage_map(kmp_info_t *thr, int gtid) {
+ __kmp_print_storage_map_gtid(gtid, thr, thr + 1, sizeof(kmp_info_t), "th_%d",
+ gtid);
+
+ __kmp_print_storage_map_gtid(gtid, &thr->th.th_info, &thr->th.th_team,
+ sizeof(kmp_desc_t), "th_%d.th_info", gtid);
+
+ __kmp_print_storage_map_gtid(gtid, &thr->th.th_local, &thr->th.th_pri_head,
+ sizeof(kmp_local_t), "th_%d.th_local", gtid);
+
+ __kmp_print_storage_map_gtid(
+ gtid, &thr->th.th_bar[0], &thr->th.th_bar[bs_last_barrier],
+ sizeof(kmp_balign_t) * bs_last_barrier, "th_%d.th_bar", gtid);
+
+ __kmp_print_storage_map_gtid(gtid, &thr->th.th_bar[bs_plain_barrier],
+ &thr->th.th_bar[bs_plain_barrier + 1],
+ sizeof(kmp_balign_t), "th_%d.th_bar[plain]",
+ gtid);
+
+ __kmp_print_storage_map_gtid(gtid, &thr->th.th_bar[bs_forkjoin_barrier],
+ &thr->th.th_bar[bs_forkjoin_barrier + 1],
+ sizeof(kmp_balign_t), "th_%d.th_bar[forkjoin]",
+ gtid);
+#if KMP_FAST_REDUCTION_BARRIER
+ __kmp_print_storage_map_gtid(gtid, &thr->th.th_bar[bs_reduction_barrier],
+ &thr->th.th_bar[bs_reduction_barrier + 1],
+ sizeof(kmp_balign_t), "th_%d.th_bar[reduction]",
+ gtid);
+#endif // KMP_FAST_REDUCTION_BARRIER
+}
+
+/* Print out the storage map for the major kmp_team_t team data structures
+ that are allocated together. */
+
+static void __kmp_print_team_storage_map(const char *header, kmp_team_t *team,
+ int team_id, int num_thr) {
+ int num_disp_buff = team->t.t_max_nproc > 1 ? __kmp_dispatch_num_buffers : 2;
+ __kmp_print_storage_map_gtid(-1, team, team + 1, sizeof(kmp_team_t), "%s_%d",
+ header, team_id);
+
+ __kmp_print_storage_map_gtid(-1, &team->t.t_bar[0],
+ &team->t.t_bar[bs_last_barrier],
+ sizeof(kmp_balign_team_t) * bs_last_barrier,
+ "%s_%d.t_bar", header, team_id);
+
+ __kmp_print_storage_map_gtid(-1, &team->t.t_bar[bs_plain_barrier],
+ &team->t.t_bar[bs_plain_barrier + 1],
+ sizeof(kmp_balign_team_t), "%s_%d.t_bar[plain]",
+ header, team_id);
+
+ __kmp_print_storage_map_gtid(-1, &team->t.t_bar[bs_forkjoin_barrier],
+ &team->t.t_bar[bs_forkjoin_barrier + 1],
+ sizeof(kmp_balign_team_t),
+ "%s_%d.t_bar[forkjoin]", header, team_id);
- __kmp_print_storage_map_gtid( -1, &team->t.t_taskq, &team->t.t_copypriv_data,
- sizeof(kmp_taskq_t), "%s_%d.t_taskq", header, team_id );
+#if KMP_FAST_REDUCTION_BARRIER
+ __kmp_print_storage_map_gtid(-1, &team->t.t_bar[bs_reduction_barrier],
+ &team->t.t_bar[bs_reduction_barrier + 1],
+ sizeof(kmp_balign_team_t),
+ "%s_%d.t_bar[reduction]", header, team_id);
+#endif // KMP_FAST_REDUCTION_BARRIER
+
+ __kmp_print_storage_map_gtid(
+ -1, &team->t.t_dispatch[0], &team->t.t_dispatch[num_thr],
+ sizeof(kmp_disp_t) * num_thr, "%s_%d.t_dispatch", header, team_id);
+
+ __kmp_print_storage_map_gtid(
+ -1, &team->t.t_threads[0], &team->t.t_threads[num_thr],
+ sizeof(kmp_info_t *) * num_thr, "%s_%d.t_threads", header, team_id);
+
+ __kmp_print_storage_map_gtid(-1, &team->t.t_disp_buffer[0],
+ &team->t.t_disp_buffer[num_disp_buff],
+ sizeof(dispatch_shared_info_t) * num_disp_buff,
+ "%s_%d.t_disp_buffer", header, team_id);
+
+ __kmp_print_storage_map_gtid(-1, &team->t.t_taskq, &team->t.t_copypriv_data,
+ sizeof(kmp_taskq_t), "%s_%d.t_taskq", header,
+ team_id);
}
static void __kmp_init_allocator() {}
@@ -537,915 +542,866 @@ static void __kmp_fini_allocator() {}
/* ------------------------------------------------------------------------ */
#ifdef KMP_DYNAMIC_LIB
-# if KMP_OS_WINDOWS
+#if KMP_OS_WINDOWS
-static void
-__kmp_reset_lock( kmp_bootstrap_lock_t* lck ) {
- // TODO: Change to __kmp_break_bootstrap_lock().
- __kmp_init_bootstrap_lock( lck ); // make the lock released
+static void __kmp_reset_lock(kmp_bootstrap_lock_t *lck) {
+ // TODO: Change to __kmp_break_bootstrap_lock().
+ __kmp_init_bootstrap_lock(lck); // make the lock released
+}
+
+static void __kmp_reset_locks_on_process_detach(int gtid_req) {
+ int i;
+ int thread_count;
+
+ // PROCESS_DETACH is expected to be called by a thread that executes
+ // ProcessExit() or FreeLibrary(). OS terminates other threads (except the one
+ // calling ProcessExit or FreeLibrary). So, it might be safe to access the
+ // __kmp_threads[] without taking the forkjoin_lock. However, in fact, some
+ // threads can be still alive here, although being about to be terminated. The
+ // threads in the array with ds_thread==0 are most suspicious. Actually, it
+ // can be not safe to access the __kmp_threads[].
+
+ // TODO: does it make sense to check __kmp_roots[] ?
+
+ // Let's check that there are no other alive threads registered with the OMP
+ // lib.
+ while (1) {
+ thread_count = 0;
+ for (i = 0; i < __kmp_threads_capacity; ++i) {
+ if (!__kmp_threads)
+ continue;
+ kmp_info_t *th = __kmp_threads[i];
+ if (th == NULL)
+ continue;
+ int gtid = th->th.th_info.ds.ds_gtid;
+ if (gtid == gtid_req)
+ continue;
+ if (gtid < 0)
+ continue;
+ DWORD exit_val;
+ int alive = __kmp_is_thread_alive(th, &exit_val);
+ if (alive) {
+ ++thread_count;
+ }
+ }
+ if (thread_count == 0)
+ break; // success
+ }
+
+ // Assume that I'm alone. Now it might be safe to check and reset locks.
+ // __kmp_forkjoin_lock and __kmp_stdio_lock are expected to be reset.
+ __kmp_reset_lock(&__kmp_forkjoin_lock);
+#ifdef KMP_DEBUG
+ __kmp_reset_lock(&__kmp_stdio_lock);
+#endif // KMP_DEBUG
}
-static void
-__kmp_reset_locks_on_process_detach( int gtid_req ) {
- int i;
- int thread_count;
+BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved) {
+ //__kmp_acquire_bootstrap_lock( &__kmp_initz_lock );
- // PROCESS_DETACH is expected to be called by a thread
- // that executes ProcessExit() or FreeLibrary().
- // OS terminates other threads (except the one calling ProcessExit or FreeLibrary).
- // So, it might be safe to access the __kmp_threads[] without taking the forkjoin_lock.
- // However, in fact, some threads can be still alive here, although being about to be terminated.
- // The threads in the array with ds_thread==0 are most suspicious.
- // Actually, it can be not safe to access the __kmp_threads[].
-
- // TODO: does it make sense to check __kmp_roots[] ?
-
- // Let's check that there are no other alive threads registered with the OMP lib.
- while( 1 ) {
- thread_count = 0;
- for( i = 0; i < __kmp_threads_capacity; ++i ) {
- if( !__kmp_threads ) continue;
- kmp_info_t* th = __kmp_threads[ i ];
- if( th == NULL ) continue;
- int gtid = th->th.th_info.ds.ds_gtid;
- if( gtid == gtid_req ) continue;
- if( gtid < 0 ) continue;
- DWORD exit_val;
- int alive = __kmp_is_thread_alive( th, &exit_val );
- if( alive ) {
- ++thread_count;
- }
- }
- if( thread_count == 0 ) break; // success
- }
+ switch (fdwReason) {
- // Assume that I'm alone.
+ case DLL_PROCESS_ATTACH:
+ KA_TRACE(10, ("DllMain: PROCESS_ATTACH\n"));
- // Now it might be probably safe to check and reset locks.
- // __kmp_forkjoin_lock and __kmp_stdio_lock are expected to be reset.
- __kmp_reset_lock( &__kmp_forkjoin_lock );
- #ifdef KMP_DEBUG
- __kmp_reset_lock( &__kmp_stdio_lock );
- #endif // KMP_DEBUG
-}
-
-BOOL WINAPI
-DllMain( HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved ) {
- //__kmp_acquire_bootstrap_lock( &__kmp_initz_lock );
-
- switch( fdwReason ) {
-
- case DLL_PROCESS_ATTACH:
- KA_TRACE( 10, ("DllMain: PROCESS_ATTACH\n" ));
-
- return TRUE;
-
- case DLL_PROCESS_DETACH:
- KA_TRACE( 10, ("DllMain: PROCESS_DETACH T#%d\n",
- __kmp_gtid_get_specific() ));
-
- if( lpReserved != NULL )
- {
- // lpReserved is used for telling the difference:
- // lpReserved == NULL when FreeLibrary() was called,
- // lpReserved != NULL when the process terminates.
- // When FreeLibrary() is called, worker threads remain alive.
- // So they will release the forkjoin lock by themselves.
- // When the process terminates, worker threads disappear triggering
- // the problem of unreleased forkjoin lock as described below.
-
- // A worker thread can take the forkjoin lock.
- // The problem comes up if that worker thread becomes dead
- // before it releases the forkjoin lock.
- // The forkjoin lock remains taken, while the thread
- // executing DllMain()->PROCESS_DETACH->__kmp_internal_end_library() below
- // will try to take the forkjoin lock and will always fail,
- // so that the application will never finish [normally].
- // This scenario is possible if __kmpc_end() has not been executed.
- // It looks like it's not a corner case, but common cases:
- // - the main function was compiled by an alternative compiler;
- // - the main function was compiled by icl but without /Qopenmp (application with plugins);
- // - application terminates by calling C exit(), Fortran CALL EXIT() or Fortran STOP.
- // - alive foreign thread prevented __kmpc_end from doing cleanup.
-
- // This is a hack to work around the problem.
- // TODO: !!! to figure out something better.
- __kmp_reset_locks_on_process_detach( __kmp_gtid_get_specific() );
- }
+ return TRUE;
- __kmp_internal_end_library( __kmp_gtid_get_specific() );
+ case DLL_PROCESS_DETACH:
+ KA_TRACE(10, ("DllMain: PROCESS_DETACH T#%d\n", __kmp_gtid_get_specific()));
- return TRUE;
+ if (lpReserved != NULL) {
+ // lpReserved is used for telling the difference:
+ // lpReserved == NULL when FreeLibrary() was called,
+ // lpReserved != NULL when the process terminates.
+ // When FreeLibrary() is called, worker threads remain alive. So they will
+ // release the forkjoin lock by themselves. When the process terminates,
+ // worker threads disappear triggering the problem of unreleased forkjoin
+ // lock as described below.
+
+ // A worker thread can take the forkjoin lock. The problem comes up if
+ // that worker thread becomes dead before it releases the forkjoin lock.
+ // The forkjoin lock remains taken, while the thread executing
+ // DllMain()->PROCESS_DETACH->__kmp_internal_end_library() below will try
+ // to take the forkjoin lock and will always fail, so that the application
+ // will never finish [normally]. This scenario is possible if
+ // __kmpc_end() has not been executed. It looks like it's not a corner
+ // case, but common cases:
+ // - the main function was compiled by an alternative compiler;
+ // - the main function was compiled by icl but without /Qopenmp
+ // (application with plugins);
+ // - application terminates by calling C exit(), Fortran CALL EXIT() or
+ // Fortran STOP.
+ // - alive foreign thread prevented __kmpc_end from doing cleanup.
+ //
+ // This is a hack to work around the problem.
+ // TODO: !!! figure out something better.
+ __kmp_reset_locks_on_process_detach(__kmp_gtid_get_specific());
+ }
- case DLL_THREAD_ATTACH:
- KA_TRACE( 10, ("DllMain: THREAD_ATTACH\n" ));
+ __kmp_internal_end_library(__kmp_gtid_get_specific());
- /* if we wanted to register new siblings all the time here call
- * __kmp_get_gtid(); */
- return TRUE;
+ return TRUE;
- case DLL_THREAD_DETACH:
- KA_TRACE( 10, ("DllMain: THREAD_DETACH T#%d\n",
- __kmp_gtid_get_specific() ));
+ case DLL_THREAD_ATTACH:
+ KA_TRACE(10, ("DllMain: THREAD_ATTACH\n"));
- __kmp_internal_end_thread( __kmp_gtid_get_specific() );
- return TRUE;
- }
+ /* if we want to register new siblings all the time here call
+ * __kmp_get_gtid(); */
+ return TRUE;
+ case DLL_THREAD_DETACH:
+ KA_TRACE(10, ("DllMain: THREAD_DETACH T#%d\n", __kmp_gtid_get_specific()));
+
+ __kmp_internal_end_thread(__kmp_gtid_get_specific());
return TRUE;
+ }
+
+ return TRUE;
}
-# endif /* KMP_OS_WINDOWS */
+#endif /* KMP_OS_WINDOWS */
#endif /* KMP_DYNAMIC_LIB */
-
-/* ------------------------------------------------------------------------ */
-
/* Change the library type to "status" and return the old type */
/* called from within initialization routines where __kmp_initz_lock is held */
-int
-__kmp_change_library( int status )
-{
- int old_status;
+int __kmp_change_library(int status) {
+ int old_status;
- old_status = __kmp_yield_init & 1; // check whether KMP_LIBRARY=throughput (even init count)
+ old_status = __kmp_yield_init &
+ 1; // check whether KMP_LIBRARY=throughput (even init count)
- if (status) {
- __kmp_yield_init |= 1; // throughput => turnaround (odd init count)
- }
- else {
- __kmp_yield_init &= ~1; // turnaround => throughput (even init count)
- }
+ if (status) {
+ __kmp_yield_init |= 1; // throughput => turnaround (odd init count)
+ } else {
+ __kmp_yield_init &= ~1; // turnaround => throughput (even init count)
+ }
- return old_status; // return previous setting of whether KMP_LIBRARY=throughput
+ return old_status; // return previous setting of whether
+ // KMP_LIBRARY=throughput
}
-/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
-
-/* __kmp_parallel_deo --
- * Wait until it's our turn.
- */
-void
-__kmp_parallel_deo( int *gtid_ref, int *cid_ref, ident_t *loc_ref )
-{
- int gtid = *gtid_ref;
+/* __kmp_parallel_deo -- Wait until it's our turn. */
+void __kmp_parallel_deo(int *gtid_ref, int *cid_ref, ident_t *loc_ref) {
+ int gtid = *gtid_ref;
#ifdef BUILD_PARALLEL_ORDERED
- kmp_team_t *team = __kmp_team_from_gtid( gtid );
+ kmp_team_t *team = __kmp_team_from_gtid(gtid);
#endif /* BUILD_PARALLEL_ORDERED */
- if( __kmp_env_consistency_check ) {
- if( __kmp_threads[gtid]->th.th_root->r.r_active )
+ if (__kmp_env_consistency_check) {
+ if (__kmp_threads[gtid]->th.th_root->r.r_active)
#if KMP_USE_DYNAMIC_LOCK
- __kmp_push_sync( gtid, ct_ordered_in_parallel, loc_ref, NULL, 0 );
+ __kmp_push_sync(gtid, ct_ordered_in_parallel, loc_ref, NULL, 0);
#else
- __kmp_push_sync( gtid, ct_ordered_in_parallel, loc_ref, NULL );
+ __kmp_push_sync(gtid, ct_ordered_in_parallel, loc_ref, NULL);
#endif
- }
+ }
#ifdef BUILD_PARALLEL_ORDERED
- if( !team->t.t_serialized ) {
- KMP_MB();
- KMP_WAIT_YIELD(&team->t.t_ordered.dt.t_value, __kmp_tid_from_gtid( gtid ), KMP_EQ, NULL);
- KMP_MB();
- }
+ if (!team->t.t_serialized) {
+ KMP_MB();
+ KMP_WAIT_YIELD(&team->t.t_ordered.dt.t_value, __kmp_tid_from_gtid(gtid),
+ KMP_EQ, NULL);
+ KMP_MB();
+ }
#endif /* BUILD_PARALLEL_ORDERED */
}
-/* __kmp_parallel_dxo --
- * Signal the next task.
- */
-
-void
-__kmp_parallel_dxo( int *gtid_ref, int *cid_ref, ident_t *loc_ref )
-{
- int gtid = *gtid_ref;
+/* __kmp_parallel_dxo -- Signal the next task. */
+void __kmp_parallel_dxo(int *gtid_ref, int *cid_ref, ident_t *loc_ref) {
+ int gtid = *gtid_ref;
#ifdef BUILD_PARALLEL_ORDERED
- int tid = __kmp_tid_from_gtid( gtid );
- kmp_team_t *team = __kmp_team_from_gtid( gtid );
+ int tid = __kmp_tid_from_gtid(gtid);
+ kmp_team_t *team = __kmp_team_from_gtid(gtid);
#endif /* BUILD_PARALLEL_ORDERED */
- if( __kmp_env_consistency_check ) {
- if( __kmp_threads[gtid]->th.th_root->r.r_active )
- __kmp_pop_sync( gtid, ct_ordered_in_parallel, loc_ref );
- }
+ if (__kmp_env_consistency_check) {
+ if (__kmp_threads[gtid]->th.th_root->r.r_active)
+ __kmp_pop_sync(gtid, ct_ordered_in_parallel, loc_ref);
+ }
#ifdef BUILD_PARALLEL_ORDERED
- if ( ! team->t.t_serialized ) {
- KMP_MB(); /* Flush all pending memory write invalidates. */
+ if (!team->t.t_serialized) {
+ KMP_MB(); /* Flush all pending memory write invalidates. */
- /* use the tid of the next thread in this team */
- /* TODO repleace with general release procedure */
- team->t.t_ordered.dt.t_value = ((tid + 1) % team->t.t_nproc );
+ /* use the tid of the next thread in this team */
+ /* TODO replace with general release procedure */
+ team->t.t_ordered.dt.t_value = ((tid + 1) % team->t.t_nproc);
#if OMPT_SUPPORT && OMPT_BLAME
- if (ompt_enabled &&
- ompt_callbacks.ompt_callback(ompt_event_release_ordered)) {
- /* accept blame for "ordered" waiting */
- kmp_info_t *this_thread = __kmp_threads[gtid];
- ompt_callbacks.ompt_callback(ompt_event_release_ordered)(
- this_thread->th.ompt_thread_info.wait_id);
- }
+ if (ompt_enabled &&
+ ompt_callbacks.ompt_callback(ompt_event_release_ordered)) {
+ /* accept blame for "ordered" waiting */
+ kmp_info_t *this_thread = __kmp_threads[gtid];
+ ompt_callbacks.ompt_callback(ompt_event_release_ordered)(
+ this_thread->th.ompt_thread_info.wait_id);
+ }
#endif
- KMP_MB(); /* Flush all pending memory write invalidates. */
- }
+ KMP_MB(); /* Flush all pending memory write invalidates. */
+ }
#endif /* BUILD_PARALLEL_ORDERED */
}
/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
-
-/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
-
/* The BARRIER for a SINGLE process section is always explicit */
-int
-__kmp_enter_single( int gtid, ident_t *id_ref, int push_ws )
-{
- int status;
- kmp_info_t *th;
- kmp_team_t *team;
-
- if( ! TCR_4(__kmp_init_parallel) )
- __kmp_parallel_initialize();
-
- th = __kmp_threads[ gtid ];
- team = th->th.th_team;
- status = 0;
-
- th->th.th_ident = id_ref;
-
- if ( team->t.t_serialized ) {
- status = 1;
- } else {
- kmp_int32 old_this = th->th.th_local.this_construct;
-
- ++th->th.th_local.this_construct;
- /* try to set team count to thread count--success means thread got the
- single block
- */
- /* TODO: Should this be acquire or release? */
- if (team->t.t_construct == old_this) {
- status = KMP_COMPARE_AND_STORE_ACQ32(&team->t.t_construct, old_this,
- th->th.th_local.this_construct);
- }
+int __kmp_enter_single(int gtid, ident_t *id_ref, int push_ws) {
+ int status;
+ kmp_info_t *th;
+ kmp_team_t *team;
+
+ if (!TCR_4(__kmp_init_parallel))
+ __kmp_parallel_initialize();
+
+ th = __kmp_threads[gtid];
+ team = th->th.th_team;
+ status = 0;
+
+ th->th.th_ident = id_ref;
+
+ if (team->t.t_serialized) {
+ status = 1;
+ } else {
+ kmp_int32 old_this = th->th.th_local.this_construct;
+
+ ++th->th.th_local.this_construct;
+ /* try to set team count to thread count--success means thread got the
+ single block */
+ /* TODO: Should this be acquire or release? */
+ if (team->t.t_construct == old_this) {
+ status = KMP_COMPARE_AND_STORE_ACQ32(&team->t.t_construct, old_this,
+ th->th.th_local.this_construct);
+ }
#if USE_ITT_BUILD
- if ( __itt_metadata_add_ptr && __kmp_forkjoin_frames_mode == 3 && KMP_MASTER_GTID(gtid) &&
+ if (__itt_metadata_add_ptr && __kmp_forkjoin_frames_mode == 3 &&
+ KMP_MASTER_GTID(gtid) &&
#if OMP_40_ENABLED
- th->th.th_teams_microtask == NULL &&
+ th->th.th_teams_microtask == NULL &&
#endif
- team->t.t_active_level == 1 )
- { // Only report metadata by master of active team at level 1
- __kmp_itt_metadata_single( id_ref );
- }
-#endif /* USE_ITT_BUILD */
+ team->t.t_active_level ==
+ 1) { // Only report metadata by master of active team at level 1
+ __kmp_itt_metadata_single(id_ref);
}
+#endif /* USE_ITT_BUILD */
+ }
- if( __kmp_env_consistency_check ) {
- if (status && push_ws) {
- __kmp_push_workshare( gtid, ct_psingle, id_ref );
- } else {
- __kmp_check_workshare( gtid, ct_psingle, id_ref );
- }
+ if (__kmp_env_consistency_check) {
+ if (status && push_ws) {
+ __kmp_push_workshare(gtid, ct_psingle, id_ref);
+ } else {
+ __kmp_check_workshare(gtid, ct_psingle, id_ref);
}
+ }
#if USE_ITT_BUILD
- if ( status ) {
- __kmp_itt_single_start( gtid );
- }
+ if (status) {
+ __kmp_itt_single_start(gtid);
+ }
#endif /* USE_ITT_BUILD */
- return status;
+ return status;
}
-void
-__kmp_exit_single( int gtid )
-{
+void __kmp_exit_single(int gtid) {
#if USE_ITT_BUILD
- __kmp_itt_single_end( gtid );
+ __kmp_itt_single_end(gtid);
#endif /* USE_ITT_BUILD */
- if( __kmp_env_consistency_check )
- __kmp_pop_workshare( gtid, ct_psingle, NULL );
+ if (__kmp_env_consistency_check)
+ __kmp_pop_workshare(gtid, ct_psingle, NULL);
}
-
-/*
- * determine if we can go parallel or must use a serialized parallel region and
+/* determine if we can go parallel or must use a serialized parallel region and
* how many threads we can use
* set_nproc is the number of threads requested for the team
* returns 0 if we should serialize or only use one thread,
* otherwise the number of threads to use
- * The forkjoin lock is held by the caller.
- */
-static int
-__kmp_reserve_threads( kmp_root_t *root, kmp_team_t *parent_team,
- int master_tid, int set_nthreads
+ * The forkjoin lock is held by the caller. */
+static int __kmp_reserve_threads(kmp_root_t *root, kmp_team_t *parent_team,
+ int master_tid, int set_nthreads
#if OMP_40_ENABLED
- , int enter_teams
+ ,
+ int enter_teams
#endif /* OMP_40_ENABLED */
-)
-{
- int capacity;
- int new_nthreads;
- KMP_DEBUG_ASSERT( __kmp_init_serial );
- KMP_DEBUG_ASSERT( root && parent_team );
-
- //
- // If dyn-var is set, dynamically adjust the number of desired threads,
- // according to the method specified by dynamic_mode.
- //
- new_nthreads = set_nthreads;
- if ( ! get__dynamic_2( parent_team, master_tid ) ) {
- ;
- }
+ ) {
+ int capacity;
+ int new_nthreads;
+ KMP_DEBUG_ASSERT(__kmp_init_serial);
+ KMP_DEBUG_ASSERT(root && parent_team);
+
+ // If dyn-var is set, dynamically adjust the number of desired threads,
+ // according to the method specified by dynamic_mode.
+ new_nthreads = set_nthreads;
+ if (!get__dynamic_2(parent_team, master_tid)) {
+ ;
+ }
#ifdef USE_LOAD_BALANCE
- else if ( __kmp_global.g.g_dynamic_mode == dynamic_load_balance ) {
- new_nthreads = __kmp_load_balance_nproc( root, set_nthreads );
- if ( new_nthreads == 1 ) {
- KC_TRACE( 10, ( "__kmp_reserve_threads: T#%d load balance reduced reservation to 1 thread\n",
- master_tid ));
- return 1;
- }
- if ( new_nthreads < set_nthreads ) {
- KC_TRACE( 10, ( "__kmp_reserve_threads: T#%d load balance reduced reservation to %d threads\n",
- master_tid, new_nthreads ));
- }
+ else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
+ new_nthreads = __kmp_load_balance_nproc(root, set_nthreads);
+ if (new_nthreads == 1) {
+ KC_TRACE(10, ("__kmp_reserve_threads: T#%d load balance reduced "
+ "reservation to 1 thread\n",
+ master_tid));
+ return 1;
+ }
+ if (new_nthreads < set_nthreads) {
+ KC_TRACE(10, ("__kmp_reserve_threads: T#%d load balance reduced "
+ "reservation to %d threads\n",
+ master_tid, new_nthreads));
}
+ }
#endif /* USE_LOAD_BALANCE */
- else if ( __kmp_global.g.g_dynamic_mode == dynamic_thread_limit ) {
- new_nthreads = __kmp_avail_proc - __kmp_nth + (root->r.r_active ? 1
- : root->r.r_hot_team->t.t_nproc);
- if ( new_nthreads <= 1 ) {
- KC_TRACE( 10, ( "__kmp_reserve_threads: T#%d thread limit reduced reservation to 1 thread\n",
- master_tid ));
- return 1;
- }
- if ( new_nthreads < set_nthreads ) {
- KC_TRACE( 10, ( "__kmp_reserve_threads: T#%d thread limit reduced reservation to %d threads\n",
- master_tid, new_nthreads ));
- }
- else {
- new_nthreads = set_nthreads;
- }
- }
- else if ( __kmp_global.g.g_dynamic_mode == dynamic_random ) {
- if ( set_nthreads > 2 ) {
- new_nthreads = __kmp_get_random( parent_team->t.t_threads[master_tid] );
- new_nthreads = ( new_nthreads % set_nthreads ) + 1;
- if ( new_nthreads == 1 ) {
- KC_TRACE( 10, ( "__kmp_reserve_threads: T#%d dynamic random reduced reservation to 1 thread\n",
- master_tid ));
- return 1;
- }
- if ( new_nthreads < set_nthreads ) {
- KC_TRACE( 10, ( "__kmp_reserve_threads: T#%d dynamic random reduced reservation to %d threads\n",
- master_tid, new_nthreads ));
- }
- }
- }
- else {
- KMP_ASSERT( 0 );
- }
-
- //
- // Respect KMP_ALL_THREADS, KMP_MAX_THREADS, OMP_THREAD_LIMIT.
- //
- if ( __kmp_nth + new_nthreads - ( root->r.r_active ? 1 :
- root->r.r_hot_team->t.t_nproc ) > __kmp_max_nth ) {
- int tl_nthreads = __kmp_max_nth - __kmp_nth + ( root->r.r_active ? 1 :
- root->r.r_hot_team->t.t_nproc );
- if ( tl_nthreads <= 0 ) {
- tl_nthreads = 1;
- }
-
- //
- // If dyn-var is false, emit a 1-time warning.
- //
- if ( ! get__dynamic_2( parent_team, master_tid )
- && ( ! __kmp_reserve_warn ) ) {
- __kmp_reserve_warn = 1;
- __kmp_msg(
- kmp_ms_warning,
- KMP_MSG( CantFormThrTeam, set_nthreads, tl_nthreads ),
- KMP_HNT( Unset_ALL_THREADS ),
- __kmp_msg_null
- );
- }
- if ( tl_nthreads == 1 ) {
- KC_TRACE( 10, ( "__kmp_reserve_threads: T#%d KMP_ALL_THREADS reduced reservation to 1 thread\n",
- master_tid ));
- return 1;
- }
- KC_TRACE( 10, ( "__kmp_reserve_threads: T#%d KMP_ALL_THREADS reduced reservation to %d threads\n",
- master_tid, tl_nthreads ));
- new_nthreads = tl_nthreads;
- }
-
- //
- // Check if the threads array is large enough, or needs expanding.
- //
- // See comment in __kmp_register_root() about the adjustment if
- // __kmp_threads[0] == NULL.
- //
- capacity = __kmp_threads_capacity;
- if ( TCR_PTR(__kmp_threads[0]) == NULL ) {
- --capacity;
- }
- if ( __kmp_nth + new_nthreads - ( root->r.r_active ? 1 :
- root->r.r_hot_team->t.t_nproc ) > capacity ) {
- //
- // Expand the threads array.
- //
- int slotsRequired = __kmp_nth + new_nthreads - ( root->r.r_active ? 1 :
- root->r.r_hot_team->t.t_nproc ) - capacity;
- int slotsAdded = __kmp_expand_threads(slotsRequired, slotsRequired);
- if ( slotsAdded < slotsRequired ) {
- //
- // The threads array was not expanded enough.
- //
- new_nthreads -= ( slotsRequired - slotsAdded );
- KMP_ASSERT( new_nthreads >= 1 );
-
- //
- // If dyn-var is false, emit a 1-time warning.
- //
- if ( ! get__dynamic_2( parent_team, master_tid )
- && ( ! __kmp_reserve_warn ) ) {
- __kmp_reserve_warn = 1;
- if ( __kmp_tp_cached ) {
- __kmp_msg(
- kmp_ms_warning,
- KMP_MSG( CantFormThrTeam, set_nthreads, new_nthreads ),
- KMP_HNT( Set_ALL_THREADPRIVATE, __kmp_tp_capacity ),
- KMP_HNT( PossibleSystemLimitOnThreads ),
- __kmp_msg_null
- );
- }
- else {
- __kmp_msg(
- kmp_ms_warning,
- KMP_MSG( CantFormThrTeam, set_nthreads, new_nthreads ),
- KMP_HNT( SystemLimitOnThreads ),
- __kmp_msg_null
- );
- }
- }
- }
+ else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
+ new_nthreads = __kmp_avail_proc - __kmp_nth +
+ (root->r.r_active ? 1 : root->r.r_hot_team->t.t_nproc);
+ if (new_nthreads <= 1) {
+ KC_TRACE(10, ("__kmp_reserve_threads: T#%d thread limit reduced "
+ "reservation to 1 thread\n",
+ master_tid));
+ return 1;
+ }
+ if (new_nthreads < set_nthreads) {
+ KC_TRACE(10, ("__kmp_reserve_threads: T#%d thread limit reduced "
+ "reservation to %d threads\n",
+ master_tid, new_nthreads));
+ } else {
+ new_nthreads = set_nthreads;
}
-
- if ( new_nthreads == 1 ) {
- KC_TRACE( 10, ( "__kmp_reserve_threads: T#%d serializing team after reclaiming dead roots and rechecking; requested %d threads\n",
- __kmp_get_gtid(), set_nthreads ) );
+ } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
+ if (set_nthreads > 2) {
+ new_nthreads = __kmp_get_random(parent_team->t.t_threads[master_tid]);
+ new_nthreads = (new_nthreads % set_nthreads) + 1;
+ if (new_nthreads == 1) {
+ KC_TRACE(10, ("__kmp_reserve_threads: T#%d dynamic random reduced "
+ "reservation to 1 thread\n",
+ master_tid));
return 1;
- }
-
- KC_TRACE( 10, ( "__kmp_reserve_threads: T#%d allocating %d threads; requested %d threads\n",
- __kmp_get_gtid(), new_nthreads, set_nthreads ));
- return new_nthreads;
-}
-
-/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
-
-/* allocate threads from the thread pool and assign them to the new team */
-/* we are assured that there are enough threads available, because we
- * checked on that earlier within critical section forkjoin */
-
-static void
-__kmp_fork_team_threads( kmp_root_t *root, kmp_team_t *team,
- kmp_info_t *master_th, int master_gtid )
-{
- int i;
- int use_hot_team;
-
- KA_TRACE( 10, ("__kmp_fork_team_threads: new_nprocs = %d\n", team->t.t_nproc ) );
- KMP_DEBUG_ASSERT( master_gtid == __kmp_get_gtid() );
- KMP_MB();
+ }
+ if (new_nthreads < set_nthreads) {
+ KC_TRACE(10, ("__kmp_reserve_threads: T#%d dynamic random reduced "
+ "reservation to %d threads\n",
+ master_tid, new_nthreads));
+ }
+ }
+ } else {
+ KMP_ASSERT(0);
+ }
+
+ // Respect KMP_ALL_THREADS, KMP_MAX_THREADS, OMP_THREAD_LIMIT.
+ if (__kmp_nth + new_nthreads -
+ (root->r.r_active ? 1 : root->r.r_hot_team->t.t_nproc) >
+ __kmp_max_nth) {
+ int tl_nthreads = __kmp_max_nth - __kmp_nth +
+ (root->r.r_active ? 1 : root->r.r_hot_team->t.t_nproc);
+ if (tl_nthreads <= 0) {
+ tl_nthreads = 1;
+ }
+
+ // If dyn-var is false, emit a 1-time warning.
+ if (!get__dynamic_2(parent_team, master_tid) && (!__kmp_reserve_warn)) {
+ __kmp_reserve_warn = 1;
+ __kmp_msg(kmp_ms_warning,
+ KMP_MSG(CantFormThrTeam, set_nthreads, tl_nthreads),
+ KMP_HNT(Unset_ALL_THREADS), __kmp_msg_null);
+ }
+ if (tl_nthreads == 1) {
+ KC_TRACE(10, ("__kmp_reserve_threads: T#%d KMP_ALL_THREADS reduced "
+ "reservation to 1 thread\n",
+ master_tid));
+ return 1;
+ }
+ KC_TRACE(10, ("__kmp_reserve_threads: T#%d KMP_ALL_THREADS reduced "
+ "reservation to %d threads\n",
+ master_tid, tl_nthreads));
+ new_nthreads = tl_nthreads;
+ }
+
+ // Check if the threads array is large enough, or needs expanding.
+ //
+ // See comment in __kmp_register_root() about the adjustment if
+ // __kmp_threads[0] == NULL.
+ capacity = __kmp_threads_capacity;
+ if (TCR_PTR(__kmp_threads[0]) == NULL) {
+ --capacity;
+ }
+ if (__kmp_nth + new_nthreads -
+ (root->r.r_active ? 1 : root->r.r_hot_team->t.t_nproc) >
+ capacity) {
+ // Expand the threads array.
+ int slotsRequired = __kmp_nth + new_nthreads -
+ (root->r.r_active ? 1 : root->r.r_hot_team->t.t_nproc) -
+ capacity;
+ int slotsAdded = __kmp_expand_threads(slotsRequired, slotsRequired);
+ if (slotsAdded < slotsRequired) {
+ // The threads array was not expanded enough.
+ new_nthreads -= (slotsRequired - slotsAdded);
+ KMP_ASSERT(new_nthreads >= 1);
+
+ // If dyn-var is false, emit a 1-time warning.
+ if (!get__dynamic_2(parent_team, master_tid) && (!__kmp_reserve_warn)) {
+ __kmp_reserve_warn = 1;
+ if (__kmp_tp_cached) {
+ __kmp_msg(kmp_ms_warning,
+ KMP_MSG(CantFormThrTeam, set_nthreads, new_nthreads),
+ KMP_HNT(Set_ALL_THREADPRIVATE, __kmp_tp_capacity),
+ KMP_HNT(PossibleSystemLimitOnThreads), __kmp_msg_null);
+ } else {
+ __kmp_msg(kmp_ms_warning,
+ KMP_MSG(CantFormThrTeam, set_nthreads, new_nthreads),
+ KMP_HNT(SystemLimitOnThreads), __kmp_msg_null);
+ }
+ }
+ }
+ }
+
+ if (new_nthreads == 1) {
+ KC_TRACE(10,
+ ("__kmp_reserve_threads: T#%d serializing team after reclaiming "
+ "dead roots and rechecking; requested %d threads\n",
+ __kmp_get_gtid(), set_nthreads));
+ return 1;
+ }
- /* first, let's setup the master thread */
- master_th->th.th_info.ds.ds_tid = 0;
- master_th->th.th_team = team;
- master_th->th.th_team_nproc = team->t.t_nproc;
- master_th->th.th_team_master = master_th;
- master_th->th.th_team_serialized = FALSE;
- master_th->th.th_dispatch = & team->t.t_dispatch[ 0 ];
+ KC_TRACE(10, ("__kmp_reserve_threads: T#%d allocating %d threads; requested "
+ "%d threads\n",
+ __kmp_get_gtid(), new_nthreads, set_nthreads));
+ return new_nthreads;
+}
+
+/* Allocate threads from the thread pool and assign them to the new team. We are
+ assured that there are enough threads available, because we checked on that
+ earlier within critical section forkjoin */
+static void __kmp_fork_team_threads(kmp_root_t *root, kmp_team_t *team,
+ kmp_info_t *master_th, int master_gtid) {
+ int i;
+ int use_hot_team;
+
+ KA_TRACE(10, ("__kmp_fork_team_threads: new_nprocs = %d\n", team->t.t_nproc));
+ KMP_DEBUG_ASSERT(master_gtid == __kmp_get_gtid());
+ KMP_MB();
+
+ /* first, let's setup the master thread */
+ master_th->th.th_info.ds.ds_tid = 0;
+ master_th->th.th_team = team;
+ master_th->th.th_team_nproc = team->t.t_nproc;
+ master_th->th.th_team_master = master_th;
+ master_th->th.th_team_serialized = FALSE;
+ master_th->th.th_dispatch = &team->t.t_dispatch[0];
- /* make sure we are not the optimized hot team */
+/* make sure we are not the optimized hot team */
#if KMP_NESTED_HOT_TEAMS
- use_hot_team = 0;
- kmp_hot_team_ptr_t *hot_teams = master_th->th.th_hot_teams;
- if( hot_teams ) { // hot teams array is not allocated if KMP_HOT_TEAMS_MAX_LEVEL=0
- int level = team->t.t_active_level - 1; // index in array of hot teams
- if( master_th->th.th_teams_microtask ) { // are we inside the teams?
- if( master_th->th.th_teams_size.nteams > 1 ) {
- ++level; // level was not increased in teams construct for team_of_masters
- }
- if( team->t.t_pkfn != (microtask_t)__kmp_teams_master &&
- master_th->th.th_teams_level == team->t.t_level ) {
- ++level; // level was not increased in teams construct for team_of_workers before the parallel
- } // team->t.t_level will be increased inside parallel
- }
- if( level < __kmp_hot_teams_max_level ) {
- if( hot_teams[level].hot_team ) {
- // hot team has already been allocated for given level
- KMP_DEBUG_ASSERT(hot_teams[level].hot_team == team);
- use_hot_team = 1; // the team is ready to use
- } else {
- use_hot_team = 0; // AC: threads are not allocated yet
- hot_teams[level].hot_team = team; // remember new hot team
- hot_teams[level].hot_team_nth = team->t.t_nproc;
- }
- } else {
- use_hot_team = 0;
- }
+ use_hot_team = 0;
+ kmp_hot_team_ptr_t *hot_teams = master_th->th.th_hot_teams;
+ if (hot_teams) { // hot teams array is not allocated if
+ // KMP_HOT_TEAMS_MAX_LEVEL=0
+ int level = team->t.t_active_level - 1; // index in array of hot teams
+ if (master_th->th.th_teams_microtask) { // are we inside the teams?
+ if (master_th->th.th_teams_size.nteams > 1) {
+ ++level; // level was not increased in teams construct for
+ // team_of_masters
+ }
+ if (team->t.t_pkfn != (microtask_t)__kmp_teams_master &&
+ master_th->th.th_teams_level == team->t.t_level) {
+ ++level; // level was not increased in teams construct for
+ // team_of_workers before the parallel
+ } // team->t.t_level will be increased inside parallel
+ }
+ if (level < __kmp_hot_teams_max_level) {
+ if (hot_teams[level].hot_team) {
+ // hot team has already been allocated for given level
+ KMP_DEBUG_ASSERT(hot_teams[level].hot_team == team);
+ use_hot_team = 1; // the team is ready to use
+ } else {
+ use_hot_team = 0; // AC: threads are not allocated yet
+ hot_teams[level].hot_team = team; // remember new hot team
+ hot_teams[level].hot_team_nth = team->t.t_nproc;
+ }
+ } else {
+ use_hot_team = 0;
}
+ }
#else
- use_hot_team = team == root->r.r_hot_team;
+ use_hot_team = team == root->r.r_hot_team;
#endif
- if ( !use_hot_team ) {
+ if (!use_hot_team) {
- /* install the master thread */
- team->t.t_threads[ 0 ] = master_th;
- __kmp_initialize_info( master_th, team, 0, master_gtid );
-
- /* now, install the worker threads */
- for ( i=1 ; i < team->t.t_nproc ; i++ ) {
-
- /* fork or reallocate a new thread and install it in team */
- kmp_info_t *thr = __kmp_allocate_thread( root, team, i );
- team->t.t_threads[ i ] = thr;
- KMP_DEBUG_ASSERT( thr );
- KMP_DEBUG_ASSERT( thr->th.th_team == team );
- /* align team and thread arrived states */
- KA_TRACE( 20, ("__kmp_fork_team_threads: T#%d(%d:%d) init arrived T#%d(%d:%d) join =%llu, plain=%llu\n",
- __kmp_gtid_from_tid( 0, team ), team->t.t_id, 0,
- __kmp_gtid_from_tid( i, team ), team->t.t_id, i,
- team->t.t_bar[ bs_forkjoin_barrier ].b_arrived,
- team->t.t_bar[ bs_plain_barrier ].b_arrived ) );
-#if OMP_40_ENABLED
- thr->th.th_teams_microtask = master_th->th.th_teams_microtask;
- thr->th.th_teams_level = master_th->th.th_teams_level;
- thr->th.th_teams_size = master_th->th.th_teams_size;
-#endif
- { // Initialize threads' barrier data.
- int b;
- kmp_balign_t * balign = team->t.t_threads[ i ]->th.th_bar;
- for ( b = 0; b < bs_last_barrier; ++ b ) {
- balign[ b ].bb.b_arrived = team->t.t_bar[ b ].b_arrived;
- KMP_DEBUG_ASSERT(balign[b].bb.wait_flag != KMP_BARRIER_PARENT_FLAG);
+ /* install the master thread */
+ team->t.t_threads[0] = master_th;
+ __kmp_initialize_info(master_th, team, 0, master_gtid);
+
+ /* now, install the worker threads */
+ for (i = 1; i < team->t.t_nproc; i++) {
+
+ /* fork or reallocate a new thread and install it in team */
+ kmp_info_t *thr = __kmp_allocate_thread(root, team, i);
+ team->t.t_threads[i] = thr;
+ KMP_DEBUG_ASSERT(thr);
+ KMP_DEBUG_ASSERT(thr->th.th_team == team);
+ /* align team and thread arrived states */
+ KA_TRACE(20, ("__kmp_fork_team_threads: T#%d(%d:%d) init arrived "
+ "T#%d(%d:%d) join =%llu, plain=%llu\n",
+ __kmp_gtid_from_tid(0, team), team->t.t_id, 0,
+ __kmp_gtid_from_tid(i, team), team->t.t_id, i,
+ team->t.t_bar[bs_forkjoin_barrier].b_arrived,
+ team->t.t_bar[bs_plain_barrier].b_arrived));
+#if OMP_40_ENABLED
+ thr->th.th_teams_microtask = master_th->th.th_teams_microtask;
+ thr->th.th_teams_level = master_th->th.th_teams_level;
+ thr->th.th_teams_size = master_th->th.th_teams_size;
+#endif
+ { // Initialize threads' barrier data.
+ int b;
+ kmp_balign_t *balign = team->t.t_threads[i]->th.th_bar;
+ for (b = 0; b < bs_last_barrier; ++b) {
+ balign[b].bb.b_arrived = team->t.t_bar[b].b_arrived;
+ KMP_DEBUG_ASSERT(balign[b].bb.wait_flag != KMP_BARRIER_PARENT_FLAG);
#if USE_DEBUGGER
- balign[ b ].bb.b_worker_arrived = team->t.t_bar[ b ].b_team_arrived;
+ balign[b].bb.b_worker_arrived = team->t.t_bar[b].b_team_arrived;
#endif
- }; // for b
- }
- }
+ }; // for b
+ }
+ }
#if OMP_40_ENABLED && KMP_AFFINITY_SUPPORTED
- __kmp_partition_places( team );
+ __kmp_partition_places(team);
#endif
+ }
- }
-
- KMP_MB();
+ KMP_MB();
}
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
-//
// Propagate any changes to the floating point control registers out to the team
-// We try to avoid unnecessary writes to the relevant cache line in the team structure,
-// so we don't make changes unless they are needed.
-//
-inline static void
-propagateFPControl(kmp_team_t * team)
-{
- if ( __kmp_inherit_fp_control ) {
- kmp_int16 x87_fpu_control_word;
- kmp_uint32 mxcsr;
-
- // Get master values of FPU control flags (both X87 and vector)
- __kmp_store_x87_fpu_control_word( &x87_fpu_control_word );
- __kmp_store_mxcsr( &mxcsr );
- mxcsr &= KMP_X86_MXCSR_MASK;
-
- // There is no point looking at t_fp_control_saved here.
- // If it is TRUE, we still have to update the values if they are different from those we now have.
- // If it is FALSE we didn't save anything yet, but our objective is the same. We have to ensure
- // that the values in the team are the same as those we have.
- // So, this code achieves what we need whether or not t_fp_control_saved is true.
- // By checking whether the value needs updating we avoid unnecessary writes that would put the
- // cache-line into a written state, causing all threads in the team to have to read it again.
- KMP_CHECK_UPDATE(team->t.t_x87_fpu_control_word, x87_fpu_control_word);
- KMP_CHECK_UPDATE(team->t.t_mxcsr, mxcsr);
- // Although we don't use this value, other code in the runtime wants to know whether it should restore them.
- // So we must ensure it is correct.
- KMP_CHECK_UPDATE(team->t.t_fp_control_saved, TRUE);
- }
- else {
- // Similarly here. Don't write to this cache-line in the team structure unless we have to.
- KMP_CHECK_UPDATE(team->t.t_fp_control_saved, FALSE);
+// We try to avoid unnecessary writes to the relevant cache line in the team
+// structure, so we don't make changes unless they are needed.
+inline static void propagateFPControl(kmp_team_t *team) {
+ if (__kmp_inherit_fp_control) {
+ kmp_int16 x87_fpu_control_word;
+ kmp_uint32 mxcsr;
+
+ // Get master values of FPU control flags (both X87 and vector)
+ __kmp_store_x87_fpu_control_word(&x87_fpu_control_word);
+ __kmp_store_mxcsr(&mxcsr);
+ mxcsr &= KMP_X86_MXCSR_MASK;
+
+// There is no point looking at t_fp_control_saved here.
+// If it is TRUE, we still have to update the values if they are different from
+// those we now have.
+// If it is FALSE we didn't save anything yet, but our objective is the same. We
+// have to ensure that the values in the team are the same as those we have.
+// So, this code achieves what we need whether or not t_fp_control_saved is
+// true. By checking whether the value needs updating we avoid unnecessary
+// writes that would put the cache-line into a written state, causing all
+// threads in the team to have to read it again.
+ KMP_CHECK_UPDATE(team->t.t_x87_fpu_control_word, x87_fpu_control_word);
+ KMP_CHECK_UPDATE(team->t.t_mxcsr, mxcsr);
+ // Although we don't use this value, other code in the runtime wants to know
+ // whether it should restore them. So we must ensure it is correct.
+ KMP_CHECK_UPDATE(team->t.t_fp_control_saved, TRUE);
+ } else {
+ // Similarly here. Don't write to this cache-line in the team structure
+ // unless we have to.
+ KMP_CHECK_UPDATE(team->t.t_fp_control_saved, FALSE);
+ }
+}
+
+// Do the opposite, setting the hardware registers to the updated values from
+// the team.
+inline static void updateHWFPControl(kmp_team_t *team) {
+ if (__kmp_inherit_fp_control && team->t.t_fp_control_saved) {
+ // Only reset the fp control regs if they have been changed in the team.
+ // the parallel region that we are exiting.
+ kmp_int16 x87_fpu_control_word;
+ kmp_uint32 mxcsr;
+ __kmp_store_x87_fpu_control_word(&x87_fpu_control_word);
+ __kmp_store_mxcsr(&mxcsr);
+ mxcsr &= KMP_X86_MXCSR_MASK;
+
+ if (team->t.t_x87_fpu_control_word != x87_fpu_control_word) {
+ __kmp_clear_x87_fpu_status_word();
+ __kmp_load_x87_fpu_control_word(&team->t.t_x87_fpu_control_word);
}
-}
-
-// Do the opposite, setting the hardware registers to the updated values from the team.
-inline static void
-updateHWFPControl(kmp_team_t * team)
-{
- if ( __kmp_inherit_fp_control && team->t.t_fp_control_saved ) {
- //
- // Only reset the fp control regs if they have been changed in the team.
- // the parallel region that we are exiting.
- //
- kmp_int16 x87_fpu_control_word;
- kmp_uint32 mxcsr;
- __kmp_store_x87_fpu_control_word( &x87_fpu_control_word );
- __kmp_store_mxcsr( &mxcsr );
- mxcsr &= KMP_X86_MXCSR_MASK;
-
- if ( team->t.t_x87_fpu_control_word != x87_fpu_control_word ) {
- __kmp_clear_x87_fpu_status_word();
- __kmp_load_x87_fpu_control_word( &team->t.t_x87_fpu_control_word );
- }
- if ( team->t.t_mxcsr != mxcsr ) {
- __kmp_load_mxcsr( &team->t.t_mxcsr );
- }
+ if (team->t.t_mxcsr != mxcsr) {
+ __kmp_load_mxcsr(&team->t.t_mxcsr);
}
+ }
}
#else
-# define propagateFPControl(x) ((void)0)
-# define updateHWFPControl(x) ((void)0)
+#define propagateFPControl(x) ((void)0)
+#define updateHWFPControl(x) ((void)0)
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
-static void
-__kmp_alloc_argv_entries( int argc, kmp_team_t *team, int realloc ); // forward declaration
-
-/*
- * Run a parallel region that has been serialized, so runs only in a team of the single master thread.
- */
-void
-__kmp_serialized_parallel(ident_t *loc, kmp_int32 global_tid)
-{
- kmp_info_t *this_thr;
- kmp_team_t *serial_team;
-
- KC_TRACE( 10, ("__kmpc_serialized_parallel: called by T#%d\n", global_tid ) );
-
- /* Skip all this code for autopar serialized loops since it results in
- unacceptable overhead */
- if( loc != NULL && (loc->flags & KMP_IDENT_AUTOPAR ) )
- return;
-
- if( ! TCR_4( __kmp_init_parallel ) )
- __kmp_parallel_initialize();
-
- this_thr = __kmp_threads[ global_tid ];
- serial_team = this_thr->th.th_serial_team;
-
- /* utilize the serialized team held by this thread */
- KMP_DEBUG_ASSERT( serial_team );
- KMP_MB();
+static void __kmp_alloc_argv_entries(int argc, kmp_team_t *team,
+ int realloc); // forward declaration
- if ( __kmp_tasking_mode != tskm_immediate_exec ) {
- KMP_DEBUG_ASSERT(this_thr->th.th_task_team == this_thr->th.th_team->t.t_task_team[this_thr->th.th_task_state]);
- KMP_DEBUG_ASSERT( serial_team->t.t_task_team[this_thr->th.th_task_state] == NULL );
- KA_TRACE( 20, ( "__kmpc_serialized_parallel: T#%d pushing task_team %p / team %p, new task_team = NULL\n",
- global_tid, this_thr->th.th_task_team, this_thr->th.th_team ) );
- this_thr->th.th_task_team = NULL;
- }
+/* Run a parallel region that has been serialized, so runs only in a team of the
+ single master thread. */
+void __kmp_serialized_parallel(ident_t *loc, kmp_int32 global_tid) {
+ kmp_info_t *this_thr;
+ kmp_team_t *serial_team;
+
+ KC_TRACE(10, ("__kmpc_serialized_parallel: called by T#%d\n", global_tid));
+
+ /* Skip all this code for autopar serialized loops since it results in
+ unacceptable overhead */
+ if (loc != NULL && (loc->flags & KMP_IDENT_AUTOPAR))
+ return;
+
+ if (!TCR_4(__kmp_init_parallel))
+ __kmp_parallel_initialize();
+
+ this_thr = __kmp_threads[global_tid];
+ serial_team = this_thr->th.th_serial_team;
+
+ /* utilize the serialized team held by this thread */
+ KMP_DEBUG_ASSERT(serial_team);
+ KMP_MB();
+
+ if (__kmp_tasking_mode != tskm_immediate_exec) {
+ KMP_DEBUG_ASSERT(
+ this_thr->th.th_task_team ==
+ this_thr->th.th_team->t.t_task_team[this_thr->th.th_task_state]);
+ KMP_DEBUG_ASSERT(serial_team->t.t_task_team[this_thr->th.th_task_state] ==
+ NULL);
+ KA_TRACE(20, ("__kmpc_serialized_parallel: T#%d pushing task_team %p / "
+ "team %p, new task_team = NULL\n",
+ global_tid, this_thr->th.th_task_team, this_thr->th.th_team));
+ this_thr->th.th_task_team = NULL;
+ }
#if OMP_40_ENABLED
- kmp_proc_bind_t proc_bind = this_thr->th.th_set_proc_bind;
- if ( this_thr->th.th_current_task->td_icvs.proc_bind == proc_bind_false ) {
- proc_bind = proc_bind_false;
- }
- else if ( proc_bind == proc_bind_default ) {
- //
- // No proc_bind clause was specified, so use the current value
- // of proc-bind-var for this parallel region.
- //
- proc_bind = this_thr->th.th_current_task->td_icvs.proc_bind;
- }
- //
- // Reset for next parallel region
- //
- this_thr->th.th_set_proc_bind = proc_bind_default;
+ kmp_proc_bind_t proc_bind = this_thr->th.th_set_proc_bind;
+ if (this_thr->th.th_current_task->td_icvs.proc_bind == proc_bind_false) {
+ proc_bind = proc_bind_false;
+ } else if (proc_bind == proc_bind_default) {
+ // No proc_bind clause was specified, so use the current value
+ // of proc-bind-var for this parallel region.
+ proc_bind = this_thr->th.th_current_task->td_icvs.proc_bind;
+ }
+ // Reset for next parallel region
+ this_thr->th.th_set_proc_bind = proc_bind_default;
#endif /* OMP_40_ENABLED */
- if( this_thr->th.th_team != serial_team ) {
- // Nested level will be an index in the nested nthreads array
- int level = this_thr->th.th_team->t.t_level;
+ if (this_thr->th.th_team != serial_team) {
+ // Nested level will be an index in the nested nthreads array
+ int level = this_thr->th.th_team->t.t_level;
- if( serial_team->t.t_serialized ) {
- /* this serial team was already used
- * TODO increase performance by making this locks more specific */
- kmp_team_t *new_team;
+ if (serial_team->t.t_serialized) {
+ /* this serial team was already used
+ TODO increase performance by making this locks more specific */
+ kmp_team_t *new_team;
- __kmp_acquire_bootstrap_lock( &__kmp_forkjoin_lock );
+ __kmp_acquire_bootstrap_lock(&__kmp_forkjoin_lock);
#if OMPT_SUPPORT
- ompt_parallel_id_t ompt_parallel_id = __ompt_parallel_id_new(global_tid);
+ ompt_parallel_id_t ompt_parallel_id = __ompt_parallel_id_new(global_tid);
#endif
- new_team = __kmp_allocate_team(this_thr->th.th_root, 1, 1,
+ new_team = __kmp_allocate_team(this_thr->th.th_root, 1, 1,
#if OMPT_SUPPORT
- ompt_parallel_id,
+ ompt_parallel_id,
#endif
#if OMP_40_ENABLED
- proc_bind,
+ proc_bind,
#endif
- & this_thr->th.th_current_task->td_icvs,
- 0 USE_NESTED_HOT_ARG(NULL) );
- __kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
- KMP_ASSERT( new_team );
-
- /* setup new serialized team and install it */
- new_team->t.t_threads[0] = this_thr;
- new_team->t.t_parent = this_thr->th.th_team;
- serial_team = new_team;
- this_thr->th.th_serial_team = serial_team;
+ &this_thr->th.th_current_task->td_icvs,
+ 0 USE_NESTED_HOT_ARG(NULL));
+ __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
+ KMP_ASSERT(new_team);
- KF_TRACE( 10, ( "__kmpc_serialized_parallel: T#%d allocated new serial team %p\n",
- global_tid, serial_team ) );
+ /* setup new serialized team and install it */
+ new_team->t.t_threads[0] = this_thr;
+ new_team->t.t_parent = this_thr->th.th_team;
+ serial_team = new_team;
+ this_thr->th.th_serial_team = serial_team;
+ KF_TRACE(
+ 10,
+ ("__kmpc_serialized_parallel: T#%d allocated new serial team %p\n",
+ global_tid, serial_team));
- /* TODO the above breaks the requirement that if we run out of
- * resources, then we can still guarantee that serialized teams
- * are ok, since we may need to allocate a new one */
- } else {
- KF_TRACE( 10, ( "__kmpc_serialized_parallel: T#%d reusing cached serial team %p\n",
- global_tid, serial_team ) );
- }
-
- /* we have to initialize this serial team */
- KMP_DEBUG_ASSERT( serial_team->t.t_threads );
- KMP_DEBUG_ASSERT( serial_team->t.t_threads[0] == this_thr );
- KMP_DEBUG_ASSERT( this_thr->th.th_team != serial_team );
- serial_team->t.t_ident = loc;
- serial_team->t.t_serialized = 1;
- serial_team->t.t_nproc = 1;
- serial_team->t.t_parent = this_thr->th.th_team;
- serial_team->t.t_sched = this_thr->th.th_team->t.t_sched;
- this_thr->th.th_team = serial_team;
- serial_team->t.t_master_tid = this_thr->th.th_info.ds.ds_tid;
-
- KF_TRACE( 10, ( "__kmpc_serialized_parallel: T#d curtask=%p\n",
- global_tid, this_thr->th.th_current_task ) );
- KMP_ASSERT( this_thr->th.th_current_task->td_flags.executing == 1 );
- this_thr->th.th_current_task->td_flags.executing = 0;
-
- __kmp_push_current_task_to_thread( this_thr, serial_team, 0 );
-
- /* TODO: GEH: do the ICVs work for nested serialized teams? Don't we need an implicit task for
- each serialized task represented by team->t.t_serialized? */
- copy_icvs(
- & this_thr->th.th_current_task->td_icvs,
- & this_thr->th.th_current_task->td_parent->td_icvs );
-
- // Thread value exists in the nested nthreads array for the next nested level
- if ( __kmp_nested_nth.used && ( level + 1 < __kmp_nested_nth.used ) ) {
- this_thr->th.th_current_task->td_icvs.nproc = __kmp_nested_nth.nth[ level + 1 ];
- }
+ /* TODO the above breaks the requirement that if we run out of resources,
+ then we can still guarantee that serialized teams are ok, since we may
+ need to allocate a new one */
+ } else {
+ KF_TRACE(
+ 10,
+ ("__kmpc_serialized_parallel: T#%d reusing cached serial team %p\n",
+ global_tid, serial_team));
+ }
+
+ /* we have to initialize this serial team */
+ KMP_DEBUG_ASSERT(serial_team->t.t_threads);
+ KMP_DEBUG_ASSERT(serial_team->t.t_threads[0] == this_thr);
+ KMP_DEBUG_ASSERT(this_thr->th.th_team != serial_team);
+ serial_team->t.t_ident = loc;
+ serial_team->t.t_serialized = 1;
+ serial_team->t.t_nproc = 1;
+ serial_team->t.t_parent = this_thr->th.th_team;
+ serial_team->t.t_sched = this_thr->th.th_team->t.t_sched;
+ this_thr->th.th_team = serial_team;
+ serial_team->t.t_master_tid = this_thr->th.th_info.ds.ds_tid;
+
+ KF_TRACE(10, ("__kmpc_serialized_parallel: T#d curtask=%p\n", global_tid,
+ this_thr->th.th_current_task));
+ KMP_ASSERT(this_thr->th.th_current_task->td_flags.executing == 1);
+ this_thr->th.th_current_task->td_flags.executing = 0;
+
+ __kmp_push_current_task_to_thread(this_thr, serial_team, 0);
+
+ /* TODO: GEH: do ICVs work for nested serialized teams? Don't we need an
+ implicit task for each serialized task represented by
+ team->t.t_serialized? */
+ copy_icvs(&this_thr->th.th_current_task->td_icvs,
+ &this_thr->th.th_current_task->td_parent->td_icvs);
+
+ // Thread value exists in the nested nthreads array for the next nested
+ // level
+ if (__kmp_nested_nth.used && (level + 1 < __kmp_nested_nth.used)) {
+ this_thr->th.th_current_task->td_icvs.nproc =
+ __kmp_nested_nth.nth[level + 1];
+ }
#if OMP_40_ENABLED
- if ( __kmp_nested_proc_bind.used && ( level + 1 < __kmp_nested_proc_bind.used ) ) {
- this_thr->th.th_current_task->td_icvs.proc_bind
- = __kmp_nested_proc_bind.bind_types[ level + 1 ];
- }
+ if (__kmp_nested_proc_bind.used &&
+ (level + 1 < __kmp_nested_proc_bind.used)) {
+ this_thr->th.th_current_task->td_icvs.proc_bind =
+ __kmp_nested_proc_bind.bind_types[level + 1];
+ }
#endif /* OMP_40_ENABLED */
#if USE_DEBUGGER
- serial_team->t.t_pkfn = (microtask_t)( ~0 ); // For the debugger.
+ serial_team->t.t_pkfn = (microtask_t)(~0); // For the debugger.
#endif
- this_thr->th.th_info.ds.ds_tid = 0;
+ this_thr->th.th_info.ds.ds_tid = 0;
- /* set thread cache values */
- this_thr->th.th_team_nproc = 1;
- this_thr->th.th_team_master = this_thr;
- this_thr->th.th_team_serialized = 1;
+ /* set thread cache values */
+ this_thr->th.th_team_nproc = 1;
+ this_thr->th.th_team_master = this_thr;
+ this_thr->th.th_team_serialized = 1;
- serial_team->t.t_level = serial_team->t.t_parent->t.t_level + 1;
- serial_team->t.t_active_level = serial_team->t.t_parent->t.t_active_level;
+ serial_team->t.t_level = serial_team->t.t_parent->t.t_level + 1;
+ serial_team->t.t_active_level = serial_team->t.t_parent->t.t_active_level;
- propagateFPControl (serial_team);
+ propagateFPControl(serial_team);
- /* check if we need to allocate dispatch buffers stack */
- KMP_DEBUG_ASSERT(serial_team->t.t_dispatch);
- if ( !serial_team->t.t_dispatch->th_disp_buffer ) {
- serial_team->t.t_dispatch->th_disp_buffer = (dispatch_private_info_t *)
- __kmp_allocate( sizeof( dispatch_private_info_t ) );
- }
- this_thr->th.th_dispatch = serial_team->t.t_dispatch;
+ /* check if we need to allocate dispatch buffers stack */
+ KMP_DEBUG_ASSERT(serial_team->t.t_dispatch);
+ if (!serial_team->t.t_dispatch->th_disp_buffer) {
+ serial_team->t.t_dispatch->th_disp_buffer =
+ (dispatch_private_info_t *)__kmp_allocate(
+ sizeof(dispatch_private_info_t));
+ }
+ this_thr->th.th_dispatch = serial_team->t.t_dispatch;
#if OMPT_SUPPORT
- ompt_parallel_id_t ompt_parallel_id = __ompt_parallel_id_new(global_tid);
- __ompt_team_assign_id(serial_team, ompt_parallel_id);
+ ompt_parallel_id_t ompt_parallel_id = __ompt_parallel_id_new(global_tid);
+ __ompt_team_assign_id(serial_team, ompt_parallel_id);
#endif
- KMP_MB();
+ KMP_MB();
- } else {
- /* this serialized team is already being used,
- * that's fine, just add another nested level */
- KMP_DEBUG_ASSERT( this_thr->th.th_team == serial_team );
- KMP_DEBUG_ASSERT( serial_team->t.t_threads );
- KMP_DEBUG_ASSERT( serial_team->t.t_threads[0] == this_thr );
- ++ serial_team->t.t_serialized;
- this_thr->th.th_team_serialized = serial_team->t.t_serialized;
-
- // Nested level will be an index in the nested nthreads array
- int level = this_thr->th.th_team->t.t_level;
- // Thread value exists in the nested nthreads array for the next nested level
- if ( __kmp_nested_nth.used && ( level + 1 < __kmp_nested_nth.used ) ) {
- this_thr->th.th_current_task->td_icvs.nproc = __kmp_nested_nth.nth[ level + 1 ];
- }
- serial_team->t.t_level++;
- KF_TRACE( 10, ( "__kmpc_serialized_parallel: T#%d increasing nesting level of serial team %p to %d\n",
- global_tid, serial_team, serial_team->t.t_level ) );
+ } else {
+ /* this serialized team is already being used,
+ * that's fine, just add another nested level */
+ KMP_DEBUG_ASSERT(this_thr->th.th_team == serial_team);
+ KMP_DEBUG_ASSERT(serial_team->t.t_threads);
+ KMP_DEBUG_ASSERT(serial_team->t.t_threads[0] == this_thr);
+ ++serial_team->t.t_serialized;
+ this_thr->th.th_team_serialized = serial_team->t.t_serialized;
- /* allocate/push dispatch buffers stack */
- KMP_DEBUG_ASSERT(serial_team->t.t_dispatch);
- {
- dispatch_private_info_t * disp_buffer = (dispatch_private_info_t *)
- __kmp_allocate( sizeof( dispatch_private_info_t ) );
- disp_buffer->next = serial_team->t.t_dispatch->th_disp_buffer;
- serial_team->t.t_dispatch->th_disp_buffer = disp_buffer;
- }
- this_thr->th.th_dispatch = serial_team->t.t_dispatch;
+ // Nested level will be an index in the nested nthreads array
+ int level = this_thr->th.th_team->t.t_level;
+ // Thread value exists in the nested nthreads array for the next nested
+ // level
+ if (__kmp_nested_nth.used && (level + 1 < __kmp_nested_nth.used)) {
+ this_thr->th.th_current_task->td_icvs.nproc =
+ __kmp_nested_nth.nth[level + 1];
+ }
+ serial_team->t.t_level++;
+ KF_TRACE(10, ("__kmpc_serialized_parallel: T#%d increasing nesting level "
+ "of serial team %p to %d\n",
+ global_tid, serial_team, serial_team->t.t_level));
- KMP_MB();
+ /* allocate/push dispatch buffers stack */
+ KMP_DEBUG_ASSERT(serial_team->t.t_dispatch);
+ {
+ dispatch_private_info_t *disp_buffer =
+ (dispatch_private_info_t *)__kmp_allocate(
+ sizeof(dispatch_private_info_t));
+ disp_buffer->next = serial_team->t.t_dispatch->th_disp_buffer;
+ serial_team->t.t_dispatch->th_disp_buffer = disp_buffer;
}
+ this_thr->th.th_dispatch = serial_team->t.t_dispatch;
+
+ KMP_MB();
+ }
#if OMP_40_ENABLED
- KMP_CHECK_UPDATE(serial_team->t.t_cancel_request, cancel_noreq);
+ KMP_CHECK_UPDATE(serial_team->t.t_cancel_request, cancel_noreq);
#endif
- if ( __kmp_env_consistency_check )
- __kmp_push_parallel( global_tid, NULL );
-
+ if (__kmp_env_consistency_check)
+ __kmp_push_parallel(global_tid, NULL);
}
/* most of the work for a fork */
/* return true if we really went parallel, false if serialized */
-int
-__kmp_fork_call(
- ident_t * loc,
- int gtid,
- enum fork_context_e call_context, // Intel, GNU, ...
- kmp_int32 argc,
+int __kmp_fork_call(ident_t *loc, int gtid,
+ enum fork_context_e call_context, // Intel, GNU, ...
+ kmp_int32 argc,
#if OMPT_SUPPORT
- void *unwrapped_task,
+ void *unwrapped_task,
#endif
- microtask_t microtask,
- launch_t invoker,
+ microtask_t microtask, launch_t invoker,
/* TODO: revert workaround for Intel(R) 64 tracker #96 */
#if (KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) && KMP_OS_LINUX
- va_list * ap
+ va_list *ap
#else
- va_list ap
+ va_list ap
#endif
- )
-{
- void **argv;
- int i;
- int master_tid;
- int master_this_cons;
- kmp_team_t *team;
- kmp_team_t *parent_team;
- kmp_info_t *master_th;
- kmp_root_t *root;
- int nthreads;
- int master_active;
- int master_set_numthreads;
- int level;
+ ) {
+ void **argv;
+ int i;
+ int master_tid;
+ int master_this_cons;
+ kmp_team_t *team;
+ kmp_team_t *parent_team;
+ kmp_info_t *master_th;
+ kmp_root_t *root;
+ int nthreads;
+ int master_active;
+ int master_set_numthreads;
+ int level;
#if OMP_40_ENABLED
- int active_level;
- int teams_level;
+ int active_level;
+ int teams_level;
#endif
#if KMP_NESTED_HOT_TEAMS
- kmp_hot_team_ptr_t **p_hot_teams;
+ kmp_hot_team_ptr_t **p_hot_teams;
#endif
- { // KMP_TIME_BLOCK
+ { // KMP_TIME_BLOCK
KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_fork_call);
KMP_COUNT_VALUE(OMP_PARALLEL_args, argc);
- KA_TRACE( 20, ("__kmp_fork_call: enter T#%d\n", gtid ));
- if ( __kmp_stkpadding > 0 && __kmp_root[gtid] != NULL ) {
- /* Some systems prefer the stack for the root thread(s) to start with */
- /* some gap from the parent stack to prevent false sharing. */
- void *dummy = KMP_ALLOCA(__kmp_stkpadding);
- /* These 2 lines below are so this does not get optimized out */
- if ( __kmp_stkpadding > KMP_MAX_STKPADDING )
- __kmp_stkpadding += (short)((kmp_int64)dummy);
+ KA_TRACE(20, ("__kmp_fork_call: enter T#%d\n", gtid));
+ if (__kmp_stkpadding > 0 && __kmp_root[gtid] != NULL) {
+ /* Some systems prefer the stack for the root thread(s) to start with */
+ /* some gap from the parent stack to prevent false sharing. */
+ void *dummy = KMP_ALLOCA(__kmp_stkpadding);
+ /* These 2 lines below are so this does not get optimized out */
+ if (__kmp_stkpadding > KMP_MAX_STKPADDING)
+ __kmp_stkpadding += (short)((kmp_int64)dummy);
}
/* initialize if needed */
- KMP_DEBUG_ASSERT( __kmp_init_serial ); // AC: potentially unsafe, not in sync with shutdown
- if( ! TCR_4(__kmp_init_parallel) )
- __kmp_parallel_initialize();
+ KMP_DEBUG_ASSERT(
+ __kmp_init_serial); // AC: potentially unsafe, not in sync with shutdown
+ if (!TCR_4(__kmp_init_parallel))
+ __kmp_parallel_initialize();
/* setup current data */
- master_th = __kmp_threads[ gtid ]; // AC: potentially unsafe, not in sync with shutdown
- parent_team = master_th->th.th_team;
- master_tid = master_th->th.th_info.ds.ds_tid;
+ master_th = __kmp_threads[gtid]; // AC: potentially unsafe, not in sync with
+ // shutdown
+ parent_team = master_th->th.th_team;
+ master_tid = master_th->th.th_info.ds.ds_tid;
master_this_cons = master_th->th.th_local.this_construct;
- root = master_th->th.th_root;
+ root = master_th->th.th_root;
master_active = root->r.r_active;
master_set_numthreads = master_th->th.th_set_nproc;
@@ -1457,511 +1413,548 @@ __kmp_fork_call(
ompt_parallel_id_t my_parallel_id;
if (ompt_enabled) {
- ompt_parallel_id = __ompt_parallel_id_new(gtid);
- ompt_task_id = __ompt_get_task_id_internal(0);
- ompt_frame = __ompt_get_task_frame_internal(0);
+ ompt_parallel_id = __ompt_parallel_id_new(gtid);
+ ompt_task_id = __ompt_get_task_id_internal(0);
+ ompt_frame = __ompt_get_task_frame_internal(0);
}
#endif
// Nested level will be an index in the nested nthreads array
- level = parent_team->t.t_level;
- active_level = parent_team->t.t_active_level; // is used to launch non-serial teams even if nested is not allowed
-#if OMP_40_ENABLED
- teams_level = master_th->th.th_teams_level; // needed to check nesting inside the teams
+ level = parent_team->t.t_level;
+ // used to launch non-serial teams even if nested is not allowed
+ active_level = parent_team->t.t_active_level;
+#if OMP_40_ENABLED
+ teams_level =
+ master_th->th
+ .th_teams_level; // needed to check nesting inside the teams
#endif
#if KMP_NESTED_HOT_TEAMS
- p_hot_teams = &master_th->th.th_hot_teams;
- if( *p_hot_teams == NULL && __kmp_hot_teams_max_level > 0 ) {
- *p_hot_teams = (kmp_hot_team_ptr_t*)__kmp_allocate(
- sizeof(kmp_hot_team_ptr_t) * __kmp_hot_teams_max_level);
- (*p_hot_teams)[0].hot_team = root->r.r_hot_team;
- (*p_hot_teams)[0].hot_team_nth = 1; // it is either actual or not needed (when active_level > 0)
+ p_hot_teams = &master_th->th.th_hot_teams;
+ if (*p_hot_teams == NULL && __kmp_hot_teams_max_level > 0) {
+ *p_hot_teams = (kmp_hot_team_ptr_t *)__kmp_allocate(
+ sizeof(kmp_hot_team_ptr_t) * __kmp_hot_teams_max_level);
+ (*p_hot_teams)[0].hot_team = root->r.r_hot_team;
+ (*p_hot_teams)[0].hot_team_nth =
+ 1; // it is either actual or not needed (when active_level > 0)
}
#endif
#if OMPT_SUPPORT
if (ompt_enabled &&
ompt_callbacks.ompt_callback(ompt_event_parallel_begin)) {
- int team_size = master_set_numthreads;
+ int team_size = master_set_numthreads;
- ompt_callbacks.ompt_callback(ompt_event_parallel_begin)(
- ompt_task_id, ompt_frame, ompt_parallel_id,
- team_size, unwrapped_task, OMPT_INVOKER(call_context));
+ ompt_callbacks.ompt_callback(ompt_event_parallel_begin)(
+ ompt_task_id, ompt_frame, ompt_parallel_id, team_size, unwrapped_task,
+ OMPT_INVOKER(call_context));
}
#endif
master_th->th.th_ident = loc;
#if OMP_40_ENABLED
- if ( master_th->th.th_teams_microtask &&
- ap && microtask != (microtask_t)__kmp_teams_master && level == teams_level ) {
- // AC: This is start of parallel that is nested inside teams construct.
- // The team is actual (hot), all workers are ready at the fork barrier.
- // No lock needed to initialize the team a bit, then free workers.
- parent_team->t.t_ident = loc;
- __kmp_alloc_argv_entries( argc, parent_team, TRUE );
- parent_team->t.t_argc = argc;
- argv = (void**)parent_team->t.t_argv;
- for( i=argc-1; i >= 0; --i )
+ if (master_th->th.th_teams_microtask && ap &&
+ microtask != (microtask_t)__kmp_teams_master && level == teams_level) {
+ // AC: This is start of parallel that is nested inside teams construct.
+ // The team is actual (hot), all workers are ready at the fork barrier.
+ // No lock needed to initialize the team a bit, then free workers.
+ parent_team->t.t_ident = loc;
+ __kmp_alloc_argv_entries(argc, parent_team, TRUE);
+ parent_team->t.t_argc = argc;
+ argv = (void **)parent_team->t.t_argv;
+ for (i = argc - 1; i >= 0; --i)
/* TODO: revert workaround for Intel(R) 64 tracker #96 */
#if (KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) && KMP_OS_LINUX
- *argv++ = va_arg( *ap, void * );
+ *argv++ = va_arg(*ap, void *);
#else
- *argv++ = va_arg( ap, void * );
+ *argv++ = va_arg(ap, void *);
#endif
- /* Increment our nested depth levels, but not increase the serialization */
- if ( parent_team == master_th->th.th_serial_team ) {
- // AC: we are in serialized parallel
- __kmpc_serialized_parallel(loc, gtid);
- KMP_DEBUG_ASSERT( parent_team->t.t_serialized > 1 );
- parent_team->t.t_serialized--; // AC: need this in order enquiry functions
- // work correctly, will restore at join time
-
+ // Increment our nested depth levels, but not increase the serialization
+ if (parent_team == master_th->th.th_serial_team) {
+ // AC: we are in serialized parallel
+ __kmpc_serialized_parallel(loc, gtid);
+ KMP_DEBUG_ASSERT(parent_team->t.t_serialized > 1);
+ // AC: need this in order enquiry functions work
+ // correctly, will restore at join time
+ parent_team->t.t_serialized--;
#if OMPT_SUPPORT
- void *dummy;
- void **exit_runtime_p;
+ void *dummy;
+ void **exit_runtime_p;
- ompt_lw_taskteam_t lw_taskteam;
+ ompt_lw_taskteam_t lw_taskteam;
- if (ompt_enabled) {
- __ompt_lw_taskteam_init(&lw_taskteam, master_th, gtid,
- unwrapped_task, ompt_parallel_id);
- lw_taskteam.ompt_task_info.task_id = __ompt_task_id_new(gtid);
- exit_runtime_p = &(lw_taskteam.ompt_task_info.frame.exit_runtime_frame);
+ if (ompt_enabled) {
+ __ompt_lw_taskteam_init(&lw_taskteam, master_th, gtid, unwrapped_task,
+ ompt_parallel_id);
+ lw_taskteam.ompt_task_info.task_id = __ompt_task_id_new(gtid);
+ exit_runtime_p =
+ &(lw_taskteam.ompt_task_info.frame.exit_runtime_frame);
- __ompt_lw_taskteam_link(&lw_taskteam, master_th);
+ __ompt_lw_taskteam_link(&lw_taskteam, master_th);
#if OMPT_TRACE
- /* OMPT implicit task begin */
- my_task_id = lw_taskteam.ompt_task_info.task_id;
- my_parallel_id = parent_team->t.ompt_team_info.parallel_id;
- if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
- ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(
- my_parallel_id, my_task_id);
- }
+ /* OMPT implicit task begin */
+ my_task_id = lw_taskteam.ompt_task_info.task_id;
+ my_parallel_id = parent_team->t.ompt_team_info.parallel_id;
+ if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
+ ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(
+ my_parallel_id, my_task_id);
+ }
#endif
- /* OMPT state */
- master_th->th.ompt_thread_info.state = ompt_state_work_parallel;
- } else {
- exit_runtime_p = &dummy;
- }
-#endif
+ /* OMPT state */
+ master_th->th.ompt_thread_info.state = ompt_state_work_parallel;
+ } else {
+ exit_runtime_p = &dummy;
+ }
+#endif
- {
- KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
- KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
- __kmp_invoke_microtask( microtask, gtid, 0, argc, parent_team->t.t_argv
+ {
+ KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
+ KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
+ __kmp_invoke_microtask(microtask, gtid, 0, argc, parent_team->t.t_argv
#if OMPT_SUPPORT
- , exit_runtime_p
+ ,
+ exit_runtime_p
#endif
- );
- }
+ );
+ }
#if OMPT_SUPPORT
- *exit_runtime_p = NULL;
- if (ompt_enabled) {
+ *exit_runtime_p = NULL;
+ if (ompt_enabled) {
#if OMPT_TRACE
- lw_taskteam.ompt_task_info.frame.exit_runtime_frame = NULL;
+ lw_taskteam.ompt_task_info.frame.exit_runtime_frame = NULL;
- if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
- ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
- ompt_parallel_id, ompt_task_id);
- }
-
- __ompt_lw_taskteam_unlink(master_th);
- // reset clear the task id only after unlinking the task
- lw_taskteam.ompt_task_info.task_id = ompt_task_id_none;
-#endif
-
- if (ompt_callbacks.ompt_callback(ompt_event_parallel_end)) {
- ompt_callbacks.ompt_callback(ompt_event_parallel_end)(
- ompt_parallel_id, ompt_task_id,
- OMPT_INVOKER(call_context));
- }
- master_th->th.ompt_thread_info.state = ompt_state_overhead;
- }
-#endif
- return TRUE;
+ if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
+ ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
+ ompt_parallel_id, ompt_task_id);
+ }
+
+ __ompt_lw_taskteam_unlink(master_th);
+ // reset clear the task id only after unlinking the task
+ lw_taskteam.ompt_task_info.task_id = ompt_task_id_none;
+#endif
+
+ if (ompt_callbacks.ompt_callback(ompt_event_parallel_end)) {
+ ompt_callbacks.ompt_callback(ompt_event_parallel_end)(
+ ompt_parallel_id, ompt_task_id, OMPT_INVOKER(call_context));
+ }
+ master_th->th.ompt_thread_info.state = ompt_state_overhead;
}
+#endif
+ return TRUE;
+ }
- parent_team->t.t_pkfn = microtask;
+ parent_team->t.t_pkfn = microtask;
#if OMPT_SUPPORT
- parent_team->t.ompt_team_info.microtask = unwrapped_task;
+ parent_team->t.ompt_team_info.microtask = unwrapped_task;
#endif
- parent_team->t.t_invoke = invoker;
- KMP_TEST_THEN_INC32( (kmp_int32*) &root->r.r_in_parallel );
- parent_team->t.t_active_level ++;
- parent_team->t.t_level ++;
-
- /* Change number of threads in the team if requested */
- if ( master_set_numthreads ) { // The parallel has num_threads clause
- if ( master_set_numthreads < master_th->th.th_teams_size.nth ) {
- // AC: only can reduce the number of threads dynamically, cannot increase
- kmp_info_t **other_threads = parent_team->t.t_threads;
- parent_team->t.t_nproc = master_set_numthreads;
- for ( i = 0; i < master_set_numthreads; ++i ) {
- other_threads[i]->th.th_team_nproc = master_set_numthreads;
- }
- // Keep extra threads hot in the team for possible next parallels
- }
- master_th->th.th_set_nproc = 0;
+ parent_team->t.t_invoke = invoker;
+ KMP_TEST_THEN_INC32((kmp_int32 *)&root->r.r_in_parallel);
+ parent_team->t.t_active_level++;
+ parent_team->t.t_level++;
+
+ /* Change number of threads in the team if requested */
+ if (master_set_numthreads) { // The parallel has num_threads clause
+ if (master_set_numthreads < master_th->th.th_teams_size.nth) {
+ // AC: only can reduce number of threads dynamically, can't increase
+ kmp_info_t **other_threads = parent_team->t.t_threads;
+ parent_team->t.t_nproc = master_set_numthreads;
+ for (i = 0; i < master_set_numthreads; ++i) {
+ other_threads[i]->th.th_team_nproc = master_set_numthreads;
+ }
+ // Keep extra threads hot in the team for possible next parallels
}
+ master_th->th.th_set_nproc = 0;
+ }
#if USE_DEBUGGER
- if ( __kmp_debugging ) { // Let debugger override number of threads.
- int nth = __kmp_omp_num_threads( loc );
- if ( nth > 0 ) { // 0 means debugger does not want to change number of threads.
- master_set_numthreads = nth;
+ if (__kmp_debugging) { // Let debugger override number of threads.
+ int nth = __kmp_omp_num_threads(loc);
+ if (nth >
+ 0) { // 0 means debugger does not want to change number of threads.
+ master_set_numthreads = nth;
}; // if
- }; // if
+ }; // if
#endif
- KF_TRACE( 10, ( "__kmp_fork_call: before internal fork: root=%p, team=%p, master_th=%p, gtid=%d\n", root, parent_team, master_th, gtid ) );
- __kmp_internal_fork( loc, gtid, parent_team );
- KF_TRACE( 10, ( "__kmp_fork_call: after internal fork: root=%p, team=%p, master_th=%p, gtid=%d\n", root, parent_team, master_th, gtid ) );
-
- /* Invoke microtask for MASTER thread */
- KA_TRACE( 20, ("__kmp_fork_call: T#%d(%d:0) invoke microtask = %p\n",
- gtid, parent_team->t.t_id, parent_team->t.t_pkfn ) );
+ KF_TRACE(10, ("__kmp_fork_call: before internal fork: root=%p, team=%p, "
+ "master_th=%p, gtid=%d\n",
+ root, parent_team, master_th, gtid));
+ __kmp_internal_fork(loc, gtid, parent_team);
+ KF_TRACE(10, ("__kmp_fork_call: after internal fork: root=%p, team=%p, "
+ "master_th=%p, gtid=%d\n",
+ root, parent_team, master_th, gtid));
+
+ /* Invoke microtask for MASTER thread */
+ KA_TRACE(20, ("__kmp_fork_call: T#%d(%d:0) invoke microtask = %p\n", gtid,
+ parent_team->t.t_id, parent_team->t.t_pkfn));
- {
- KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
- KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
- if (! parent_team->t.t_invoke( gtid )) {
- KMP_ASSERT2( 0, "cannot invoke microtask for MASTER thread" );
- }
+ {
+ KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
+ KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
+ if (!parent_team->t.t_invoke(gtid)) {
+ KMP_ASSERT2(0, "cannot invoke microtask for MASTER thread");
}
- KA_TRACE( 20, ("__kmp_fork_call: T#%d(%d:0) done microtask = %p\n",
- gtid, parent_team->t.t_id, parent_team->t.t_pkfn ) );
- KMP_MB(); /* Flush all pending memory write invalidates. */
+ }
+ KA_TRACE(20, ("__kmp_fork_call: T#%d(%d:0) done microtask = %p\n", gtid,
+ parent_team->t.t_id, parent_team->t.t_pkfn));
+ KMP_MB(); /* Flush all pending memory write invalidates. */
- KA_TRACE( 20, ("__kmp_fork_call: parallel exit T#%d\n", gtid ));
+ KA_TRACE(20, ("__kmp_fork_call: parallel exit T#%d\n", gtid));
- return TRUE;
+ return TRUE;
} // Parallel closely nested in teams construct
#endif /* OMP_40_ENABLED */
#if KMP_DEBUG
- if ( __kmp_tasking_mode != tskm_immediate_exec ) {
- KMP_DEBUG_ASSERT(master_th->th.th_task_team == parent_team->t.t_task_team[master_th->th.th_task_state]);
+ if (__kmp_tasking_mode != tskm_immediate_exec) {
+ KMP_DEBUG_ASSERT(master_th->th.th_task_team ==
+ parent_team->t.t_task_team[master_th->th.th_task_state]);
}
#endif
- if ( parent_team->t.t_active_level >= master_th->th.th_current_task->td_icvs.max_active_levels ) {
- nthreads = 1;
+ if (parent_team->t.t_active_level >=
+ master_th->th.th_current_task->td_icvs.max_active_levels) {
+ nthreads = 1;
} else {
#if OMP_40_ENABLED
- int enter_teams = ((ap==NULL && active_level==0)||(ap && teams_level>0 && teams_level==level));
+ int enter_teams = ((ap == NULL && active_level == 0) ||
+ (ap && teams_level > 0 && teams_level == level));
#endif
- nthreads = master_set_numthreads ?
- master_set_numthreads : get__nproc_2( parent_team, master_tid ); // TODO: get nproc directly from current task
-
- // Check if we need to take forkjoin lock? (no need for serialized parallel out of teams construct).
- // This code moved here from __kmp_reserve_threads() to speedup nested serialized parallels.
- if (nthreads > 1) {
- if ( ( !get__nested(master_th) && (root->r.r_in_parallel
+ nthreads =
+ master_set_numthreads
+ ? master_set_numthreads
+ : get__nproc_2(
+ parent_team,
+ master_tid); // TODO: get nproc directly from current task
+
+ // Check if we need to take forkjoin lock? (no need for serialized
+ // parallel out of teams construct). This code moved here from
+ // __kmp_reserve_threads() to speedup nested serialized parallels.
+ if (nthreads > 1) {
+ if ((!get__nested(master_th) && (root->r.r_in_parallel
#if OMP_40_ENABLED
- && !enter_teams
+ && !enter_teams
#endif /* OMP_40_ENABLED */
- ) ) || ( __kmp_library == library_serial ) ) {
- KC_TRACE( 10, ( "__kmp_fork_call: T#%d serializing team; requested %d threads\n",
- gtid, nthreads ));
- nthreads = 1;
- }
- }
- if ( nthreads > 1 ) {
- /* determine how many new threads we can use */
- __kmp_acquire_bootstrap_lock( &__kmp_forkjoin_lock );
-
- nthreads = __kmp_reserve_threads(root, parent_team, master_tid, nthreads
-#if OMP_40_ENABLED
-/* AC: If we execute teams from parallel region (on host), then teams should be created
- but each can only have 1 thread if nesting is disabled. If teams called from serial region,
- then teams and their threads should be created regardless of the nesting setting. */
- , enter_teams
+ )) ||
+ (__kmp_library == library_serial)) {
+ KC_TRACE(
+ 10,
+ ("__kmp_fork_call: T#%d serializing team; requested %d threads\n",
+ gtid, nthreads));
+ nthreads = 1;
+ }
+ }
+ if (nthreads > 1) {
+ /* determine how many new threads we can use */
+ __kmp_acquire_bootstrap_lock(&__kmp_forkjoin_lock);
+
+ nthreads = __kmp_reserve_threads(
+ root, parent_team, master_tid, nthreads
+#if OMP_40_ENABLED
+ /* AC: If we execute teams from parallel region (on host), then
+ teams should be created but each can only have 1 thread if
+ nesting is disabled. If teams called from serial region, then
+ teams and their threads should be created regardless of the
+ nesting setting. */
+ ,
+ enter_teams
#endif /* OMP_40_ENABLED */
- );
- if ( nthreads == 1 ) {
- // Free lock for single thread execution here;
- // for multi-thread execution it will be freed later
- // after team of threads created and initialized
- __kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
- }
+ );
+ if (nthreads == 1) {
+ // Free lock for single thread execution here; for multi-thread
+ // execution it will be freed later after team of threads created
+ // and initialized
+ __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
}
+ }
}
- KMP_DEBUG_ASSERT( nthreads > 0 );
+ KMP_DEBUG_ASSERT(nthreads > 0);
- /* If we temporarily changed the set number of threads then restore it now */
+ // If we temporarily changed the set number of threads then restore it now
master_th->th.th_set_nproc = 0;
/* create a serialized parallel region? */
- if ( nthreads == 1 ) {
- /* josh todo: hypothetical question: what do we do for OS X*? */
-#if KMP_OS_LINUX && ( KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64)
- void * args[ argc ];
+ if (nthreads == 1) {
+/* josh todo: hypothetical question: what do we do for OS X*? */
+#if KMP_OS_LINUX && \
+ (KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64)
+ void *args[argc];
#else
- void * * args = (void**) KMP_ALLOCA( argc * sizeof( void * ) );
-#endif /* KMP_OS_LINUX && ( KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) */
+ void **args = (void **)KMP_ALLOCA(argc * sizeof(void *));
+#endif /* KMP_OS_LINUX && ( KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_ARCH_ARM || \
+ KMP_ARCH_AARCH64) */
- KA_TRACE( 20, ("__kmp_fork_call: T#%d serializing parallel region\n", gtid ));
+ KA_TRACE(20,
+ ("__kmp_fork_call: T#%d serializing parallel region\n", gtid));
- __kmpc_serialized_parallel(loc, gtid);
+ __kmpc_serialized_parallel(loc, gtid);
- if ( call_context == fork_context_intel ) {
- /* TODO this sucks, use the compiler itself to pass args! :) */
- master_th->th.th_serial_team->t.t_ident = loc;
+ if (call_context == fork_context_intel) {
+ /* TODO this sucks, use the compiler itself to pass args! :) */
+ master_th->th.th_serial_team->t.t_ident = loc;
#if OMP_40_ENABLED
- if ( !ap ) {
- // revert change made in __kmpc_serialized_parallel()
- master_th->th.th_serial_team->t.t_level--;
- // Get args from parent team for teams construct
+ if (!ap) {
+ // revert change made in __kmpc_serialized_parallel()
+ master_th->th.th_serial_team->t.t_level--;
+// Get args from parent team for teams construct
#if OMPT_SUPPORT
- void *dummy;
- void **exit_runtime_p;
+ void *dummy;
+ void **exit_runtime_p;
- ompt_lw_taskteam_t lw_taskteam;
+ ompt_lw_taskteam_t lw_taskteam;
- if (ompt_enabled) {
- __ompt_lw_taskteam_init(&lw_taskteam, master_th, gtid,
- unwrapped_task, ompt_parallel_id);
- lw_taskteam.ompt_task_info.task_id = __ompt_task_id_new(gtid);
- exit_runtime_p = &(lw_taskteam.ompt_task_info.frame.exit_runtime_frame);
+ if (ompt_enabled) {
+ __ompt_lw_taskteam_init(&lw_taskteam, master_th, gtid,
+ unwrapped_task, ompt_parallel_id);
+ lw_taskteam.ompt_task_info.task_id = __ompt_task_id_new(gtid);
+ exit_runtime_p =
+ &(lw_taskteam.ompt_task_info.frame.exit_runtime_frame);
- __ompt_lw_taskteam_link(&lw_taskteam, master_th);
+ __ompt_lw_taskteam_link(&lw_taskteam, master_th);
#if OMPT_TRACE
- my_task_id = lw_taskteam.ompt_task_info.task_id;
- if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
- ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(
- ompt_parallel_id, my_task_id);
- }
+ my_task_id = lw_taskteam.ompt_task_info.task_id;
+ if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
+ ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(
+ ompt_parallel_id, my_task_id);
+ }
#endif
- /* OMPT state */
- master_th->th.ompt_thread_info.state = ompt_state_work_parallel;
- } else {
- exit_runtime_p = &dummy;
- }
+ /* OMPT state */
+ master_th->th.ompt_thread_info.state = ompt_state_work_parallel;
+ } else {
+ exit_runtime_p = &dummy;
+ }
#endif
- {
- KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
- KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
- __kmp_invoke_microtask( microtask, gtid, 0, argc, parent_team->t.t_argv
+ {
+ KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
+ KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
+ __kmp_invoke_microtask(microtask, gtid, 0, argc,
+ parent_team->t.t_argv
#if OMPT_SUPPORT
- , exit_runtime_p
+ ,
+ exit_runtime_p
#endif
- );
- }
+ );
+ }
#if OMPT_SUPPORT
- *exit_runtime_p = NULL;
- if (ompt_enabled) {
- lw_taskteam.ompt_task_info.frame.exit_runtime_frame = NULL;
+ *exit_runtime_p = NULL;
+ if (ompt_enabled) {
+ lw_taskteam.ompt_task_info.frame.exit_runtime_frame = NULL;
#if OMPT_TRACE
- if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
- ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
- ompt_parallel_id, ompt_task_id);
- }
-#endif
-
- __ompt_lw_taskteam_unlink(master_th);
- // reset clear the task id only after unlinking the task
- lw_taskteam.ompt_task_info.task_id = ompt_task_id_none;
-
- if (ompt_callbacks.ompt_callback(ompt_event_parallel_end)) {
- ompt_callbacks.ompt_callback(ompt_event_parallel_end)(
- ompt_parallel_id, ompt_task_id,
- OMPT_INVOKER(call_context));
- }
- master_th->th.ompt_thread_info.state = ompt_state_overhead;
- }
-#endif
- } else if ( microtask == (microtask_t)__kmp_teams_master ) {
- KMP_DEBUG_ASSERT( master_th->th.th_team == master_th->th.th_serial_team );
- team = master_th->th.th_team;
- //team->t.t_pkfn = microtask;
- team->t.t_invoke = invoker;
- __kmp_alloc_argv_entries( argc, team, TRUE );
- team->t.t_argc = argc;
- argv = (void**) team->t.t_argv;
- if ( ap ) {
- for( i=argc-1; i >= 0; --i )
+ if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
+ ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
+ ompt_parallel_id, ompt_task_id);
+ }
+#endif
+
+ __ompt_lw_taskteam_unlink(master_th);
+ // reset clear the task id only after unlinking the task
+ lw_taskteam.ompt_task_info.task_id = ompt_task_id_none;
+
+ if (ompt_callbacks.ompt_callback(ompt_event_parallel_end)) {
+ ompt_callbacks.ompt_callback(ompt_event_parallel_end)(
+ ompt_parallel_id, ompt_task_id, OMPT_INVOKER(call_context));
+ }
+ master_th->th.ompt_thread_info.state = ompt_state_overhead;
+ }
+#endif
+ } else if (microtask == (microtask_t)__kmp_teams_master) {
+ KMP_DEBUG_ASSERT(master_th->th.th_team ==
+ master_th->th.th_serial_team);
+ team = master_th->th.th_team;
+ // team->t.t_pkfn = microtask;
+ team->t.t_invoke = invoker;
+ __kmp_alloc_argv_entries(argc, team, TRUE);
+ team->t.t_argc = argc;
+ argv = (void **)team->t.t_argv;
+ if (ap) {
+ for (i = argc - 1; i >= 0; --i)
// TODO: revert workaround for Intel(R) 64 tracker #96
-# if (KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) && KMP_OS_LINUX
- *argv++ = va_arg( *ap, void * );
-# else
- *argv++ = va_arg( ap, void * );
-# endif
- } else {
- for( i=0; i < argc; ++i )
- // Get args from parent team for teams construct
- argv[i] = parent_team->t.t_argv[i];
- }
- // AC: revert change made in __kmpc_serialized_parallel()
- // because initial code in teams should have level=0
- team->t.t_level--;
- // AC: call special invoker for outer "parallel" of the teams construct
- {
- KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
- KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
- invoker(gtid);
- }
- } else {
+#if (KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) && KMP_OS_LINUX
+ *argv++ = va_arg(*ap, void *);
+#else
+ *argv++ = va_arg(ap, void *);
+#endif
+ } else {
+ for (i = 0; i < argc; ++i)
+ // Get args from parent team for teams construct
+ argv[i] = parent_team->t.t_argv[i];
+ }
+ // AC: revert change made in __kmpc_serialized_parallel()
+ // because initial code in teams should have level=0
+ team->t.t_level--;
+ // AC: call special invoker for outer "parallel" of teams construct
+ {
+ KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
+ KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
+ invoker(gtid);
+ }
+ } else {
#endif /* OMP_40_ENABLED */
- argv = args;
- for( i=argc-1; i >= 0; --i )
+ argv = args;
+ for (i = argc - 1; i >= 0; --i)
// TODO: revert workaround for Intel(R) 64 tracker #96
#if (KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) && KMP_OS_LINUX
- *argv++ = va_arg( *ap, void * );
+ *argv++ = va_arg(*ap, void *);
#else
- *argv++ = va_arg( ap, void * );
+ *argv++ = va_arg(ap, void *);
#endif
- KMP_MB();
+ KMP_MB();
#if OMPT_SUPPORT
- void *dummy;
- void **exit_runtime_p;
+ void *dummy;
+ void **exit_runtime_p;
- ompt_lw_taskteam_t lw_taskteam;
+ ompt_lw_taskteam_t lw_taskteam;
- if (ompt_enabled) {
- __ompt_lw_taskteam_init(&lw_taskteam, master_th, gtid,
- unwrapped_task, ompt_parallel_id);
- lw_taskteam.ompt_task_info.task_id = __ompt_task_id_new(gtid);
- exit_runtime_p = &(lw_taskteam.ompt_task_info.frame.exit_runtime_frame);
+ if (ompt_enabled) {
+ __ompt_lw_taskteam_init(&lw_taskteam, master_th, gtid,
+ unwrapped_task, ompt_parallel_id);
+ lw_taskteam.ompt_task_info.task_id = __ompt_task_id_new(gtid);
+ exit_runtime_p =
+ &(lw_taskteam.ompt_task_info.frame.exit_runtime_frame);
- __ompt_lw_taskteam_link(&lw_taskteam, master_th);
+ __ompt_lw_taskteam_link(&lw_taskteam, master_th);
#if OMPT_TRACE
- /* OMPT implicit task begin */
- my_task_id = lw_taskteam.ompt_task_info.task_id;
- my_parallel_id = ompt_parallel_id;
- if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
- ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(
- my_parallel_id, my_task_id);
- }
+ /* OMPT implicit task begin */
+ my_task_id = lw_taskteam.ompt_task_info.task_id;
+ my_parallel_id = ompt_parallel_id;
+ if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
+ ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(
+ my_parallel_id, my_task_id);
+ }
#endif
- /* OMPT state */
- master_th->th.ompt_thread_info.state = ompt_state_work_parallel;
- } else {
- exit_runtime_p = &dummy;
- }
+ /* OMPT state */
+ master_th->th.ompt_thread_info.state = ompt_state_work_parallel;
+ } else {
+ exit_runtime_p = &dummy;
+ }
#endif
- {
- KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
- KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
- __kmp_invoke_microtask( microtask, gtid, 0, argc, args
+ {
+ KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
+ KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
+ __kmp_invoke_microtask(microtask, gtid, 0, argc, args
#if OMPT_SUPPORT
- , exit_runtime_p
+ ,
+ exit_runtime_p
#endif
- );
- }
+ );
+ }
#if OMPT_SUPPORT
- *exit_runtime_p = NULL;
- if (ompt_enabled) {
+ *exit_runtime_p = NULL;
+ if (ompt_enabled) {
#if OMPT_TRACE
- lw_taskteam.ompt_task_info.frame.exit_runtime_frame = NULL;
+ lw_taskteam.ompt_task_info.frame.exit_runtime_frame = NULL;
- if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
- ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
- my_parallel_id, my_task_id);
- }
-#endif
-
- __ompt_lw_taskteam_unlink(master_th);
- // reset clear the task id only after unlinking the task
- lw_taskteam.ompt_task_info.task_id = ompt_task_id_none;
-
- if (ompt_callbacks.ompt_callback(ompt_event_parallel_end)) {
- ompt_callbacks.ompt_callback(ompt_event_parallel_end)(
- ompt_parallel_id, ompt_task_id,
- OMPT_INVOKER(call_context));
- }
- master_th->th.ompt_thread_info.state = ompt_state_overhead;
- }
+ if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
+ ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
+ my_parallel_id, my_task_id);
+ }
#endif
-#if OMP_40_ENABLED
+
+ __ompt_lw_taskteam_unlink(master_th);
+ // reset clear the task id only after unlinking the task
+ lw_taskteam.ompt_task_info.task_id = ompt_task_id_none;
+
+ if (ompt_callbacks.ompt_callback(ompt_event_parallel_end)) {
+ ompt_callbacks.ompt_callback(ompt_event_parallel_end)(
+ ompt_parallel_id, ompt_task_id, OMPT_INVOKER(call_context));
}
-#endif /* OMP_40_ENABLED */
+ master_th->th.ompt_thread_info.state = ompt_state_overhead;
+ }
+#endif
+#if OMP_40_ENABLED
}
- else if ( call_context == fork_context_gnu ) {
+#endif /* OMP_40_ENABLED */
+ } else if (call_context == fork_context_gnu) {
#if OMPT_SUPPORT
- ompt_lw_taskteam_t *lwt = (ompt_lw_taskteam_t *)
- __kmp_allocate(sizeof(ompt_lw_taskteam_t));
- __ompt_lw_taskteam_init(lwt, master_th, gtid,
- unwrapped_task, ompt_parallel_id);
+ ompt_lw_taskteam_t *lwt =
+ (ompt_lw_taskteam_t *)__kmp_allocate(sizeof(ompt_lw_taskteam_t));
+ __ompt_lw_taskteam_init(lwt, master_th, gtid, unwrapped_task,
+ ompt_parallel_id);
- lwt->ompt_task_info.task_id = __ompt_task_id_new(gtid);
- lwt->ompt_task_info.frame.exit_runtime_frame = NULL;
- __ompt_lw_taskteam_link(lwt, master_th);
+ lwt->ompt_task_info.task_id = __ompt_task_id_new(gtid);
+ lwt->ompt_task_info.frame.exit_runtime_frame = NULL;
+ __ompt_lw_taskteam_link(lwt, master_th);
#endif
- // we were called from GNU native code
- KA_TRACE( 20, ("__kmp_fork_call: T#%d serial exit\n", gtid ));
- return FALSE;
- }
- else {
- KMP_ASSERT2( call_context < fork_context_last, "__kmp_fork_call: unknown fork_context parameter" );
- }
-
-
- KA_TRACE( 20, ("__kmp_fork_call: T#%d serial exit\n", gtid ));
- KMP_MB();
+ // we were called from GNU native code
+ KA_TRACE(20, ("__kmp_fork_call: T#%d serial exit\n", gtid));
return FALSE;
+ }
+ else {
+ KMP_ASSERT2(call_context < fork_context_last,
+ "__kmp_fork_call: unknown fork_context parameter");
+ }
+
+ KA_TRACE(20, ("__kmp_fork_call: T#%d serial exit\n", gtid));
+ KMP_MB();
+ return FALSE;
}
// GEH: only modify the executing flag in the case when not serialized
// serialized case is handled in kmpc_serialized_parallel
- KF_TRACE( 10, ( "__kmp_fork_call: parent_team_aclevel=%d, master_th=%p, curtask=%p, curtask_max_aclevel=%d\n",
- parent_team->t.t_active_level, master_th, master_th->th.th_current_task,
- master_th->th.th_current_task->td_icvs.max_active_levels ) );
- // TODO: GEH - cannot do this assertion because root thread not set up as executing
+ KF_TRACE(10, ("__kmp_fork_call: parent_team_aclevel=%d, master_th=%p, "
+ "curtask=%p, curtask_max_aclevel=%d\n",
+ parent_team->t.t_active_level, master_th,
+ master_th->th.th_current_task,
+ master_th->th.th_current_task->td_icvs.max_active_levels));
+ // TODO: GEH - cannot do this assertion because root thread not set up as
+ // executing
// KMP_ASSERT( master_th->th.th_current_task->td_flags.executing == 1 );
master_th->th.th_current_task->td_flags.executing = 0;
#if OMP_40_ENABLED
- if ( !master_th->th.th_teams_microtask || level > teams_level )
+ if (!master_th->th.th_teams_microtask || level > teams_level)
#endif /* OMP_40_ENABLED */
{
- /* Increment our nested depth level */
- KMP_TEST_THEN_INC32( (kmp_int32*) &root->r.r_in_parallel );
+ /* Increment our nested depth level */
+ KMP_TEST_THEN_INC32((kmp_int32 *)&root->r.r_in_parallel);
}
// See if we need to make a copy of the ICVs.
int nthreads_icv = master_th->th.th_current_task->td_icvs.nproc;
- if ((level+1 < __kmp_nested_nth.used) && (__kmp_nested_nth.nth[level+1] != nthreads_icv)) {
- nthreads_icv = __kmp_nested_nth.nth[level+1];
- }
- else {
- nthreads_icv = 0; // don't update
+ if ((level + 1 < __kmp_nested_nth.used) &&
+ (__kmp_nested_nth.nth[level + 1] != nthreads_icv)) {
+ nthreads_icv = __kmp_nested_nth.nth[level + 1];
+ } else {
+ nthreads_icv = 0; // don't update
}
#if OMP_40_ENABLED
// Figure out the proc_bind_policy for the new team.
kmp_proc_bind_t proc_bind = master_th->th.th_set_proc_bind;
- kmp_proc_bind_t proc_bind_icv = proc_bind_default; // proc_bind_default means don't update
- if ( master_th->th.th_current_task->td_icvs.proc_bind == proc_bind_false ) {
- proc_bind = proc_bind_false;
- }
- else {
- if (proc_bind == proc_bind_default) {
- // No proc_bind clause specified; use current proc-bind-var for this parallel region
- proc_bind = master_th->th.th_current_task->td_icvs.proc_bind;
- }
- /* else: The proc_bind policy was specified explicitly on parallel clause. This
- overrides proc-bind-var for this parallel region, but does not change proc-bind-var. */
- // Figure the value of proc-bind-var for the child threads.
- if ((level+1 < __kmp_nested_proc_bind.used)
- && (__kmp_nested_proc_bind.bind_types[level+1] != master_th->th.th_current_task->td_icvs.proc_bind)) {
- proc_bind_icv = __kmp_nested_proc_bind.bind_types[level+1];
- }
+ kmp_proc_bind_t proc_bind_icv =
+ proc_bind_default; // proc_bind_default means don't update
+ if (master_th->th.th_current_task->td_icvs.proc_bind == proc_bind_false) {
+ proc_bind = proc_bind_false;
+ } else {
+ if (proc_bind == proc_bind_default) {
+ // No proc_bind clause specified; use current proc-bind-var for this
+ // parallel region
+ proc_bind = master_th->th.th_current_task->td_icvs.proc_bind;
+ }
+ /* else: The proc_bind policy was specified explicitly on parallel clause.
+ This overrides proc-bind-var for this parallel region, but does not
+ change proc-bind-var. */
+ // Figure the value of proc-bind-var for the child threads.
+ if ((level + 1 < __kmp_nested_proc_bind.used) &&
+ (__kmp_nested_proc_bind.bind_types[level + 1] !=
+ master_th->th.th_current_task->td_icvs.proc_bind)) {
+ proc_bind_icv = __kmp_nested_proc_bind.bind_types[level + 1];
+ }
}
// Reset for next parallel region
@@ -1972,44 +1965,45 @@ __kmp_fork_call(
#if OMP_40_ENABLED
|| (proc_bind_icv != proc_bind_default)
#endif /* OMP_40_ENABLED */
- ) {
- kmp_internal_control_t new_icvs;
- copy_icvs(&new_icvs, &master_th->th.th_current_task->td_icvs);
- new_icvs.next = NULL;
- if (nthreads_icv > 0) {
- new_icvs.nproc = nthreads_icv;
- }
+ ) {
+ kmp_internal_control_t new_icvs;
+ copy_icvs(&new_icvs, &master_th->th.th_current_task->td_icvs);
+ new_icvs.next = NULL;
+ if (nthreads_icv > 0) {
+ new_icvs.nproc = nthreads_icv;
+ }
#if OMP_40_ENABLED
- if (proc_bind_icv != proc_bind_default) {
- new_icvs.proc_bind = proc_bind_icv;
- }
+ if (proc_bind_icv != proc_bind_default) {
+ new_icvs.proc_bind = proc_bind_icv;
+ }
#endif /* OMP_40_ENABLED */
- /* allocate a new parallel team */
- KF_TRACE( 10, ( "__kmp_fork_call: before __kmp_allocate_team\n" ) );
- team = __kmp_allocate_team(root, nthreads, nthreads,
+ /* allocate a new parallel team */
+ KF_TRACE(10, ("__kmp_fork_call: before __kmp_allocate_team\n"));
+ team = __kmp_allocate_team(root, nthreads, nthreads,
#if OMPT_SUPPORT
- ompt_parallel_id,
+ ompt_parallel_id,
#endif
#if OMP_40_ENABLED
- proc_bind,
+ proc_bind,
#endif
- &new_icvs, argc USE_NESTED_HOT_ARG(master_th) );
+ &new_icvs, argc USE_NESTED_HOT_ARG(master_th));
} else {
- /* allocate a new parallel team */
- KF_TRACE( 10, ( "__kmp_fork_call: before __kmp_allocate_team\n" ) );
- team = __kmp_allocate_team(root, nthreads, nthreads,
+ /* allocate a new parallel team */
+ KF_TRACE(10, ("__kmp_fork_call: before __kmp_allocate_team\n"));
+ team = __kmp_allocate_team(root, nthreads, nthreads,
#if OMPT_SUPPORT
- ompt_parallel_id,
+ ompt_parallel_id,
#endif
#if OMP_40_ENABLED
- proc_bind,
+ proc_bind,
#endif
- &master_th->th.th_current_task->td_icvs, argc
- USE_NESTED_HOT_ARG(master_th) );
+ &master_th->th.th_current_task->td_icvs,
+ argc USE_NESTED_HOT_ARG(master_th));
}
- KF_TRACE( 10, ( "__kmp_fork_call: after __kmp_allocate_team - team = %p\n", team ) );
+ KF_TRACE(
+ 10, ("__kmp_fork_call: after __kmp_allocate_team - team = %p\n", team));
/* setup the new team */
KMP_CHECK_UPDATE(team->t.t_master_tid, master_tid);
@@ -2020,27 +2014,29 @@ __kmp_fork_call(
#if OMPT_SUPPORT
KMP_CHECK_UPDATE_SYNC(team->t.ompt_team_info.microtask, unwrapped_task);
#endif
- KMP_CHECK_UPDATE(team->t.t_invoke, invoker); /* TODO move this to root, maybe */
- // TODO: parent_team->t.t_level == INT_MAX ???
+ KMP_CHECK_UPDATE(team->t.t_invoke, invoker); // TODO move to root, maybe
+// TODO: parent_team->t.t_level == INT_MAX ???
#if OMP_40_ENABLED
- if ( !master_th->th.th_teams_microtask || level > teams_level ) {
+ if (!master_th->th.th_teams_microtask || level > teams_level) {
#endif /* OMP_40_ENABLED */
- int new_level = parent_team->t.t_level + 1;
- KMP_CHECK_UPDATE(team->t.t_level, new_level);
- new_level = parent_team->t.t_active_level + 1;
- KMP_CHECK_UPDATE(team->t.t_active_level, new_level);
+ int new_level = parent_team->t.t_level + 1;
+ KMP_CHECK_UPDATE(team->t.t_level, new_level);
+ new_level = parent_team->t.t_active_level + 1;
+ KMP_CHECK_UPDATE(team->t.t_active_level, new_level);
#if OMP_40_ENABLED
} else {
- // AC: Do not increase parallel level at start of the teams construct
- int new_level = parent_team->t.t_level;
- KMP_CHECK_UPDATE(team->t.t_level, new_level);
- new_level = parent_team->t.t_active_level;
- KMP_CHECK_UPDATE(team->t.t_active_level, new_level);
+ // AC: Do not increase parallel level at start of the teams construct
+ int new_level = parent_team->t.t_level;
+ KMP_CHECK_UPDATE(team->t.t_level, new_level);
+ new_level = parent_team->t.t_active_level;
+ KMP_CHECK_UPDATE(team->t.t_active_level, new_level);
}
#endif /* OMP_40_ENABLED */
kmp_r_sched_t new_sched = get__sched_2(parent_team, master_tid);
- if (team->t.t_sched.r_sched_type != new_sched.r_sched_type || team->t.t_sched.chunk != new_sched.chunk)
- team->t.t_sched = new_sched; // set master's schedule as new run-time schedule
+ if (team->t.t_sched.r_sched_type != new_sched.r_sched_type ||
+ team->t.t_sched.chunk != new_sched.chunk)
+ team->t.t_sched =
+ new_sched; // set master's schedule as new run-time schedule
#if OMP_40_ENABLED
KMP_CHECK_UPDATE(team->t.t_cancel_request, cancel_noreq);
@@ -2049,3174 +2045,3185 @@ __kmp_fork_call(
// Update the floating point rounding in the team if required.
propagateFPControl(team);
- if ( __kmp_tasking_mode != tskm_immediate_exec ) {
- // Set master's task team to team's task team. Unless this is hot team, it should be NULL.
+ if (__kmp_tasking_mode != tskm_immediate_exec) {
+ // Set master's task team to team's task team. Unless this is hot team, it
+ // should be NULL.
#if 0
- // Patch out an assertion that trips while the runtime seems to operate correctly.
- // Avoiding the preconditions that cause the assertion to trip has been promised as a forthcoming patch.
- KMP_DEBUG_ASSERT(master_th->th.th_task_team == parent_team->t.t_task_team[master_th->th.th_task_state]);
-#endif
- KA_TRACE( 20, ( "__kmp_fork_call: Master T#%d pushing task_team %p / team %p, new task_team %p / team %p\n",
- __kmp_gtid_from_thread( master_th ), master_th->th.th_task_team,
- parent_team, team->t.t_task_team[master_th->th.th_task_state], team ) );
-
- if ( active_level || master_th->th.th_task_team ) {
- // Take a memo of master's task_state
- KMP_DEBUG_ASSERT(master_th->th.th_task_state_memo_stack);
- if (master_th->th.th_task_state_top >= master_th->th.th_task_state_stack_sz) { // increase size
- kmp_uint32 new_size = 2*master_th->th.th_task_state_stack_sz;
- kmp_uint8 *old_stack, *new_stack;
- kmp_uint32 i;
- new_stack = (kmp_uint8 *)__kmp_allocate(new_size);
- for (i=0; i<master_th->th.th_task_state_stack_sz; ++i) {
- new_stack[i] = master_th->th.th_task_state_memo_stack[i];
- }
- for (i=master_th->th.th_task_state_stack_sz; i<new_size; ++i) { // zero-init rest of stack
- new_stack[i] = 0;
- }
- old_stack = master_th->th.th_task_state_memo_stack;
- master_th->th.th_task_state_memo_stack = new_stack;
- master_th->th.th_task_state_stack_sz = new_size;
- __kmp_free(old_stack);
- }
- // Store master's task_state on stack
- master_th->th.th_task_state_memo_stack[master_th->th.th_task_state_top] = master_th->th.th_task_state;
- master_th->th.th_task_state_top++;
+ // Patch out an assertion that trips while the runtime seems to operate
+ // correctly. Avoiding the preconditions that cause the assertion to trip
+ // has been promised as a forthcoming patch.
+ KMP_DEBUG_ASSERT(master_th->th.th_task_team ==
+ parent_team->t.t_task_team[master_th->th.th_task_state]);
+#endif
+ KA_TRACE(20, ("__kmp_fork_call: Master T#%d pushing task_team %p / team "
+ "%p, new task_team %p / team %p\n",
+ __kmp_gtid_from_thread(master_th),
+ master_th->th.th_task_team, parent_team,
+ team->t.t_task_team[master_th->th.th_task_state], team));
+
+ if (active_level || master_th->th.th_task_team) {
+ // Take a memo of master's task_state
+ KMP_DEBUG_ASSERT(master_th->th.th_task_state_memo_stack);
+ if (master_th->th.th_task_state_top >=
+ master_th->th.th_task_state_stack_sz) { // increase size
+ kmp_uint32 new_size = 2 * master_th->th.th_task_state_stack_sz;
+ kmp_uint8 *old_stack, *new_stack;
+ kmp_uint32 i;
+ new_stack = (kmp_uint8 *)__kmp_allocate(new_size);
+ for (i = 0; i < master_th->th.th_task_state_stack_sz; ++i) {
+ new_stack[i] = master_th->th.th_task_state_memo_stack[i];
+ }
+ for (i = master_th->th.th_task_state_stack_sz; i < new_size;
+ ++i) { // zero-init rest of stack
+ new_stack[i] = 0;
+ }
+ old_stack = master_th->th.th_task_state_memo_stack;
+ master_th->th.th_task_state_memo_stack = new_stack;
+ master_th->th.th_task_state_stack_sz = new_size;
+ __kmp_free(old_stack);
+ }
+ // Store master's task_state on stack
+ master_th->th
+ .th_task_state_memo_stack[master_th->th.th_task_state_top] =
+ master_th->th.th_task_state;
+ master_th->th.th_task_state_top++;
#if KMP_NESTED_HOT_TEAMS
- if (team == master_th->th.th_hot_teams[active_level].hot_team) { // Restore master's nested state if nested hot team
- master_th->th.th_task_state = master_th->th.th_task_state_memo_stack[master_th->th.th_task_state_top];
- }
- else {
+ if (team ==
+ master_th->th.th_hot_teams[active_level]
+ .hot_team) { // Restore master's nested state if nested hot team
+ master_th->th.th_task_state =
+ master_th->th
+ .th_task_state_memo_stack[master_th->th.th_task_state_top];
+ } else {
#endif
- master_th->th.th_task_state = 0;
+ master_th->th.th_task_state = 0;
#if KMP_NESTED_HOT_TEAMS
- }
-#endif
}
+#endif
+ }
#if !KMP_NESTED_HOT_TEAMS
- KMP_DEBUG_ASSERT((master_th->th.th_task_team == NULL) || (team == root->r.r_hot_team));
+ KMP_DEBUG_ASSERT((master_th->th.th_task_team == NULL) ||
+ (team == root->r.r_hot_team));
#endif
}
- KA_TRACE( 20, ("__kmp_fork_call: T#%d(%d:%d)->(%d:0) created a team of %d threads\n",
- gtid, parent_team->t.t_id, team->t.t_master_tid, team->t.t_id, team->t.t_nproc ));
- KMP_DEBUG_ASSERT( team != root->r.r_hot_team ||
- ( team->t.t_master_tid == 0 &&
- ( team->t.t_parent == root->r.r_root_team || team->t.t_parent->t.t_serialized ) ));
+ KA_TRACE(
+ 20,
+ ("__kmp_fork_call: T#%d(%d:%d)->(%d:0) created a team of %d threads\n",
+ gtid, parent_team->t.t_id, team->t.t_master_tid, team->t.t_id,
+ team->t.t_nproc));
+ KMP_DEBUG_ASSERT(team != root->r.r_hot_team ||
+ (team->t.t_master_tid == 0 &&
+ (team->t.t_parent == root->r.r_root_team ||
+ team->t.t_parent->t.t_serialized)));
KMP_MB();
/* now, setup the arguments */
- argv = (void**)team->t.t_argv;
+ argv = (void **)team->t.t_argv;
#if OMP_40_ENABLED
- if ( ap ) {
+ if (ap) {
#endif /* OMP_40_ENABLED */
- for ( i=argc-1; i >= 0; --i ) {
+ for (i = argc - 1; i >= 0; --i) {
// TODO: revert workaround for Intel(R) 64 tracker #96
#if (KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) && KMP_OS_LINUX
- void *new_argv = va_arg(*ap, void *);
+ void *new_argv = va_arg(*ap, void *);
#else
- void *new_argv = va_arg(ap, void *);
+ void *new_argv = va_arg(ap, void *);
#endif
- KMP_CHECK_UPDATE(*argv, new_argv);
- argv++;
- }
+ KMP_CHECK_UPDATE(*argv, new_argv);
+ argv++;
+ }
#if OMP_40_ENABLED
} else {
- for ( i=0; i < argc; ++i ) {
- // Get args from parent team for teams construct
- KMP_CHECK_UPDATE(argv[i], team->t.t_parent->t.t_argv[i]);
- }
+ for (i = 0; i < argc; ++i) {
+ // Get args from parent team for teams construct
+ KMP_CHECK_UPDATE(argv[i], team->t.t_parent->t.t_argv[i]);
+ }
}
#endif /* OMP_40_ENABLED */
/* now actually fork the threads */
KMP_CHECK_UPDATE(team->t.t_master_active, master_active);
if (!root->r.r_active) // Only do assignment if it prevents cache ping-pong
- root->r.r_active = TRUE;
+ root->r.r_active = TRUE;
- __kmp_fork_team_threads( root, team, master_th, gtid );
- __kmp_setup_icv_copy( team, nthreads, &master_th->th.th_current_task->td_icvs, loc );
+ __kmp_fork_team_threads(root, team, master_th, gtid);
+ __kmp_setup_icv_copy(team, nthreads,
+ &master_th->th.th_current_task->td_icvs, loc);
#if OMPT_SUPPORT
master_th->th.ompt_thread_info.state = ompt_state_work_parallel;
#endif
- __kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
+ __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
#if USE_ITT_BUILD
- if ( team->t.t_active_level == 1 // only report frames at level 1
-# if OMP_40_ENABLED
+ if (team->t.t_active_level == 1 // only report frames at level 1
+#if OMP_40_ENABLED
&& !master_th->th.th_teams_microtask // not in teams construct
-# endif /* OMP_40_ENABLED */
- ) {
+#endif /* OMP_40_ENABLED */
+ ) {
#if USE_ITT_NOTIFY
- if ( ( __itt_frame_submit_v3_ptr || KMP_ITT_DEBUG ) &&
- ( __kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 1 ) )
- {
- kmp_uint64 tmp_time = 0;
- if ( __itt_get_timestamp_ptr )
- tmp_time = __itt_get_timestamp();
- // Internal fork - report frame begin
- master_th->th.th_frame_time = tmp_time;
- if ( __kmp_forkjoin_frames_mode == 3 )
- team->t.t_region_time = tmp_time;
- } else // only one notification scheme (either "submit" or "forking/joined", not both)
+ if ((__itt_frame_submit_v3_ptr || KMP_ITT_DEBUG) &&
+ (__kmp_forkjoin_frames_mode == 3 ||
+ __kmp_forkjoin_frames_mode == 1)) {
+ kmp_uint64 tmp_time = 0;
+ if (__itt_get_timestamp_ptr)
+ tmp_time = __itt_get_timestamp();
+ // Internal fork - report frame begin
+ master_th->th.th_frame_time = tmp_time;
+ if (__kmp_forkjoin_frames_mode == 3)
+ team->t.t_region_time = tmp_time;
+ } else // only one notification scheme (either "submit" or
+// "forking/joined", not both)
#endif /* USE_ITT_NOTIFY */
- if ( ( __itt_frame_begin_v3_ptr || KMP_ITT_DEBUG ) &&
- __kmp_forkjoin_frames && !__kmp_forkjoin_frames_mode )
- { // Mark start of "parallel" region for VTune.
- __kmp_itt_region_forking(gtid, team->t.t_nproc, 0);
- }
+ if ((__itt_frame_begin_v3_ptr || KMP_ITT_DEBUG) &&
+ __kmp_forkjoin_frames && !__kmp_forkjoin_frames_mode) {
+ // Mark start of "parallel" region for VTune.
+ __kmp_itt_region_forking(gtid, team->t.t_nproc, 0);
+ }
}
#endif /* USE_ITT_BUILD */
/* now go on and do the work */
- KMP_DEBUG_ASSERT( team == __kmp_threads[gtid]->th.th_team );
+ KMP_DEBUG_ASSERT(team == __kmp_threads[gtid]->th.th_team);
KMP_MB();
- KF_TRACE(10, ("__kmp_internal_fork : root=%p, team=%p, master_th=%p, gtid=%d\n",
- root, team, master_th, gtid));
+ KF_TRACE(10,
+ ("__kmp_internal_fork : root=%p, team=%p, master_th=%p, gtid=%d\n",
+ root, team, master_th, gtid));
#if USE_ITT_BUILD
- if ( __itt_stack_caller_create_ptr ) {
- team->t.t_stack_id = __kmp_itt_stack_caller_create(); // create new stack stitching id before entering fork barrier
+ if (__itt_stack_caller_create_ptr) {
+ team->t.t_stack_id =
+ __kmp_itt_stack_caller_create(); // create new stack stitching id
+ // before entering fork barrier
}
#endif /* USE_ITT_BUILD */
#if OMP_40_ENABLED
- if ( ap ) // AC: skip __kmp_internal_fork at teams construct, let only master threads execute
+ if (ap) // AC: skip __kmp_internal_fork at teams construct, let only master
+// threads execute
#endif /* OMP_40_ENABLED */
{
- __kmp_internal_fork( loc, gtid, team );
- KF_TRACE(10, ("__kmp_internal_fork : after : root=%p, team=%p, master_th=%p, gtid=%d\n",
- root, team, master_th, gtid));
+ __kmp_internal_fork(loc, gtid, team);
+ KF_TRACE(10, ("__kmp_internal_fork : after : root=%p, team=%p, "
+ "master_th=%p, gtid=%d\n",
+ root, team, master_th, gtid));
}
if (call_context == fork_context_gnu) {
- KA_TRACE( 20, ("__kmp_fork_call: parallel exit T#%d\n", gtid ));
- return TRUE;
+ KA_TRACE(20, ("__kmp_fork_call: parallel exit T#%d\n", gtid));
+ return TRUE;
}
/* Invoke microtask for MASTER thread */
- KA_TRACE( 20, ("__kmp_fork_call: T#%d(%d:0) invoke microtask = %p\n",
- gtid, team->t.t_id, team->t.t_pkfn ) );
- } // END of timer KMP_fork_call block
+ KA_TRACE(20, ("__kmp_fork_call: T#%d(%d:0) invoke microtask = %p\n", gtid,
+ team->t.t_id, team->t.t_pkfn));
+ } // END of timer KMP_fork_call block
- {
- KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
- KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
- if (! team->t.t_invoke( gtid )) {
- KMP_ASSERT2( 0, "cannot invoke microtask for MASTER thread" );
- }
+ {
+ KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
+ KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
+ if (!team->t.t_invoke(gtid)) {
+ KMP_ASSERT2(0, "cannot invoke microtask for MASTER thread");
}
- KA_TRACE( 20, ("__kmp_fork_call: T#%d(%d:0) done microtask = %p\n",
- gtid, team->t.t_id, team->t.t_pkfn ) );
- KMP_MB(); /* Flush all pending memory write invalidates. */
+ }
+ KA_TRACE(20, ("__kmp_fork_call: T#%d(%d:0) done microtask = %p\n", gtid,
+ team->t.t_id, team->t.t_pkfn));
+ KMP_MB(); /* Flush all pending memory write invalidates. */
- KA_TRACE( 20, ("__kmp_fork_call: parallel exit T#%d\n", gtid ));
+ KA_TRACE(20, ("__kmp_fork_call: parallel exit T#%d\n", gtid));
#if OMPT_SUPPORT
- if (ompt_enabled) {
- master_th->th.ompt_thread_info.state = ompt_state_overhead;
- }
+ if (ompt_enabled) {
+ master_th->th.ompt_thread_info.state = ompt_state_overhead;
+ }
#endif
- return TRUE;
+ return TRUE;
}
#if OMPT_SUPPORT
-static inline void
-__kmp_join_restore_state(
- kmp_info_t *thread,
- kmp_team_t *team)
-{
- // restore state outside the region
- thread->th.ompt_thread_info.state = ((team->t.t_serialized) ?
- ompt_state_work_serial : ompt_state_work_parallel);
-}
-
-static inline void
-__kmp_join_ompt(
- kmp_info_t *thread,
- kmp_team_t *team,
- ompt_parallel_id_t parallel_id,
- fork_context_e fork_context)
-{
- ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
- if (ompt_callbacks.ompt_callback(ompt_event_parallel_end)) {
- ompt_callbacks.ompt_callback(ompt_event_parallel_end)(
- parallel_id, task_info->task_id, OMPT_INVOKER(fork_context));
- }
+static inline void __kmp_join_restore_state(kmp_info_t *thread,
+ kmp_team_t *team) {
+ // restore state outside the region
+ thread->th.ompt_thread_info.state =
+ ((team->t.t_serialized) ? ompt_state_work_serial
+ : ompt_state_work_parallel);
+}
+
+static inline void __kmp_join_ompt(kmp_info_t *thread, kmp_team_t *team,
+ ompt_parallel_id_t parallel_id,
+ fork_context_e fork_context) {
+ ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
+ if (ompt_callbacks.ompt_callback(ompt_event_parallel_end)) {
+ ompt_callbacks.ompt_callback(ompt_event_parallel_end)(
+ parallel_id, task_info->task_id, OMPT_INVOKER(fork_context));
+ }
- task_info->frame.reenter_runtime_frame = NULL;
- __kmp_join_restore_state(thread,team);
+ task_info->frame.reenter_runtime_frame = NULL;
+ __kmp_join_restore_state(thread, team);
}
#endif
-void
-__kmp_join_call(ident_t *loc, int gtid
+void __kmp_join_call(ident_t *loc, int gtid
#if OMPT_SUPPORT
- , enum fork_context_e fork_context
+ ,
+ enum fork_context_e fork_context
#endif
#if OMP_40_ENABLED
- , int exit_teams
+ ,
+ int exit_teams
#endif /* OMP_40_ENABLED */
-)
-{
- KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_join_call);
- kmp_team_t *team;
- kmp_team_t *parent_team;
- kmp_info_t *master_th;
- kmp_root_t *root;
- int master_active;
- int i;
-
- KA_TRACE( 20, ("__kmp_join_call: enter T#%d\n", gtid ));
-
- /* setup current data */
- master_th = __kmp_threads[ gtid ];
- root = master_th->th.th_root;
- team = master_th->th.th_team;
- parent_team = team->t.t_parent;
-
- master_th->th.th_ident = loc;
-
-#if OMPT_SUPPORT
- if (ompt_enabled) {
- master_th->th.ompt_thread_info.state = ompt_state_overhead;
- }
+ ) {
+ KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_join_call);
+ kmp_team_t *team;
+ kmp_team_t *parent_team;
+ kmp_info_t *master_th;
+ kmp_root_t *root;
+ int master_active;
+ int i;
+
+ KA_TRACE(20, ("__kmp_join_call: enter T#%d\n", gtid));
+
+ /* setup current data */
+ master_th = __kmp_threads[gtid];
+ root = master_th->th.th_root;
+ team = master_th->th.th_team;
+ parent_team = team->t.t_parent;
+
+ master_th->th.th_ident = loc;
+
+#if OMPT_SUPPORT
+ if (ompt_enabled) {
+ master_th->th.ompt_thread_info.state = ompt_state_overhead;
+ }
#endif
#if KMP_DEBUG
- if (__kmp_tasking_mode != tskm_immediate_exec && !exit_teams) {
- KA_TRACE( 20, ( "__kmp_join_call: T#%d, old team = %p old task_team = %p, th_task_team = %p\n",
- __kmp_gtid_from_thread( master_th ), team,
- team->t.t_task_team[master_th->th.th_task_state], master_th->th.th_task_team) );
- KMP_DEBUG_ASSERT( master_th->th.th_task_team == team->t.t_task_team[master_th->th.th_task_state] );
+ if (__kmp_tasking_mode != tskm_immediate_exec && !exit_teams) {
+ KA_TRACE(20, ("__kmp_join_call: T#%d, old team = %p old task_team = %p, "
+ "th_task_team = %p\n",
+ __kmp_gtid_from_thread(master_th), team,
+ team->t.t_task_team[master_th->th.th_task_state],
+ master_th->th.th_task_team));
+ KMP_DEBUG_ASSERT(master_th->th.th_task_team ==
+ team->t.t_task_team[master_th->th.th_task_state]);
+ }
+#endif
+
+ if (team->t.t_serialized) {
+#if OMP_40_ENABLED
+ if (master_th->th.th_teams_microtask) {
+ // We are in teams construct
+ int level = team->t.t_level;
+ int tlevel = master_th->th.th_teams_level;
+ if (level == tlevel) {
+ // AC: we haven't incremented it earlier at start of teams construct,
+ // so do it here - at the end of teams construct
+ team->t.t_level++;
+ } else if (level == tlevel + 1) {
+ // AC: we are exiting parallel inside teams, need to increment
+ // serialization in order to restore it in the next call to
+ // __kmpc_end_serialized_parallel
+ team->t.t_serialized++;
+ }
}
-#endif
-
- if( team->t.t_serialized ) {
-#if OMP_40_ENABLED
- if ( master_th->th.th_teams_microtask ) {
- // We are in teams construct
- int level = team->t.t_level;
- int tlevel = master_th->th.th_teams_level;
- if ( level == tlevel ) {
- // AC: we haven't incremented it earlier at start of teams construct,
- // so do it here - at the end of teams construct
- team->t.t_level++;
- } else if ( level == tlevel + 1 ) {
- // AC: we are exiting parallel inside teams, need to increment serialization
- // in order to restore it in the next call to __kmpc_end_serialized_parallel
- team->t.t_serialized++;
- }
- }
#endif /* OMP_40_ENABLED */
- __kmpc_end_serialized_parallel( loc, gtid );
+ __kmpc_end_serialized_parallel(loc, gtid);
#if OMPT_SUPPORT
- if (ompt_enabled) {
- __kmp_join_restore_state(master_th, parent_team);
- }
+ if (ompt_enabled) {
+ __kmp_join_restore_state(master_th, parent_team);
+ }
#endif
- return;
- }
+ return;
+ }
- master_active = team->t.t_master_active;
+ master_active = team->t.t_master_active;
#if OMP_40_ENABLED
- if (!exit_teams)
+ if (!exit_teams)
#endif /* OMP_40_ENABLED */
- {
- // AC: No barrier for internal teams at exit from teams construct.
- // But there is barrier for external team (league).
- __kmp_internal_join( loc, gtid, team );
- }
-#if OMP_40_ENABLED
- else {
- master_th->th.th_task_state = 0; // AC: no tasking in teams (out of any parallel)
- }
+ {
+ // AC: No barrier for internal teams at exit from teams construct.
+ // But there is barrier for external team (league).
+ __kmp_internal_join(loc, gtid, team);
+ }
+#if OMP_40_ENABLED
+ else {
+ master_th->th.th_task_state =
+ 0; // AC: no tasking in teams (out of any parallel)
+ }
#endif /* OMP_40_ENABLED */
- KMP_MB();
+ KMP_MB();
#if OMPT_SUPPORT
- ompt_parallel_id_t parallel_id = team->t.ompt_team_info.parallel_id;
+ ompt_parallel_id_t parallel_id = team->t.ompt_team_info.parallel_id;
#endif
#if USE_ITT_BUILD
- if ( __itt_stack_caller_create_ptr ) {
- __kmp_itt_stack_caller_destroy( (__itt_caller)team->t.t_stack_id ); // destroy the stack stitching id after join barrier
- }
+ if (__itt_stack_caller_create_ptr) {
+ __kmp_itt_stack_caller_destroy(
+ (__itt_caller)team->t
+ .t_stack_id); // destroy the stack stitching id after join barrier
+ }
- // Mark end of "parallel" region for VTune.
- if ( team->t.t_active_level == 1
-# if OMP_40_ENABLED
- && !master_th->th.th_teams_microtask /* not in teams construct */
-# endif /* OMP_40_ENABLED */
- ) {
- master_th->th.th_ident = loc;
- // only one notification scheme (either "submit" or "forking/joined", not both)
- if ( ( __itt_frame_submit_v3_ptr || KMP_ITT_DEBUG ) && __kmp_forkjoin_frames_mode == 3 )
- __kmp_itt_frame_submit( gtid, team->t.t_region_time, master_th->th.th_frame_time,
- 0, loc, master_th->th.th_team_nproc, 1 );
- else if ( ( __itt_frame_end_v3_ptr || KMP_ITT_DEBUG ) &&
- ! __kmp_forkjoin_frames_mode && __kmp_forkjoin_frames )
- __kmp_itt_region_joined( gtid );
- } // active_level == 1
+ // Mark end of "parallel" region for VTune.
+ if (team->t.t_active_level == 1
+#if OMP_40_ENABLED
+ && !master_th->th.th_teams_microtask /* not in teams construct */
+#endif /* OMP_40_ENABLED */
+ ) {
+ master_th->th.th_ident = loc;
+ // only one notification scheme (either "submit" or "forking/joined", not
+ // both)
+ if ((__itt_frame_submit_v3_ptr || KMP_ITT_DEBUG) &&
+ __kmp_forkjoin_frames_mode == 3)
+ __kmp_itt_frame_submit(gtid, team->t.t_region_time,
+ master_th->th.th_frame_time, 0, loc,
+ master_th->th.th_team_nproc, 1);
+ else if ((__itt_frame_end_v3_ptr || KMP_ITT_DEBUG) &&
+ !__kmp_forkjoin_frames_mode && __kmp_forkjoin_frames)
+ __kmp_itt_region_joined(gtid);
+ } // active_level == 1
#endif /* USE_ITT_BUILD */
#if OMP_40_ENABLED
- if ( master_th->th.th_teams_microtask &&
- !exit_teams &&
- team->t.t_pkfn != (microtask_t)__kmp_teams_master &&
- team->t.t_level == master_th->th.th_teams_level + 1 ) {
- // AC: We need to leave the team structure intact at the end
- // of parallel inside the teams construct, so that at the next
- // parallel same (hot) team works, only adjust nesting levels
-
- /* Decrement our nested depth level */
- team->t.t_level --;
- team->t.t_active_level --;
- KMP_TEST_THEN_DEC32( (kmp_int32*) &root->r.r_in_parallel );
-
- /* Restore number of threads in the team if needed */
- if ( master_th->th.th_team_nproc < master_th->th.th_teams_size.nth ) {
- int old_num = master_th->th.th_team_nproc;
- int new_num = master_th->th.th_teams_size.nth;
- kmp_info_t **other_threads = team->t.t_threads;
- team->t.t_nproc = new_num;
- for ( i = 0; i < old_num; ++i ) {
- other_threads[i]->th.th_team_nproc = new_num;
- }
- // Adjust states of non-used threads of the team
- for ( i = old_num; i < new_num; ++i ) {
- // Re-initialize thread's barrier data.
- int b;
- kmp_balign_t * balign = other_threads[i]->th.th_bar;
- for ( b = 0; b < bs_last_barrier; ++ b ) {
- balign[ b ].bb.b_arrived = team->t.t_bar[ b ].b_arrived;
- KMP_DEBUG_ASSERT(balign[ b ].bb.wait_flag != KMP_BARRIER_PARENT_FLAG);
+ if (master_th->th.th_teams_microtask && !exit_teams &&
+ team->t.t_pkfn != (microtask_t)__kmp_teams_master &&
+ team->t.t_level == master_th->th.th_teams_level + 1) {
+ // AC: We need to leave the team structure intact at the end of parallel
+ // inside the teams construct, so that at the next parallel same (hot) team
+ // works, only adjust nesting levels
+
+ /* Decrement our nested depth level */
+ team->t.t_level--;
+ team->t.t_active_level--;
+ KMP_TEST_THEN_DEC32((kmp_int32 *)&root->r.r_in_parallel);
+
+ /* Restore number of threads in the team if needed */
+ if (master_th->th.th_team_nproc < master_th->th.th_teams_size.nth) {
+ int old_num = master_th->th.th_team_nproc;
+ int new_num = master_th->th.th_teams_size.nth;
+ kmp_info_t **other_threads = team->t.t_threads;
+ team->t.t_nproc = new_num;
+ for (i = 0; i < old_num; ++i) {
+ other_threads[i]->th.th_team_nproc = new_num;
+ }
+ // Adjust states of non-used threads of the team
+ for (i = old_num; i < new_num; ++i) {
+ // Re-initialize thread's barrier data.
+ int b;
+ kmp_balign_t *balign = other_threads[i]->th.th_bar;
+ for (b = 0; b < bs_last_barrier; ++b) {
+ balign[b].bb.b_arrived = team->t.t_bar[b].b_arrived;
+ KMP_DEBUG_ASSERT(balign[b].bb.wait_flag != KMP_BARRIER_PARENT_FLAG);
#if USE_DEBUGGER
- balign[ b ].bb.b_worker_arrived = team->t.t_bar[ b ].b_team_arrived;
+ balign[b].bb.b_worker_arrived = team->t.t_bar[b].b_team_arrived;
#endif
- }
- if ( __kmp_tasking_mode != tskm_immediate_exec ) {
- // Synchronize thread's task state
- other_threads[i]->th.th_task_state = master_th->th.th_task_state;
- }
- }
}
+ if (__kmp_tasking_mode != tskm_immediate_exec) {
+ // Synchronize thread's task state
+ other_threads[i]->th.th_task_state = master_th->th.th_task_state;
+ }
+ }
+ }
#if OMPT_SUPPORT
- if (ompt_enabled) {
- __kmp_join_ompt(master_th, parent_team, parallel_id, fork_context);
- }
+ if (ompt_enabled) {
+ __kmp_join_ompt(master_th, parent_team, parallel_id, fork_context);
+ }
#endif
- return;
- }
+ return;
+ }
#endif /* OMP_40_ENABLED */
- /* do cleanup and restore the parent team */
- master_th->th.th_info .ds.ds_tid = team->t.t_master_tid;
- master_th->th.th_local.this_construct = team->t.t_master_this_cons;
+ /* do cleanup and restore the parent team */
+ master_th->th.th_info.ds.ds_tid = team->t.t_master_tid;
+ master_th->th.th_local.this_construct = team->t.t_master_this_cons;
- master_th->th.th_dispatch =
- & parent_team->t.t_dispatch[ team->t.t_master_tid ];
+ master_th->th.th_dispatch = &parent_team->t.t_dispatch[team->t.t_master_tid];
- /* jc: The following lock has instructions with REL and ACQ semantics,
- separating the parallel user code called in this parallel region
- from the serial user code called after this function returns.
- */
- __kmp_acquire_bootstrap_lock( &__kmp_forkjoin_lock );
+ /* jc: The following lock has instructions with REL and ACQ semantics,
+ separating the parallel user code called in this parallel region
+ from the serial user code called after this function returns. */
+ __kmp_acquire_bootstrap_lock(&__kmp_forkjoin_lock);
#if OMP_40_ENABLED
- if ( !master_th->th.th_teams_microtask || team->t.t_level > master_th->th.th_teams_level )
+ if (!master_th->th.th_teams_microtask ||
+ team->t.t_level > master_th->th.th_teams_level)
#endif /* OMP_40_ENABLED */
- {
- /* Decrement our nested depth level */
- KMP_TEST_THEN_DEC32( (kmp_int32*) &root->r.r_in_parallel );
- }
- KMP_DEBUG_ASSERT( root->r.r_in_parallel >= 0 );
+ {
+ /* Decrement our nested depth level */
+ KMP_TEST_THEN_DEC32((kmp_int32 *)&root->r.r_in_parallel);
+ }
+ KMP_DEBUG_ASSERT(root->r.r_in_parallel >= 0);
#if OMPT_SUPPORT && OMPT_TRACE
- if(ompt_enabled){
- ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
- if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
- ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
- parallel_id, task_info->task_id);
- }
- task_info->frame.exit_runtime_frame = NULL;
- task_info->task_id = 0;
- }
+ if (ompt_enabled) {
+ ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
+ if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
+ ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
+ parallel_id, task_info->task_id);
+ }
+ task_info->frame.exit_runtime_frame = NULL;
+ task_info->task_id = 0;
+ }
#endif
- KF_TRACE( 10, ("__kmp_join_call1: T#%d, this_thread=%p team=%p\n",
- 0, master_th, team ) );
- __kmp_pop_current_task_from_thread( master_th );
+ KF_TRACE(10, ("__kmp_join_call1: T#%d, this_thread=%p team=%p\n", 0,
+ master_th, team));
+ __kmp_pop_current_task_from_thread(master_th);
#if OMP_40_ENABLED && KMP_AFFINITY_SUPPORTED
- //
- // Restore master thread's partition.
- //
- master_th->th.th_first_place = team->t.t_first_place;
- master_th->th.th_last_place = team->t.t_last_place;
+ // Restore master thread's partition.
+ master_th->th.th_first_place = team->t.t_first_place;
+ master_th->th.th_last_place = team->t.t_last_place;
#endif /* OMP_40_ENABLED */
- updateHWFPControl (team);
-
- if ( root->r.r_active != master_active )
- root->r.r_active = master_active;
-
- __kmp_free_team( root, team USE_NESTED_HOT_ARG(master_th) ); // this will free worker threads
-
- /* this race was fun to find. make sure the following is in the critical
- * region otherwise assertions may fail occasionally since the old team
- * may be reallocated and the hierarchy appears inconsistent. it is
- * actually safe to run and won't cause any bugs, but will cause those
- * assertion failures. it's only one deref&assign so might as well put this
- * in the critical region */
- master_th->th.th_team = parent_team;
- master_th->th.th_team_nproc = parent_team->t.t_nproc;
- master_th->th.th_team_master = parent_team->t.t_threads[0];
- master_th->th.th_team_serialized = parent_team->t.t_serialized;
-
- /* restore serialized team, if need be */
- if( parent_team->t.t_serialized &&
- parent_team != master_th->th.th_serial_team &&
- parent_team != root->r.r_root_team ) {
- __kmp_free_team( root, master_th->th.th_serial_team USE_NESTED_HOT_ARG(NULL) );
- master_th->th.th_serial_team = parent_team;
- }
-
- if ( __kmp_tasking_mode != tskm_immediate_exec ) {
- if (master_th->th.th_task_state_top > 0) { // Restore task state from memo stack
- KMP_DEBUG_ASSERT(master_th->th.th_task_state_memo_stack);
- // Remember master's state if we re-use this nested hot team
- master_th->th.th_task_state_memo_stack[master_th->th.th_task_state_top] = master_th->th.th_task_state;
- --master_th->th.th_task_state_top; // pop
- // Now restore state at this level
- master_th->th.th_task_state = master_th->th.th_task_state_memo_stack[master_th->th.th_task_state_top];
- }
- // Copy the task team from the parent team to the master thread
- master_th->th.th_task_team = parent_team->t.t_task_team[master_th->th.th_task_state];
- KA_TRACE( 20, ( "__kmp_join_call: Master T#%d restoring task_team %p / team %p\n",
- __kmp_gtid_from_thread( master_th ), master_th->th.th_task_team, parent_team ) );
- }
+ updateHWFPControl(team);
- // TODO: GEH - cannot do this assertion because root thread not set up as executing
- // KMP_ASSERT( master_th->th.th_current_task->td_flags.executing == 0 );
- master_th->th.th_current_task->td_flags.executing = 1;
+ if (root->r.r_active != master_active)
+ root->r.r_active = master_active;
- __kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
+ __kmp_free_team(root, team USE_NESTED_HOT_ARG(
+ master_th)); // this will free worker threads
-#if OMPT_SUPPORT
- if (ompt_enabled) {
- __kmp_join_ompt(master_th, parent_team, parallel_id, fork_context);
- }
+ /* this race was fun to find. make sure the following is in the critical
+ region otherwise assertions may fail occasionally since the old team may be
+ reallocated and the hierarchy appears inconsistent. it is actually safe to
+ run and won't cause any bugs, but will cause those assertion failures. it's
+ only one deref&assign so might as well put this in the critical region */
+ master_th->th.th_team = parent_team;
+ master_th->th.th_team_nproc = parent_team->t.t_nproc;
+ master_th->th.th_team_master = parent_team->t.t_threads[0];
+ master_th->th.th_team_serialized = parent_team->t.t_serialized;
+
+ /* restore serialized team, if need be */
+ if (parent_team->t.t_serialized &&
+ parent_team != master_th->th.th_serial_team &&
+ parent_team != root->r.r_root_team) {
+ __kmp_free_team(root,
+ master_th->th.th_serial_team USE_NESTED_HOT_ARG(NULL));
+ master_th->th.th_serial_team = parent_team;
+ }
+
+ if (__kmp_tasking_mode != tskm_immediate_exec) {
+ if (master_th->th.th_task_state_top >
+ 0) { // Restore task state from memo stack
+ KMP_DEBUG_ASSERT(master_th->th.th_task_state_memo_stack);
+ // Remember master's state if we re-use this nested hot team
+ master_th->th.th_task_state_memo_stack[master_th->th.th_task_state_top] =
+ master_th->th.th_task_state;
+ --master_th->th.th_task_state_top; // pop
+ // Now restore state at this level
+ master_th->th.th_task_state =
+ master_th->th
+ .th_task_state_memo_stack[master_th->th.th_task_state_top];
+ }
+ // Copy the task team from the parent team to the master thread
+ master_th->th.th_task_team =
+ parent_team->t.t_task_team[master_th->th.th_task_state];
+ KA_TRACE(20,
+ ("__kmp_join_call: Master T#%d restoring task_team %p / team %p\n",
+ __kmp_gtid_from_thread(master_th), master_th->th.th_task_team,
+ parent_team));
+ }
+
+ // TODO: GEH - cannot do this assertion because root thread not set up as
+ // executing
+ // KMP_ASSERT( master_th->th.th_current_task->td_flags.executing == 0 );
+ master_th->th.th_current_task->td_flags.executing = 1;
+
+ __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
+
+#if OMPT_SUPPORT
+ if (ompt_enabled) {
+ __kmp_join_ompt(master_th, parent_team, parallel_id, fork_context);
+ }
#endif
- KMP_MB();
- KA_TRACE( 20, ("__kmp_join_call: exit T#%d\n", gtid ));
+ KMP_MB();
+ KA_TRACE(20, ("__kmp_join_call: exit T#%d\n", gtid));
}
-/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
-
/* Check whether we should push an internal control record onto the
serial team stack. If so, do it. */
-void
-__kmp_save_internal_controls ( kmp_info_t * thread )
-{
+void __kmp_save_internal_controls(kmp_info_t *thread) {
- if ( thread->th.th_team != thread->th.th_serial_team ) {
- return;
- }
- if (thread->th.th_team->t.t_serialized > 1) {
- int push = 0;
+ if (thread->th.th_team != thread->th.th_serial_team) {
+ return;
+ }
+ if (thread->th.th_team->t.t_serialized > 1) {
+ int push = 0;
- if (thread->th.th_team->t.t_control_stack_top == NULL) {
- push = 1;
- } else {
- if ( thread->th.th_team->t.t_control_stack_top->serial_nesting_level !=
- thread->th.th_team->t.t_serialized ) {
- push = 1;
- }
- }
- if (push) { /* push a record on the serial team's stack */
- kmp_internal_control_t * control = (kmp_internal_control_t *) __kmp_allocate(sizeof(kmp_internal_control_t));
+ if (thread->th.th_team->t.t_control_stack_top == NULL) {
+ push = 1;
+ } else {
+ if (thread->th.th_team->t.t_control_stack_top->serial_nesting_level !=
+ thread->th.th_team->t.t_serialized) {
+ push = 1;
+ }
+ }
+ if (push) { /* push a record on the serial team's stack */
+ kmp_internal_control_t *control =
+ (kmp_internal_control_t *)__kmp_allocate(
+ sizeof(kmp_internal_control_t));
- copy_icvs( control, & thread->th.th_current_task->td_icvs );
+ copy_icvs(control, &thread->th.th_current_task->td_icvs);
- control->serial_nesting_level = thread->th.th_team->t.t_serialized;
+ control->serial_nesting_level = thread->th.th_team->t.t_serialized;
- control->next = thread->th.th_team->t.t_control_stack_top;
- thread->th.th_team->t.t_control_stack_top = control;
- }
+ control->next = thread->th.th_team->t.t_control_stack_top;
+ thread->th.th_team->t.t_control_stack_top = control;
}
+ }
}
/* Changes set_nproc */
-void
-__kmp_set_num_threads( int new_nth, int gtid )
-{
- kmp_info_t *thread;
- kmp_root_t *root;
-
- KF_TRACE( 10, ("__kmp_set_num_threads: new __kmp_nth = %d\n", new_nth ));
- KMP_DEBUG_ASSERT( __kmp_init_serial );
-
- if (new_nth < 1)
- new_nth = 1;
- else if (new_nth > __kmp_max_nth)
- new_nth = __kmp_max_nth;
-
- KMP_COUNT_VALUE(OMP_set_numthreads, new_nth);
- thread = __kmp_threads[gtid];
-
- __kmp_save_internal_controls( thread );
-
- set__nproc( thread, new_nth );
-
- //
- // If this omp_set_num_threads() call will cause the hot team size to be
- // reduced (in the absence of a num_threads clause), then reduce it now,
- // rather than waiting for the next parallel region.
- //
- root = thread->th.th_root;
- if ( __kmp_init_parallel && ( ! root->r.r_active )
- && ( root->r.r_hot_team->t.t_nproc > new_nth )
+void __kmp_set_num_threads(int new_nth, int gtid) {
+ kmp_info_t *thread;
+ kmp_root_t *root;
+
+ KF_TRACE(10, ("__kmp_set_num_threads: new __kmp_nth = %d\n", new_nth));
+ KMP_DEBUG_ASSERT(__kmp_init_serial);
+
+ if (new_nth < 1)
+ new_nth = 1;
+ else if (new_nth > __kmp_max_nth)
+ new_nth = __kmp_max_nth;
+
+ KMP_COUNT_VALUE(OMP_set_numthreads, new_nth);
+ thread = __kmp_threads[gtid];
+
+ __kmp_save_internal_controls(thread);
+
+ set__nproc(thread, new_nth);
+
+ // If this omp_set_num_threads() call will cause the hot team size to be
+ // reduced (in the absence of a num_threads clause), then reduce it now,
+ // rather than waiting for the next parallel region.
+ root = thread->th.th_root;
+ if (__kmp_init_parallel && (!root->r.r_active) &&
+ (root->r.r_hot_team->t.t_nproc > new_nth)
#if KMP_NESTED_HOT_TEAMS
&& __kmp_hot_teams_max_level && !__kmp_hot_teams_mode
#endif
- ) {
- kmp_team_t *hot_team = root->r.r_hot_team;
- int f;
+ ) {
+ kmp_team_t *hot_team = root->r.r_hot_team;
+ int f;
- __kmp_acquire_bootstrap_lock( &__kmp_forkjoin_lock );
+ __kmp_acquire_bootstrap_lock(&__kmp_forkjoin_lock);
- // Release the extra threads we don't need any more.
- for ( f = new_nth; f < hot_team->t.t_nproc; f++ ) {
- KMP_DEBUG_ASSERT( hot_team->t.t_threads[f] != NULL );
- if ( __kmp_tasking_mode != tskm_immediate_exec) {
- // When decreasing team size, threads no longer in the team should unref task team.
- hot_team->t.t_threads[f]->th.th_task_team = NULL;
- }
- __kmp_free_thread( hot_team->t.t_threads[f] );
- hot_team->t.t_threads[f] = NULL;
- }
- hot_team->t.t_nproc = new_nth;
+ // Release the extra threads we don't need any more.
+ for (f = new_nth; f < hot_team->t.t_nproc; f++) {
+ KMP_DEBUG_ASSERT(hot_team->t.t_threads[f] != NULL);
+ if (__kmp_tasking_mode != tskm_immediate_exec) {
+ // When decreasing team size, threads no longer in the team should unref
+ // task team.
+ hot_team->t.t_threads[f]->th.th_task_team = NULL;
+ }
+ __kmp_free_thread(hot_team->t.t_threads[f]);
+ hot_team->t.t_threads[f] = NULL;
+ }
+ hot_team->t.t_nproc = new_nth;
#if KMP_NESTED_HOT_TEAMS
- if( thread->th.th_hot_teams ) {
- KMP_DEBUG_ASSERT( hot_team == thread->th.th_hot_teams[0].hot_team );
- thread->th.th_hot_teams[0].hot_team_nth = new_nth;
- }
+ if (thread->th.th_hot_teams) {
+ KMP_DEBUG_ASSERT(hot_team == thread->th.th_hot_teams[0].hot_team);
+ thread->th.th_hot_teams[0].hot_team_nth = new_nth;
+ }
#endif
- __kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
+ __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
- //
- // Update the t_nproc field in the threads that are still active.
- //
- for( f=0 ; f < new_nth; f++ ) {
- KMP_DEBUG_ASSERT( hot_team->t.t_threads[f] != NULL );
- hot_team->t.t_threads[f]->th.th_team_nproc = new_nth;
- }
- // Special flag in case omp_set_num_threads() call
- hot_team->t.t_size_changed = -1;
+ // Update the t_nproc field in the threads that are still active.
+ for (f = 0; f < new_nth; f++) {
+ KMP_DEBUG_ASSERT(hot_team->t.t_threads[f] != NULL);
+ hot_team->t.t_threads[f]->th.th_team_nproc = new_nth;
}
+ // Special flag in case omp_set_num_threads() call
+ hot_team->t.t_size_changed = -1;
+ }
}
/* Changes max_active_levels */
-void
-__kmp_set_max_active_levels( int gtid, int max_active_levels )
-{
- kmp_info_t *thread;
-
- KF_TRACE( 10, ( "__kmp_set_max_active_levels: new max_active_levels for thread %d = (%d)\n", gtid, max_active_levels ) );
- KMP_DEBUG_ASSERT( __kmp_init_serial );
-
- // validate max_active_levels
- if( max_active_levels < 0 ) {
- KMP_WARNING( ActiveLevelsNegative, max_active_levels );
- // We ignore this call if the user has specified a negative value.
- // The current setting won't be changed. The last valid setting will be used.
- // A warning will be issued (if warnings are allowed as controlled by the KMP_WARNINGS env var).
- KF_TRACE( 10, ( "__kmp_set_max_active_levels: the call is ignored: new max_active_levels for thread %d = (%d)\n", gtid, max_active_levels ) );
- return;
- }
- if( max_active_levels <= KMP_MAX_ACTIVE_LEVELS_LIMIT ) {
- // it's OK, the max_active_levels is within the valid range: [ 0; KMP_MAX_ACTIVE_LEVELS_LIMIT ]
- // We allow a zero value. (implementation defined behavior)
- } else {
- KMP_WARNING( ActiveLevelsExceedLimit, max_active_levels, KMP_MAX_ACTIVE_LEVELS_LIMIT );
- max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
- // Current upper limit is MAX_INT. (implementation defined behavior)
- // If the input exceeds the upper limit, we correct the input to be the upper limit. (implementation defined behavior)
- // Actually, the flow should never get here until we use MAX_INT limit.
- }
- KF_TRACE( 10, ( "__kmp_set_max_active_levels: after validation: new max_active_levels for thread %d = (%d)\n", gtid, max_active_levels ) );
+void __kmp_set_max_active_levels(int gtid, int max_active_levels) {
+ kmp_info_t *thread;
- thread = __kmp_threads[ gtid ];
+ KF_TRACE(10, ("__kmp_set_max_active_levels: new max_active_levels for thread "
+ "%d = (%d)\n",
+ gtid, max_active_levels));
+ KMP_DEBUG_ASSERT(__kmp_init_serial);
+
+ // validate max_active_levels
+ if (max_active_levels < 0) {
+ KMP_WARNING(ActiveLevelsNegative, max_active_levels);
+ // We ignore this call if the user has specified a negative value.
+ // The current setting won't be changed. The last valid setting will be
+ // used. A warning will be issued (if warnings are allowed as controlled by
+ // the KMP_WARNINGS env var).
+ KF_TRACE(10, ("__kmp_set_max_active_levels: the call is ignored: new "
+ "max_active_levels for thread %d = (%d)\n",
+ gtid, max_active_levels));
+ return;
+ }
+ if (max_active_levels <= KMP_MAX_ACTIVE_LEVELS_LIMIT) {
+ // it's OK, the max_active_levels is within the valid range: [ 0;
+ // KMP_MAX_ACTIVE_LEVELS_LIMIT ]
+ // We allow a zero value. (implementation defined behavior)
+ } else {
+ KMP_WARNING(ActiveLevelsExceedLimit, max_active_levels,
+ KMP_MAX_ACTIVE_LEVELS_LIMIT);
+ max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
+ // Current upper limit is MAX_INT. (implementation defined behavior)
+ // If the input exceeds the upper limit, we correct the input to be the
+ // upper limit. (implementation defined behavior)
+ // Actually, the flow should never get here until we use MAX_INT limit.
+ }
+ KF_TRACE(10, ("__kmp_set_max_active_levels: after validation: new "
+ "max_active_levels for thread %d = (%d)\n",
+ gtid, max_active_levels));
- __kmp_save_internal_controls( thread );
+ thread = __kmp_threads[gtid];
- set__max_active_levels( thread, max_active_levels );
+ __kmp_save_internal_controls(thread);
+ set__max_active_levels(thread, max_active_levels);
}
/* Gets max_active_levels */
-int
-__kmp_get_max_active_levels( int gtid )
-{
- kmp_info_t *thread;
-
- KF_TRACE( 10, ( "__kmp_get_max_active_levels: thread %d\n", gtid ) );
- KMP_DEBUG_ASSERT( __kmp_init_serial );
-
- thread = __kmp_threads[ gtid ];
- KMP_DEBUG_ASSERT( thread->th.th_current_task );
- KF_TRACE( 10, ( "__kmp_get_max_active_levels: thread %d, curtask=%p, curtask_maxaclevel=%d\n",
- gtid, thread->th.th_current_task, thread->th.th_current_task->td_icvs.max_active_levels ) );
- return thread->th.th_current_task->td_icvs.max_active_levels;
+int __kmp_get_max_active_levels(int gtid) {
+ kmp_info_t *thread;
+
+ KF_TRACE(10, ("__kmp_get_max_active_levels: thread %d\n", gtid));
+ KMP_DEBUG_ASSERT(__kmp_init_serial);
+
+ thread = __kmp_threads[gtid];
+ KMP_DEBUG_ASSERT(thread->th.th_current_task);
+ KF_TRACE(10, ("__kmp_get_max_active_levels: thread %d, curtask=%p, "
+ "curtask_maxaclevel=%d\n",
+ gtid, thread->th.th_current_task,
+ thread->th.th_current_task->td_icvs.max_active_levels));
+ return thread->th.th_current_task->td_icvs.max_active_levels;
}
/* Changes def_sched_var ICV values (run-time schedule kind and chunk) */
-void
-__kmp_set_schedule( int gtid, kmp_sched_t kind, int chunk )
-{
- kmp_info_t *thread;
-// kmp_team_t *team;
-
- KF_TRACE( 10, ("__kmp_set_schedule: new schedule for thread %d = (%d, %d)\n", gtid, (int)kind, chunk ));
- KMP_DEBUG_ASSERT( __kmp_init_serial );
-
- // Check if the kind parameter is valid, correct if needed.
- // Valid parameters should fit in one of two intervals - standard or extended:
- // <lower>, <valid>, <upper_std>, <lower_ext>, <valid>, <upper>
- // 2008-01-25: 0, 1 - 4, 5, 100, 101 - 102, 103
- if ( kind <= kmp_sched_lower || kind >= kmp_sched_upper ||
- ( kind <= kmp_sched_lower_ext && kind >= kmp_sched_upper_std ) )
- {
- // TODO: Hint needs attention in case we change the default schedule.
- __kmp_msg(
- kmp_ms_warning,
- KMP_MSG( ScheduleKindOutOfRange, kind ),
- KMP_HNT( DefaultScheduleKindUsed, "static, no chunk" ),
- __kmp_msg_null
- );
- kind = kmp_sched_default;
- chunk = 0; // ignore chunk value in case of bad kind
- }
-
- thread = __kmp_threads[ gtid ];
-
- __kmp_save_internal_controls( thread );
-
- if ( kind < kmp_sched_upper_std ) {
- if ( kind == kmp_sched_static && chunk < KMP_DEFAULT_CHUNK ) {
- // differ static chunked vs. unchunked:
- // chunk should be invalid to indicate unchunked schedule (which is the default)
- thread->th.th_current_task->td_icvs.sched.r_sched_type = kmp_sch_static;
- } else {
- thread->th.th_current_task->td_icvs.sched.r_sched_type = __kmp_sch_map[ kind - kmp_sched_lower - 1 ];
- }
+void __kmp_set_schedule(int gtid, kmp_sched_t kind, int chunk) {
+ kmp_info_t *thread;
+ // kmp_team_t *team;
+
+ KF_TRACE(10, ("__kmp_set_schedule: new schedule for thread %d = (%d, %d)\n",
+ gtid, (int)kind, chunk));
+ KMP_DEBUG_ASSERT(__kmp_init_serial);
+
+ // Check if the kind parameter is valid, correct if needed.
+ // Valid parameters should fit in one of two intervals - standard or extended:
+ // <lower>, <valid>, <upper_std>, <lower_ext>, <valid>, <upper>
+ // 2008-01-25: 0, 1 - 4, 5, 100, 101 - 102, 103
+ if (kind <= kmp_sched_lower || kind >= kmp_sched_upper ||
+ (kind <= kmp_sched_lower_ext && kind >= kmp_sched_upper_std)) {
+ // TODO: Hint needs attention in case we change the default schedule.
+ __kmp_msg(kmp_ms_warning, KMP_MSG(ScheduleKindOutOfRange, kind),
+ KMP_HNT(DefaultScheduleKindUsed, "static, no chunk"),
+ __kmp_msg_null);
+ kind = kmp_sched_default;
+ chunk = 0; // ignore chunk value in case of bad kind
+ }
+
+ thread = __kmp_threads[gtid];
+
+ __kmp_save_internal_controls(thread);
+
+ if (kind < kmp_sched_upper_std) {
+ if (kind == kmp_sched_static && chunk < KMP_DEFAULT_CHUNK) {
+ // differ static chunked vs. unchunked: chunk should be invalid to
+ // indicate unchunked schedule (which is the default)
+ thread->th.th_current_task->td_icvs.sched.r_sched_type = kmp_sch_static;
} else {
- // __kmp_sch_map[ kind - kmp_sched_lower_ext + kmp_sched_upper_std - kmp_sched_lower - 2 ];
- thread->th.th_current_task->td_icvs.sched.r_sched_type =
- __kmp_sch_map[ kind - kmp_sched_lower_ext + kmp_sched_upper_std - kmp_sched_lower - 2 ];
- }
- if ( kind == kmp_sched_auto ) {
- // ignore parameter chunk for schedule auto
- thread->th.th_current_task->td_icvs.sched.chunk = KMP_DEFAULT_CHUNK;
- } else {
- thread->th.th_current_task->td_icvs.sched.chunk = chunk;
+ thread->th.th_current_task->td_icvs.sched.r_sched_type =
+ __kmp_sch_map[kind - kmp_sched_lower - 1];
}
+ } else {
+ // __kmp_sch_map[ kind - kmp_sched_lower_ext + kmp_sched_upper_std -
+ // kmp_sched_lower - 2 ];
+ thread->th.th_current_task->td_icvs.sched.r_sched_type =
+ __kmp_sch_map[kind - kmp_sched_lower_ext + kmp_sched_upper_std -
+ kmp_sched_lower - 2];
+ }
+ if (kind == kmp_sched_auto) {
+ // ignore parameter chunk for schedule auto
+ thread->th.th_current_task->td_icvs.sched.chunk = KMP_DEFAULT_CHUNK;
+ } else {
+ thread->th.th_current_task->td_icvs.sched.chunk = chunk;
+ }
}
/* Gets def_sched_var ICV values */
-void
-__kmp_get_schedule( int gtid, kmp_sched_t * kind, int * chunk )
-{
- kmp_info_t *thread;
- enum sched_type th_type;
-
- KF_TRACE( 10, ("__kmp_get_schedule: thread %d\n", gtid ));
- KMP_DEBUG_ASSERT( __kmp_init_serial );
-
- thread = __kmp_threads[ gtid ];
-
- th_type = thread->th.th_current_task->td_icvs.sched.r_sched_type;
-
- switch ( th_type ) {
- case kmp_sch_static:
- case kmp_sch_static_greedy:
- case kmp_sch_static_balanced:
- *kind = kmp_sched_static;
- *chunk = 0; // chunk was not set, try to show this fact via zero value
- return;
- case kmp_sch_static_chunked:
- *kind = kmp_sched_static;
- break;
- case kmp_sch_dynamic_chunked:
- *kind = kmp_sched_dynamic;
- break;
- case kmp_sch_guided_chunked:
- case kmp_sch_guided_iterative_chunked:
- case kmp_sch_guided_analytical_chunked:
- *kind = kmp_sched_guided;
- break;
- case kmp_sch_auto:
- *kind = kmp_sched_auto;
- break;
- case kmp_sch_trapezoidal:
- *kind = kmp_sched_trapezoidal;
- break;
+void __kmp_get_schedule(int gtid, kmp_sched_t *kind, int *chunk) {
+ kmp_info_t *thread;
+ enum sched_type th_type;
+
+ KF_TRACE(10, ("__kmp_get_schedule: thread %d\n", gtid));
+ KMP_DEBUG_ASSERT(__kmp_init_serial);
+
+ thread = __kmp_threads[gtid];
+
+ th_type = thread->th.th_current_task->td_icvs.sched.r_sched_type;
+
+ switch (th_type) {
+ case kmp_sch_static:
+ case kmp_sch_static_greedy:
+ case kmp_sch_static_balanced:
+ *kind = kmp_sched_static;
+ *chunk = 0; // chunk was not set, try to show this fact via zero value
+ return;
+ case kmp_sch_static_chunked:
+ *kind = kmp_sched_static;
+ break;
+ case kmp_sch_dynamic_chunked:
+ *kind = kmp_sched_dynamic;
+ break;
+ case kmp_sch_guided_chunked:
+ case kmp_sch_guided_iterative_chunked:
+ case kmp_sch_guided_analytical_chunked:
+ *kind = kmp_sched_guided;
+ break;
+ case kmp_sch_auto:
+ *kind = kmp_sched_auto;
+ break;
+ case kmp_sch_trapezoidal:
+ *kind = kmp_sched_trapezoidal;
+ break;
#if KMP_STATIC_STEAL_ENABLED
- case kmp_sch_static_steal:
- *kind = kmp_sched_static_steal;
- break;
+ case kmp_sch_static_steal:
+ *kind = kmp_sched_static_steal;
+ break;
#endif
- default:
- KMP_FATAL( UnknownSchedulingType, th_type );
- }
+ default:
+ KMP_FATAL(UnknownSchedulingType, th_type);
+ }
- *chunk = thread->th.th_current_task->td_icvs.sched.chunk;
+ *chunk = thread->th.th_current_task->td_icvs.sched.chunk;
}
-int
-__kmp_get_ancestor_thread_num( int gtid, int level ) {
+int __kmp_get_ancestor_thread_num(int gtid, int level) {
- int ii, dd;
- kmp_team_t *team;
- kmp_info_t *thr;
+ int ii, dd;
+ kmp_team_t *team;
+ kmp_info_t *thr;
- KF_TRACE( 10, ("__kmp_get_ancestor_thread_num: thread %d %d\n", gtid, level ));
- KMP_DEBUG_ASSERT( __kmp_init_serial );
+ KF_TRACE(10, ("__kmp_get_ancestor_thread_num: thread %d %d\n", gtid, level));
+ KMP_DEBUG_ASSERT(__kmp_init_serial);
- // validate level
- if( level == 0 ) return 0;
- if( level < 0 ) return -1;
- thr = __kmp_threads[ gtid ];
- team = thr->th.th_team;
- ii = team->t.t_level;
- if( level > ii ) return -1;
+ // validate level
+ if (level == 0)
+ return 0;
+ if (level < 0)
+ return -1;
+ thr = __kmp_threads[gtid];
+ team = thr->th.th_team;
+ ii = team->t.t_level;
+ if (level > ii)
+ return -1;
#if OMP_40_ENABLED
- if( thr->th.th_teams_microtask ) {
- // AC: we are in teams region where multiple nested teams have same level
- int tlevel = thr->th.th_teams_level; // the level of the teams construct
- if( level <= tlevel ) { // otherwise usual algorithm works (will not touch the teams)
- KMP_DEBUG_ASSERT( ii >= tlevel );
- // AC: As we need to pass by the teams league, we need to artificially increase ii
- if ( ii == tlevel ) {
- ii += 2; // three teams have same level
- } else {
- ii ++; // two teams have same level
- }
- }
+ if (thr->th.th_teams_microtask) {
+ // AC: we are in teams region where multiple nested teams have same level
+ int tlevel = thr->th.th_teams_level; // the level of the teams construct
+ if (level <=
+ tlevel) { // otherwise usual algorithm works (will not touch the teams)
+ KMP_DEBUG_ASSERT(ii >= tlevel);
+ // AC: As we need to pass by the teams league, we need to artificially
+ // increase ii
+ if (ii == tlevel) {
+ ii += 2; // three teams have same level
+ } else {
+ ii++; // two teams have same level
+ }
}
+ }
#endif
- if( ii == level ) return __kmp_tid_from_gtid( gtid );
-
- dd = team->t.t_serialized;
- level++;
- while( ii > level )
- {
- for( dd = team->t.t_serialized; ( dd > 0 ) && ( ii > level ); dd--, ii-- )
- {
- }
- if( ( team->t.t_serialized ) && ( !dd ) ) {
- team = team->t.t_parent;
- continue;
- }
- if( ii > level ) {
- team = team->t.t_parent;
- dd = team->t.t_serialized;
- ii--;
- }
- }
-
- return ( dd > 1 ) ? ( 0 ) : ( team->t.t_master_tid );
-}
-
-int
-__kmp_get_team_size( int gtid, int level ) {
-
- int ii, dd;
- kmp_team_t *team;
- kmp_info_t *thr;
-
- KF_TRACE( 10, ("__kmp_get_team_size: thread %d %d\n", gtid, level ));
- KMP_DEBUG_ASSERT( __kmp_init_serial );
-
- // validate level
- if( level == 0 ) return 1;
- if( level < 0 ) return -1;
- thr = __kmp_threads[ gtid ];
- team = thr->th.th_team;
- ii = team->t.t_level;
- if( level > ii ) return -1;
-
-#if OMP_40_ENABLED
- if( thr->th.th_teams_microtask ) {
- // AC: we are in teams region where multiple nested teams have same level
- int tlevel = thr->th.th_teams_level; // the level of the teams construct
- if( level <= tlevel ) { // otherwise usual algorithm works (will not touch the teams)
- KMP_DEBUG_ASSERT( ii >= tlevel );
- // AC: As we need to pass by the teams league, we need to artificially increase ii
- if ( ii == tlevel ) {
- ii += 2; // three teams have same level
- } else {
- ii ++; // two teams have same level
- }
- }
- }
-#endif
+ if (ii == level)
+ return __kmp_tid_from_gtid(gtid);
- while( ii > level )
- {
- for( dd = team->t.t_serialized; ( dd > 0 ) && ( ii > level ); dd--, ii-- )
- {
- }
- if( team->t.t_serialized && ( !dd ) ) {
- team = team->t.t_parent;
- continue;
- }
- if( ii > level ) {
- team = team->t.t_parent;
- ii--;
- }
+ dd = team->t.t_serialized;
+ level++;
+ while (ii > level) {
+ for (dd = team->t.t_serialized; (dd > 0) && (ii > level); dd--, ii--) {
}
-
- return team->t.t_nproc;
-}
-
-kmp_r_sched_t
-__kmp_get_schedule_global() {
-// This routine created because pairs (__kmp_sched, __kmp_chunk) and (__kmp_static, __kmp_guided)
-// may be changed by kmp_set_defaults independently. So one can get the updated schedule here.
-
- kmp_r_sched_t r_sched;
-
- // create schedule from 4 globals: __kmp_sched, __kmp_chunk, __kmp_static, __kmp_guided
- // __kmp_sched should keep original value, so that user can set KMP_SCHEDULE multiple times,
- // and thus have different run-time schedules in different roots (even in OMP 2.5)
- if ( __kmp_sched == kmp_sch_static ) {
- r_sched.r_sched_type = __kmp_static; // replace STATIC with more detailed schedule (balanced or greedy)
- } else if ( __kmp_sched == kmp_sch_guided_chunked ) {
- r_sched.r_sched_type = __kmp_guided; // replace GUIDED with more detailed schedule (iterative or analytical)
- } else {
- r_sched.r_sched_type = __kmp_sched; // (STATIC_CHUNKED), or (DYNAMIC_CHUNKED), or other
+ if ((team->t.t_serialized) && (!dd)) {
+ team = team->t.t_parent;
+ continue;
}
-
- if ( __kmp_chunk < KMP_DEFAULT_CHUNK ) { // __kmp_chunk may be wrong here (if it was not ever set)
- r_sched.chunk = KMP_DEFAULT_CHUNK;
- } else {
- r_sched.chunk = __kmp_chunk;
+ if (ii > level) {
+ team = team->t.t_parent;
+ dd = team->t.t_serialized;
+ ii--;
}
+ }
- return r_sched;
+ return (dd > 1) ? (0) : (team->t.t_master_tid);
}
-/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
-
-
-/*
- * Allocate (realloc == FALSE) * or reallocate (realloc == TRUE)
- * at least argc number of *t_argv entries for the requested team.
- */
-static void
-__kmp_alloc_argv_entries( int argc, kmp_team_t *team, int realloc )
-{
+int __kmp_get_team_size(int gtid, int level) {
- KMP_DEBUG_ASSERT( team );
- if( !realloc || argc > team->t.t_max_argc ) {
+ int ii, dd;
+ kmp_team_t *team;
+ kmp_info_t *thr;
- KA_TRACE( 100, ( "__kmp_alloc_argv_entries: team %d: needed entries=%d, current entries=%d\n",
- team->t.t_id, argc, ( realloc ) ? team->t.t_max_argc : 0 ));
- /* if previously allocated heap space for args, free them */
- if ( realloc && team->t.t_argv != &team->t.t_inline_argv[0] )
- __kmp_free( (void *) team->t.t_argv );
-
- if ( argc <= KMP_INLINE_ARGV_ENTRIES ) {
- /* use unused space in the cache line for arguments */
- team->t.t_max_argc = KMP_INLINE_ARGV_ENTRIES;
- KA_TRACE( 100, ( "__kmp_alloc_argv_entries: team %d: inline allocate %d argv entries\n",
- team->t.t_id, team->t.t_max_argc ));
- team->t.t_argv = &team->t.t_inline_argv[0];
- if ( __kmp_storage_map ) {
- __kmp_print_storage_map_gtid( -1, &team->t.t_inline_argv[0],
- &team->t.t_inline_argv[KMP_INLINE_ARGV_ENTRIES],
- (sizeof(void *) * KMP_INLINE_ARGV_ENTRIES),
- "team_%d.t_inline_argv",
- team->t.t_id );
- }
- } else {
- /* allocate space for arguments in the heap */
- team->t.t_max_argc = ( argc <= (KMP_MIN_MALLOC_ARGV_ENTRIES >> 1 )) ?
- KMP_MIN_MALLOC_ARGV_ENTRIES : 2 * argc;
- KA_TRACE( 100, ( "__kmp_alloc_argv_entries: team %d: dynamic allocate %d argv entries\n",
- team->t.t_id, team->t.t_max_argc ));
- team->t.t_argv = (void**) __kmp_page_allocate( sizeof(void*) * team->t.t_max_argc );
- if ( __kmp_storage_map ) {
- __kmp_print_storage_map_gtid( -1, &team->t.t_argv[0], &team->t.t_argv[team->t.t_max_argc],
- sizeof(void *) * team->t.t_max_argc, "team_%d.t_argv",
- team->t.t_id );
- }
- }
- }
-}
+ KF_TRACE(10, ("__kmp_get_team_size: thread %d %d\n", gtid, level));
+ KMP_DEBUG_ASSERT(__kmp_init_serial);
-static void
-__kmp_allocate_team_arrays(kmp_team_t *team, int max_nth)
-{
- int i;
- int num_disp_buff = max_nth > 1 ? __kmp_dispatch_num_buffers : 2;
- team->t.t_threads = (kmp_info_t**) __kmp_allocate( sizeof(kmp_info_t*) * max_nth );
- team->t.t_disp_buffer = (dispatch_shared_info_t*)
- __kmp_allocate( sizeof(dispatch_shared_info_t) * num_disp_buff );
- team->t.t_dispatch = (kmp_disp_t*) __kmp_allocate( sizeof(kmp_disp_t) * max_nth );
- team->t.t_implicit_task_taskdata = (kmp_taskdata_t*) __kmp_allocate( sizeof(kmp_taskdata_t) * max_nth );
- team->t.t_max_nproc = max_nth;
-
- /* setup dispatch buffers */
- for(i = 0 ; i < num_disp_buff; ++i) {
- team->t.t_disp_buffer[i].buffer_index = i;
+ // validate level
+ if (level == 0)
+ return 1;
+ if (level < 0)
+ return -1;
+ thr = __kmp_threads[gtid];
+ team = thr->th.th_team;
+ ii = team->t.t_level;
+ if (level > ii)
+ return -1;
+
+#if OMP_40_ENABLED
+ if (thr->th.th_teams_microtask) {
+ // AC: we are in teams region where multiple nested teams have same level
+ int tlevel = thr->th.th_teams_level; // the level of the teams construct
+ if (level <=
+ tlevel) { // otherwise usual algorithm works (will not touch the teams)
+ KMP_DEBUG_ASSERT(ii >= tlevel);
+ // AC: As we need to pass by the teams league, we need to artificially
+ // increase ii
+ if (ii == tlevel) {
+ ii += 2; // three teams have same level
+ } else {
+ ii++; // two teams have same level
+ }
+ }
+ }
+#endif
+
+ while (ii > level) {
+ for (dd = team->t.t_serialized; (dd > 0) && (ii > level); dd--, ii--) {
+ }
+ if (team->t.t_serialized && (!dd)) {
+ team = team->t.t_parent;
+ continue;
+ }
+ if (ii > level) {
+ team = team->t.t_parent;
+ ii--;
+ }
+ }
+
+ return team->t.t_nproc;
+}
+
+kmp_r_sched_t __kmp_get_schedule_global() {
+ // This routine created because pairs (__kmp_sched, __kmp_chunk) and
+ // (__kmp_static, __kmp_guided) may be changed by kmp_set_defaults
+ // independently. So one can get the updated schedule here.
+
+ kmp_r_sched_t r_sched;
+
+ // create schedule from 4 globals: __kmp_sched, __kmp_chunk, __kmp_static,
+ // __kmp_guided. __kmp_sched should keep original value, so that user can set
+ // KMP_SCHEDULE multiple times, and thus have different run-time schedules in
+ // different roots (even in OMP 2.5)
+ if (__kmp_sched == kmp_sch_static) {
+ r_sched.r_sched_type = __kmp_static; // replace STATIC with more detailed
+ // schedule (balanced or greedy)
+ } else if (__kmp_sched == kmp_sch_guided_chunked) {
+ r_sched.r_sched_type = __kmp_guided; // replace GUIDED with more detailed
+ // schedule (iterative or analytical)
+ } else {
+ r_sched.r_sched_type =
+ __kmp_sched; // (STATIC_CHUNKED), or (DYNAMIC_CHUNKED), or other
+ }
+
+ if (__kmp_chunk < KMP_DEFAULT_CHUNK) { // __kmp_chunk may be wrong here (if it
+ // was not ever set)
+ r_sched.chunk = KMP_DEFAULT_CHUNK;
+ } else {
+ r_sched.chunk = __kmp_chunk;
+ }
+
+ return r_sched;
+}
+
+/* Allocate (realloc == FALSE) * or reallocate (realloc == TRUE)
+ at least argc number of *t_argv entries for the requested team. */
+static void __kmp_alloc_argv_entries(int argc, kmp_team_t *team, int realloc) {
+
+ KMP_DEBUG_ASSERT(team);
+ if (!realloc || argc > team->t.t_max_argc) {
+
+ KA_TRACE(100, ("__kmp_alloc_argv_entries: team %d: needed entries=%d, "
+ "current entries=%d\n",
+ team->t.t_id, argc, (realloc) ? team->t.t_max_argc : 0));
+ /* if previously allocated heap space for args, free them */
+ if (realloc && team->t.t_argv != &team->t.t_inline_argv[0])
+ __kmp_free((void *)team->t.t_argv);
+
+ if (argc <= KMP_INLINE_ARGV_ENTRIES) {
+ /* use unused space in the cache line for arguments */
+ team->t.t_max_argc = KMP_INLINE_ARGV_ENTRIES;
+ KA_TRACE(100, ("__kmp_alloc_argv_entries: team %d: inline allocate %d "
+ "argv entries\n",
+ team->t.t_id, team->t.t_max_argc));
+ team->t.t_argv = &team->t.t_inline_argv[0];
+ if (__kmp_storage_map) {
+ __kmp_print_storage_map_gtid(
+ -1, &team->t.t_inline_argv[0],
+ &team->t.t_inline_argv[KMP_INLINE_ARGV_ENTRIES],
+ (sizeof(void *) * KMP_INLINE_ARGV_ENTRIES), "team_%d.t_inline_argv",
+ team->t.t_id);
+ }
+ } else {
+ /* allocate space for arguments in the heap */
+ team->t.t_max_argc = (argc <= (KMP_MIN_MALLOC_ARGV_ENTRIES >> 1))
+ ? KMP_MIN_MALLOC_ARGV_ENTRIES
+ : 2 * argc;
+ KA_TRACE(100, ("__kmp_alloc_argv_entries: team %d: dynamic allocate %d "
+ "argv entries\n",
+ team->t.t_id, team->t.t_max_argc));
+ team->t.t_argv =
+ (void **)__kmp_page_allocate(sizeof(void *) * team->t.t_max_argc);
+ if (__kmp_storage_map) {
+ __kmp_print_storage_map_gtid(-1, &team->t.t_argv[0],
+ &team->t.t_argv[team->t.t_max_argc],
+ sizeof(void *) * team->t.t_max_argc,
+ "team_%d.t_argv", team->t.t_id);
+ }
+ }
+ }
+}
+
+static void __kmp_allocate_team_arrays(kmp_team_t *team, int max_nth) {
+ int i;
+ int num_disp_buff = max_nth > 1 ? __kmp_dispatch_num_buffers : 2;
+ team->t.t_threads =
+ (kmp_info_t **)__kmp_allocate(sizeof(kmp_info_t *) * max_nth);
+ team->t.t_disp_buffer = (dispatch_shared_info_t *)__kmp_allocate(
+ sizeof(dispatch_shared_info_t) * num_disp_buff);
+ team->t.t_dispatch =
+ (kmp_disp_t *)__kmp_allocate(sizeof(kmp_disp_t) * max_nth);
+ team->t.t_implicit_task_taskdata =
+ (kmp_taskdata_t *)__kmp_allocate(sizeof(kmp_taskdata_t) * max_nth);
+ team->t.t_max_nproc = max_nth;
+
+ /* setup dispatch buffers */
+ for (i = 0; i < num_disp_buff; ++i) {
+ team->t.t_disp_buffer[i].buffer_index = i;
#if OMP_45_ENABLED
- team->t.t_disp_buffer[i].doacross_buf_idx = i;
+ team->t.t_disp_buffer[i].doacross_buf_idx = i;
#endif
- }
+ }
}
-static void
-__kmp_free_team_arrays(kmp_team_t *team) {
- /* Note: this does not free the threads in t_threads (__kmp_free_threads) */
- int i;
- for ( i = 0; i < team->t.t_max_nproc; ++ i ) {
- if ( team->t.t_dispatch[ i ].th_disp_buffer != NULL ) {
- __kmp_free( team->t.t_dispatch[ i ].th_disp_buffer );
- team->t.t_dispatch[ i ].th_disp_buffer = NULL;
- }; // if
- }; // for
- __kmp_free(team->t.t_threads);
- __kmp_free(team->t.t_disp_buffer);
- __kmp_free(team->t.t_dispatch);
- __kmp_free(team->t.t_implicit_task_taskdata);
- team->t.t_threads = NULL;
- team->t.t_disp_buffer = NULL;
- team->t.t_dispatch = NULL;
- team->t.t_implicit_task_taskdata = 0;
+static void __kmp_free_team_arrays(kmp_team_t *team) {
+ /* Note: this does not free the threads in t_threads (__kmp_free_threads) */
+ int i;
+ for (i = 0; i < team->t.t_max_nproc; ++i) {
+ if (team->t.t_dispatch[i].th_disp_buffer != NULL) {
+ __kmp_free(team->t.t_dispatch[i].th_disp_buffer);
+ team->t.t_dispatch[i].th_disp_buffer = NULL;
+ }; // if
+ }; // for
+ __kmp_free(team->t.t_threads);
+ __kmp_free(team->t.t_disp_buffer);
+ __kmp_free(team->t.t_dispatch);
+ __kmp_free(team->t.t_implicit_task_taskdata);
+ team->t.t_threads = NULL;
+ team->t.t_disp_buffer = NULL;
+ team->t.t_dispatch = NULL;
+ team->t.t_implicit_task_taskdata = 0;
}
-static void
-__kmp_reallocate_team_arrays(kmp_team_t *team, int max_nth) {
- kmp_info_t **oldThreads = team->t.t_threads;
+static void __kmp_reallocate_team_arrays(kmp_team_t *team, int max_nth) {
+ kmp_info_t **oldThreads = team->t.t_threads;
- __kmp_free(team->t.t_disp_buffer);
- __kmp_free(team->t.t_dispatch);
- __kmp_free(team->t.t_implicit_task_taskdata);
- __kmp_allocate_team_arrays(team, max_nth);
+ __kmp_free(team->t.t_disp_buffer);
+ __kmp_free(team->t.t_dispatch);
+ __kmp_free(team->t.t_implicit_task_taskdata);
+ __kmp_allocate_team_arrays(team, max_nth);
- KMP_MEMCPY(team->t.t_threads, oldThreads, team->t.t_nproc * sizeof (kmp_info_t*));
+ KMP_MEMCPY(team->t.t_threads, oldThreads,
+ team->t.t_nproc * sizeof(kmp_info_t *));
- __kmp_free(oldThreads);
+ __kmp_free(oldThreads);
}
-static kmp_internal_control_t
-__kmp_get_global_icvs( void ) {
+static kmp_internal_control_t __kmp_get_global_icvs(void) {
- kmp_r_sched_t r_sched = __kmp_get_schedule_global(); // get current state of scheduling globals
+ kmp_r_sched_t r_sched =
+ __kmp_get_schedule_global(); // get current state of scheduling globals
#if OMP_40_ENABLED
- KMP_DEBUG_ASSERT( __kmp_nested_proc_bind.used > 0 );
+ KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.used > 0);
#endif /* OMP_40_ENABLED */
- kmp_internal_control_t g_icvs = {
- 0, //int serial_nesting_level; //corresponds to the value of the th_team_serialized field
- (kmp_int8)__kmp_dflt_nested, //int nested; //internal control for nested parallelism (per thread)
- (kmp_int8)__kmp_global.g.g_dynamic, //internal control for dynamic adjustment of threads (per thread)
- (kmp_int8)__kmp_env_blocktime, //int bt_set; //internal control for whether blocktime is explicitly set
- __kmp_dflt_blocktime, //int blocktime; //internal control for blocktime
+ kmp_internal_control_t g_icvs = {
+ 0, // int serial_nesting_level; //corresponds to value of th_team_serialized
+ (kmp_int8)__kmp_dflt_nested, // int nested; //internal control
+ // for nested parallelism (per thread)
+ (kmp_int8)__kmp_global.g.g_dynamic, // internal control for dynamic
+ // adjustment of threads (per thread)
+ (kmp_int8)__kmp_env_blocktime, // int bt_set; //internal control for
+ // whether blocktime is explicitly set
+ __kmp_dflt_blocktime, // int blocktime; //internal control for blocktime
#if KMP_USE_MONITOR
- __kmp_bt_intervals, //int bt_intervals; //internal control for blocktime intervals
+ __kmp_bt_intervals, // int bt_intervals; //internal control for blocktime
+// intervals
#endif
- __kmp_dflt_team_nth, //int nproc; //internal control for # of threads for next parallel region (per thread)
- // (use a max ub on value if __kmp_parallel_initialize not called yet)
- __kmp_dflt_max_active_levels, //int max_active_levels; //internal control for max_active_levels
- r_sched, //kmp_r_sched_t sched; //internal control for runtime schedule {sched,chunk} pair
+ __kmp_dflt_team_nth, // int nproc; //internal control for # of threads for
+ // next parallel region (per thread)
+ // (use a max ub on value if __kmp_parallel_initialize not called yet)
+ __kmp_dflt_max_active_levels, // int max_active_levels; //internal control
+ // for max_active_levels
+ r_sched, // kmp_r_sched_t sched; //internal control for runtime schedule
+// {sched,chunk} pair
#if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0],
- __kmp_default_device,
+ __kmp_nested_proc_bind.bind_types[0],
+ __kmp_default_device,
#endif /* OMP_40_ENABLED */
- NULL //struct kmp_internal_control *next;
- };
+ NULL // struct kmp_internal_control *next;
+ };
- return g_icvs;
+ return g_icvs;
}
-static kmp_internal_control_t
-__kmp_get_x_global_icvs( const kmp_team_t *team ) {
+static kmp_internal_control_t __kmp_get_x_global_icvs(const kmp_team_t *team) {
- kmp_internal_control_t gx_icvs;
- gx_icvs.serial_nesting_level = 0; // probably =team->t.t_serial like in save_inter_controls
- copy_icvs( & gx_icvs, & team->t.t_threads[0]->th.th_current_task->td_icvs );
- gx_icvs.next = NULL;
+ kmp_internal_control_t gx_icvs;
+ gx_icvs.serial_nesting_level =
+ 0; // probably =team->t.t_serial like in save_inter_controls
+ copy_icvs(&gx_icvs, &team->t.t_threads[0]->th.th_current_task->td_icvs);
+ gx_icvs.next = NULL;
- return gx_icvs;
+ return gx_icvs;
}
-static void
-__kmp_initialize_root( kmp_root_t *root )
-{
- int f;
- kmp_team_t *root_team;
- kmp_team_t *hot_team;
- int hot_team_max_nth;
- kmp_r_sched_t r_sched = __kmp_get_schedule_global(); // get current state of scheduling globals
- kmp_internal_control_t r_icvs = __kmp_get_global_icvs();
- KMP_DEBUG_ASSERT( root );
- KMP_ASSERT( ! root->r.r_begin );
-
- /* setup the root state structure */
- __kmp_init_lock( &root->r.r_begin_lock );
- root->r.r_begin = FALSE;
- root->r.r_active = FALSE;
- root->r.r_in_parallel = 0;
- root->r.r_blocktime = __kmp_dflt_blocktime;
- root->r.r_nested = __kmp_dflt_nested;
-
- /* setup the root team for this task */
- /* allocate the root team structure */
- KF_TRACE( 10, ( "__kmp_initialize_root: before root_team\n" ) );
-
- root_team =
- __kmp_allocate_team(
- root,
- 1, // new_nproc
- 1, // max_nproc
-#if OMPT_SUPPORT
- 0, // root parallel id
-#endif
-#if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0],
-#endif
- &r_icvs,
- 0 // argc
- USE_NESTED_HOT_ARG(NULL) // master thread is unknown
- );
-#if USE_DEBUGGER
- // Non-NULL value should be assigned to make the debugger display the root team.
- TCW_SYNC_PTR(root_team->t.t_pkfn, (microtask_t)( ~ 0 ));
-#endif
-
- KF_TRACE( 10, ( "__kmp_initialize_root: after root_team = %p\n", root_team ) );
-
- root->r.r_root_team = root_team;
- root_team->t.t_control_stack_top = NULL;
+static void __kmp_initialize_root(kmp_root_t *root) {
+ int f;
+ kmp_team_t *root_team;
+ kmp_team_t *hot_team;
+ int hot_team_max_nth;
+ kmp_r_sched_t r_sched =
+ __kmp_get_schedule_global(); // get current state of scheduling globals
+ kmp_internal_control_t r_icvs = __kmp_get_global_icvs();
+ KMP_DEBUG_ASSERT(root);
+ KMP_ASSERT(!root->r.r_begin);
- /* initialize root team */
- root_team->t.t_threads[0] = NULL;
- root_team->t.t_nproc = 1;
- root_team->t.t_serialized = 1;
- // TODO???: root_team->t.t_max_active_levels = __kmp_dflt_max_active_levels;
- root_team->t.t_sched.r_sched_type = r_sched.r_sched_type;
- root_team->t.t_sched.chunk = r_sched.chunk;
- KA_TRACE( 20, ("__kmp_initialize_root: init root team %d arrived: join=%u, plain=%u\n",
- root_team->t.t_id, KMP_INIT_BARRIER_STATE, KMP_INIT_BARRIER_STATE ));
+ /* setup the root state structure */
+ __kmp_init_lock(&root->r.r_begin_lock);
+ root->r.r_begin = FALSE;
+ root->r.r_active = FALSE;
+ root->r.r_in_parallel = 0;
+ root->r.r_blocktime = __kmp_dflt_blocktime;
+ root->r.r_nested = __kmp_dflt_nested;
- /* setup the hot team for this task */
- /* allocate the hot team structure */
- KF_TRACE( 10, ( "__kmp_initialize_root: before hot_team\n" ) );
+ /* setup the root team for this task */
+ /* allocate the root team structure */
+ KF_TRACE(10, ("__kmp_initialize_root: before root_team\n"));
- hot_team =
- __kmp_allocate_team(
- root,
- 1, // new_nproc
- __kmp_dflt_team_nth_ub * 2, // max_nproc
+ root_team =
+ __kmp_allocate_team(root,
+ 1, // new_nproc
+ 1, // max_nproc
#if OMPT_SUPPORT
- 0, // root parallel id
+ 0, // root parallel id
#endif
#if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0],
+ __kmp_nested_proc_bind.bind_types[0],
#endif
- &r_icvs,
- 0 // argc
- USE_NESTED_HOT_ARG(NULL) // master thread is unknown
- );
- KF_TRACE( 10, ( "__kmp_initialize_root: after hot_team = %p\n", hot_team ) );
-
- root->r.r_hot_team = hot_team;
- root_team->t.t_control_stack_top = NULL;
-
- /* first-time initialization */
- hot_team->t.t_parent = root_team;
-
- /* initialize hot team */
- hot_team_max_nth = hot_team->t.t_max_nproc;
- for ( f = 0; f < hot_team_max_nth; ++ f ) {
- hot_team->t.t_threads[ f ] = NULL;
- }; // for
- hot_team->t.t_nproc = 1;
- // TODO???: hot_team->t.t_max_active_levels = __kmp_dflt_max_active_levels;
- hot_team->t.t_sched.r_sched_type = r_sched.r_sched_type;
- hot_team->t.t_sched.chunk = r_sched.chunk;
- hot_team->t.t_size_changed = 0;
-}
-
-#ifdef KMP_DEBUG
+ &r_icvs,
+ 0 // argc
+ USE_NESTED_HOT_ARG(NULL) // master thread is unknown
+ );
+#if USE_DEBUGGER
+ // Non-NULL value should be assigned to make the debugger display the root
+ // team.
+ TCW_SYNC_PTR(root_team->t.t_pkfn, (microtask_t)(~0));
+#endif
+
+ KF_TRACE(10, ("__kmp_initialize_root: after root_team = %p\n", root_team));
+
+ root->r.r_root_team = root_team;
+ root_team->t.t_control_stack_top = NULL;
+
+ /* initialize root team */
+ root_team->t.t_threads[0] = NULL;
+ root_team->t.t_nproc = 1;
+ root_team->t.t_serialized = 1;
+ // TODO???: root_team->t.t_max_active_levels = __kmp_dflt_max_active_levels;
+ root_team->t.t_sched.r_sched_type = r_sched.r_sched_type;
+ root_team->t.t_sched.chunk = r_sched.chunk;
+ KA_TRACE(
+ 20,
+ ("__kmp_initialize_root: init root team %d arrived: join=%u, plain=%u\n",
+ root_team->t.t_id, KMP_INIT_BARRIER_STATE, KMP_INIT_BARRIER_STATE));
+
+ /* setup the hot team for this task */
+ /* allocate the hot team structure */
+ KF_TRACE(10, ("__kmp_initialize_root: before hot_team\n"));
+
+ hot_team =
+ __kmp_allocate_team(root,
+ 1, // new_nproc
+ __kmp_dflt_team_nth_ub * 2, // max_nproc
+#if OMPT_SUPPORT
+ 0, // root parallel id
+#endif
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0],
+#endif
+ &r_icvs,
+ 0 // argc
+ USE_NESTED_HOT_ARG(NULL) // master thread is unknown
+ );
+ KF_TRACE(10, ("__kmp_initialize_root: after hot_team = %p\n", hot_team));
+
+ root->r.r_hot_team = hot_team;
+ root_team->t.t_control_stack_top = NULL;
+
+ /* first-time initialization */
+ hot_team->t.t_parent = root_team;
+
+ /* initialize hot team */
+ hot_team_max_nth = hot_team->t.t_max_nproc;
+ for (f = 0; f < hot_team_max_nth; ++f) {
+ hot_team->t.t_threads[f] = NULL;
+ }; // for
+ hot_team->t.t_nproc = 1;
+ // TODO???: hot_team->t.t_max_active_levels = __kmp_dflt_max_active_levels;
+ hot_team->t.t_sched.r_sched_type = r_sched.r_sched_type;
+ hot_team->t.t_sched.chunk = r_sched.chunk;
+ hot_team->t.t_size_changed = 0;
+}
+#ifdef KMP_DEBUG
typedef struct kmp_team_list_item {
- kmp_team_p const * entry;
- struct kmp_team_list_item * next;
+ kmp_team_p const *entry;
+ struct kmp_team_list_item *next;
} kmp_team_list_item_t;
-typedef kmp_team_list_item_t * kmp_team_list_t;
-
-
-static void
-__kmp_print_structure_team_accum( // Add team to list of teams.
- kmp_team_list_t list, // List of teams.
- kmp_team_p const * team // Team to add.
-) {
-
- // List must terminate with item where both entry and next are NULL.
- // Team is added to the list only once.
- // List is sorted in ascending order by team id.
- // Team id is *not* a key.
-
- kmp_team_list_t l;
-
- KMP_DEBUG_ASSERT( list != NULL );
- if ( team == NULL ) {
- return;
- }; // if
-
- __kmp_print_structure_team_accum( list, team->t.t_parent );
- __kmp_print_structure_team_accum( list, team->t.t_next_pool );
-
- // Search list for the team.
- l = list;
- while ( l->next != NULL && l->entry != team ) {
- l = l->next;
- }; // while
- if ( l->next != NULL ) {
- return; // Team has been added before, exit.
- }; // if
-
- // Team is not found. Search list again for insertion point.
- l = list;
- while ( l->next != NULL && l->entry->t.t_id <= team->t.t_id ) {
- l = l->next;
- }; // while
-
- // Insert team.
- {
- kmp_team_list_item_t * item =
- (kmp_team_list_item_t *)KMP_INTERNAL_MALLOC( sizeof( kmp_team_list_item_t ) );
- * item = * l;
- l->entry = team;
- l->next = item;
- }
-
-}
-
-static void
-__kmp_print_structure_team(
- char const * title,
- kmp_team_p const * team
-
-) {
- __kmp_printf( "%s", title );
- if ( team != NULL ) {
- __kmp_printf( "%2x %p\n", team->t.t_id, team );
- } else {
- __kmp_printf( " - (nil)\n" );
- }; // if
-}
-
-static void
-__kmp_print_structure_thread(
- char const * title,
- kmp_info_p const * thread
-
-) {
- __kmp_printf( "%s", title );
- if ( thread != NULL ) {
- __kmp_printf( "%2d %p\n", thread->th.th_info.ds.ds_gtid, thread );
- } else {
- __kmp_printf( " - (nil)\n" );
- }; // if
-}
-
-void
-__kmp_print_structure(
- void
-) {
-
- kmp_team_list_t list;
-
- // Initialize list of teams.
- list = (kmp_team_list_item_t *)KMP_INTERNAL_MALLOC( sizeof( kmp_team_list_item_t ) );
- list->entry = NULL;
- list->next = NULL;
-
- __kmp_printf( "\n------------------------------\nGlobal Thread Table\n------------------------------\n" );
- {
- int gtid;
- for ( gtid = 0; gtid < __kmp_threads_capacity; ++ gtid ) {
- __kmp_printf( "%2d", gtid );
- if ( __kmp_threads != NULL ) {
- __kmp_printf( " %p", __kmp_threads[ gtid ] );
- }; // if
- if ( __kmp_root != NULL ) {
- __kmp_printf( " %p", __kmp_root[ gtid ] );
- }; // if
- __kmp_printf( "\n" );
- }; // for gtid
- }
-
- // Print out __kmp_threads array.
- __kmp_printf( "\n------------------------------\nThreads\n------------------------------\n" );
- if ( __kmp_threads != NULL ) {
- int gtid;
- for ( gtid = 0; gtid < __kmp_threads_capacity; ++ gtid ) {
- kmp_info_t const * thread = __kmp_threads[ gtid ];
- if ( thread != NULL ) {
- __kmp_printf( "GTID %2d %p:\n", gtid, thread );
- __kmp_printf( " Our Root: %p\n", thread->th.th_root );
- __kmp_print_structure_team( " Our Team: ", thread->th.th_team );
- __kmp_print_structure_team( " Serial Team: ", thread->th.th_serial_team );
- __kmp_printf( " Threads: %2d\n", thread->th.th_team_nproc );
- __kmp_print_structure_thread( " Master: ", thread->th.th_team_master );
- __kmp_printf( " Serialized?: %2d\n", thread->th.th_team_serialized );
- __kmp_printf( " Set NProc: %2d\n", thread->th.th_set_nproc );
-#if OMP_40_ENABLED
- __kmp_printf( " Set Proc Bind: %2d\n", thread->th.th_set_proc_bind );
-#endif
- __kmp_print_structure_thread( " Next in pool: ", thread->th.th_next_pool );
- __kmp_printf( "\n" );
- __kmp_print_structure_team_accum( list, thread->th.th_team );
- __kmp_print_structure_team_accum( list, thread->th.th_serial_team );
- }; // if
- }; // for gtid
- } else {
- __kmp_printf( "Threads array is not allocated.\n" );
- }; // if
+typedef kmp_team_list_item_t *kmp_team_list_t;
- // Print out __kmp_root array.
- __kmp_printf( "\n------------------------------\nUbers\n------------------------------\n" );
- if ( __kmp_root != NULL ) {
- int gtid;
- for ( gtid = 0; gtid < __kmp_threads_capacity; ++ gtid ) {
- kmp_root_t const * root = __kmp_root[ gtid ];
- if ( root != NULL ) {
- __kmp_printf( "GTID %2d %p:\n", gtid, root );
- __kmp_print_structure_team( " Root Team: ", root->r.r_root_team );
- __kmp_print_structure_team( " Hot Team: ", root->r.r_hot_team );
- __kmp_print_structure_thread( " Uber Thread: ", root->r.r_uber_thread );
- __kmp_printf( " Active?: %2d\n", root->r.r_active );
- __kmp_printf( " Nested?: %2d\n", root->r.r_nested );
- __kmp_printf( " In Parallel: %2d\n", root->r.r_in_parallel );
- __kmp_printf( "\n" );
- __kmp_print_structure_team_accum( list, root->r.r_root_team );
- __kmp_print_structure_team_accum( list, root->r.r_hot_team );
- }; // if
- }; // for gtid
- } else {
- __kmp_printf( "Ubers array is not allocated.\n" );
- }; // if
-
- __kmp_printf( "\n------------------------------\nTeams\n------------------------------\n" );
- while ( list->next != NULL ) {
- kmp_team_p const * team = list->entry;
- int i;
- __kmp_printf( "Team %2x %p:\n", team->t.t_id, team );
- __kmp_print_structure_team( " Parent Team: ", team->t.t_parent );
- __kmp_printf( " Master TID: %2d\n", team->t.t_master_tid );
- __kmp_printf( " Max threads: %2d\n", team->t.t_max_nproc );
- __kmp_printf( " Levels of serial: %2d\n", team->t.t_serialized );
- __kmp_printf( " Number threads: %2d\n", team->t.t_nproc );
- for ( i = 0; i < team->t.t_nproc; ++ i ) {
- __kmp_printf( " Thread %2d: ", i );
- __kmp_print_structure_thread( "", team->t.t_threads[ i ] );
- }; // for i
- __kmp_print_structure_team( " Next in pool: ", team->t.t_next_pool );
- __kmp_printf( "\n" );
- list = list->next;
- }; // while
-
- // Print out __kmp_thread_pool and __kmp_team_pool.
- __kmp_printf( "\n------------------------------\nPools\n------------------------------\n" );
- __kmp_print_structure_thread( "Thread pool: ", (kmp_info_t *)__kmp_thread_pool );
- __kmp_print_structure_team( "Team pool: ", (kmp_team_t *)__kmp_team_pool );
- __kmp_printf( "\n" );
-
- // Free team list.
- while ( list != NULL ) {
- kmp_team_list_item_t * item = list;
- list = list->next;
- KMP_INTERNAL_FREE( item );
- }; // while
+static void __kmp_print_structure_team_accum( // Add team to list of teams.
+ kmp_team_list_t list, // List of teams.
+ kmp_team_p const *team // Team to add.
+ ) {
+ // List must terminate with item where both entry and next are NULL.
+ // Team is added to the list only once.
+ // List is sorted in ascending order by team id.
+ // Team id is *not* a key.
+
+ kmp_team_list_t l;
+
+ KMP_DEBUG_ASSERT(list != NULL);
+ if (team == NULL) {
+ return;
+ }; // if
+
+ __kmp_print_structure_team_accum(list, team->t.t_parent);
+ __kmp_print_structure_team_accum(list, team->t.t_next_pool);
+
+ // Search list for the team.
+ l = list;
+ while (l->next != NULL && l->entry != team) {
+ l = l->next;
+ }; // while
+ if (l->next != NULL) {
+ return; // Team has been added before, exit.
+ }; // if
+
+ // Team is not found. Search list again for insertion point.
+ l = list;
+ while (l->next != NULL && l->entry->t.t_id <= team->t.t_id) {
+ l = l->next;
+ }; // while
+
+ // Insert team.
+ {
+ kmp_team_list_item_t *item = (kmp_team_list_item_t *)KMP_INTERNAL_MALLOC(
+ sizeof(kmp_team_list_item_t));
+ *item = *l;
+ l->entry = team;
+ l->next = item;
+ }
+}
+
+static void __kmp_print_structure_team(char const *title, kmp_team_p const *team
+
+ ) {
+ __kmp_printf("%s", title);
+ if (team != NULL) {
+ __kmp_printf("%2x %p\n", team->t.t_id, team);
+ } else {
+ __kmp_printf(" - (nil)\n");
+ }; // if
+}
+
+static void __kmp_print_structure_thread(char const *title,
+ kmp_info_p const *thread) {
+ __kmp_printf("%s", title);
+ if (thread != NULL) {
+ __kmp_printf("%2d %p\n", thread->th.th_info.ds.ds_gtid, thread);
+ } else {
+ __kmp_printf(" - (nil)\n");
+ }; // if
+}
+
+void __kmp_print_structure(void) {
+
+ kmp_team_list_t list;
+
+ // Initialize list of teams.
+ list =
+ (kmp_team_list_item_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_team_list_item_t));
+ list->entry = NULL;
+ list->next = NULL;
+
+ __kmp_printf("\n------------------------------\nGlobal Thread "
+ "Table\n------------------------------\n");
+ {
+ int gtid;
+ for (gtid = 0; gtid < __kmp_threads_capacity; ++gtid) {
+ __kmp_printf("%2d", gtid);
+ if (__kmp_threads != NULL) {
+ __kmp_printf(" %p", __kmp_threads[gtid]);
+ }; // if
+ if (__kmp_root != NULL) {
+ __kmp_printf(" %p", __kmp_root[gtid]);
+ }; // if
+ __kmp_printf("\n");
+ }; // for gtid
+ }
+
+ // Print out __kmp_threads array.
+ __kmp_printf("\n------------------------------\nThreads\n--------------------"
+ "----------\n");
+ if (__kmp_threads != NULL) {
+ int gtid;
+ for (gtid = 0; gtid < __kmp_threads_capacity; ++gtid) {
+ kmp_info_t const *thread = __kmp_threads[gtid];
+ if (thread != NULL) {
+ __kmp_printf("GTID %2d %p:\n", gtid, thread);
+ __kmp_printf(" Our Root: %p\n", thread->th.th_root);
+ __kmp_print_structure_team(" Our Team: ", thread->th.th_team);
+ __kmp_print_structure_team(" Serial Team: ",
+ thread->th.th_serial_team);
+ __kmp_printf(" Threads: %2d\n", thread->th.th_team_nproc);
+ __kmp_print_structure_thread(" Master: ",
+ thread->th.th_team_master);
+ __kmp_printf(" Serialized?: %2d\n", thread->th.th_team_serialized);
+ __kmp_printf(" Set NProc: %2d\n", thread->th.th_set_nproc);
+#if OMP_40_ENABLED
+ __kmp_printf(" Set Proc Bind: %2d\n", thread->th.th_set_proc_bind);
+#endif
+ __kmp_print_structure_thread(" Next in pool: ",
+ thread->th.th_next_pool);
+ __kmp_printf("\n");
+ __kmp_print_structure_team_accum(list, thread->th.th_team);
+ __kmp_print_structure_team_accum(list, thread->th.th_serial_team);
+ }; // if
+ }; // for gtid
+ } else {
+ __kmp_printf("Threads array is not allocated.\n");
+ }; // if
+
+ // Print out __kmp_root array.
+ __kmp_printf("\n------------------------------\nUbers\n----------------------"
+ "--------\n");
+ if (__kmp_root != NULL) {
+ int gtid;
+ for (gtid = 0; gtid < __kmp_threads_capacity; ++gtid) {
+ kmp_root_t const *root = __kmp_root[gtid];
+ if (root != NULL) {
+ __kmp_printf("GTID %2d %p:\n", gtid, root);
+ __kmp_print_structure_team(" Root Team: ", root->r.r_root_team);
+ __kmp_print_structure_team(" Hot Team: ", root->r.r_hot_team);
+ __kmp_print_structure_thread(" Uber Thread: ",
+ root->r.r_uber_thread);
+ __kmp_printf(" Active?: %2d\n", root->r.r_active);
+ __kmp_printf(" Nested?: %2d\n", root->r.r_nested);
+ __kmp_printf(" In Parallel: %2d\n", root->r.r_in_parallel);
+ __kmp_printf("\n");
+ __kmp_print_structure_team_accum(list, root->r.r_root_team);
+ __kmp_print_structure_team_accum(list, root->r.r_hot_team);
+ }; // if
+ }; // for gtid
+ } else {
+ __kmp_printf("Ubers array is not allocated.\n");
+ }; // if
+
+ __kmp_printf("\n------------------------------\nTeams\n----------------------"
+ "--------\n");
+ while (list->next != NULL) {
+ kmp_team_p const *team = list->entry;
+ int i;
+ __kmp_printf("Team %2x %p:\n", team->t.t_id, team);
+ __kmp_print_structure_team(" Parent Team: ", team->t.t_parent);
+ __kmp_printf(" Master TID: %2d\n", team->t.t_master_tid);
+ __kmp_printf(" Max threads: %2d\n", team->t.t_max_nproc);
+ __kmp_printf(" Levels of serial: %2d\n", team->t.t_serialized);
+ __kmp_printf(" Number threads: %2d\n", team->t.t_nproc);
+ for (i = 0; i < team->t.t_nproc; ++i) {
+ __kmp_printf(" Thread %2d: ", i);
+ __kmp_print_structure_thread("", team->t.t_threads[i]);
+ }; // for i
+ __kmp_print_structure_team(" Next in pool: ", team->t.t_next_pool);
+ __kmp_printf("\n");
+ list = list->next;
+ }; // while
+
+ // Print out __kmp_thread_pool and __kmp_team_pool.
+ __kmp_printf("\n------------------------------\nPools\n----------------------"
+ "--------\n");
+ __kmp_print_structure_thread("Thread pool: ",
+ (kmp_info_t *)__kmp_thread_pool);
+ __kmp_print_structure_team("Team pool: ",
+ (kmp_team_t *)__kmp_team_pool);
+ __kmp_printf("\n");
+
+ // Free team list.
+ while (list != NULL) {
+ kmp_team_list_item_t *item = list;
+ list = list->next;
+ KMP_INTERNAL_FREE(item);
+ }; // while
}
#endif
-
//---------------------------------------------------------------------------
// Stuff for per-thread fast random number generator
// Table of primes
-
static const unsigned __kmp_primes[] = {
- 0x9e3779b1, 0xffe6cc59, 0x2109f6dd, 0x43977ab5,
- 0xba5703f5, 0xb495a877, 0xe1626741, 0x79695e6b,
- 0xbc98c09f, 0xd5bee2b3, 0x287488f9, 0x3af18231,
- 0x9677cd4d, 0xbe3a6929, 0xadc6a877, 0xdcf0674b,
- 0xbe4d6fe9, 0x5f15e201, 0x99afc3fd, 0xf3f16801,
- 0xe222cfff, 0x24ba5fdb, 0x0620452d, 0x79f149e3,
- 0xc8b93f49, 0x972702cd, 0xb07dd827, 0x6c97d5ed,
- 0x085a3d61, 0x46eb5ea7, 0x3d9910ed, 0x2e687b5b,
- 0x29609227, 0x6eb081f1, 0x0954c4e1, 0x9d114db9,
- 0x542acfa9, 0xb3e6bd7b, 0x0742d917, 0xe9f3ffa7,
- 0x54581edb, 0xf2480f45, 0x0bb9288f, 0xef1affc7,
- 0x85fa0ca7, 0x3ccc14db, 0xe6baf34b, 0x343377f7,
- 0x5ca19031, 0xe6d9293b, 0xf0a9f391, 0x5d2e980b,
- 0xfc411073, 0xc3749363, 0xb892d829, 0x3549366b,
- 0x629750ad, 0xb98294e5, 0x892d9483, 0xc235baf3,
- 0x3d2402a3, 0x6bdef3c9, 0xbec333cd, 0x40c9520f
-};
+ 0x9e3779b1, 0xffe6cc59, 0x2109f6dd, 0x43977ab5, 0xba5703f5, 0xb495a877,
+ 0xe1626741, 0x79695e6b, 0xbc98c09f, 0xd5bee2b3, 0x287488f9, 0x3af18231,
+ 0x9677cd4d, 0xbe3a6929, 0xadc6a877, 0xdcf0674b, 0xbe4d6fe9, 0x5f15e201,
+ 0x99afc3fd, 0xf3f16801, 0xe222cfff, 0x24ba5fdb, 0x0620452d, 0x79f149e3,
+ 0xc8b93f49, 0x972702cd, 0xb07dd827, 0x6c97d5ed, 0x085a3d61, 0x46eb5ea7,
+ 0x3d9910ed, 0x2e687b5b, 0x29609227, 0x6eb081f1, 0x0954c4e1, 0x9d114db9,
+ 0x542acfa9, 0xb3e6bd7b, 0x0742d917, 0xe9f3ffa7, 0x54581edb, 0xf2480f45,
+ 0x0bb9288f, 0xef1affc7, 0x85fa0ca7, 0x3ccc14db, 0xe6baf34b, 0x343377f7,
+ 0x5ca19031, 0xe6d9293b, 0xf0a9f391, 0x5d2e980b, 0xfc411073, 0xc3749363,
+ 0xb892d829, 0x3549366b, 0x629750ad, 0xb98294e5, 0x892d9483, 0xc235baf3,
+ 0x3d2402a3, 0x6bdef3c9, 0xbec333cd, 0x40c9520f};
//---------------------------------------------------------------------------
// __kmp_get_random: Get a random number using a linear congruential method.
-
-unsigned short
-__kmp_get_random( kmp_info_t * thread )
-{
+unsigned short __kmp_get_random(kmp_info_t *thread) {
unsigned x = thread->th.th_x;
- unsigned short r = x>>16;
+ unsigned short r = x >> 16;
- thread->th.th_x = x*thread->th.th_a+1;
+ thread->th.th_x = x * thread->th.th_a + 1;
KA_TRACE(30, ("__kmp_get_random: THREAD: %d, RETURN: %u\n",
- thread->th.th_info.ds.ds_tid, r) );
+ thread->th.th_info.ds.ds_tid, r));
return r;
}
//--------------------------------------------------------
// __kmp_init_random: Initialize a random number generator
-
-void
-__kmp_init_random( kmp_info_t * thread )
-{
+void __kmp_init_random(kmp_info_t *thread) {
unsigned seed = thread->th.th_info.ds.ds_tid;
- thread->th.th_a = __kmp_primes[seed%(sizeof(__kmp_primes)/sizeof(__kmp_primes[0]))];
- thread->th.th_x = (seed+1)*thread->th.th_a+1;
- KA_TRACE(30, ("__kmp_init_random: THREAD: %u; A: %u\n", seed, thread->th.th_a) );
+ thread->th.th_a =
+ __kmp_primes[seed % (sizeof(__kmp_primes) / sizeof(__kmp_primes[0]))];
+ thread->th.th_x = (seed + 1) * thread->th.th_a + 1;
+ KA_TRACE(30,
+ ("__kmp_init_random: THREAD: %u; A: %u\n", seed, thread->th.th_a));
}
-
#if KMP_OS_WINDOWS
-/* reclaim array entries for root threads that are already dead, returns number reclaimed */
-static int
-__kmp_reclaim_dead_roots(void) {
- int i, r = 0;
-
- for(i = 0; i < __kmp_threads_capacity; ++i) {
- if( KMP_UBER_GTID( i ) &&
- !__kmp_still_running((kmp_info_t *)TCR_SYNC_PTR(__kmp_threads[i])) &&
- !__kmp_root[i]->r.r_active ) { // AC: reclaim only roots died in non-active state
- r += __kmp_unregister_root_other_thread(i);
- }
+/* reclaim array entries for root threads that are already dead, returns number
+ * reclaimed */
+static int __kmp_reclaim_dead_roots(void) {
+ int i, r = 0;
+
+ for (i = 0; i < __kmp_threads_capacity; ++i) {
+ if (KMP_UBER_GTID(i) &&
+ !__kmp_still_running((kmp_info_t *)TCR_SYNC_PTR(__kmp_threads[i])) &&
+ !__kmp_root[i]
+ ->r.r_active) { // AC: reclaim only roots died in non-active state
+ r += __kmp_unregister_root_other_thread(i);
}
- return r;
+ }
+ return r;
}
#endif
-/*
- This function attempts to create free entries in __kmp_threads and __kmp_root, and returns the number of
- free entries generated.
+/* This function attempts to create free entries in __kmp_threads and
+ __kmp_root, and returns the number of free entries generated.
- For Windows* OS static library, the first mechanism used is to reclaim array entries for root threads that are
- already dead.
+ For Windows* OS static library, the first mechanism used is to reclaim array
+ entries for root threads that are already dead.
- On all platforms, expansion is attempted on the arrays __kmp_threads_ and __kmp_root, with appropriate
- update to __kmp_threads_capacity. Array capacity is increased by doubling with clipping to
- __kmp_tp_capacity, if threadprivate cache array has been created.
- Synchronization with __kmpc_threadprivate_cached is done using __kmp_tp_cached_lock.
-
- After any dead root reclamation, if the clipping value allows array expansion to result in the generation
- of a total of nWish free slots, the function does that expansion. If not, but the clipping value allows
- array expansion to result in the generation of a total of nNeed free slots, the function does that expansion.
- Otherwise, nothing is done beyond the possible initial root thread reclamation. However, if nNeed is zero,
- a best-effort attempt is made to fulfil nWish as far as possible, i.e. the function will attempt to create
+ On all platforms, expansion is attempted on the arrays __kmp_threads_ and
+ __kmp_root, with appropriate update to __kmp_threads_capacity. Array
+ capacity is increased by doubling with clipping to __kmp_tp_capacity, if
+ threadprivate cache array has been created. Synchronization with
+ __kmpc_threadprivate_cached is done using __kmp_tp_cached_lock.
+
+ After any dead root reclamation, if the clipping value allows array expansion
+ to result in the generation of a total of nWish free slots, the function does
+ that expansion. If not, but the clipping value allows array expansion to
+ result in the generation of a total of nNeed free slots, the function does
+ that expansion. Otherwise, nothing is done beyond the possible initial root
+ thread reclamation. However, if nNeed is zero, a best-effort attempt is made
+ to fulfil nWish as far as possible, i.e. the function will attempt to create
as many free slots as possible up to nWish.
- If any argument is negative, the behavior is undefined.
-*/
-static int
-__kmp_expand_threads(int nWish, int nNeed) {
- int added = 0;
- int old_tp_cached;
- int __kmp_actual_max_nth;
+ If any argument is negative, the behavior is undefined. */
+static int __kmp_expand_threads(int nWish, int nNeed) {
+ int added = 0;
+ int old_tp_cached;
+ int __kmp_actual_max_nth;
- if(nNeed > nWish) /* normalize the arguments */
- nWish = nNeed;
+ if (nNeed > nWish) /* normalize the arguments */
+ nWish = nNeed;
#if KMP_OS_WINDOWS && !defined KMP_DYNAMIC_LIB
-/* only for Windows static library */
- /* reclaim array entries for root threads that are already dead */
- added = __kmp_reclaim_dead_roots();
-
- if(nNeed) {
- nNeed -= added;
- if(nNeed < 0)
- nNeed = 0;
- }
- if(nWish) {
- nWish -= added;
- if(nWish < 0)
- nWish = 0;
- }
-#endif
- if(nWish <= 0)
- return added;
-
- while(1) {
- int nTarget;
- int minimumRequiredCapacity;
- int newCapacity;
- kmp_info_t **newThreads;
- kmp_root_t **newRoot;
-
- //
- // Note that __kmp_threads_capacity is not bounded by __kmp_max_nth.
- // If __kmp_max_nth is set to some value less than __kmp_sys_max_nth
- // by the user via OMP_THREAD_LIMIT, then __kmp_threads_capacity may
- // become > __kmp_max_nth in one of two ways:
- //
- // 1) The initialization thread (gtid = 0) exits. __kmp_threads[0]
- // may not be resused by another thread, so we may need to increase
- // __kmp_threads_capacity to __kmp_max_threads + 1.
- //
- // 2) New foreign root(s) are encountered. We always register new
- // foreign roots. This may cause a smaller # of threads to be
- // allocated at subsequent parallel regions, but the worker threads
- // hang around (and eventually go to sleep) and need slots in the
- // __kmp_threads[] array.
- //
- // Anyway, that is the reason for moving the check to see if
- // __kmp_max_threads was exceeded into __kmp_reseerve_threads()
- // instead of having it performed here. -BB
- //
- old_tp_cached = __kmp_tp_cached;
- __kmp_actual_max_nth = old_tp_cached ? __kmp_tp_capacity : __kmp_sys_max_nth;
- KMP_DEBUG_ASSERT(__kmp_actual_max_nth >= __kmp_threads_capacity);
-
- /* compute expansion headroom to check if we can expand and whether to aim for nWish or nNeed */
- nTarget = nWish;
- if(__kmp_actual_max_nth - __kmp_threads_capacity < nTarget) {
- /* can't fulfil nWish, so try nNeed */
- if(nNeed) {
- nTarget = nNeed;
- if(__kmp_actual_max_nth - __kmp_threads_capacity < nTarget) {
- /* possible expansion too small -- give up */
- break;
- }
- } else {
- /* best-effort */
- nTarget = __kmp_actual_max_nth - __kmp_threads_capacity;
- if(!nTarget) {
- /* can expand at all -- give up */
- break;
- }
- }
- }
- minimumRequiredCapacity = __kmp_threads_capacity + nTarget;
-
- newCapacity = __kmp_threads_capacity;
- do{
- newCapacity =
- newCapacity <= (__kmp_actual_max_nth >> 1) ?
- (newCapacity << 1) :
- __kmp_actual_max_nth;
- } while(newCapacity < minimumRequiredCapacity);
- newThreads = (kmp_info_t**) __kmp_allocate((sizeof(kmp_info_t*) + sizeof(kmp_root_t*)) * newCapacity + CACHE_LINE);
- newRoot = (kmp_root_t**) ((char*)newThreads + sizeof(kmp_info_t*) * newCapacity );
- KMP_MEMCPY(newThreads, __kmp_threads, __kmp_threads_capacity * sizeof(kmp_info_t*));
- KMP_MEMCPY(newRoot, __kmp_root, __kmp_threads_capacity * sizeof(kmp_root_t*));
- memset(newThreads + __kmp_threads_capacity, 0,
- (newCapacity - __kmp_threads_capacity) * sizeof(kmp_info_t*));
- memset(newRoot + __kmp_threads_capacity, 0,
- (newCapacity - __kmp_threads_capacity) * sizeof(kmp_root_t*));
-
- if(!old_tp_cached && __kmp_tp_cached && newCapacity > __kmp_tp_capacity) {
- /* __kmp_tp_cached has changed, i.e. __kmpc_threadprivate_cached has allocated a threadprivate cache
- while we were allocating the expanded array, and our new capacity is larger than the threadprivate
- cache capacity, so we should deallocate the expanded arrays and try again. This is the first check
- of a double-check pair.
- */
- __kmp_free(newThreads);
- continue; /* start over and try again */
- }
- __kmp_acquire_bootstrap_lock(&__kmp_tp_cached_lock);
- if(!old_tp_cached && __kmp_tp_cached && newCapacity > __kmp_tp_capacity) {
- /* Same check as above, but this time with the lock so we can be sure if we can succeed. */
- __kmp_release_bootstrap_lock(&__kmp_tp_cached_lock);
- __kmp_free(newThreads);
- continue; /* start over and try again */
- } else {
- /* success */
- // __kmp_free( __kmp_threads ); // ATT: It leads to crash. Need to be investigated.
- //
- *(kmp_info_t**volatile*)&__kmp_threads = newThreads;
- *(kmp_root_t**volatile*)&__kmp_root = newRoot;
- added += newCapacity - __kmp_threads_capacity;
- *(volatile int*)&__kmp_threads_capacity = newCapacity;
- __kmp_release_bootstrap_lock(&__kmp_tp_cached_lock);
- break; /* succeeded, so we can exit the loop */
- }
- }
+ /* only for Windows static library */
+ /* reclaim array entries for root threads that are already dead */
+ added = __kmp_reclaim_dead_roots();
+
+ if (nNeed) {
+ nNeed -= added;
+ if (nNeed < 0)
+ nNeed = 0;
+ }
+ if (nWish) {
+ nWish -= added;
+ if (nWish < 0)
+ nWish = 0;
+ }
+#endif
+ if (nWish <= 0)
return added;
-}
-/* register the current thread as a root thread and obtain our gtid */
-/* we must have the __kmp_initz_lock held at this point */
-/* Argument TRUE only if are the thread that calls from __kmp_do_serial_initialize() */
-int
-__kmp_register_root( int initial_thread )
-{
- kmp_info_t *root_thread;
- kmp_root_t *root;
- int gtid;
- int capacity;
- __kmp_acquire_bootstrap_lock( &__kmp_forkjoin_lock );
- KA_TRACE( 20, ("__kmp_register_root: entered\n"));
- KMP_MB();
-
-
- /*
- 2007-03-02:
-
- If initial thread did not invoke OpenMP RTL yet, and this thread is not an initial one,
- "__kmp_all_nth >= __kmp_threads_capacity" condition does not work as expected -- it may
- return false (that means there is at least one empty slot in __kmp_threads array), but it
- is possible the only free slot is #0, which is reserved for initial thread and so cannot be
- used for this one. Following code workarounds this bug.
-
- However, right solution seems to be not reserving slot #0 for initial thread because:
- (1) there is no magic in slot #0,
- (2) we cannot detect initial thread reliably (the first thread which does serial
- initialization may be not a real initial thread).
- */
- capacity = __kmp_threads_capacity;
- if ( ! initial_thread && TCR_PTR(__kmp_threads[0]) == NULL ) {
- -- capacity;
- }; // if
-
- /* see if there are too many threads */
- if ( __kmp_all_nth >= capacity && !__kmp_expand_threads( 1, 1 ) ) {
- if ( __kmp_tp_cached ) {
- __kmp_msg(
- kmp_ms_fatal,
- KMP_MSG( CantRegisterNewThread ),
- KMP_HNT( Set_ALL_THREADPRIVATE, __kmp_tp_capacity ),
- KMP_HNT( PossibleSystemLimitOnThreads ),
- __kmp_msg_null
- );
- }
- else {
- __kmp_msg(
- kmp_ms_fatal,
- KMP_MSG( CantRegisterNewThread ),
- KMP_HNT( SystemLimitOnThreads ),
- __kmp_msg_null
- );
- }
- }; // if
-
- /* find an available thread slot */
- /* Don't reassign the zero slot since we need that to only be used by initial
- thread */
- for( gtid=(initial_thread ? 0 : 1) ; TCR_PTR(__kmp_threads[gtid]) != NULL ; gtid++ )
- ;
- KA_TRACE( 1, ("__kmp_register_root: found slot in threads array: T#%d\n", gtid ));
- KMP_ASSERT( gtid < __kmp_threads_capacity );
-
- /* update global accounting */
- __kmp_all_nth ++;
- TCW_4(__kmp_nth, __kmp_nth + 1);
+ while (1) {
+ int nTarget;
+ int minimumRequiredCapacity;
+ int newCapacity;
+ kmp_info_t **newThreads;
+ kmp_root_t **newRoot;
+
+ // Note that __kmp_threads_capacity is not bounded by __kmp_max_nth. If
+ // __kmp_max_nth is set to some value less than __kmp_sys_max_nth by the
+ // user via OMP_THREAD_LIMIT, then __kmp_threads_capacity may become
+ // > __kmp_max_nth in one of two ways:
+ //
+ // 1) The initialization thread (gtid = 0) exits. __kmp_threads[0]
+ // may not be resused by another thread, so we may need to increase
+ // __kmp_threads_capacity to __kmp_max_threads + 1.
+ //
+ // 2) New foreign root(s) are encountered. We always register new foreign
+ // roots. This may cause a smaller # of threads to be allocated at
+ // subsequent parallel regions, but the worker threads hang around (and
+ // eventually go to sleep) and need slots in the __kmp_threads[] array.
+ //
+ // Anyway, that is the reason for moving the check to see if
+ // __kmp_max_threads was exceeded into __kmp_reseerve_threads()
+ // instead of having it performed here. -BB
+ old_tp_cached = __kmp_tp_cached;
+ __kmp_actual_max_nth =
+ old_tp_cached ? __kmp_tp_capacity : __kmp_sys_max_nth;
+ KMP_DEBUG_ASSERT(__kmp_actual_max_nth >= __kmp_threads_capacity);
+
+ /* compute expansion headroom to check if we can expand and whether to aim
+ for nWish or nNeed */
+ nTarget = nWish;
+ if (__kmp_actual_max_nth - __kmp_threads_capacity < nTarget) {
+ /* can't fulfil nWish, so try nNeed */
+ if (nNeed) {
+ nTarget = nNeed;
+ if (__kmp_actual_max_nth - __kmp_threads_capacity < nTarget) {
+ /* possible expansion too small -- give up */
+ break;
+ }
+ } else {
+ /* best-effort */
+ nTarget = __kmp_actual_max_nth - __kmp_threads_capacity;
+ if (!nTarget) {
+ /* can expand at all -- give up */
+ break;
+ }
+ }
+ }
+ minimumRequiredCapacity = __kmp_threads_capacity + nTarget;
+
+ newCapacity = __kmp_threads_capacity;
+ do {
+ newCapacity = newCapacity <= (__kmp_actual_max_nth >> 1)
+ ? (newCapacity << 1)
+ : __kmp_actual_max_nth;
+ } while (newCapacity < minimumRequiredCapacity);
+ newThreads = (kmp_info_t **)__kmp_allocate(
+ (sizeof(kmp_info_t *) + sizeof(kmp_root_t *)) * newCapacity +
+ CACHE_LINE);
+ newRoot = (kmp_root_t **)((char *)newThreads +
+ sizeof(kmp_info_t *) * newCapacity);
+ KMP_MEMCPY(newThreads, __kmp_threads,
+ __kmp_threads_capacity * sizeof(kmp_info_t *));
+ KMP_MEMCPY(newRoot, __kmp_root,
+ __kmp_threads_capacity * sizeof(kmp_root_t *));
+ memset(newThreads + __kmp_threads_capacity, 0,
+ (newCapacity - __kmp_threads_capacity) * sizeof(kmp_info_t *));
+ memset(newRoot + __kmp_threads_capacity, 0,
+ (newCapacity - __kmp_threads_capacity) * sizeof(kmp_root_t *));
+
+ if (!old_tp_cached && __kmp_tp_cached && newCapacity > __kmp_tp_capacity) {
+ /* __kmp_tp_cached has changed, i.e. __kmpc_threadprivate_cached has
+ allocated a threadprivate cache while we were allocating the expanded
+ array, and our new capacity is larger than the threadprivate cache
+ capacity, so we should deallocate the expanded arrays and try again.
+ This is the first check of a double-check pair. */
+ __kmp_free(newThreads);
+ continue; /* start over and try again */
+ }
+ __kmp_acquire_bootstrap_lock(&__kmp_tp_cached_lock);
+ if (!old_tp_cached && __kmp_tp_cached && newCapacity > __kmp_tp_capacity) {
+ /* Same check as above, but this time with the lock so we can be sure if
+ we can succeed. */
+ __kmp_release_bootstrap_lock(&__kmp_tp_cached_lock);
+ __kmp_free(newThreads);
+ continue; /* start over and try again */
+ } else {
+ /* success */
+ // __kmp_free( __kmp_threads ); // ATT: It leads to crash. Need to be
+ // investigated.
+ *(kmp_info_t * *volatile *)&__kmp_threads = newThreads;
+ *(kmp_root_t * *volatile *)&__kmp_root = newRoot;
+ added += newCapacity - __kmp_threads_capacity;
+ *(volatile int *)&__kmp_threads_capacity = newCapacity;
+ __kmp_release_bootstrap_lock(&__kmp_tp_cached_lock);
+ break; /* succeeded, so we can exit the loop */
+ }
+ }
+ return added;
+}
+
+/* Register the current thread as a root thread and obtain our gtid. We must
+ have the __kmp_initz_lock held at this point. Argument TRUE only if are the
+ thread that calls from __kmp_do_serial_initialize() */
+int __kmp_register_root(int initial_thread) {
+ kmp_info_t *root_thread;
+ kmp_root_t *root;
+ int gtid;
+ int capacity;
+ __kmp_acquire_bootstrap_lock(&__kmp_forkjoin_lock);
+ KA_TRACE(20, ("__kmp_register_root: entered\n"));
+ KMP_MB();
+
+ /* 2007-03-02:
+ If initial thread did not invoke OpenMP RTL yet, and this thread is not an
+ initial one, "__kmp_all_nth >= __kmp_threads_capacity" condition does not
+ work as expected -- it may return false (that means there is at least one
+ empty slot in __kmp_threads array), but it is possible the only free slot
+ is #0, which is reserved for initial thread and so cannot be used for this
+ one. Following code workarounds this bug.
+
+ However, right solution seems to be not reserving slot #0 for initial
+ thread because:
+ (1) there is no magic in slot #0,
+ (2) we cannot detect initial thread reliably (the first thread which does
+ serial initialization may be not a real initial thread).
+ */
+ capacity = __kmp_threads_capacity;
+ if (!initial_thread && TCR_PTR(__kmp_threads[0]) == NULL) {
+ --capacity;
+ }; // if
+
+ /* see if there are too many threads */
+ if (__kmp_all_nth >= capacity && !__kmp_expand_threads(1, 1)) {
+ if (__kmp_tp_cached) {
+ __kmp_msg(kmp_ms_fatal, KMP_MSG(CantRegisterNewThread),
+ KMP_HNT(Set_ALL_THREADPRIVATE, __kmp_tp_capacity),
+ KMP_HNT(PossibleSystemLimitOnThreads), __kmp_msg_null);
+ } else {
+ __kmp_msg(kmp_ms_fatal, KMP_MSG(CantRegisterNewThread),
+ KMP_HNT(SystemLimitOnThreads), __kmp_msg_null);
+ }
+ }; // if
- //
- // if __kmp_adjust_gtid_mode is set, then we use method #1 (sp search)
- // for low numbers of procs, and method #2 (keyed API call) for higher
- // numbers of procs.
- //
- if ( __kmp_adjust_gtid_mode ) {
- if ( __kmp_all_nth >= __kmp_tls_gtid_min ) {
- if ( TCR_4(__kmp_gtid_mode) != 2) {
- TCW_4(__kmp_gtid_mode, 2);
- }
- }
- else {
- if (TCR_4(__kmp_gtid_mode) != 1 ) {
- TCW_4(__kmp_gtid_mode, 1);
- }
- }
+ /* find an available thread slot */
+ /* Don't reassign the zero slot since we need that to only be used by initial
+ thread */
+ for (gtid = (initial_thread ? 0 : 1); TCR_PTR(__kmp_threads[gtid]) != NULL;
+ gtid++)
+ ;
+ KA_TRACE(1,
+ ("__kmp_register_root: found slot in threads array: T#%d\n", gtid));
+ KMP_ASSERT(gtid < __kmp_threads_capacity);
+
+ /* update global accounting */
+ __kmp_all_nth++;
+ TCW_4(__kmp_nth, __kmp_nth + 1);
+
+ // if __kmp_adjust_gtid_mode is set, then we use method #1 (sp search) for low
+ // numbers of procs, and method #2 (keyed API call) for higher numbers.
+ if (__kmp_adjust_gtid_mode) {
+ if (__kmp_all_nth >= __kmp_tls_gtid_min) {
+ if (TCR_4(__kmp_gtid_mode) != 2) {
+ TCW_4(__kmp_gtid_mode, 2);
+ }
+ } else {
+ if (TCR_4(__kmp_gtid_mode) != 1) {
+ TCW_4(__kmp_gtid_mode, 1);
+ }
}
+ }
#ifdef KMP_ADJUST_BLOCKTIME
- /* Adjust blocktime to zero if necessary */
- /* Middle initialization might not have occurred yet */
- if ( !__kmp_env_blocktime && ( __kmp_avail_proc > 0 ) ) {
- if ( __kmp_nth > __kmp_avail_proc ) {
- __kmp_zero_bt = TRUE;
- }
+ /* Adjust blocktime to zero if necessary */
+ /* Middle initialization might not have occurred yet */
+ if (!__kmp_env_blocktime && (__kmp_avail_proc > 0)) {
+ if (__kmp_nth > __kmp_avail_proc) {
+ __kmp_zero_bt = TRUE;
}
+ }
#endif /* KMP_ADJUST_BLOCKTIME */
- /* setup this new hierarchy */
- if( ! ( root = __kmp_root[gtid] )) {
- root = __kmp_root[gtid] = (kmp_root_t*) __kmp_allocate( sizeof(kmp_root_t) );
- KMP_DEBUG_ASSERT( ! root->r.r_root_team );
- }
+ /* setup this new hierarchy */
+ if (!(root = __kmp_root[gtid])) {
+ root = __kmp_root[gtid] = (kmp_root_t *)__kmp_allocate(sizeof(kmp_root_t));
+ KMP_DEBUG_ASSERT(!root->r.r_root_team);
+ }
#if KMP_STATS_ENABLED
- // Initialize stats as soon as possible (right after gtid assignment).
- __kmp_stats_thread_ptr = __kmp_stats_list->push_back(gtid);
- KMP_START_EXPLICIT_TIMER(OMP_worker_thread_life);
- KMP_SET_THREAD_STATE(SERIAL_REGION);
- KMP_INIT_PARTITIONED_TIMERS(OMP_serial);
-#endif
- __kmp_initialize_root( root );
-
- /* setup new root thread structure */
- if( root->r.r_uber_thread ) {
- root_thread = root->r.r_uber_thread;
- } else {
- root_thread = (kmp_info_t*) __kmp_allocate( sizeof(kmp_info_t) );
- if ( __kmp_storage_map ) {
- __kmp_print_thread_storage_map( root_thread, gtid );
- }
- root_thread->th.th_info .ds.ds_gtid = gtid;
- root_thread->th.th_root = root;
- if( __kmp_env_consistency_check ) {
- root_thread->th.th_cons = __kmp_allocate_cons_stack( gtid );
- }
- #if USE_FAST_MEMORY
- __kmp_initialize_fast_memory( root_thread );
- #endif /* USE_FAST_MEMORY */
-
- #if KMP_USE_BGET
- KMP_DEBUG_ASSERT( root_thread->th.th_local.bget_data == NULL );
- __kmp_initialize_bget( root_thread );
- #endif
- __kmp_init_random( root_thread ); // Initialize random number generator
- }
-
- /* setup the serial team held in reserve by the root thread */
- if( ! root_thread->th.th_serial_team ) {
- kmp_internal_control_t r_icvs = __kmp_get_global_icvs();
- KF_TRACE( 10, ( "__kmp_register_root: before serial_team\n" ) );
+ // Initialize stats as soon as possible (right after gtid assignment).
+ __kmp_stats_thread_ptr = __kmp_stats_list->push_back(gtid);
+ KMP_START_EXPLICIT_TIMER(OMP_worker_thread_life);
+ KMP_SET_THREAD_STATE(SERIAL_REGION);
+ KMP_INIT_PARTITIONED_TIMERS(OMP_serial);
+#endif
+ __kmp_initialize_root(root);
+
+ /* setup new root thread structure */
+ if (root->r.r_uber_thread) {
+ root_thread = root->r.r_uber_thread;
+ } else {
+ root_thread = (kmp_info_t *)__kmp_allocate(sizeof(kmp_info_t));
+ if (__kmp_storage_map) {
+ __kmp_print_thread_storage_map(root_thread, gtid);
+ }
+ root_thread->th.th_info.ds.ds_gtid = gtid;
+ root_thread->th.th_root = root;
+ if (__kmp_env_consistency_check) {
+ root_thread->th.th_cons = __kmp_allocate_cons_stack(gtid);
+ }
+#if USE_FAST_MEMORY
+ __kmp_initialize_fast_memory(root_thread);
+#endif /* USE_FAST_MEMORY */
+
+#if KMP_USE_BGET
+ KMP_DEBUG_ASSERT(root_thread->th.th_local.bget_data == NULL);
+ __kmp_initialize_bget(root_thread);
+#endif
+ __kmp_init_random(root_thread); // Initialize random number generator
+ }
- root_thread->th.th_serial_team = __kmp_allocate_team( root, 1, 1,
+ /* setup the serial team held in reserve by the root thread */
+ if (!root_thread->th.th_serial_team) {
+ kmp_internal_control_t r_icvs = __kmp_get_global_icvs();
+ KF_TRACE(10, ("__kmp_register_root: before serial_team\n"));
+ root_thread->th.th_serial_team =
+ __kmp_allocate_team(root, 1, 1,
#if OMPT_SUPPORT
- 0, // root parallel id
+ 0, // root parallel id
#endif
#if OMP_40_ENABLED
- proc_bind_default,
+ proc_bind_default,
#endif
- &r_icvs,
- 0 USE_NESTED_HOT_ARG(NULL) );
- }
- KMP_ASSERT( root_thread->th.th_serial_team );
- KF_TRACE( 10, ( "__kmp_register_root: after serial_team = %p\n",
- root_thread->th.th_serial_team ) );
+ &r_icvs, 0 USE_NESTED_HOT_ARG(NULL));
+ }
+ KMP_ASSERT(root_thread->th.th_serial_team);
+ KF_TRACE(10, ("__kmp_register_root: after serial_team = %p\n",
+ root_thread->th.th_serial_team));
- /* drop root_thread into place */
- TCW_SYNC_PTR(__kmp_threads[gtid], root_thread);
+ /* drop root_thread into place */
+ TCW_SYNC_PTR(__kmp_threads[gtid], root_thread);
- root->r.r_root_team->t.t_threads[0] = root_thread;
- root->r.r_hot_team ->t.t_threads[0] = root_thread;
- root_thread->th.th_serial_team->t.t_threads[0] = root_thread;
- root_thread->th.th_serial_team->t.t_serialized = 0; // AC: the team created in reserve, not for execution (it is unused for now).
- root->r.r_uber_thread = root_thread;
+ root->r.r_root_team->t.t_threads[0] = root_thread;
+ root->r.r_hot_team->t.t_threads[0] = root_thread;
+ root_thread->th.th_serial_team->t.t_threads[0] = root_thread;
+ // AC: the team created in reserve, not for execution (it is unused for now).
+ root_thread->th.th_serial_team->t.t_serialized = 0;
+ root->r.r_uber_thread = root_thread;
- /* initialize the thread, get it ready to go */
- __kmp_initialize_info( root_thread, root->r.r_root_team, 0, gtid );
- TCW_4(__kmp_init_gtid, TRUE);
+ /* initialize the thread, get it ready to go */
+ __kmp_initialize_info(root_thread, root->r.r_root_team, 0, gtid);
+ TCW_4(__kmp_init_gtid, TRUE);
- /* prepare the master thread for get_gtid() */
- __kmp_gtid_set_specific( gtid );
+ /* prepare the master thread for get_gtid() */
+ __kmp_gtid_set_specific(gtid);
#if USE_ITT_BUILD
- __kmp_itt_thread_name( gtid );
+ __kmp_itt_thread_name(gtid);
#endif /* USE_ITT_BUILD */
- #ifdef KMP_TDATA_GTID
- __kmp_gtid = gtid;
- #endif
- __kmp_create_worker( gtid, root_thread, __kmp_stksize );
- KMP_DEBUG_ASSERT( __kmp_gtid_get_specific() == gtid );
-
- KA_TRACE( 20, ("__kmp_register_root: T#%d init T#%d(%d:%d) arrived: join=%u, plain=%u\n",
- gtid, __kmp_gtid_from_tid( 0, root->r.r_hot_team ),
- root->r.r_hot_team->t.t_id, 0, KMP_INIT_BARRIER_STATE,
- KMP_INIT_BARRIER_STATE ) );
- { // Initialize barrier data.
- int b;
- for ( b = 0; b < bs_last_barrier; ++ b ) {
- root_thread->th.th_bar[ b ].bb.b_arrived = KMP_INIT_BARRIER_STATE;
+#ifdef KMP_TDATA_GTID
+ __kmp_gtid = gtid;
+#endif
+ __kmp_create_worker(gtid, root_thread, __kmp_stksize);
+ KMP_DEBUG_ASSERT(__kmp_gtid_get_specific() == gtid);
+
+ KA_TRACE(20, ("__kmp_register_root: T#%d init T#%d(%d:%d) arrived: join=%u, "
+ "plain=%u\n",
+ gtid, __kmp_gtid_from_tid(0, root->r.r_hot_team),
+ root->r.r_hot_team->t.t_id, 0, KMP_INIT_BARRIER_STATE,
+ KMP_INIT_BARRIER_STATE));
+ { // Initialize barrier data.
+ int b;
+ for (b = 0; b < bs_last_barrier; ++b) {
+ root_thread->th.th_bar[b].bb.b_arrived = KMP_INIT_BARRIER_STATE;
#if USE_DEBUGGER
- root_thread->th.th_bar[ b ].bb.b_worker_arrived = 0;
+ root_thread->th.th_bar[b].bb.b_worker_arrived = 0;
#endif
- }; // for
- }
- KMP_DEBUG_ASSERT( root->r.r_hot_team->t.t_bar[ bs_forkjoin_barrier ].b_arrived == KMP_INIT_BARRIER_STATE );
+ }; // for
+ }
+ KMP_DEBUG_ASSERT(root->r.r_hot_team->t.t_bar[bs_forkjoin_barrier].b_arrived ==
+ KMP_INIT_BARRIER_STATE);
#if KMP_AFFINITY_SUPPORTED
-# if OMP_40_ENABLED
- root_thread->th.th_current_place = KMP_PLACE_UNDEFINED;
- root_thread->th.th_new_place = KMP_PLACE_UNDEFINED;
- root_thread->th.th_first_place = KMP_PLACE_UNDEFINED;
- root_thread->th.th_last_place = KMP_PLACE_UNDEFINED;
-# endif
+#if OMP_40_ENABLED
+ root_thread->th.th_current_place = KMP_PLACE_UNDEFINED;
+ root_thread->th.th_new_place = KMP_PLACE_UNDEFINED;
+ root_thread->th.th_first_place = KMP_PLACE_UNDEFINED;
+ root_thread->th.th_last_place = KMP_PLACE_UNDEFINED;
+#endif
- if ( TCR_4(__kmp_init_middle) ) {
- __kmp_affinity_set_init_mask( gtid, TRUE );
- }
+ if (TCR_4(__kmp_init_middle)) {
+ __kmp_affinity_set_init_mask(gtid, TRUE);
+ }
#endif /* KMP_AFFINITY_SUPPORTED */
- __kmp_root_counter ++;
+ __kmp_root_counter++;
- KMP_MB();
- __kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
+ KMP_MB();
+ __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
- return gtid;
+ return gtid;
}
#if KMP_NESTED_HOT_TEAMS
-static int
-__kmp_free_hot_teams( kmp_root_t *root, kmp_info_t *thr, int level, const int max_level )
-{
- int i, n, nth;
- kmp_hot_team_ptr_t *hot_teams = thr->th.th_hot_teams;
- if( !hot_teams || !hot_teams[level].hot_team ) {
- return 0;
- }
- KMP_DEBUG_ASSERT( level < max_level );
- kmp_team_t *team = hot_teams[level].hot_team;
- nth = hot_teams[level].hot_team_nth;
- n = nth - 1; // master is not freed
- if( level < max_level - 1 ) {
- for( i = 0; i < nth; ++i ) {
- kmp_info_t *th = team->t.t_threads[i];
- n += __kmp_free_hot_teams( root, th, level + 1, max_level );
- if( i > 0 && th->th.th_hot_teams ) {
- __kmp_free( th->th.th_hot_teams );
- th->th.th_hot_teams = NULL;
- }
- }
- }
- __kmp_free_team( root, team, NULL );
- return n;
+static int __kmp_free_hot_teams(kmp_root_t *root, kmp_info_t *thr, int level,
+ const int max_level) {
+ int i, n, nth;
+ kmp_hot_team_ptr_t *hot_teams = thr->th.th_hot_teams;
+ if (!hot_teams || !hot_teams[level].hot_team) {
+ return 0;
+ }
+ KMP_DEBUG_ASSERT(level < max_level);
+ kmp_team_t *team = hot_teams[level].hot_team;
+ nth = hot_teams[level].hot_team_nth;
+ n = nth - 1; // master is not freed
+ if (level < max_level - 1) {
+ for (i = 0; i < nth; ++i) {
+ kmp_info_t *th = team->t.t_threads[i];
+ n += __kmp_free_hot_teams(root, th, level + 1, max_level);
+ if (i > 0 && th->th.th_hot_teams) {
+ __kmp_free(th->th.th_hot_teams);
+ th->th.th_hot_teams = NULL;
+ }
+ }
+ }
+ __kmp_free_team(root, team, NULL);
+ return n;
}
#endif
-/* Resets a root thread and clear its root and hot teams.
- Returns the number of __kmp_threads entries directly and indirectly freed.
-*/
-static int
-__kmp_reset_root(int gtid, kmp_root_t *root)
-{
- kmp_team_t * root_team = root->r.r_root_team;
- kmp_team_t * hot_team = root->r.r_hot_team;
- int n = hot_team->t.t_nproc;
- int i;
-
- KMP_DEBUG_ASSERT( ! root->r.r_active );
-
- root->r.r_root_team = NULL;
- root->r.r_hot_team = NULL;
- // __kmp_free_team() does not free hot teams, so we have to clear r_hot_team before call
- // to __kmp_free_team().
- __kmp_free_team( root, root_team USE_NESTED_HOT_ARG(NULL) );
+// Resets a root thread and clear its root and hot teams.
+// Returns the number of __kmp_threads entries directly and indirectly freed.
+static int __kmp_reset_root(int gtid, kmp_root_t *root) {
+ kmp_team_t *root_team = root->r.r_root_team;
+ kmp_team_t *hot_team = root->r.r_hot_team;
+ int n = hot_team->t.t_nproc;
+ int i;
+
+ KMP_DEBUG_ASSERT(!root->r.r_active);
+
+ root->r.r_root_team = NULL;
+ root->r.r_hot_team = NULL;
+ // __kmp_free_team() does not free hot teams, so we have to clear r_hot_team
+ // before call to __kmp_free_team().
+ __kmp_free_team(root, root_team USE_NESTED_HOT_ARG(NULL));
#if KMP_NESTED_HOT_TEAMS
- if( __kmp_hot_teams_max_level > 0 ) { // need to free nested hot teams and their threads if any
- for( i = 0; i < hot_team->t.t_nproc; ++i ) {
- kmp_info_t *th = hot_team->t.t_threads[i];
- if( __kmp_hot_teams_max_level > 1 ) {
- n += __kmp_free_hot_teams( root, th, 1, __kmp_hot_teams_max_level );
- }
- if( th->th.th_hot_teams ) {
- __kmp_free( th->th.th_hot_teams );
- th->th.th_hot_teams = NULL;
- }
- }
- }
-#endif
- __kmp_free_team( root, hot_team USE_NESTED_HOT_ARG(NULL) );
-
- //
- // Before we can reap the thread, we need to make certain that all
- // other threads in the teams that had this root as ancestor have stopped trying to steal tasks.
- //
- if ( __kmp_tasking_mode != tskm_immediate_exec ) {
- __kmp_wait_to_unref_task_teams();
- }
-
- #if KMP_OS_WINDOWS
- /* Close Handle of root duplicated in __kmp_create_worker (tr #62919) */
- KA_TRACE( 10, ("__kmp_reset_root: free handle, th = %p, handle = %" KMP_UINTPTR_SPEC "\n",
- (LPVOID)&(root->r.r_uber_thread->th),
- root->r.r_uber_thread->th.th_info.ds.ds_thread ) );
- __kmp_free_handle( root->r.r_uber_thread->th.th_info.ds.ds_thread );
- #endif /* KMP_OS_WINDOWS */
-
-#if OMPT_SUPPORT
- if (ompt_enabled &&
- ompt_callbacks.ompt_callback(ompt_event_thread_end)) {
- int gtid = __kmp_get_gtid();
- __ompt_thread_end(ompt_thread_initial, gtid);
- }
-#endif
-
- TCW_4(__kmp_nth, __kmp_nth - 1); // __kmp_reap_thread will decrement __kmp_all_nth.
- __kmp_reap_thread( root->r.r_uber_thread, 1 );
-
- // We canot put root thread to __kmp_thread_pool, so we have to reap it istead of freeing.
- root->r.r_uber_thread = NULL;
- /* mark root as no longer in use */
- root->r.r_begin = FALSE;
-
- return n;
-}
-
-void
-__kmp_unregister_root_current_thread( int gtid )
-{
- KA_TRACE( 1, ("__kmp_unregister_root_current_thread: enter T#%d\n", gtid ));
- /* this lock should be ok, since unregister_root_current_thread is never called during
- * and abort, only during a normal close. furthermore, if you have the
- * forkjoin lock, you should never try to get the initz lock */
-
- __kmp_acquire_bootstrap_lock( &__kmp_forkjoin_lock );
- if( TCR_4(__kmp_global.g.g_done) || !__kmp_init_serial ) {
- KC_TRACE( 10, ("__kmp_unregister_root_current_thread: already finished, exiting T#%d\n", gtid ));
- __kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
- return;
- }
- kmp_root_t *root = __kmp_root[gtid];
-
- KMP_DEBUG_ASSERT( __kmp_threads && __kmp_threads[gtid] );
- KMP_ASSERT( KMP_UBER_GTID( gtid ));
- KMP_ASSERT( root == __kmp_threads[gtid]->th.th_root );
- KMP_ASSERT( root->r.r_active == FALSE );
+ if (__kmp_hot_teams_max_level >
+ 0) { // need to free nested hot teams and their threads if any
+ for (i = 0; i < hot_team->t.t_nproc; ++i) {
+ kmp_info_t *th = hot_team->t.t_threads[i];
+ if (__kmp_hot_teams_max_level > 1) {
+ n += __kmp_free_hot_teams(root, th, 1, __kmp_hot_teams_max_level);
+ }
+ if (th->th.th_hot_teams) {
+ __kmp_free(th->th.th_hot_teams);
+ th->th.th_hot_teams = NULL;
+ }
+ }
+ }
+#endif
+ __kmp_free_team(root, hot_team USE_NESTED_HOT_ARG(NULL));
+
+ // Before we can reap the thread, we need to make certain that all other
+ // threads in the teams that had this root as ancestor have stopped trying to
+ // steal tasks.
+ if (__kmp_tasking_mode != tskm_immediate_exec) {
+ __kmp_wait_to_unref_task_teams();
+ }
+#if KMP_OS_WINDOWS
+ /* Close Handle of root duplicated in __kmp_create_worker (tr #62919) */
+ KA_TRACE(
+ 10, ("__kmp_reset_root: free handle, th = %p, handle = %" KMP_UINTPTR_SPEC
+ "\n",
+ (LPVOID) & (root->r.r_uber_thread->th),
+ root->r.r_uber_thread->th.th_info.ds.ds_thread));
+ __kmp_free_handle(root->r.r_uber_thread->th.th_info.ds.ds_thread);
+#endif /* KMP_OS_WINDOWS */
+
+#if OMPT_SUPPORT
+ if (ompt_enabled && ompt_callbacks.ompt_callback(ompt_event_thread_end)) {
+ int gtid = __kmp_get_gtid();
+ __ompt_thread_end(ompt_thread_initial, gtid);
+ }
+#endif
+
+ TCW_4(__kmp_nth,
+ __kmp_nth - 1); // __kmp_reap_thread will decrement __kmp_all_nth.
+ __kmp_reap_thread(root->r.r_uber_thread, 1);
+
+ // We canot put root thread to __kmp_thread_pool, so we have to reap it istead
+ // of freeing.
+ root->r.r_uber_thread = NULL;
+ /* mark root as no longer in use */
+ root->r.r_begin = FALSE;
+
+ return n;
+}
+
+void __kmp_unregister_root_current_thread(int gtid) {
+ KA_TRACE(1, ("__kmp_unregister_root_current_thread: enter T#%d\n", gtid));
+ /* this lock should be ok, since unregister_root_current_thread is never
+ called during an abort, only during a normal close. furthermore, if you
+ have the forkjoin lock, you should never try to get the initz lock */
+ __kmp_acquire_bootstrap_lock(&__kmp_forkjoin_lock);
+ if (TCR_4(__kmp_global.g.g_done) || !__kmp_init_serial) {
+ KC_TRACE(10, ("__kmp_unregister_root_current_thread: already finished, "
+ "exiting T#%d\n",
+ gtid));
+ __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
+ return;
+ }
+ kmp_root_t *root = __kmp_root[gtid];
+
+ KMP_DEBUG_ASSERT(__kmp_threads && __kmp_threads[gtid]);
+ KMP_ASSERT(KMP_UBER_GTID(gtid));
+ KMP_ASSERT(root == __kmp_threads[gtid]->th.th_root);
+ KMP_ASSERT(root->r.r_active == FALSE);
- KMP_MB();
+ KMP_MB();
#if OMP_45_ENABLED
- kmp_info_t * thread = __kmp_threads[gtid];
- kmp_team_t * team = thread->th.th_team;
- kmp_task_team_t * task_team = thread->th.th_task_team;
+ kmp_info_t *thread = __kmp_threads[gtid];
+ kmp_team_t *team = thread->th.th_team;
+ kmp_task_team_t *task_team = thread->th.th_task_team;
- // we need to wait for the proxy tasks before finishing the thread
- if ( task_team != NULL && task_team->tt.tt_found_proxy_tasks ) {
+ // we need to wait for the proxy tasks before finishing the thread
+ if (task_team != NULL && task_team->tt.tt_found_proxy_tasks) {
#if OMPT_SUPPORT
- // the runtime is shutting down so we won't report any events
- thread->th.ompt_thread_info.state = ompt_state_undefined;
+ // the runtime is shutting down so we won't report any events
+ thread->th.ompt_thread_info.state = ompt_state_undefined;
#endif
- __kmp_task_team_wait(thread, team USE_ITT_BUILD_ARG(NULL));
- }
+ __kmp_task_team_wait(thread, team USE_ITT_BUILD_ARG(NULL));
+ }
#endif
- __kmp_reset_root(gtid, root);
+ __kmp_reset_root(gtid, root);
- /* free up this thread slot */
- __kmp_gtid_set_specific( KMP_GTID_DNE );
+ /* free up this thread slot */
+ __kmp_gtid_set_specific(KMP_GTID_DNE);
#ifdef KMP_TDATA_GTID
- __kmp_gtid = KMP_GTID_DNE;
+ __kmp_gtid = KMP_GTID_DNE;
#endif
- KMP_MB();
- KC_TRACE( 10, ("__kmp_unregister_root_current_thread: T#%d unregistered\n", gtid ));
+ KMP_MB();
+ KC_TRACE(10,
+ ("__kmp_unregister_root_current_thread: T#%d unregistered\n", gtid));
- __kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
+ __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
}
#if KMP_OS_WINDOWS
/* __kmp_forkjoin_lock must be already held
- Unregisters a root thread that is not the current thread. Returns the number of
- __kmp_threads entries freed as a result.
- */
-static int
-__kmp_unregister_root_other_thread( int gtid )
-{
- kmp_root_t *root = __kmp_root[gtid];
- int r;
-
- KA_TRACE( 1, ("__kmp_unregister_root_other_thread: enter T#%d\n", gtid ));
- KMP_DEBUG_ASSERT( __kmp_threads && __kmp_threads[gtid] );
- KMP_ASSERT( KMP_UBER_GTID( gtid ));
- KMP_ASSERT( root == __kmp_threads[gtid]->th.th_root );
- KMP_ASSERT( root->r.r_active == FALSE );
-
- r = __kmp_reset_root(gtid, root);
- KC_TRACE( 10, ("__kmp_unregister_root_other_thread: T#%d unregistered\n", gtid ));
- return r;
+ Unregisters a root thread that is not the current thread. Returns the number
+ of __kmp_threads entries freed as a result. */
+static int __kmp_unregister_root_other_thread(int gtid) {
+ kmp_root_t *root = __kmp_root[gtid];
+ int r;
+
+ KA_TRACE(1, ("__kmp_unregister_root_other_thread: enter T#%d\n", gtid));
+ KMP_DEBUG_ASSERT(__kmp_threads && __kmp_threads[gtid]);
+ KMP_ASSERT(KMP_UBER_GTID(gtid));
+ KMP_ASSERT(root == __kmp_threads[gtid]->th.th_root);
+ KMP_ASSERT(root->r.r_active == FALSE);
+
+ r = __kmp_reset_root(gtid, root);
+ KC_TRACE(10,
+ ("__kmp_unregister_root_other_thread: T#%d unregistered\n", gtid));
+ return r;
}
#endif
#if KMP_DEBUG
void __kmp_task_info() {
- kmp_int32 gtid = __kmp_entry_gtid();
- kmp_int32 tid = __kmp_tid_from_gtid( gtid );
- kmp_info_t *this_thr = __kmp_threads[ gtid ];
- kmp_team_t *steam = this_thr->th.th_serial_team;
- kmp_team_t *team = this_thr->th.th_team;
-
- __kmp_printf( "__kmp_task_info: gtid=%d tid=%d t_thread=%p team=%p curtask=%p ptask=%p\n",
- gtid, tid, this_thr, team, this_thr->th.th_current_task, team->t.t_implicit_task_taskdata[tid].td_parent );
+ kmp_int32 gtid = __kmp_entry_gtid();
+ kmp_int32 tid = __kmp_tid_from_gtid(gtid);
+ kmp_info_t *this_thr = __kmp_threads[gtid];
+ kmp_team_t *steam = this_thr->th.th_serial_team;
+ kmp_team_t *team = this_thr->th.th_team;
+
+ __kmp_printf("__kmp_task_info: gtid=%d tid=%d t_thread=%p team=%p curtask=%p "
+ "ptask=%p\n",
+ gtid, tid, this_thr, team, this_thr->th.th_current_task,
+ team->t.t_implicit_task_taskdata[tid].td_parent);
}
#endif // KMP_DEBUG
-/* TODO optimize with one big memclr, take out what isn't needed,
- * split responsibility to workers as much as possible, and delay
- * initialization of features as much as possible */
-static void
-__kmp_initialize_info( kmp_info_t *this_thr, kmp_team_t *team, int tid, int gtid )
-{
- /* this_thr->th.th_info.ds.ds_gtid is setup in kmp_allocate_thread/create_worker
- * this_thr->th.th_serial_team is setup in __kmp_allocate_thread */
- kmp_info_t *master = team->t.t_threads[0];
- KMP_DEBUG_ASSERT( this_thr != NULL );
- KMP_DEBUG_ASSERT( this_thr->th.th_serial_team );
- KMP_DEBUG_ASSERT( team );
- KMP_DEBUG_ASSERT( team->t.t_threads );
- KMP_DEBUG_ASSERT( team->t.t_dispatch );
- KMP_DEBUG_ASSERT( master );
- KMP_DEBUG_ASSERT( master->th.th_root );
-
- KMP_MB();
-
- TCW_SYNC_PTR(this_thr->th.th_team, team);
-
- this_thr->th.th_info.ds.ds_tid = tid;
- this_thr->th.th_set_nproc = 0;
- if (__kmp_tasking_mode != tskm_immediate_exec)
- // When tasking is possible, threads are not safe to reap until they are
- // done tasking; this will be set when tasking code is exited in wait
- this_thr->th.th_reap_state = KMP_NOT_SAFE_TO_REAP;
- else // no tasking --> always safe to reap
- this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
+/* TODO optimize with one big memclr, take out what isn't needed, split
+ responsibility to workers as much as possible, and delay initialization of
+ features as much as possible */
+static void __kmp_initialize_info(kmp_info_t *this_thr, kmp_team_t *team,
+ int tid, int gtid) {
+ /* this_thr->th.th_info.ds.ds_gtid is setup in
+ kmp_allocate_thread/create_worker.
+ this_thr->th.th_serial_team is setup in __kmp_allocate_thread */
+ kmp_info_t *master = team->t.t_threads[0];
+ KMP_DEBUG_ASSERT(this_thr != NULL);
+ KMP_DEBUG_ASSERT(this_thr->th.th_serial_team);
+ KMP_DEBUG_ASSERT(team);
+ KMP_DEBUG_ASSERT(team->t.t_threads);
+ KMP_DEBUG_ASSERT(team->t.t_dispatch);
+ KMP_DEBUG_ASSERT(master);
+ KMP_DEBUG_ASSERT(master->th.th_root);
+
+ KMP_MB();
+
+ TCW_SYNC_PTR(this_thr->th.th_team, team);
+
+ this_thr->th.th_info.ds.ds_tid = tid;
+ this_thr->th.th_set_nproc = 0;
+ if (__kmp_tasking_mode != tskm_immediate_exec)
+ // When tasking is possible, threads are not safe to reap until they are
+ // done tasking; this will be set when tasking code is exited in wait
+ this_thr->th.th_reap_state = KMP_NOT_SAFE_TO_REAP;
+ else // no tasking --> always safe to reap
+ this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
#if OMP_40_ENABLED
- this_thr->th.th_set_proc_bind = proc_bind_default;
-# if KMP_AFFINITY_SUPPORTED
- this_thr->th.th_new_place = this_thr->th.th_current_place;
-# endif
+ this_thr->th.th_set_proc_bind = proc_bind_default;
+#if KMP_AFFINITY_SUPPORTED
+ this_thr->th.th_new_place = this_thr->th.th_current_place;
+#endif
#endif
- this_thr->th.th_root = master->th.th_root;
+ this_thr->th.th_root = master->th.th_root;
- /* setup the thread's cache of the team structure */
- this_thr->th.th_team_nproc = team->t.t_nproc;
- this_thr->th.th_team_master = master;
- this_thr->th.th_team_serialized = team->t.t_serialized;
- TCW_PTR(this_thr->th.th_sleep_loc, NULL);
+ /* setup the thread's cache of the team structure */
+ this_thr->th.th_team_nproc = team->t.t_nproc;
+ this_thr->th.th_team_master = master;
+ this_thr->th.th_team_serialized = team->t.t_serialized;
+ TCW_PTR(this_thr->th.th_sleep_loc, NULL);
- KMP_DEBUG_ASSERT( team->t.t_implicit_task_taskdata );
+ KMP_DEBUG_ASSERT(team->t.t_implicit_task_taskdata);
- KF_TRACE( 10, ( "__kmp_initialize_info1: T#%d:%d this_thread=%p curtask=%p\n",
- tid, gtid, this_thr, this_thr->th.th_current_task ) );
+ KF_TRACE(10, ("__kmp_initialize_info1: T#%d:%d this_thread=%p curtask=%p\n",
+ tid, gtid, this_thr, this_thr->th.th_current_task));
- __kmp_init_implicit_task( this_thr->th.th_team_master->th.th_ident, this_thr, team, tid, TRUE );
+ __kmp_init_implicit_task(this_thr->th.th_team_master->th.th_ident, this_thr,
+ team, tid, TRUE);
- KF_TRACE( 10, ( "__kmp_initialize_info2: T#%d:%d this_thread=%p curtask=%p\n",
- tid, gtid, this_thr, this_thr->th.th_current_task ) );
- // TODO: Initialize ICVs from parent; GEH - isn't that already done in __kmp_initialize_team()?
+ KF_TRACE(10, ("__kmp_initialize_info2: T#%d:%d this_thread=%p curtask=%p\n",
+ tid, gtid, this_thr, this_thr->th.th_current_task));
+ // TODO: Initialize ICVs from parent; GEH - isn't that already done in
+ // __kmp_initialize_team()?
- /* TODO no worksharing in speculative threads */
- this_thr->th.th_dispatch = &team->t.t_dispatch[ tid ];
+ /* TODO no worksharing in speculative threads */
+ this_thr->th.th_dispatch = &team->t.t_dispatch[tid];
- this_thr->th.th_local.this_construct = 0;
+ this_thr->th.th_local.this_construct = 0;
#ifdef BUILD_TV
- this_thr->th.th_local.tv_data = 0;
+ this_thr->th.th_local.tv_data = 0;
#endif
- if ( ! this_thr->th.th_pri_common ) {
- this_thr->th.th_pri_common = (struct common_table *) __kmp_allocate( sizeof(struct common_table) );
- if ( __kmp_storage_map ) {
- __kmp_print_storage_map_gtid(
- gtid, this_thr->th.th_pri_common, this_thr->th.th_pri_common + 1,
- sizeof( struct common_table ), "th_%d.th_pri_common\n", gtid
- );
- }; // if
- this_thr->th.th_pri_head = NULL;
+ if (!this_thr->th.th_pri_common) {
+ this_thr->th.th_pri_common =
+ (struct common_table *)__kmp_allocate(sizeof(struct common_table));
+ if (__kmp_storage_map) {
+ __kmp_print_storage_map_gtid(
+ gtid, this_thr->th.th_pri_common, this_thr->th.th_pri_common + 1,
+ sizeof(struct common_table), "th_%d.th_pri_common\n", gtid);
}; // if
+ this_thr->th.th_pri_head = NULL;
+ }; // if
- /* Initialize dynamic dispatch */
- {
- volatile kmp_disp_t *dispatch = this_thr->th.th_dispatch;
- /*
- * Use team max_nproc since this will never change for the team.
- */
- size_t disp_size = sizeof( dispatch_private_info_t ) *
- ( team->t.t_max_nproc == 1 ? 1 : __kmp_dispatch_num_buffers );
- KD_TRACE( 10, ("__kmp_initialize_info: T#%d max_nproc: %d\n", gtid, team->t.t_max_nproc ) );
- KMP_ASSERT( dispatch );
- KMP_DEBUG_ASSERT( team->t.t_dispatch );
- KMP_DEBUG_ASSERT( dispatch == &team->t.t_dispatch[ tid ] );
+ /* Initialize dynamic dispatch */
+ {
+ volatile kmp_disp_t *dispatch = this_thr->th.th_dispatch;
+ // Use team max_nproc since this will never change for the team.
+ size_t disp_size =
+ sizeof(dispatch_private_info_t) *
+ (team->t.t_max_nproc == 1 ? 1 : __kmp_dispatch_num_buffers);
+ KD_TRACE(10, ("__kmp_initialize_info: T#%d max_nproc: %d\n", gtid,
+ team->t.t_max_nproc));
+ KMP_ASSERT(dispatch);
+ KMP_DEBUG_ASSERT(team->t.t_dispatch);
+ KMP_DEBUG_ASSERT(dispatch == &team->t.t_dispatch[tid]);
- dispatch->th_disp_index = 0;
+ dispatch->th_disp_index = 0;
#if OMP_45_ENABLED
- dispatch->th_doacross_buf_idx = 0;
+ dispatch->th_doacross_buf_idx = 0;
#endif
- if( ! dispatch->th_disp_buffer ) {
- dispatch->th_disp_buffer = (dispatch_private_info_t *) __kmp_allocate( disp_size );
-
- if ( __kmp_storage_map ) {
- __kmp_print_storage_map_gtid( gtid, &dispatch->th_disp_buffer[ 0 ],
- &dispatch->th_disp_buffer[ team->t.t_max_nproc == 1 ? 1 : __kmp_dispatch_num_buffers ],
- disp_size, "th_%d.th_dispatch.th_disp_buffer "
- "(team_%d.t_dispatch[%d].th_disp_buffer)",
- gtid, team->t.t_id, gtid );
- }
- } else {
- memset( & dispatch->th_disp_buffer[0], '\0', disp_size );
- }
-
- dispatch->th_dispatch_pr_current = 0;
- dispatch->th_dispatch_sh_current = 0;
-
- dispatch->th_deo_fcn = 0; /* ORDERED */
- dispatch->th_dxo_fcn = 0; /* END ORDERED */
- }
-
- this_thr->th.th_next_pool = NULL;
-
- if (!this_thr->th.th_task_state_memo_stack) {
- size_t i;
- this_thr->th.th_task_state_memo_stack = (kmp_uint8 *) __kmp_allocate( 4*sizeof(kmp_uint8) );
- this_thr->th.th_task_state_top = 0;
- this_thr->th.th_task_state_stack_sz = 4;
- for (i=0; i<this_thr->th.th_task_state_stack_sz; ++i) // zero init the stack
- this_thr->th.th_task_state_memo_stack[i] = 0;
+ if (!dispatch->th_disp_buffer) {
+ dispatch->th_disp_buffer =
+ (dispatch_private_info_t *)__kmp_allocate(disp_size);
+
+ if (__kmp_storage_map) {
+ __kmp_print_storage_map_gtid(
+ gtid, &dispatch->th_disp_buffer[0],
+ &dispatch->th_disp_buffer[team->t.t_max_nproc == 1
+ ? 1
+ : __kmp_dispatch_num_buffers],
+ disp_size, "th_%d.th_dispatch.th_disp_buffer "
+ "(team_%d.t_dispatch[%d].th_disp_buffer)",
+ gtid, team->t.t_id, gtid);
+ }
+ } else {
+ memset(&dispatch->th_disp_buffer[0], '\0', disp_size);
}
- KMP_DEBUG_ASSERT( !this_thr->th.th_spin_here );
- KMP_DEBUG_ASSERT( this_thr->th.th_next_waiting == 0 );
+ dispatch->th_dispatch_pr_current = 0;
+ dispatch->th_dispatch_sh_current = 0;
- KMP_MB();
-}
+ dispatch->th_deo_fcn = 0; /* ORDERED */
+ dispatch->th_dxo_fcn = 0; /* END ORDERED */
+ }
+
+ this_thr->th.th_next_pool = NULL;
+
+ if (!this_thr->th.th_task_state_memo_stack) {
+ size_t i;
+ this_thr->th.th_task_state_memo_stack =
+ (kmp_uint8 *)__kmp_allocate(4 * sizeof(kmp_uint8));
+ this_thr->th.th_task_state_top = 0;
+ this_thr->th.th_task_state_stack_sz = 4;
+ for (i = 0; i < this_thr->th.th_task_state_stack_sz;
+ ++i) // zero init the stack
+ this_thr->th.th_task_state_memo_stack[i] = 0;
+ }
+
+ KMP_DEBUG_ASSERT(!this_thr->th.th_spin_here);
+ KMP_DEBUG_ASSERT(this_thr->th.th_next_waiting == 0);
+
+ KMP_MB();
+}
+
+/* allocate a new thread for the requesting team. this is only called from
+ within a forkjoin critical section. we will first try to get an available
+ thread from the thread pool. if none is available, we will fork a new one
+ assuming we are able to create a new one. this should be assured, as the
+ caller should check on this first. */
+kmp_info_t *__kmp_allocate_thread(kmp_root_t *root, kmp_team_t *team,
+ int new_tid) {
+ kmp_team_t *serial_team;
+ kmp_info_t *new_thr;
+ int new_gtid;
-
-/* allocate a new thread for the requesting team. this is only called from within a
- * forkjoin critical section. we will first try to get an available thread from the
- * thread pool. if none is available, we will fork a new one assuming we are able
- * to create a new one. this should be assured, as the caller should check on this
- * first.
- */
-kmp_info_t *
-__kmp_allocate_thread( kmp_root_t *root, kmp_team_t *team, int new_tid )
-{
- kmp_team_t *serial_team;
- kmp_info_t *new_thr;
- int new_gtid;
-
- KA_TRACE( 20, ("__kmp_allocate_thread: T#%d\n", __kmp_get_gtid() ));
- KMP_DEBUG_ASSERT( root && team );
+ KA_TRACE(20, ("__kmp_allocate_thread: T#%d\n", __kmp_get_gtid()));
+ KMP_DEBUG_ASSERT(root && team);
#if !KMP_NESTED_HOT_TEAMS
- KMP_DEBUG_ASSERT( KMP_MASTER_GTID( __kmp_get_gtid() ));
+ KMP_DEBUG_ASSERT(KMP_MASTER_GTID(__kmp_get_gtid()));
#endif
- KMP_MB();
+ KMP_MB();
- /* first, try to get one from the thread pool */
- if ( __kmp_thread_pool ) {
+ /* first, try to get one from the thread pool */
+ if (__kmp_thread_pool) {
- new_thr = (kmp_info_t*)__kmp_thread_pool;
- __kmp_thread_pool = (volatile kmp_info_t *) new_thr->th.th_next_pool;
- if ( new_thr == __kmp_thread_pool_insert_pt ) {
- __kmp_thread_pool_insert_pt = NULL;
- }
- TCW_4(new_thr->th.th_in_pool, FALSE);
- //
- // Don't touch th_active_in_pool or th_active.
- // The worker thread adjusts those flags as it sleeps/awakens.
- //
- __kmp_thread_pool_nth--;
-
- KA_TRACE( 20, ("__kmp_allocate_thread: T#%d using thread T#%d\n",
- __kmp_get_gtid(), new_thr->th.th_info.ds.ds_gtid ));
- KMP_ASSERT( ! new_thr->th.th_team );
- KMP_DEBUG_ASSERT( __kmp_nth < __kmp_threads_capacity );
- KMP_DEBUG_ASSERT( __kmp_thread_pool_nth >= 0 );
-
- /* setup the thread structure */
- __kmp_initialize_info( new_thr, team, new_tid, new_thr->th.th_info.ds.ds_gtid );
- KMP_DEBUG_ASSERT( new_thr->th.th_serial_team );
-
- TCW_4(__kmp_nth, __kmp_nth + 1);
-
- new_thr->th.th_task_state = 0;
- new_thr->th.th_task_state_top = 0;
- new_thr->th.th_task_state_stack_sz = 4;
+ new_thr = (kmp_info_t *)__kmp_thread_pool;
+ __kmp_thread_pool = (volatile kmp_info_t *)new_thr->th.th_next_pool;
+ if (new_thr == __kmp_thread_pool_insert_pt) {
+ __kmp_thread_pool_insert_pt = NULL;
+ }
+ TCW_4(new_thr->th.th_in_pool, FALSE);
+ // Don't touch th_active_in_pool or th_active.
+ // The worker thread adjusts those flags as it sleeps/awakens.
+ __kmp_thread_pool_nth--;
+
+ KA_TRACE(20, ("__kmp_allocate_thread: T#%d using thread T#%d\n",
+ __kmp_get_gtid(), new_thr->th.th_info.ds.ds_gtid));
+ KMP_ASSERT(!new_thr->th.th_team);
+ KMP_DEBUG_ASSERT(__kmp_nth < __kmp_threads_capacity);
+ KMP_DEBUG_ASSERT(__kmp_thread_pool_nth >= 0);
+
+ /* setup the thread structure */
+ __kmp_initialize_info(new_thr, team, new_tid,
+ new_thr->th.th_info.ds.ds_gtid);
+ KMP_DEBUG_ASSERT(new_thr->th.th_serial_team);
+
+ TCW_4(__kmp_nth, __kmp_nth + 1);
+
+ new_thr->th.th_task_state = 0;
+ new_thr->th.th_task_state_top = 0;
+ new_thr->th.th_task_state_stack_sz = 4;
#ifdef KMP_ADJUST_BLOCKTIME
- /* Adjust blocktime back to zero if necessar y */
- /* Middle initialization might not have occurred yet */
- if ( !__kmp_env_blocktime && ( __kmp_avail_proc > 0 ) ) {
- if ( __kmp_nth > __kmp_avail_proc ) {
- __kmp_zero_bt = TRUE;
- }
- }
+ /* Adjust blocktime back to zero if necessary */
+ /* Middle initialization might not have occurred yet */
+ if (!__kmp_env_blocktime && (__kmp_avail_proc > 0)) {
+ if (__kmp_nth > __kmp_avail_proc) {
+ __kmp_zero_bt = TRUE;
+ }
+ }
#endif /* KMP_ADJUST_BLOCKTIME */
#if KMP_DEBUG
- // If thread entered pool via __kmp_free_thread, wait_flag should != KMP_BARRIER_PARENT_FLAG.
- int b;
- kmp_balign_t * balign = new_thr->th.th_bar;
- for( b = 0; b < bs_last_barrier; ++ b )
- KMP_DEBUG_ASSERT(balign[b].bb.wait_flag != KMP_BARRIER_PARENT_FLAG);
+ // If thread entered pool via __kmp_free_thread, wait_flag should !=
+ // KMP_BARRIER_PARENT_FLAG.
+ int b;
+ kmp_balign_t *balign = new_thr->th.th_bar;
+ for (b = 0; b < bs_last_barrier; ++b)
+ KMP_DEBUG_ASSERT(balign[b].bb.wait_flag != KMP_BARRIER_PARENT_FLAG);
#endif
- KF_TRACE( 10, ("__kmp_allocate_thread: T#%d using thread %p T#%d\n",
- __kmp_get_gtid(), new_thr, new_thr->th.th_info.ds.ds_gtid ));
-
- KMP_MB();
- return new_thr;
- }
-
-
- /* no, well fork a new one */
- KMP_ASSERT( __kmp_nth == __kmp_all_nth );
- KMP_ASSERT( __kmp_all_nth < __kmp_threads_capacity );
-
-#if KMP_USE_MONITOR
- //
- // If this is the first worker thread the RTL is creating, then also
- // launch the monitor thread. We try to do this as early as possible.
- //
- if ( ! TCR_4( __kmp_init_monitor ) ) {
- __kmp_acquire_bootstrap_lock( & __kmp_monitor_lock );
- if ( ! TCR_4( __kmp_init_monitor ) ) {
- KF_TRACE( 10, ( "before __kmp_create_monitor\n" ) );
- TCW_4( __kmp_init_monitor, 1 );
- __kmp_create_monitor( & __kmp_monitor );
- KF_TRACE( 10, ( "after __kmp_create_monitor\n" ) );
- #if KMP_OS_WINDOWS
- // AC: wait until monitor has started. This is a fix for CQ232808.
- // The reason is that if the library is loaded/unloaded in a loop with small (parallel)
- // work in between, then there is high probability that monitor thread started after
- // the library shutdown. At shutdown it is too late to cope with the problem, because
- // when the master is in DllMain (process detach) the monitor has no chances to start
- // (it is blocked), and master has no means to inform the monitor that the library has gone,
- // because all the memory which the monitor can access is going to be released/reset.
- while ( TCR_4(__kmp_init_monitor) < 2 ) {
- KMP_YIELD( TRUE );
- }
- KF_TRACE( 10, ( "after monitor thread has started\n" ) );
- #endif
- }
- __kmp_release_bootstrap_lock( & __kmp_monitor_lock );
- }
-#endif
+ KF_TRACE(10, ("__kmp_allocate_thread: T#%d using thread %p T#%d\n",
+ __kmp_get_gtid(), new_thr, new_thr->th.th_info.ds.ds_gtid));
KMP_MB();
- for( new_gtid=1 ; TCR_PTR(__kmp_threads[new_gtid]) != NULL; ++new_gtid ) {
- KMP_DEBUG_ASSERT( new_gtid < __kmp_threads_capacity );
- }
-
- /* allocate space for it. */
- new_thr = (kmp_info_t*) __kmp_allocate( sizeof(kmp_info_t) );
-
- TCW_SYNC_PTR(__kmp_threads[new_gtid], new_thr);
-
- if ( __kmp_storage_map ) {
- __kmp_print_thread_storage_map( new_thr, new_gtid );
- }
+ return new_thr;
+ }
- /* add the reserve serialized team, initialized from the team's master thread */
- {
- kmp_internal_control_t r_icvs = __kmp_get_x_global_icvs( team );
- KF_TRACE( 10, ( "__kmp_allocate_thread: before th_serial/serial_team\n" ) );
+ /* no, well fork a new one */
+ KMP_ASSERT(__kmp_nth == __kmp_all_nth);
+ KMP_ASSERT(__kmp_all_nth < __kmp_threads_capacity);
+#if KMP_USE_MONITOR
+ // If this is the first worker thread the RTL is creating, then also
+ // launch the monitor thread. We try to do this as early as possible.
+ if (!TCR_4(__kmp_init_monitor)) {
+ __kmp_acquire_bootstrap_lock(&__kmp_monitor_lock);
+ if (!TCR_4(__kmp_init_monitor)) {
+ KF_TRACE(10, ("before __kmp_create_monitor\n"));
+ TCW_4(__kmp_init_monitor, 1);
+ __kmp_create_monitor(&__kmp_monitor);
+ KF_TRACE(10, ("after __kmp_create_monitor\n"));
+#if KMP_OS_WINDOWS
+ // AC: wait until monitor has started. This is a fix for CQ232808.
+ // The reason is that if the library is loaded/unloaded in a loop with
+ // small (parallel) work in between, then there is high probability that
+ // monitor thread started after the library shutdown. At shutdown it is
+ // too late to cope with the problem, because when the master is in
+ // DllMain (process detach) the monitor has no chances to start (it is
+ // blocked), and master has no means to inform the monitor that the
+ // library has gone, because all the memory which the monitor can access
+ // is going to be released/reset.
+ while (TCR_4(__kmp_init_monitor) < 2) {
+ KMP_YIELD(TRUE);
+ }
+ KF_TRACE(10, ("after monitor thread has started\n"));
+#endif
+ }
+ __kmp_release_bootstrap_lock(&__kmp_monitor_lock);
+ }
+#endif
+
+ KMP_MB();
+ for (new_gtid = 1; TCR_PTR(__kmp_threads[new_gtid]) != NULL; ++new_gtid) {
+ KMP_DEBUG_ASSERT(new_gtid < __kmp_threads_capacity);
+ }
+
+ /* allocate space for it. */
+ new_thr = (kmp_info_t *)__kmp_allocate(sizeof(kmp_info_t));
+
+ TCW_SYNC_PTR(__kmp_threads[new_gtid], new_thr);
+
+ if (__kmp_storage_map) {
+ __kmp_print_thread_storage_map(new_thr, new_gtid);
+ }
+
+ // add the reserve serialized team, initialized from the team's master thread
+ {
+ kmp_internal_control_t r_icvs = __kmp_get_x_global_icvs(team);
+ KF_TRACE(10, ("__kmp_allocate_thread: before th_serial/serial_team\n"));
new_thr->th.th_serial_team = serial_team =
- (kmp_team_t*) __kmp_allocate_team( root, 1, 1,
+ (kmp_team_t *)__kmp_allocate_team(root, 1, 1,
#if OMPT_SUPPORT
- 0, // root parallel id
+ 0, // root parallel id
#endif
#if OMP_40_ENABLED
- proc_bind_default,
+ proc_bind_default,
#endif
- &r_icvs,
- 0 USE_NESTED_HOT_ARG(NULL) );
- }
- KMP_ASSERT ( serial_team );
- serial_team->t.t_serialized = 0; // AC: the team created in reserve, not for execution (it is unused for now).
- serial_team->t.t_threads[0] = new_thr;
- KF_TRACE( 10, ( "__kmp_allocate_thread: after th_serial/serial_team : new_thr=%p\n",
- new_thr ) );
+ &r_icvs, 0 USE_NESTED_HOT_ARG(NULL));
+ }
+ KMP_ASSERT(serial_team);
+ serial_team->t.t_serialized = 0; // AC: the team created in reserve, not for
+ // execution (it is unused for now).
+ serial_team->t.t_threads[0] = new_thr;
+ KF_TRACE(10,
+ ("__kmp_allocate_thread: after th_serial/serial_team : new_thr=%p\n",
+ new_thr));
- /* setup the thread structures */
- __kmp_initialize_info( new_thr, team, new_tid, new_gtid );
+ /* setup the thread structures */
+ __kmp_initialize_info(new_thr, team, new_tid, new_gtid);
- #if USE_FAST_MEMORY
- __kmp_initialize_fast_memory( new_thr );
- #endif /* USE_FAST_MEMORY */
+#if USE_FAST_MEMORY
+ __kmp_initialize_fast_memory(new_thr);
+#endif /* USE_FAST_MEMORY */
- #if KMP_USE_BGET
- KMP_DEBUG_ASSERT( new_thr->th.th_local.bget_data == NULL );
- __kmp_initialize_bget( new_thr );
- #endif
+#if KMP_USE_BGET
+ KMP_DEBUG_ASSERT(new_thr->th.th_local.bget_data == NULL);
+ __kmp_initialize_bget(new_thr);
+#endif
- __kmp_init_random( new_thr ); // Initialize random number generator
+ __kmp_init_random(new_thr); // Initialize random number generator
- /* Initialize these only once when thread is grabbed for a team allocation */
- KA_TRACE( 20, ("__kmp_allocate_thread: T#%d init go fork=%u, plain=%u\n",
- __kmp_get_gtid(), KMP_INIT_BARRIER_STATE, KMP_INIT_BARRIER_STATE ));
+ /* Initialize these only once when thread is grabbed for a team allocation */
+ KA_TRACE(20,
+ ("__kmp_allocate_thread: T#%d init go fork=%u, plain=%u\n",
+ __kmp_get_gtid(), KMP_INIT_BARRIER_STATE, KMP_INIT_BARRIER_STATE));
- int b;
- kmp_balign_t * balign = new_thr->th.th_bar;
- for(b=0; b<bs_last_barrier; ++b) {
- balign[b].bb.b_go = KMP_INIT_BARRIER_STATE;
- balign[b].bb.team = NULL;
- balign[b].bb.wait_flag = KMP_BARRIER_NOT_WAITING;
- balign[b].bb.use_oncore_barrier = 0;
- }
+ int b;
+ kmp_balign_t *balign = new_thr->th.th_bar;
+ for (b = 0; b < bs_last_barrier; ++b) {
+ balign[b].bb.b_go = KMP_INIT_BARRIER_STATE;
+ balign[b].bb.team = NULL;
+ balign[b].bb.wait_flag = KMP_BARRIER_NOT_WAITING;
+ balign[b].bb.use_oncore_barrier = 0;
+ }
- new_thr->th.th_spin_here = FALSE;
- new_thr->th.th_next_waiting = 0;
+ new_thr->th.th_spin_here = FALSE;
+ new_thr->th.th_next_waiting = 0;
#if OMP_40_ENABLED && KMP_AFFINITY_SUPPORTED
- new_thr->th.th_current_place = KMP_PLACE_UNDEFINED;
- new_thr->th.th_new_place = KMP_PLACE_UNDEFINED;
- new_thr->th.th_first_place = KMP_PLACE_UNDEFINED;
- new_thr->th.th_last_place = KMP_PLACE_UNDEFINED;
-#endif
-
- TCW_4(new_thr->th.th_in_pool, FALSE);
- new_thr->th.th_active_in_pool = FALSE;
- TCW_4(new_thr->th.th_active, TRUE);
-
- /* adjust the global counters */
- __kmp_all_nth ++;
- __kmp_nth ++;
-
- //
- // if __kmp_adjust_gtid_mode is set, then we use method #1 (sp search)
- // for low numbers of procs, and method #2 (keyed API call) for higher
- // numbers of procs.
- //
- if ( __kmp_adjust_gtid_mode ) {
- if ( __kmp_all_nth >= __kmp_tls_gtid_min ) {
- if ( TCR_4(__kmp_gtid_mode) != 2) {
- TCW_4(__kmp_gtid_mode, 2);
- }
- }
- else {
- if (TCR_4(__kmp_gtid_mode) != 1 ) {
- TCW_4(__kmp_gtid_mode, 1);
- }
- }
+ new_thr->th.th_current_place = KMP_PLACE_UNDEFINED;
+ new_thr->th.th_new_place = KMP_PLACE_UNDEFINED;
+ new_thr->th.th_first_place = KMP_PLACE_UNDEFINED;
+ new_thr->th.th_last_place = KMP_PLACE_UNDEFINED;
+#endif
+
+ TCW_4(new_thr->th.th_in_pool, FALSE);
+ new_thr->th.th_active_in_pool = FALSE;
+ TCW_4(new_thr->th.th_active, TRUE);
+
+ /* adjust the global counters */
+ __kmp_all_nth++;
+ __kmp_nth++;
+
+ // if __kmp_adjust_gtid_mode is set, then we use method #1 (sp search) for low
+ // numbers of procs, and method #2 (keyed API call) for higher numbers.
+ if (__kmp_adjust_gtid_mode) {
+ if (__kmp_all_nth >= __kmp_tls_gtid_min) {
+ if (TCR_4(__kmp_gtid_mode) != 2) {
+ TCW_4(__kmp_gtid_mode, 2);
+ }
+ } else {
+ if (TCR_4(__kmp_gtid_mode) != 1) {
+ TCW_4(__kmp_gtid_mode, 1);
+ }
}
+ }
#ifdef KMP_ADJUST_BLOCKTIME
- /* Adjust blocktime back to zero if necessary */
- /* Middle initialization might not have occurred yet */
- if ( !__kmp_env_blocktime && ( __kmp_avail_proc > 0 ) ) {
- if ( __kmp_nth > __kmp_avail_proc ) {
- __kmp_zero_bt = TRUE;
- }
+ /* Adjust blocktime back to zero if necessary */
+ /* Middle initialization might not have occurred yet */
+ if (!__kmp_env_blocktime && (__kmp_avail_proc > 0)) {
+ if (__kmp_nth > __kmp_avail_proc) {
+ __kmp_zero_bt = TRUE;
}
+ }
#endif /* KMP_ADJUST_BLOCKTIME */
- /* actually fork it and create the new worker thread */
- KF_TRACE( 10, ("__kmp_allocate_thread: before __kmp_create_worker: %p\n", new_thr ));
- __kmp_create_worker( new_gtid, new_thr, __kmp_stksize );
- KF_TRACE( 10, ("__kmp_allocate_thread: after __kmp_create_worker: %p\n", new_thr ));
-
- KA_TRACE( 20, ("__kmp_allocate_thread: T#%d forked T#%d\n", __kmp_get_gtid(), new_gtid ));
- KMP_MB();
- return new_thr;
-}
-
-/*
- * reinitialize team for reuse.
- *
- * The hot team code calls this case at every fork barrier, so EPCC barrier
- * test are extremely sensitive to changes in it, esp. writes to the team
- * struct, which cause a cache invalidation in all threads.
- *
- * IF YOU TOUCH THIS ROUTINE, RUN EPCC C SYNCBENCH ON A BIG-IRON MACHINE!!!
- */
-static void
-__kmp_reinitialize_team( kmp_team_t *team, kmp_internal_control_t *new_icvs, ident_t *loc ) {
- KF_TRACE( 10, ( "__kmp_reinitialize_team: enter this_thread=%p team=%p\n",
- team->t.t_threads[0], team ) );
- KMP_DEBUG_ASSERT( team && new_icvs);
- KMP_DEBUG_ASSERT( ( ! TCR_4(__kmp_init_parallel) ) || new_icvs->nproc );
- KMP_CHECK_UPDATE(team->t.t_ident, loc);
-
- KMP_CHECK_UPDATE(team->t.t_id, KMP_GEN_TEAM_ID());
-
- // Copy ICVs to the master thread's implicit taskdata
- __kmp_init_implicit_task( loc, team->t.t_threads[0], team, 0, FALSE );
- copy_icvs(&team->t.t_implicit_task_taskdata[0].td_icvs, new_icvs);
-
- KF_TRACE( 10, ( "__kmp_reinitialize_team: exit this_thread=%p team=%p\n",
- team->t.t_threads[0], team ) );
-}
-
-
-/* initialize the team data structure
- * this assumes the t_threads and t_max_nproc are already set
- * also, we don't touch the arguments */
-static void
-__kmp_initialize_team(
- kmp_team_t * team,
- int new_nproc,
- kmp_internal_control_t * new_icvs,
- ident_t * loc
-) {
- KF_TRACE( 10, ( "__kmp_initialize_team: enter: team=%p\n", team ) );
-
- /* verify */
- KMP_DEBUG_ASSERT( team );
- KMP_DEBUG_ASSERT( new_nproc <= team->t.t_max_nproc );
- KMP_DEBUG_ASSERT( team->t.t_threads );
- KMP_MB();
-
- team->t.t_master_tid = 0; /* not needed */
- /* team->t.t_master_bar; not needed */
- team->t.t_serialized = new_nproc > 1 ? 0 : 1;
- team->t.t_nproc = new_nproc;
-
- /* team->t.t_parent = NULL; TODO not needed & would mess up hot team */
- team->t.t_next_pool = NULL;
- /* memset( team->t.t_threads, 0, sizeof(kmp_info_t*)*new_nproc ); would mess up hot team */
+ /* actually fork it and create the new worker thread */
+ KF_TRACE(
+ 10, ("__kmp_allocate_thread: before __kmp_create_worker: %p\n", new_thr));
+ __kmp_create_worker(new_gtid, new_thr, __kmp_stksize);
+ KF_TRACE(10,
+ ("__kmp_allocate_thread: after __kmp_create_worker: %p\n", new_thr));
+
+ KA_TRACE(20, ("__kmp_allocate_thread: T#%d forked T#%d\n", __kmp_get_gtid(),
+ new_gtid));
+ KMP_MB();
+ return new_thr;
+}
+
+/* Reinitialize team for reuse.
+ The hot team code calls this case at every fork barrier, so EPCC barrier
+ test are extremely sensitive to changes in it, esp. writes to the team
+ struct, which cause a cache invalidation in all threads.
+ IF YOU TOUCH THIS ROUTINE, RUN EPCC C SYNCBENCH ON A BIG-IRON MACHINE!!! */
+static void __kmp_reinitialize_team(kmp_team_t *team,
+ kmp_internal_control_t *new_icvs,
+ ident_t *loc) {
+ KF_TRACE(10, ("__kmp_reinitialize_team: enter this_thread=%p team=%p\n",
+ team->t.t_threads[0], team));
+ KMP_DEBUG_ASSERT(team && new_icvs);
+ KMP_DEBUG_ASSERT((!TCR_4(__kmp_init_parallel)) || new_icvs->nproc);
+ KMP_CHECK_UPDATE(team->t.t_ident, loc);
+
+ KMP_CHECK_UPDATE(team->t.t_id, KMP_GEN_TEAM_ID());
+
+ // Copy ICVs to the master thread's implicit taskdata
+ __kmp_init_implicit_task(loc, team->t.t_threads[0], team, 0, FALSE);
+ copy_icvs(&team->t.t_implicit_task_taskdata[0].td_icvs, new_icvs);
+
+ KF_TRACE(10, ("__kmp_reinitialize_team: exit this_thread=%p team=%p\n",
+ team->t.t_threads[0], team));
+}
+
+/* Initialize the team data structure.
+ This assumes the t_threads and t_max_nproc are already set.
+ Also, we don't touch the arguments */
+static void __kmp_initialize_team(kmp_team_t *team, int new_nproc,
+ kmp_internal_control_t *new_icvs,
+ ident_t *loc) {
+ KF_TRACE(10, ("__kmp_initialize_team: enter: team=%p\n", team));
+
+ /* verify */
+ KMP_DEBUG_ASSERT(team);
+ KMP_DEBUG_ASSERT(new_nproc <= team->t.t_max_nproc);
+ KMP_DEBUG_ASSERT(team->t.t_threads);
+ KMP_MB();
+
+ team->t.t_master_tid = 0; /* not needed */
+ /* team->t.t_master_bar; not needed */
+ team->t.t_serialized = new_nproc > 1 ? 0 : 1;
+ team->t.t_nproc = new_nproc;
+
+ /* team->t.t_parent = NULL; TODO not needed & would mess up hot team */
+ team->t.t_next_pool = NULL;
+ /* memset( team->t.t_threads, 0, sizeof(kmp_info_t*)*new_nproc ); would mess
+ * up hot team */
- TCW_SYNC_PTR(team->t.t_pkfn, NULL); /* not needed */
- team->t.t_invoke = NULL; /* not needed */
+ TCW_SYNC_PTR(team->t.t_pkfn, NULL); /* not needed */
+ team->t.t_invoke = NULL; /* not needed */
- // TODO???: team->t.t_max_active_levels = new_max_active_levels;
- team->t.t_sched = new_icvs->sched;
+ // TODO???: team->t.t_max_active_levels = new_max_active_levels;
+ team->t.t_sched = new_icvs->sched;
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
- team->t.t_fp_control_saved = FALSE; /* not needed */
- team->t.t_x87_fpu_control_word = 0; /* not needed */
- team->t.t_mxcsr = 0; /* not needed */
+ team->t.t_fp_control_saved = FALSE; /* not needed */
+ team->t.t_x87_fpu_control_word = 0; /* not needed */
+ team->t.t_mxcsr = 0; /* not needed */
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
- team->t.t_construct = 0;
- __kmp_init_lock( & team->t.t_single_lock );
+ team->t.t_construct = 0;
+ __kmp_init_lock(&team->t.t_single_lock);
- team->t.t_ordered .dt.t_value = 0;
- team->t.t_master_active = FALSE;
+ team->t.t_ordered.dt.t_value = 0;
+ team->t.t_master_active = FALSE;
- memset( & team->t.t_taskq, '\0', sizeof( kmp_taskq_t ));
+ memset(&team->t.t_taskq, '\0', sizeof(kmp_taskq_t));
#ifdef KMP_DEBUG
- team->t.t_copypriv_data = NULL; /* not necessary, but nice for debugging */
+ team->t.t_copypriv_data = NULL; /* not necessary, but nice for debugging */
#endif
- team->t.t_copyin_counter = 0; /* for barrier-free copyin implementation */
+ team->t.t_copyin_counter = 0; /* for barrier-free copyin implementation */
- team->t.t_control_stack_top = NULL;
+ team->t.t_control_stack_top = NULL;
- __kmp_reinitialize_team( team, new_icvs, loc );
+ __kmp_reinitialize_team(team, new_icvs, loc);
- KMP_MB();
- KF_TRACE( 10, ( "__kmp_initialize_team: exit: team=%p\n", team ) );
+ KMP_MB();
+ KF_TRACE(10, ("__kmp_initialize_team: exit: team=%p\n", team));
}
#if KMP_OS_LINUX && KMP_AFFINITY_SUPPORTED
/* Sets full mask for thread and returns old mask, no changes to structures. */
static void
-__kmp_set_thread_affinity_mask_full_tmp( kmp_affin_mask_t *old_mask )
-{
- if ( KMP_AFFINITY_CAPABLE() ) {
- int status;
- if ( old_mask != NULL ) {
- status = __kmp_get_system_affinity( old_mask, TRUE );
- int error = errno;
- if ( status != 0 ) {
- __kmp_msg(
- kmp_ms_fatal,
- KMP_MSG( ChangeThreadAffMaskError ),
- KMP_ERR( error ),
- __kmp_msg_null
- );
- }
- }
- __kmp_set_system_affinity( __kmp_affin_fullMask, TRUE );
+__kmp_set_thread_affinity_mask_full_tmp(kmp_affin_mask_t *old_mask) {
+ if (KMP_AFFINITY_CAPABLE()) {
+ int status;
+ if (old_mask != NULL) {
+ status = __kmp_get_system_affinity(old_mask, TRUE);
+ int error = errno;
+ if (status != 0) {
+ __kmp_msg(kmp_ms_fatal, KMP_MSG(ChangeThreadAffMaskError),
+ KMP_ERR(error), __kmp_msg_null);
+ }
}
+ __kmp_set_system_affinity(__kmp_affin_fullMask, TRUE);
+ }
}
#endif
#if OMP_40_ENABLED && KMP_AFFINITY_SUPPORTED
-//
// __kmp_partition_places() is the heart of the OpenMP 4.0 affinity mechanism.
// It calculats the worker + master thread's partition based upon the parent
// thread's partition, and binds each worker to a thread in their partition.
// The master thread's partition should already include its current binding.
-//
-static void
-__kmp_partition_places( kmp_team_t *team, int update_master_only )
-{
- //
- // Copy the master thread's place partion to the team struct
- //
- kmp_info_t *master_th = team->t.t_threads[0];
- KMP_DEBUG_ASSERT( master_th != NULL );
- kmp_proc_bind_t proc_bind = team->t.t_proc_bind;
- int first_place = master_th->th.th_first_place;
- int last_place = master_th->th.th_last_place;
- int masters_place = master_th->th.th_current_place;
- team->t.t_first_place = first_place;
- team->t.t_last_place = last_place;
-
- KA_TRACE( 20, ("__kmp_partition_places: enter: proc_bind = %d T#%d(%d:0) bound to place %d partition = [%d,%d]\n",
- proc_bind, __kmp_gtid_from_thread( team->t.t_threads[0] ), team->t.t_id,
- masters_place, first_place, last_place ) );
-
- switch ( proc_bind ) {
-
- case proc_bind_default:
- //
- // serial teams might have the proc_bind policy set to
- // proc_bind_default. It doesn't matter, as we don't
- // rebind the master thread for any proc_bind policy.
- //
- KMP_DEBUG_ASSERT( team->t.t_nproc == 1 );
- break;
+static void __kmp_partition_places(kmp_team_t *team, int update_master_only) {
+ // Copy the master thread's place partion to the team struct
+ kmp_info_t *master_th = team->t.t_threads[0];
+ KMP_DEBUG_ASSERT(master_th != NULL);
+ kmp_proc_bind_t proc_bind = team->t.t_proc_bind;
+ int first_place = master_th->th.th_first_place;
+ int last_place = master_th->th.th_last_place;
+ int masters_place = master_th->th.th_current_place;
+ team->t.t_first_place = first_place;
+ team->t.t_last_place = last_place;
+
+ KA_TRACE(20, ("__kmp_partition_places: enter: proc_bind = %d T#%d(%d:0) "
+ "bound to place %d partition = [%d,%d]\n",
+ proc_bind, __kmp_gtid_from_thread(team->t.t_threads[0]),
+ team->t.t_id, masters_place, first_place, last_place));
+
+ switch (proc_bind) {
+
+ case proc_bind_default:
+ // serial teams might have the proc_bind policy set to proc_bind_default. It
+ // doesn't matter, as we don't rebind master thread for any proc_bind policy
+ KMP_DEBUG_ASSERT(team->t.t_nproc == 1);
+ break;
- case proc_bind_master:
- {
- int f;
- int n_th = team->t.t_nproc;
- for ( f = 1; f < n_th; f++ ) {
- kmp_info_t *th = team->t.t_threads[f];
- KMP_DEBUG_ASSERT( th != NULL );
- th->th.th_first_place = first_place;
- th->th.th_last_place = last_place;
- th->th.th_new_place = masters_place;
-
- KA_TRACE( 100, ("__kmp_partition_places: master: T#%d(%d:%d) place %d partition = [%d,%d]\n",
- __kmp_gtid_from_thread( team->t.t_threads[f] ),
- team->t.t_id, f, masters_place, first_place, last_place ) );
- }
- }
- break;
+ case proc_bind_master: {
+ int f;
+ int n_th = team->t.t_nproc;
+ for (f = 1; f < n_th; f++) {
+ kmp_info_t *th = team->t.t_threads[f];
+ KMP_DEBUG_ASSERT(th != NULL);
+ th->th.th_first_place = first_place;
+ th->th.th_last_place = last_place;
+ th->th.th_new_place = masters_place;
+
+ KA_TRACE(100, ("__kmp_partition_places: master: T#%d(%d:%d) place %d "
+ "partition = [%d,%d]\n",
+ __kmp_gtid_from_thread(team->t.t_threads[f]), team->t.t_id,
+ f, masters_place, first_place, last_place));
+ }
+ } break;
- case proc_bind_close:
- {
- int f;
- int n_th = team->t.t_nproc;
- int n_places;
- if ( first_place <= last_place ) {
- n_places = last_place - first_place + 1;
- }
- else {
- n_places = __kmp_affinity_num_masks - first_place + last_place + 1;
- }
- if ( n_th <= n_places ) {
- int place = masters_place;
- for ( f = 1; f < n_th; f++ ) {
- kmp_info_t *th = team->t.t_threads[f];
- KMP_DEBUG_ASSERT( th != NULL );
-
- if ( place == last_place ) {
- place = first_place;
- }
- else if ( place == (int)(__kmp_affinity_num_masks - 1) ) {
- place = 0;
- }
- else {
- place++;
- }
- th->th.th_first_place = first_place;
- th->th.th_last_place = last_place;
- th->th.th_new_place = place;
-
- KA_TRACE( 100, ("__kmp_partition_places: close: T#%d(%d:%d) place %d partition = [%d,%d]\n",
- __kmp_gtid_from_thread( team->t.t_threads[f] ),
- team->t.t_id, f, place, first_place, last_place ) );
- }
- }
- else {
- int S, rem, gap, s_count;
- S = n_th / n_places;
- s_count = 0;
- rem = n_th - ( S * n_places );
- gap = rem > 0 ? n_places/rem : n_places;
- int place = masters_place;
- int gap_ct = gap;
- for ( f = 0; f < n_th; f++ ) {
- kmp_info_t *th = team->t.t_threads[f];
- KMP_DEBUG_ASSERT( th != NULL );
-
- th->th.th_first_place = first_place;
- th->th.th_last_place = last_place;
- th->th.th_new_place = place;
- s_count++;
-
- if ( (s_count == S) && rem && (gap_ct == gap) ) {
- // do nothing, add an extra thread to place on next iteration
- }
- else if ( (s_count == S+1) && rem && (gap_ct == gap) ) {
- // we added an extra thread to this place; move to next place
- if ( place == last_place ) {
- place = first_place;
- }
- else if ( place == (int)(__kmp_affinity_num_masks - 1) ) {
- place = 0;
- }
- else {
- place++;
- }
- s_count = 0;
- gap_ct = 1;
- rem--;
- }
- else if (s_count == S) { // place full; don't add extra
- if ( place == last_place ) {
- place = first_place;
- }
- else if ( place == (int)(__kmp_affinity_num_masks - 1) ) {
- place = 0;
- }
- else {
- place++;
- }
- gap_ct++;
- s_count = 0;
- }
-
- KA_TRACE( 100, ("__kmp_partition_places: close: T#%d(%d:%d) place %d partition = [%d,%d]\n",
- __kmp_gtid_from_thread( team->t.t_threads[f] ),
- team->t.t_id, f, th->th.th_new_place, first_place,
- last_place ) );
- }
- KMP_DEBUG_ASSERT( place == masters_place );
- }
+ case proc_bind_close: {
+ int f;
+ int n_th = team->t.t_nproc;
+ int n_places;
+ if (first_place <= last_place) {
+ n_places = last_place - first_place + 1;
+ } else {
+ n_places = __kmp_affinity_num_masks - first_place + last_place + 1;
+ }
+ if (n_th <= n_places) {
+ int place = masters_place;
+ for (f = 1; f < n_th; f++) {
+ kmp_info_t *th = team->t.t_threads[f];
+ KMP_DEBUG_ASSERT(th != NULL);
+
+ if (place == last_place) {
+ place = first_place;
+ } else if (place == (int)(__kmp_affinity_num_masks - 1)) {
+ place = 0;
+ } else {
+ place++;
}
- break;
-
- case proc_bind_spread:
- {
- int f;
- int n_th = team->t.t_nproc;
- int n_places;
- int thidx;
- if ( first_place <= last_place ) {
- n_places = last_place - first_place + 1;
- }
- else {
- n_places = __kmp_affinity_num_masks - first_place + last_place + 1;
- }
- if ( n_th <= n_places ) {
- int place = masters_place;
- int S = n_places/n_th;
- int s_count, rem, gap, gap_ct;
- rem = n_places - n_th*S;
- gap = rem ? n_th/rem : 1;
- gap_ct = gap;
- thidx = n_th;
- if (update_master_only == 1)
- thidx = 1;
- for ( f = 0; f < thidx; f++ ) {
- kmp_info_t *th = team->t.t_threads[f];
- KMP_DEBUG_ASSERT( th != NULL );
-
- th->th.th_first_place = place;
- th->th.th_new_place = place;
- s_count = 1;
- while (s_count < S) {
- if ( place == last_place ) {
- place = first_place;
- }
- else if ( place == (int)(__kmp_affinity_num_masks - 1) ) {
- place = 0;
- }
- else {
- place++;
- }
- s_count++;
- }
- if (rem && (gap_ct == gap)) {
- if ( place == last_place ) {
- place = first_place;
- }
- else if ( place == (int)(__kmp_affinity_num_masks - 1) ) {
- place = 0;
- }
- else {
- place++;
- }
- rem--;
- gap_ct = 0;
- }
- th->th.th_last_place = place;
- gap_ct++;
-
- if ( place == last_place ) {
- place = first_place;
- }
- else if ( place == (int)(__kmp_affinity_num_masks - 1) ) {
- place = 0;
- }
- else {
- place++;
- }
-
- KA_TRACE( 100, ("__kmp_partition_places: spread: T#%d(%d:%d) place %d partition = [%d,%d]\n",
- __kmp_gtid_from_thread( team->t.t_threads[f] ),
- team->t.t_id, f, th->th.th_new_place,
- th->th.th_first_place, th->th.th_last_place ) );
- }
- KMP_DEBUG_ASSERT( update_master_only || place == masters_place );
- }
- else {
- int S, rem, gap, s_count;
- S = n_th / n_places;
- s_count = 0;
- rem = n_th - ( S * n_places );
- gap = rem > 0 ? n_places/rem : n_places;
- int place = masters_place;
- int gap_ct = gap;
- thidx = n_th;
- if (update_master_only == 1)
- thidx = 1;
- for ( f = 0; f < thidx; f++ ) {
- kmp_info_t *th = team->t.t_threads[f];
- KMP_DEBUG_ASSERT( th != NULL );
-
- th->th.th_first_place = place;
- th->th.th_last_place = place;
- th->th.th_new_place = place;
- s_count++;
-
- if ( (s_count == S) && rem && (gap_ct == gap) ) {
- // do nothing, add an extra thread to place on next iteration
- }
- else if ( (s_count == S+1) && rem && (gap_ct == gap) ) {
- // we added an extra thread to this place; move on to next place
- if ( place == last_place ) {
- place = first_place;
- }
- else if ( place == (int)(__kmp_affinity_num_masks - 1) ) {
- place = 0;
- }
- else {
- place++;
- }
- s_count = 0;
- gap_ct = 1;
- rem--;
- }
- else if (s_count == S) { // place is full; don't add extra thread
- if ( place == last_place ) {
- place = first_place;
- }
- else if ( place == (int)(__kmp_affinity_num_masks - 1) ) {
- place = 0;
- }
- else {
- place++;
- }
- gap_ct++;
- s_count = 0;
- }
+ th->th.th_first_place = first_place;
+ th->th.th_last_place = last_place;
+ th->th.th_new_place = place;
+
+ KA_TRACE(100, ("__kmp_partition_places: close: T#%d(%d:%d) place %d "
+ "partition = [%d,%d]\n",
+ __kmp_gtid_from_thread(team->t.t_threads[f]),
+ team->t.t_id, f, place, first_place, last_place));
+ }
+ } else {
+ int S, rem, gap, s_count;
+ S = n_th / n_places;
+ s_count = 0;
+ rem = n_th - (S * n_places);
+ gap = rem > 0 ? n_places / rem : n_places;
+ int place = masters_place;
+ int gap_ct = gap;
+ for (f = 0; f < n_th; f++) {
+ kmp_info_t *th = team->t.t_threads[f];
+ KMP_DEBUG_ASSERT(th != NULL);
+
+ th->th.th_first_place = first_place;
+ th->th.th_last_place = last_place;
+ th->th.th_new_place = place;
+ s_count++;
+
+ if ((s_count == S) && rem && (gap_ct == gap)) {
+ // do nothing, add an extra thread to place on next iteration
+ } else if ((s_count == S + 1) && rem && (gap_ct == gap)) {
+ // we added an extra thread to this place; move to next place
+ if (place == last_place) {
+ place = first_place;
+ } else if (place == (int)(__kmp_affinity_num_masks - 1)) {
+ place = 0;
+ } else {
+ place++;
+ }
+ s_count = 0;
+ gap_ct = 1;
+ rem--;
+ } else if (s_count == S) { // place full; don't add extra
+ if (place == last_place) {
+ place = first_place;
+ } else if (place == (int)(__kmp_affinity_num_masks - 1)) {
+ place = 0;
+ } else {
+ place++;
+ }
+ gap_ct++;
+ s_count = 0;
+ }
+
+ KA_TRACE(100,
+ ("__kmp_partition_places: close: T#%d(%d:%d) place %d "
+ "partition = [%d,%d]\n",
+ __kmp_gtid_from_thread(team->t.t_threads[f]), team->t.t_id, f,
+ th->th.th_new_place, first_place, last_place));
+ }
+ KMP_DEBUG_ASSERT(place == masters_place);
+ }
+ } break;
- KA_TRACE( 100, ("__kmp_partition_places: spread: T#%d(%d:%d) place %d partition = [%d,%d]\n",
- __kmp_gtid_from_thread( team->t.t_threads[f] ),
- team->t.t_id, f, th->th.th_new_place,
- th->th.th_first_place, th->th.th_last_place) );
- }
- KMP_DEBUG_ASSERT( update_master_only || place == masters_place );
- }
+ case proc_bind_spread: {
+ int f;
+ int n_th = team->t.t_nproc;
+ int n_places;
+ int thidx;
+ if (first_place <= last_place) {
+ n_places = last_place - first_place + 1;
+ } else {
+ n_places = __kmp_affinity_num_masks - first_place + last_place + 1;
+ }
+ if (n_th <= n_places) {
+ int place = masters_place;
+ int S = n_places / n_th;
+ int s_count, rem, gap, gap_ct;
+ rem = n_places - n_th * S;
+ gap = rem ? n_th / rem : 1;
+ gap_ct = gap;
+ thidx = n_th;
+ if (update_master_only == 1)
+ thidx = 1;
+ for (f = 0; f < thidx; f++) {
+ kmp_info_t *th = team->t.t_threads[f];
+ KMP_DEBUG_ASSERT(th != NULL);
+
+ th->th.th_first_place = place;
+ th->th.th_new_place = place;
+ s_count = 1;
+ while (s_count < S) {
+ if (place == last_place) {
+ place = first_place;
+ } else if (place == (int)(__kmp_affinity_num_masks - 1)) {
+ place = 0;
+ } else {
+ place++;
+ }
+ s_count++;
+ }
+ if (rem && (gap_ct == gap)) {
+ if (place == last_place) {
+ place = first_place;
+ } else if (place == (int)(__kmp_affinity_num_masks - 1)) {
+ place = 0;
+ } else {
+ place++;
+ }
+ rem--;
+ gap_ct = 0;
+ }
+ th->th.th_last_place = place;
+ gap_ct++;
+
+ if (place == last_place) {
+ place = first_place;
+ } else if (place == (int)(__kmp_affinity_num_masks - 1)) {
+ place = 0;
+ } else {
+ place++;
}
- break;
- default:
- break;
+ KA_TRACE(100, ("__kmp_partition_places: spread: T#%d(%d:%d) place %d "
+ "partition = [%d,%d]\n",
+ __kmp_gtid_from_thread(team->t.t_threads[f]),
+ team->t.t_id, f, th->th.th_new_place,
+ th->th.th_first_place, th->th.th_last_place));
+ }
+ KMP_DEBUG_ASSERT(update_master_only || place == masters_place);
+ } else {
+ int S, rem, gap, s_count;
+ S = n_th / n_places;
+ s_count = 0;
+ rem = n_th - (S * n_places);
+ gap = rem > 0 ? n_places / rem : n_places;
+ int place = masters_place;
+ int gap_ct = gap;
+ thidx = n_th;
+ if (update_master_only == 1)
+ thidx = 1;
+ for (f = 0; f < thidx; f++) {
+ kmp_info_t *th = team->t.t_threads[f];
+ KMP_DEBUG_ASSERT(th != NULL);
+
+ th->th.th_first_place = place;
+ th->th.th_last_place = place;
+ th->th.th_new_place = place;
+ s_count++;
+
+ if ((s_count == S) && rem && (gap_ct == gap)) {
+ // do nothing, add an extra thread to place on next iteration
+ } else if ((s_count == S + 1) && rem && (gap_ct == gap)) {
+ // we added an extra thread to this place; move on to next place
+ if (place == last_place) {
+ place = first_place;
+ } else if (place == (int)(__kmp_affinity_num_masks - 1)) {
+ place = 0;
+ } else {
+ place++;
+ }
+ s_count = 0;
+ gap_ct = 1;
+ rem--;
+ } else if (s_count == S) { // place is full; don't add extra thread
+ if (place == last_place) {
+ place = first_place;
+ } else if (place == (int)(__kmp_affinity_num_masks - 1)) {
+ place = 0;
+ } else {
+ place++;
+ }
+ gap_ct++;
+ s_count = 0;
+ }
+
+ KA_TRACE(100, ("__kmp_partition_places: spread: T#%d(%d:%d) place %d "
+ "partition = [%d,%d]\n",
+ __kmp_gtid_from_thread(team->t.t_threads[f]),
+ team->t.t_id, f, th->th.th_new_place,
+ th->th.th_first_place, th->th.th_last_place));
+ }
+ KMP_DEBUG_ASSERT(update_master_only || place == masters_place);
}
+ } break;
+
+ default:
+ break;
+ }
- KA_TRACE( 20, ("__kmp_partition_places: exit T#%d\n", team->t.t_id ) );
+ KA_TRACE(20, ("__kmp_partition_places: exit T#%d\n", team->t.t_id));
}
#endif /* OMP_40_ENABLED && KMP_AFFINITY_SUPPORTED */
-/* allocate a new team data structure to use. take one off of the free pool if available */
+/* allocate a new team data structure to use. take one off of the free pool if
+ available */
kmp_team_t *
-__kmp_allocate_team( kmp_root_t *root, int new_nproc, int max_nproc,
+__kmp_allocate_team(kmp_root_t *root, int new_nproc, int max_nproc,
#if OMPT_SUPPORT
- ompt_parallel_id_t ompt_parallel_id,
+ ompt_parallel_id_t ompt_parallel_id,
#endif
#if OMP_40_ENABLED
- kmp_proc_bind_t new_proc_bind,
+ kmp_proc_bind_t new_proc_bind,
#endif
- kmp_internal_control_t *new_icvs,
- int argc USE_NESTED_HOT_ARG(kmp_info_t *master) )
-{
- KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_allocate_team);
- int f;
- kmp_team_t *team;
- int use_hot_team = ! root->r.r_active;
- int level = 0;
-
- KA_TRACE( 20, ("__kmp_allocate_team: called\n"));
- KMP_DEBUG_ASSERT( new_nproc >=1 && argc >=0 );
- KMP_DEBUG_ASSERT( max_nproc >= new_nproc );
- KMP_MB();
+ kmp_internal_control_t *new_icvs,
+ int argc USE_NESTED_HOT_ARG(kmp_info_t *master)) {
+ KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_allocate_team);
+ int f;
+ kmp_team_t *team;
+ int use_hot_team = !root->r.r_active;
+ int level = 0;
+
+ KA_TRACE(20, ("__kmp_allocate_team: called\n"));
+ KMP_DEBUG_ASSERT(new_nproc >= 1 && argc >= 0);
+ KMP_DEBUG_ASSERT(max_nproc >= new_nproc);
+ KMP_MB();
#if KMP_NESTED_HOT_TEAMS
- kmp_hot_team_ptr_t *hot_teams;
- if( master ) {
- team = master->th.th_team;
- level = team->t.t_active_level;
- if( master->th.th_teams_microtask ) { // in teams construct?
- if( master->th.th_teams_size.nteams > 1 && ( // #teams > 1
- team->t.t_pkfn == (microtask_t)__kmp_teams_master || // inner fork of the teams
- master->th.th_teams_level < team->t.t_level ) ) { // or nested parallel inside the teams
- ++level; // not increment if #teams==1, or for outer fork of the teams; increment otherwise
- }
- }
- hot_teams = master->th.th_hot_teams;
- if( level < __kmp_hot_teams_max_level && hot_teams && hot_teams[level].hot_team )
- { // hot team has already been allocated for given level
- use_hot_team = 1;
- } else {
- use_hot_team = 0;
- }
+ kmp_hot_team_ptr_t *hot_teams;
+ if (master) {
+ team = master->th.th_team;
+ level = team->t.t_active_level;
+ if (master->th.th_teams_microtask) { // in teams construct?
+ if (master->th.th_teams_size.nteams > 1 &&
+ ( // #teams > 1
+ team->t.t_pkfn ==
+ (microtask_t)__kmp_teams_master || // inner fork of the teams
+ master->th.th_teams_level <
+ team->t.t_level)) { // or nested parallel inside the teams
+ ++level; // not increment if #teams==1, or for outer fork of the teams;
+ // increment otherwise
+ }
+ }
+ hot_teams = master->th.th_hot_teams;
+ if (level < __kmp_hot_teams_max_level && hot_teams &&
+ hot_teams[level]
+ .hot_team) { // hot team has already been allocated for given level
+ use_hot_team = 1;
+ } else {
+ use_hot_team = 0;
}
+ }
#endif
- // Optimization to use a "hot" team
- if( use_hot_team && new_nproc > 1 ) {
- KMP_DEBUG_ASSERT( new_nproc == max_nproc );
+ // Optimization to use a "hot" team
+ if (use_hot_team && new_nproc > 1) {
+ KMP_DEBUG_ASSERT(new_nproc == max_nproc);
#if KMP_NESTED_HOT_TEAMS
- team = hot_teams[level].hot_team;
+ team = hot_teams[level].hot_team;
#else
- team = root->r.r_hot_team;
+ team = root->r.r_hot_team;
#endif
#if KMP_DEBUG
- if ( __kmp_tasking_mode != tskm_immediate_exec ) {
- KA_TRACE( 20, ("__kmp_allocate_team: hot team task_team[0] = %p task_team[1] = %p before reinit\n",
- team->t.t_task_team[0], team->t.t_task_team[1] ));
- }
+ if (__kmp_tasking_mode != tskm_immediate_exec) {
+ KA_TRACE(20, ("__kmp_allocate_team: hot team task_team[0] = %p "
+ "task_team[1] = %p before reinit\n",
+ team->t.t_task_team[0], team->t.t_task_team[1]));
+ }
#endif
- // Has the number of threads changed?
- /* Let's assume the most common case is that the number of threads is unchanged, and
- put that case first. */
- if (team->t.t_nproc == new_nproc) { // Check changes in number of threads
- KA_TRACE( 20, ("__kmp_allocate_team: reusing hot team\n" ));
- // This case can mean that omp_set_num_threads() was called and the hot team size
- // was already reduced, so we check the special flag
- if ( team->t.t_size_changed == -1 ) {
- team->t.t_size_changed = 1;
- } else {
- KMP_CHECK_UPDATE(team->t.t_size_changed, 0);
- }
+ // Has the number of threads changed?
+ /* Let's assume the most common case is that the number of threads is
+ unchanged, and put that case first. */
+ if (team->t.t_nproc == new_nproc) { // Check changes in number of threads
+ KA_TRACE(20, ("__kmp_allocate_team: reusing hot team\n"));
+ // This case can mean that omp_set_num_threads() was called and the hot
+ // team size
+ // was already reduced, so we check the special flag
+ if (team->t.t_size_changed == -1) {
+ team->t.t_size_changed = 1;
+ } else {
+ KMP_CHECK_UPDATE(team->t.t_size_changed, 0);
+ }
+
+ // TODO???: team->t.t_max_active_levels = new_max_active_levels;
+ kmp_r_sched_t new_sched = new_icvs->sched;
+ if (team->t.t_sched.r_sched_type != new_sched.r_sched_type ||
+ team->t.t_sched.chunk != new_sched.chunk)
+ team->t.t_sched =
+ new_sched; // set master's schedule as new run-time schedule
+
+ __kmp_reinitialize_team(team, new_icvs,
+ root->r.r_uber_thread->th.th_ident);
+
+ KF_TRACE(10, ("__kmp_allocate_team2: T#%d, this_thread=%p team=%p\n", 0,
+ team->t.t_threads[0], team));
+ __kmp_push_current_task_to_thread(team->t.t_threads[0], team, 0);
- // TODO???: team->t.t_max_active_levels = new_max_active_levels;
- kmp_r_sched_t new_sched = new_icvs->sched;
- if (team->t.t_sched.r_sched_type != new_sched.r_sched_type ||
- team->t.t_sched.chunk != new_sched.chunk)
- team->t.t_sched = new_sched; // set master's schedule as new run-time schedule
-
- __kmp_reinitialize_team( team, new_icvs, root->r.r_uber_thread->th.th_ident );
-
- KF_TRACE( 10, ("__kmp_allocate_team2: T#%d, this_thread=%p team=%p\n",
- 0, team->t.t_threads[0], team ) );
- __kmp_push_current_task_to_thread( team->t.t_threads[ 0 ], team, 0 );
-
-#if OMP_40_ENABLED
-# if KMP_AFFINITY_SUPPORTED
- if ( ( team->t.t_size_changed == 0 )
- && ( team->t.t_proc_bind == new_proc_bind ) ) {
- if (new_proc_bind == proc_bind_spread) {
- __kmp_partition_places(team, 1); // add flag to update only master for spread
- }
- KA_TRACE( 200, ("__kmp_allocate_team: reusing hot team #%d bindings: proc_bind = %d, partition = [%d,%d]\n",
- team->t.t_id, new_proc_bind, team->t.t_first_place,
- team->t.t_last_place ) );
- }
- else {
- KMP_CHECK_UPDATE(team->t.t_proc_bind, new_proc_bind);
- __kmp_partition_places( team );
- }
-# else
- KMP_CHECK_UPDATE(team->t.t_proc_bind, new_proc_bind);
-# endif /* KMP_AFFINITY_SUPPORTED */
+#if OMP_40_ENABLED
+#if KMP_AFFINITY_SUPPORTED
+ if ((team->t.t_size_changed == 0) &&
+ (team->t.t_proc_bind == new_proc_bind)) {
+ if (new_proc_bind == proc_bind_spread) {
+ __kmp_partition_places(
+ team, 1); // add flag to update only master for spread
+ }
+ KA_TRACE(200, ("__kmp_allocate_team: reusing hot team #%d bindings: "
+ "proc_bind = %d, partition = [%d,%d]\n",
+ team->t.t_id, new_proc_bind, team->t.t_first_place,
+ team->t.t_last_place));
+ } else {
+ KMP_CHECK_UPDATE(team->t.t_proc_bind, new_proc_bind);
+ __kmp_partition_places(team);
+ }
+#else
+ KMP_CHECK_UPDATE(team->t.t_proc_bind, new_proc_bind);
+#endif /* KMP_AFFINITY_SUPPORTED */
#endif /* OMP_40_ENABLED */
- }
- else if( team->t.t_nproc > new_nproc ) {
- KA_TRACE( 20, ("__kmp_allocate_team: decreasing hot team thread count to %d\n", new_nproc ));
+ } else if (team->t.t_nproc > new_nproc) {
+ KA_TRACE(20,
+ ("__kmp_allocate_team: decreasing hot team thread count to %d\n",
+ new_nproc));
- team->t.t_size_changed = 1;
+ team->t.t_size_changed = 1;
#if KMP_NESTED_HOT_TEAMS
- if( __kmp_hot_teams_mode == 0 ) {
- // AC: saved number of threads should correspond to team's value in this mode,
- // can be bigger in mode 1, when hot team has some threads in reserve
- KMP_DEBUG_ASSERT(hot_teams[level].hot_team_nth == team->t.t_nproc);
- hot_teams[level].hot_team_nth = new_nproc;
+ if (__kmp_hot_teams_mode == 0) {
+ // AC: saved number of threads should correspond to team's value in this
+ // mode, can be bigger in mode 1, when hot team has threads in reserve
+ KMP_DEBUG_ASSERT(hot_teams[level].hot_team_nth == team->t.t_nproc);
+ hot_teams[level].hot_team_nth = new_nproc;
#endif // KMP_NESTED_HOT_TEAMS
- /* release the extra threads we don't need any more */
- for( f = new_nproc ; f < team->t.t_nproc ; f++ ) {
- KMP_DEBUG_ASSERT( team->t.t_threads[ f ] );
- if ( __kmp_tasking_mode != tskm_immediate_exec) {
- // When decreasing team size, threads no longer in the team should unref task team.
- team->t.t_threads[f]->th.th_task_team = NULL;
- }
- __kmp_free_thread( team->t.t_threads[ f ] );
- team->t.t_threads[ f ] = NULL;
- }
+ /* release the extra threads we don't need any more */
+ for (f = new_nproc; f < team->t.t_nproc; f++) {
+ KMP_DEBUG_ASSERT(team->t.t_threads[f]);
+ if (__kmp_tasking_mode != tskm_immediate_exec) {
+ // When decreasing team size, threads no longer in the team should
+ // unref task team.
+ team->t.t_threads[f]->th.th_task_team = NULL;
+ }
+ __kmp_free_thread(team->t.t_threads[f]);
+ team->t.t_threads[f] = NULL;
+ }
#if KMP_NESTED_HOT_TEAMS
- } // (__kmp_hot_teams_mode == 0)
- else {
- // When keeping extra threads in team, switch threads to wait on own b_go flag
- for (f=new_nproc; f<team->t.t_nproc; ++f) {
- KMP_DEBUG_ASSERT(team->t.t_threads[f]);
- kmp_balign_t *balign = team->t.t_threads[f]->th.th_bar;
- for (int b=0; b<bs_last_barrier; ++b) {
- if (balign[b].bb.wait_flag == KMP_BARRIER_PARENT_FLAG) {
- balign[b].bb.wait_flag = KMP_BARRIER_SWITCH_TO_OWN_FLAG;
- }
- KMP_CHECK_UPDATE(balign[b].bb.leaf_kids, 0);
- }
- }
+ } // (__kmp_hot_teams_mode == 0)
+ else {
+ // When keeping extra threads in team, switch threads to wait on own
+ // b_go flag
+ for (f = new_nproc; f < team->t.t_nproc; ++f) {
+ KMP_DEBUG_ASSERT(team->t.t_threads[f]);
+ kmp_balign_t *balign = team->t.t_threads[f]->th.th_bar;
+ for (int b = 0; b < bs_last_barrier; ++b) {
+ if (balign[b].bb.wait_flag == KMP_BARRIER_PARENT_FLAG) {
+ balign[b].bb.wait_flag = KMP_BARRIER_SWITCH_TO_OWN_FLAG;
}
+ KMP_CHECK_UPDATE(balign[b].bb.leaf_kids, 0);
+ }
+ }
+ }
#endif // KMP_NESTED_HOT_TEAMS
- team->t.t_nproc = new_nproc;
- // TODO???: team->t.t_max_active_levels = new_max_active_levels;
- if (team->t.t_sched.r_sched_type != new_icvs->sched.r_sched_type ||
- team->t.t_sched.chunk != new_icvs->sched.chunk)
- team->t.t_sched = new_icvs->sched;
- __kmp_reinitialize_team( team, new_icvs, root->r.r_uber_thread->th.th_ident );
-
- /* update the remaining threads */
- for(f = 0; f < new_nproc; ++f) {
- team->t.t_threads[f]->th.th_team_nproc = new_nproc;
- }
- // restore the current task state of the master thread: should be the implicit task
- KF_TRACE( 10, ("__kmp_allocate_team: T#%d, this_thread=%p team=%p\n",
- 0, team->t.t_threads[0], team ) );
+ team->t.t_nproc = new_nproc;
+ // TODO???: team->t.t_max_active_levels = new_max_active_levels;
+ if (team->t.t_sched.r_sched_type != new_icvs->sched.r_sched_type ||
+ team->t.t_sched.chunk != new_icvs->sched.chunk)
+ team->t.t_sched = new_icvs->sched;
+ __kmp_reinitialize_team(team, new_icvs,
+ root->r.r_uber_thread->th.th_ident);
+
+ /* update the remaining threads */
+ for (f = 0; f < new_nproc; ++f) {
+ team->t.t_threads[f]->th.th_team_nproc = new_nproc;
+ }
+ // restore the current task state of the master thread: should be the
+ // implicit task
+ KF_TRACE(10, ("__kmp_allocate_team: T#%d, this_thread=%p team=%p\n", 0,
+ team->t.t_threads[0], team));
- __kmp_push_current_task_to_thread( team->t.t_threads[ 0 ], team, 0 );
+ __kmp_push_current_task_to_thread(team->t.t_threads[0], team, 0);
#ifdef KMP_DEBUG
- for ( f = 0; f < team->t.t_nproc; f++ ) {
- KMP_DEBUG_ASSERT( team->t.t_threads[f] &&
- team->t.t_threads[f]->th.th_team_nproc == team->t.t_nproc );
- }
+ for (f = 0; f < team->t.t_nproc; f++) {
+ KMP_DEBUG_ASSERT(team->t.t_threads[f] &&
+ team->t.t_threads[f]->th.th_team_nproc ==
+ team->t.t_nproc);
+ }
#endif
#if OMP_40_ENABLED
- KMP_CHECK_UPDATE(team->t.t_proc_bind, new_proc_bind);
-# if KMP_AFFINITY_SUPPORTED
- __kmp_partition_places( team );
-# endif
+ KMP_CHECK_UPDATE(team->t.t_proc_bind, new_proc_bind);
+#if KMP_AFFINITY_SUPPORTED
+ __kmp_partition_places(team);
#endif
- }
- else { // team->t.t_nproc < new_nproc
+#endif
+ } else { // team->t.t_nproc < new_nproc
#if KMP_OS_LINUX && KMP_AFFINITY_SUPPORTED
- kmp_affin_mask_t *old_mask;
- if ( KMP_AFFINITY_CAPABLE() ) {
- KMP_CPU_ALLOC(old_mask);
- }
+ kmp_affin_mask_t *old_mask;
+ if (KMP_AFFINITY_CAPABLE()) {
+ KMP_CPU_ALLOC(old_mask);
+ }
#endif
- KA_TRACE( 20, ("__kmp_allocate_team: increasing hot team thread count to %d\n", new_nproc ));
+ KA_TRACE(20,
+ ("__kmp_allocate_team: increasing hot team thread count to %d\n",
+ new_nproc));
- team->t.t_size_changed = 1;
+ team->t.t_size_changed = 1;
#if KMP_NESTED_HOT_TEAMS
- int avail_threads = hot_teams[level].hot_team_nth;
- if( new_nproc < avail_threads )
- avail_threads = new_nproc;
- kmp_info_t **other_threads = team->t.t_threads;
- for ( f = team->t.t_nproc; f < avail_threads; ++f ) {
- // Adjust barrier data of reserved threads (if any) of the team
- // Other data will be set in __kmp_initialize_info() below.
- int b;
- kmp_balign_t * balign = other_threads[f]->th.th_bar;
- for ( b = 0; b < bs_last_barrier; ++ b ) {
- balign[b].bb.b_arrived = team->t.t_bar[b].b_arrived;
- KMP_DEBUG_ASSERT(balign[b].bb.wait_flag != KMP_BARRIER_PARENT_FLAG);
+ int avail_threads = hot_teams[level].hot_team_nth;
+ if (new_nproc < avail_threads)
+ avail_threads = new_nproc;
+ kmp_info_t **other_threads = team->t.t_threads;
+ for (f = team->t.t_nproc; f < avail_threads; ++f) {
+ // Adjust barrier data of reserved threads (if any) of the team
+ // Other data will be set in __kmp_initialize_info() below.
+ int b;
+ kmp_balign_t *balign = other_threads[f]->th.th_bar;
+ for (b = 0; b < bs_last_barrier; ++b) {
+ balign[b].bb.b_arrived = team->t.t_bar[b].b_arrived;
+ KMP_DEBUG_ASSERT(balign[b].bb.wait_flag != KMP_BARRIER_PARENT_FLAG);
#if USE_DEBUGGER
- balign[b].bb.b_worker_arrived = team->t.t_bar[b].b_team_arrived;
+ balign[b].bb.b_worker_arrived = team->t.t_bar[b].b_team_arrived;
#endif
- }
- }
- if( hot_teams[level].hot_team_nth >= new_nproc ) {
- // we have all needed threads in reserve, no need to allocate any
- // this only possible in mode 1, cannot have reserved threads in mode 0
- KMP_DEBUG_ASSERT(__kmp_hot_teams_mode == 1);
- team->t.t_nproc = new_nproc; // just get reserved threads involved
- } else {
- // we may have some threads in reserve, but not enough
- team->t.t_nproc = hot_teams[level].hot_team_nth; // get reserved threads involved if any
- hot_teams[level].hot_team_nth = new_nproc; // adjust hot team max size
+ }
+ }
+ if (hot_teams[level].hot_team_nth >= new_nproc) {
+ // we have all needed threads in reserve, no need to allocate any
+ // this only possible in mode 1, cannot have reserved threads in mode 0
+ KMP_DEBUG_ASSERT(__kmp_hot_teams_mode == 1);
+ team->t.t_nproc = new_nproc; // just get reserved threads involved
+ } else {
+ // we may have some threads in reserve, but not enough
+ team->t.t_nproc =
+ hot_teams[level]
+ .hot_team_nth; // get reserved threads involved if any
+ hot_teams[level].hot_team_nth = new_nproc; // adjust hot team max size
#endif // KMP_NESTED_HOT_TEAMS
- if(team->t.t_max_nproc < new_nproc) {
- /* reallocate larger arrays */
- __kmp_reallocate_team_arrays(team, new_nproc);
- __kmp_reinitialize_team( team, new_icvs, NULL );
- }
+ if (team->t.t_max_nproc < new_nproc) {
+ /* reallocate larger arrays */
+ __kmp_reallocate_team_arrays(team, new_nproc);
+ __kmp_reinitialize_team(team, new_icvs, NULL);
+ }
#if KMP_OS_LINUX && KMP_AFFINITY_SUPPORTED
- /* Temporarily set full mask for master thread before
- creation of workers. The reason is that workers inherit
- the affinity from master, so if a lot of workers are
- created on the single core quickly, they don't get
- a chance to set their own affinity for a long time.
- */
- __kmp_set_thread_affinity_mask_full_tmp( old_mask );
-#endif
-
- /* allocate new threads for the hot team */
- for( f = team->t.t_nproc ; f < new_nproc ; f++ ) {
- kmp_info_t * new_worker = __kmp_allocate_thread( root, team, f );
- KMP_DEBUG_ASSERT( new_worker );
- team->t.t_threads[ f ] = new_worker;
-
- KA_TRACE( 20, ("__kmp_allocate_team: team %d init T#%d arrived: join=%llu, plain=%llu\n",
- team->t.t_id, __kmp_gtid_from_tid( f, team ), team->t.t_id, f,
- team->t.t_bar[bs_forkjoin_barrier].b_arrived,
- team->t.t_bar[bs_plain_barrier].b_arrived ) );
-
- { // Initialize barrier data for new threads.
- int b;
- kmp_balign_t * balign = new_worker->th.th_bar;
- for( b = 0; b < bs_last_barrier; ++ b ) {
- balign[ b ].bb.b_arrived = team->t.t_bar[ b ].b_arrived;
- KMP_DEBUG_ASSERT(balign[b].bb.wait_flag != KMP_BARRIER_PARENT_FLAG);
+ /* Temporarily set full mask for master thread before creation of
+ workers. The reason is that workers inherit the affinity from master,
+ so if a lot of workers are created on the single core quickly, they
+ don't get a chance to set their own affinity for a long time. */
+ __kmp_set_thread_affinity_mask_full_tmp(old_mask);
+#endif
+
+ /* allocate new threads for the hot team */
+ for (f = team->t.t_nproc; f < new_nproc; f++) {
+ kmp_info_t *new_worker = __kmp_allocate_thread(root, team, f);
+ KMP_DEBUG_ASSERT(new_worker);
+ team->t.t_threads[f] = new_worker;
+
+ KA_TRACE(20,
+ ("__kmp_allocate_team: team %d init T#%d arrived: "
+ "join=%llu, plain=%llu\n",
+ team->t.t_id, __kmp_gtid_from_tid(f, team), team->t.t_id, f,
+ team->t.t_bar[bs_forkjoin_barrier].b_arrived,
+ team->t.t_bar[bs_plain_barrier].b_arrived));
+
+ { // Initialize barrier data for new threads.
+ int b;
+ kmp_balign_t *balign = new_worker->th.th_bar;
+ for (b = 0; b < bs_last_barrier; ++b) {
+ balign[b].bb.b_arrived = team->t.t_bar[b].b_arrived;
+ KMP_DEBUG_ASSERT(balign[b].bb.wait_flag !=
+ KMP_BARRIER_PARENT_FLAG);
#if USE_DEBUGGER
- balign[ b ].bb.b_worker_arrived = team->t.t_bar[ b ].b_team_arrived;
+ balign[b].bb.b_worker_arrived = team->t.t_bar[b].b_team_arrived;
#endif
- }
- }
}
+ }
+ }
#if KMP_OS_LINUX && KMP_AFFINITY_SUPPORTED
- if ( KMP_AFFINITY_CAPABLE() ) {
- /* Restore initial master thread's affinity mask */
- __kmp_set_system_affinity( old_mask, TRUE );
- KMP_CPU_FREE(old_mask);
- }
+ if (KMP_AFFINITY_CAPABLE()) {
+ /* Restore initial master thread's affinity mask */
+ __kmp_set_system_affinity(old_mask, TRUE);
+ KMP_CPU_FREE(old_mask);
+ }
#endif
#if KMP_NESTED_HOT_TEAMS
- } // end of check of t_nproc vs. new_nproc vs. hot_team_nth
+ } // end of check of t_nproc vs. new_nproc vs. hot_team_nth
#endif // KMP_NESTED_HOT_TEAMS
- /* make sure everyone is syncronized */
- int old_nproc = team->t.t_nproc; // save old value and use to update only new threads below
- __kmp_initialize_team( team, new_nproc, new_icvs, root->r.r_uber_thread->th.th_ident );
-
- /* reinitialize the threads */
- KMP_DEBUG_ASSERT(team->t.t_nproc == new_nproc);
- for (f=0; f < team->t.t_nproc; ++f)
- __kmp_initialize_info( team->t.t_threads[ f ], team, f, __kmp_gtid_from_tid( f, team ) );
- if (level) { // set th_task_state for new threads in nested hot team
- // __kmp_initialize_info() no longer zeroes th_task_state, so we should only need to set the
- // th_task_state for the new threads. th_task_state for master thread will not be accurate until
- // after this in __kmp_fork_call(), so we look to the master's memo_stack to get the correct value.
- for (f=old_nproc; f < team->t.t_nproc; ++f)
- team->t.t_threads[f]->th.th_task_state = team->t.t_threads[0]->th.th_task_state_memo_stack[level];
- }
- else { // set th_task_state for new threads in non-nested hot team
- int old_state = team->t.t_threads[0]->th.th_task_state; // copy master's state
- for (f=old_nproc; f < team->t.t_nproc; ++f)
- team->t.t_threads[f]->th.th_task_state = old_state;
- }
+ /* make sure everyone is syncronized */
+ int old_nproc = team->t.t_nproc; // save old value and use to update only
+ // new threads below
+ __kmp_initialize_team(team, new_nproc, new_icvs,
+ root->r.r_uber_thread->th.th_ident);
+
+ /* reinitialize the threads */
+ KMP_DEBUG_ASSERT(team->t.t_nproc == new_nproc);
+ for (f = 0; f < team->t.t_nproc; ++f)
+ __kmp_initialize_info(team->t.t_threads[f], team, f,
+ __kmp_gtid_from_tid(f, team));
+ if (level) { // set th_task_state for new threads in nested hot team
+ // __kmp_initialize_info() no longer zeroes th_task_state, so we should
+ // only need to set the th_task_state for the new threads. th_task_state
+ // for master thread will not be accurate until after this in
+ // __kmp_fork_call(), so we look to the master's memo_stack to get the
+ // correct value.
+ for (f = old_nproc; f < team->t.t_nproc; ++f)
+ team->t.t_threads[f]->th.th_task_state =
+ team->t.t_threads[0]->th.th_task_state_memo_stack[level];
+ } else { // set th_task_state for new threads in non-nested hot team
+ int old_state =
+ team->t.t_threads[0]->th.th_task_state; // copy master's state
+ for (f = old_nproc; f < team->t.t_nproc; ++f)
+ team->t.t_threads[f]->th.th_task_state = old_state;
+ }
#ifdef KMP_DEBUG
- for ( f = 0; f < team->t.t_nproc; ++ f ) {
- KMP_DEBUG_ASSERT( team->t.t_threads[f] &&
- team->t.t_threads[f]->th.th_team_nproc == team->t.t_nproc );
- }
+ for (f = 0; f < team->t.t_nproc; ++f) {
+ KMP_DEBUG_ASSERT(team->t.t_threads[f] &&
+ team->t.t_threads[f]->th.th_team_nproc ==
+ team->t.t_nproc);
+ }
#endif
#if OMP_40_ENABLED
- KMP_CHECK_UPDATE(team->t.t_proc_bind, new_proc_bind);
-# if KMP_AFFINITY_SUPPORTED
- __kmp_partition_places( team );
-# endif
-#endif
- } // Check changes in number of threads
-
-#if OMP_40_ENABLED
- kmp_info_t *master = team->t.t_threads[0];
- if( master->th.th_teams_microtask ) {
- for( f = 1; f < new_nproc; ++f ) {
- // propagate teams construct specific info to workers
- kmp_info_t *thr = team->t.t_threads[f];
- thr->th.th_teams_microtask = master->th.th_teams_microtask;
- thr->th.th_teams_level = master->th.th_teams_level;
- thr->th.th_teams_size = master->th.th_teams_size;
- }
- }
+ KMP_CHECK_UPDATE(team->t.t_proc_bind, new_proc_bind);
+#if KMP_AFFINITY_SUPPORTED
+ __kmp_partition_places(team);
+#endif
+#endif
+ } // Check changes in number of threads
+
+#if OMP_40_ENABLED
+ kmp_info_t *master = team->t.t_threads[0];
+ if (master->th.th_teams_microtask) {
+ for (f = 1; f < new_nproc; ++f) {
+ // propagate teams construct specific info to workers
+ kmp_info_t *thr = team->t.t_threads[f];
+ thr->th.th_teams_microtask = master->th.th_teams_microtask;
+ thr->th.th_teams_level = master->th.th_teams_level;
+ thr->th.th_teams_size = master->th.th_teams_size;
+ }
+ }
#endif /* OMP_40_ENABLED */
#if KMP_NESTED_HOT_TEAMS
- if( level ) {
- // Sync barrier state for nested hot teams, not needed for outermost hot team.
- for( f = 1; f < new_nproc; ++f ) {
- kmp_info_t *thr = team->t.t_threads[f];
- int b;
- kmp_balign_t * balign = thr->th.th_bar;
- for( b = 0; b < bs_last_barrier; ++ b ) {
- balign[ b ].bb.b_arrived = team->t.t_bar[ b ].b_arrived;
- KMP_DEBUG_ASSERT(balign[b].bb.wait_flag != KMP_BARRIER_PARENT_FLAG);
+ if (level) {
+ // Sync barrier state for nested hot teams, not needed for outermost hot
+ // team.
+ for (f = 1; f < new_nproc; ++f) {
+ kmp_info_t *thr = team->t.t_threads[f];
+ int b;
+ kmp_balign_t *balign = thr->th.th_bar;
+ for (b = 0; b < bs_last_barrier; ++b) {
+ balign[b].bb.b_arrived = team->t.t_bar[b].b_arrived;
+ KMP_DEBUG_ASSERT(balign[b].bb.wait_flag != KMP_BARRIER_PARENT_FLAG);
#if USE_DEBUGGER
- balign[ b ].bb.b_worker_arrived = team->t.t_bar[ b ].b_team_arrived;
+ balign[b].bb.b_worker_arrived = team->t.t_bar[b].b_team_arrived;
#endif
- }
- }
}
+ }
+ }
#endif // KMP_NESTED_HOT_TEAMS
- /* reallocate space for arguments if necessary */
- __kmp_alloc_argv_entries( argc, team, TRUE );
- KMP_CHECK_UPDATE(team->t.t_argc, argc);
- //
- // The hot team re-uses the previous task team,
- // if untouched during the previous release->gather phase.
- //
+ /* reallocate space for arguments if necessary */
+ __kmp_alloc_argv_entries(argc, team, TRUE);
+ KMP_CHECK_UPDATE(team->t.t_argc, argc);
+ // The hot team re-uses the previous task team,
+ // if untouched during the previous release->gather phase.
- KF_TRACE( 10, ( " hot_team = %p\n", team ) );
+ KF_TRACE(10, (" hot_team = %p\n", team));
#if KMP_DEBUG
- if ( __kmp_tasking_mode != tskm_immediate_exec ) {
- KA_TRACE( 20, ("__kmp_allocate_team: hot team task_team[0] = %p task_team[1] = %p after reinit\n",
- team->t.t_task_team[0], team->t.t_task_team[1] ));
- }
+ if (__kmp_tasking_mode != tskm_immediate_exec) {
+ KA_TRACE(20, ("__kmp_allocate_team: hot team task_team[0] = %p "
+ "task_team[1] = %p after reinit\n",
+ team->t.t_task_team[0], team->t.t_task_team[1]));
+ }
#endif
#if OMPT_SUPPORT
- __ompt_team_assign_id(team, ompt_parallel_id);
+ __ompt_team_assign_id(team, ompt_parallel_id);
#endif
- KMP_MB();
+ KMP_MB();
- return team;
- }
+ return team;
+ }
- /* next, let's try to take one from the team pool */
- KMP_MB();
- for( team = (kmp_team_t*) __kmp_team_pool ; (team) ; )
- {
- /* TODO: consider resizing undersized teams instead of reaping them, now that we have a resizing mechanism */
- if ( team->t.t_max_nproc >= max_nproc ) {
- /* take this team from the team pool */
- __kmp_team_pool = team->t.t_next_pool;
-
- /* setup the team for fresh use */
- __kmp_initialize_team( team, new_nproc, new_icvs, NULL );
-
- KA_TRACE( 20, ( "__kmp_allocate_team: setting task_team[0] %p and task_team[1] %p to NULL\n",
- &team->t.t_task_team[0], &team->t.t_task_team[1]) );
- team->t.t_task_team[0] = NULL;
- team->t.t_task_team[1] = NULL;
-
- /* reallocate space for arguments if necessary */
- __kmp_alloc_argv_entries( argc, team, TRUE );
- KMP_CHECK_UPDATE(team->t.t_argc, argc);
-
- KA_TRACE( 20, ("__kmp_allocate_team: team %d init arrived: join=%u, plain=%u\n",
- team->t.t_id, KMP_INIT_BARRIER_STATE, KMP_INIT_BARRIER_STATE ));
- { // Initialize barrier data.
- int b;
- for ( b = 0; b < bs_last_barrier; ++ b) {
- team->t.t_bar[ b ].b_arrived = KMP_INIT_BARRIER_STATE;
+ /* next, let's try to take one from the team pool */
+ KMP_MB();
+ for (team = (kmp_team_t *)__kmp_team_pool; (team);) {
+ /* TODO: consider resizing undersized teams instead of reaping them, now
+ that we have a resizing mechanism */
+ if (team->t.t_max_nproc >= max_nproc) {
+ /* take this team from the team pool */
+ __kmp_team_pool = team->t.t_next_pool;
+
+ /* setup the team for fresh use */
+ __kmp_initialize_team(team, new_nproc, new_icvs, NULL);
+
+ KA_TRACE(20, ("__kmp_allocate_team: setting task_team[0] %p and "
+ "task_team[1] %p to NULL\n",
+ &team->t.t_task_team[0], &team->t.t_task_team[1]));
+ team->t.t_task_team[0] = NULL;
+ team->t.t_task_team[1] = NULL;
+
+ /* reallocate space for arguments if necessary */
+ __kmp_alloc_argv_entries(argc, team, TRUE);
+ KMP_CHECK_UPDATE(team->t.t_argc, argc);
+
+ KA_TRACE(
+ 20, ("__kmp_allocate_team: team %d init arrived: join=%u, plain=%u\n",
+ team->t.t_id, KMP_INIT_BARRIER_STATE, KMP_INIT_BARRIER_STATE));
+ { // Initialize barrier data.
+ int b;
+ for (b = 0; b < bs_last_barrier; ++b) {
+ team->t.t_bar[b].b_arrived = KMP_INIT_BARRIER_STATE;
#if USE_DEBUGGER
- team->t.t_bar[ b ].b_master_arrived = 0;
- team->t.t_bar[ b ].b_team_arrived = 0;
+ team->t.t_bar[b].b_master_arrived = 0;
+ team->t.t_bar[b].b_team_arrived = 0;
#endif
- }
- }
+ }
+ }
#if OMP_40_ENABLED
- team->t.t_proc_bind = new_proc_bind;
+ team->t.t_proc_bind = new_proc_bind;
#endif
- KA_TRACE( 20, ("__kmp_allocate_team: using team from pool %d.\n", team->t.t_id ));
+ KA_TRACE(20, ("__kmp_allocate_team: using team from pool %d.\n",
+ team->t.t_id));
#if OMPT_SUPPORT
- __ompt_team_assign_id(team, ompt_parallel_id);
+ __ompt_team_assign_id(team, ompt_parallel_id);
#endif
- KMP_MB();
-
- return team;
- }
+ KMP_MB();
- /* reap team if it is too small, then loop back and check the next one */
- /* not sure if this is wise, but, will be redone during the hot-teams rewrite. */
- /* TODO: Use technique to find the right size hot-team, don't reap them */
- team = __kmp_reap_team( team );
- __kmp_team_pool = team;
+ return team;
}
- /* nothing available in the pool, no matter, make a new team! */
- KMP_MB();
- team = (kmp_team_t*) __kmp_allocate( sizeof( kmp_team_t ) );
+/* reap team if it is too small, then loop back and check the next one */
+// not sure if this is wise, but, will be redone during the hot-teams rewrite.
+/* TODO: Use technique to find the right size hot-team, don't reap them */
+ team = __kmp_reap_team(team);
+ __kmp_team_pool = team;
+ }
- /* and set it up */
- team->t.t_max_nproc = max_nproc;
- /* NOTE well, for some reason allocating one big buffer and dividing it
- * up seems to really hurt performance a lot on the P4, so, let's not use
- * this... */
- __kmp_allocate_team_arrays( team, max_nproc );
-
- KA_TRACE( 20, ( "__kmp_allocate_team: making a new team\n" ) );
- __kmp_initialize_team( team, new_nproc, new_icvs, NULL );
-
- KA_TRACE( 20, ( "__kmp_allocate_team: setting task_team[0] %p and task_team[1] %p to NULL\n",
- &team->t.t_task_team[0], &team->t.t_task_team[1] ) );
- team->t.t_task_team[0] = NULL; // to be removed, as __kmp_allocate zeroes memory, no need to duplicate
- team->t.t_task_team[1] = NULL; // to be removed, as __kmp_allocate zeroes memory, no need to duplicate
-
- if ( __kmp_storage_map ) {
- __kmp_print_team_storage_map( "team", team, team->t.t_id, new_nproc );
- }
-
- /* allocate space for arguments */
- __kmp_alloc_argv_entries( argc, team, FALSE );
- team->t.t_argc = argc;
-
- KA_TRACE( 20, ("__kmp_allocate_team: team %d init arrived: join=%u, plain=%u\n",
- team->t.t_id, KMP_INIT_BARRIER_STATE, KMP_INIT_BARRIER_STATE ));
- { // Initialize barrier data.
- int b;
- for ( b = 0; b < bs_last_barrier; ++ b ) {
- team->t.t_bar[ b ].b_arrived = KMP_INIT_BARRIER_STATE;
+ /* nothing available in the pool, no matter, make a new team! */
+ KMP_MB();
+ team = (kmp_team_t *)__kmp_allocate(sizeof(kmp_team_t));
+
+ /* and set it up */
+ team->t.t_max_nproc = max_nproc;
+ /* NOTE well, for some reason allocating one big buffer and dividing it up
+ seems to really hurt performance a lot on the P4, so, let's not use this */
+ __kmp_allocate_team_arrays(team, max_nproc);
+
+ KA_TRACE(20, ("__kmp_allocate_team: making a new team\n"));
+ __kmp_initialize_team(team, new_nproc, new_icvs, NULL);
+
+ KA_TRACE(20, ("__kmp_allocate_team: setting task_team[0] %p and task_team[1] "
+ "%p to NULL\n",
+ &team->t.t_task_team[0], &team->t.t_task_team[1]));
+ team->t.t_task_team[0] = NULL; // to be removed, as __kmp_allocate zeroes
+ // memory, no need to duplicate
+ team->t.t_task_team[1] = NULL; // to be removed, as __kmp_allocate zeroes
+ // memory, no need to duplicate
+
+ if (__kmp_storage_map) {
+ __kmp_print_team_storage_map("team", team, team->t.t_id, new_nproc);
+ }
+
+ /* allocate space for arguments */
+ __kmp_alloc_argv_entries(argc, team, FALSE);
+ team->t.t_argc = argc;
+
+ KA_TRACE(20,
+ ("__kmp_allocate_team: team %d init arrived: join=%u, plain=%u\n",
+ team->t.t_id, KMP_INIT_BARRIER_STATE, KMP_INIT_BARRIER_STATE));
+ { // Initialize barrier data.
+ int b;
+ for (b = 0; b < bs_last_barrier; ++b) {
+ team->t.t_bar[b].b_arrived = KMP_INIT_BARRIER_STATE;
#if USE_DEBUGGER
- team->t.t_bar[ b ].b_master_arrived = 0;
- team->t.t_bar[ b ].b_team_arrived = 0;
+ team->t.t_bar[b].b_master_arrived = 0;
+ team->t.t_bar[b].b_team_arrived = 0;
#endif
- }
}
+ }
#if OMP_40_ENABLED
- team->t.t_proc_bind = new_proc_bind;
+ team->t.t_proc_bind = new_proc_bind;
#endif
#if OMPT_SUPPORT
- __ompt_team_assign_id(team, ompt_parallel_id);
- team->t.ompt_serialized_team_info = NULL;
+ __ompt_team_assign_id(team, ompt_parallel_id);
+ team->t.ompt_serialized_team_info = NULL;
#endif
- KMP_MB();
+ KMP_MB();
- KA_TRACE( 20, ("__kmp_allocate_team: done creating a new team %d.\n", team->t.t_id ));
+ KA_TRACE(20, ("__kmp_allocate_team: done creating a new team %d.\n",
+ team->t.t_id));
- return team;
+ return team;
}
/* TODO implement hot-teams at all levels */
@@ -5224,136 +5231,138 @@ __kmp_allocate_team( kmp_root_t *root, i
/* free the team. return it to the team pool. release all the threads
* associated with it */
-void
-__kmp_free_team( kmp_root_t *root, kmp_team_t *team USE_NESTED_HOT_ARG(kmp_info_t *master) )
-{
- int f;
- KA_TRACE( 20, ("__kmp_free_team: T#%d freeing team %d\n", __kmp_get_gtid(), team->t.t_id ));
-
- /* verify state */
- KMP_DEBUG_ASSERT( root );
- KMP_DEBUG_ASSERT( team );
- KMP_DEBUG_ASSERT( team->t.t_nproc <= team->t.t_max_nproc );
- KMP_DEBUG_ASSERT( team->t.t_threads );
+void __kmp_free_team(kmp_root_t *root,
+ kmp_team_t *team USE_NESTED_HOT_ARG(kmp_info_t *master)) {
+ int f;
+ KA_TRACE(20, ("__kmp_free_team: T#%d freeing team %d\n", __kmp_get_gtid(),
+ team->t.t_id));
+
+ /* verify state */
+ KMP_DEBUG_ASSERT(root);
+ KMP_DEBUG_ASSERT(team);
+ KMP_DEBUG_ASSERT(team->t.t_nproc <= team->t.t_max_nproc);
+ KMP_DEBUG_ASSERT(team->t.t_threads);
- int use_hot_team = team == root->r.r_hot_team;
+ int use_hot_team = team == root->r.r_hot_team;
#if KMP_NESTED_HOT_TEAMS
- int level;
- kmp_hot_team_ptr_t *hot_teams;
- if( master ) {
- level = team->t.t_active_level - 1;
- if( master->th.th_teams_microtask ) { // in teams construct?
- if( master->th.th_teams_size.nteams > 1 ) {
- ++level; // level was not increased in teams construct for team_of_masters
- }
- if( team->t.t_pkfn != (microtask_t)__kmp_teams_master &&
- master->th.th_teams_level == team->t.t_level ) {
- ++level; // level was not increased in teams construct for team_of_workers before the parallel
- } // team->t.t_level will be increased inside parallel
- }
- hot_teams = master->th.th_hot_teams;
- if( level < __kmp_hot_teams_max_level ) {
- KMP_DEBUG_ASSERT( team == hot_teams[level].hot_team );
- use_hot_team = 1;
- }
+ int level;
+ kmp_hot_team_ptr_t *hot_teams;
+ if (master) {
+ level = team->t.t_active_level - 1;
+ if (master->th.th_teams_microtask) { // in teams construct?
+ if (master->th.th_teams_size.nteams > 1) {
+ ++level; // level was not increased in teams construct for
+ // team_of_masters
+ }
+ if (team->t.t_pkfn != (microtask_t)__kmp_teams_master &&
+ master->th.th_teams_level == team->t.t_level) {
+ ++level; // level was not increased in teams construct for
+ // team_of_workers before the parallel
+ } // team->t.t_level will be increased inside parallel
+ }
+ hot_teams = master->th.th_hot_teams;
+ if (level < __kmp_hot_teams_max_level) {
+ KMP_DEBUG_ASSERT(team == hot_teams[level].hot_team);
+ use_hot_team = 1;
}
+ }
#endif // KMP_NESTED_HOT_TEAMS
- /* team is done working */
- TCW_SYNC_PTR(team->t.t_pkfn, NULL); // Important for Debugging Support Library.
- team->t.t_copyin_counter = 0; // init counter for possible reuse
- // Do not reset pointer to parent team to NULL for hot teams.
-
- /* if we are non-hot team, release our threads */
- if( ! use_hot_team ) {
- if (__kmp_tasking_mode != tskm_immediate_exec) {
- // Wait for threads to reach reapable state
- for (f = 1; f < team->t.t_nproc; ++f) {
- KMP_DEBUG_ASSERT(team->t.t_threads[f]);
- kmp_info_t *th = team->t.t_threads[f];
- volatile kmp_uint32 *state = &th->th.th_reap_state;
- while (*state != KMP_SAFE_TO_REAP) {
+ /* team is done working */
+ TCW_SYNC_PTR(team->t.t_pkfn,
+ NULL); // Important for Debugging Support Library.
+ team->t.t_copyin_counter = 0; // init counter for possible reuse
+ // Do not reset pointer to parent team to NULL for hot teams.
+
+ /* if we are non-hot team, release our threads */
+ if (!use_hot_team) {
+ if (__kmp_tasking_mode != tskm_immediate_exec) {
+ // Wait for threads to reach reapable state
+ for (f = 1; f < team->t.t_nproc; ++f) {
+ KMP_DEBUG_ASSERT(team->t.t_threads[f]);
+ kmp_info_t *th = team->t.t_threads[f];
+ volatile kmp_uint32 *state = &th->th.th_reap_state;
+ while (*state != KMP_SAFE_TO_REAP) {
#if KMP_OS_WINDOWS
- // On Windows a thread can be killed at any time, check this
- DWORD ecode;
- if (!__kmp_is_thread_alive(th, &ecode)) {
- *state = KMP_SAFE_TO_REAP; // reset the flag for dead thread
- break;
- }
-#endif
- // first check if thread is sleeping
- kmp_flag_64 fl(&th->th.th_bar[bs_forkjoin_barrier].bb.b_go, th);
- if (fl.is_sleeping())
- fl.resume(__kmp_gtid_from_thread(th));
- KMP_CPU_PAUSE();
- }
- }
-
- // Delete task teams
- int tt_idx;
- for (tt_idx=0; tt_idx<2; ++tt_idx) {
- kmp_task_team_t *task_team = team->t.t_task_team[tt_idx];
- if ( task_team != NULL ) {
- for (f=0; f<team->t.t_nproc; ++f) { // Have all threads unref task teams
- team->t.t_threads[f]->th.th_task_team = NULL;
- }
- KA_TRACE( 20, ( "__kmp_free_team: T#%d deactivating task_team %p on team %d\n", __kmp_get_gtid(), task_team, team->t.t_id ) );
+ // On Windows a thread can be killed at any time, check this
+ DWORD ecode;
+ if (!__kmp_is_thread_alive(th, &ecode)) {
+ *state = KMP_SAFE_TO_REAP; // reset the flag for dead thread
+ break;
+ }
+#endif
+ // first check if thread is sleeping
+ kmp_flag_64 fl(&th->th.th_bar[bs_forkjoin_barrier].bb.b_go, th);
+ if (fl.is_sleeping())
+ fl.resume(__kmp_gtid_from_thread(th));
+ KMP_CPU_PAUSE();
+ }
+ }
+
+ // Delete task teams
+ int tt_idx;
+ for (tt_idx = 0; tt_idx < 2; ++tt_idx) {
+ kmp_task_team_t *task_team = team->t.t_task_team[tt_idx];
+ if (task_team != NULL) {
+ for (f = 0; f < team->t.t_nproc;
+ ++f) { // Have all threads unref task teams
+ team->t.t_threads[f]->th.th_task_team = NULL;
+ }
+ KA_TRACE(
+ 20,
+ ("__kmp_free_team: T#%d deactivating task_team %p on team %d\n",
+ __kmp_get_gtid(), task_team, team->t.t_id));
#if KMP_NESTED_HOT_TEAMS
- __kmp_free_task_team( master, task_team );
+ __kmp_free_task_team(master, task_team);
#endif
- team->t.t_task_team[tt_idx] = NULL;
- }
- }
+ team->t.t_task_team[tt_idx] = NULL;
}
+ }
+ }
- // Reset pointer to parent team only for non-hot teams.
- team->t.t_parent = NULL;
- team->t.t_level = 0;
- team->t.t_active_level = 0;
-
- /* free the worker threads */
- for ( f = 1; f < team->t.t_nproc; ++ f ) {
- KMP_DEBUG_ASSERT( team->t.t_threads[ f ] );
- __kmp_free_thread( team->t.t_threads[ f ] );
- team->t.t_threads[ f ] = NULL;
- }
+ // Reset pointer to parent team only for non-hot teams.
+ team->t.t_parent = NULL;
+ team->t.t_level = 0;
+ team->t.t_active_level = 0;
- /* put the team back in the team pool */
- /* TODO limit size of team pool, call reap_team if pool too large */
- team->t.t_next_pool = (kmp_team_t*) __kmp_team_pool;
- __kmp_team_pool = (volatile kmp_team_t*) team;
+ /* free the worker threads */
+ for (f = 1; f < team->t.t_nproc; ++f) {
+ KMP_DEBUG_ASSERT(team->t.t_threads[f]);
+ __kmp_free_thread(team->t.t_threads[f]);
+ team->t.t_threads[f] = NULL;
}
- KMP_MB();
-}
+ /* put the team back in the team pool */
+ /* TODO limit size of team pool, call reap_team if pool too large */
+ team->t.t_next_pool = (kmp_team_t *)__kmp_team_pool;
+ __kmp_team_pool = (volatile kmp_team_t *)team;
+ }
+ KMP_MB();
+}
/* reap the team. destroy it, reclaim all its resources and free its memory */
-kmp_team_t *
-__kmp_reap_team( kmp_team_t *team )
-{
- kmp_team_t *next_pool = team->t.t_next_pool;
-
- KMP_DEBUG_ASSERT( team );
- KMP_DEBUG_ASSERT( team->t.t_dispatch );
- KMP_DEBUG_ASSERT( team->t.t_disp_buffer );
- KMP_DEBUG_ASSERT( team->t.t_threads );
- KMP_DEBUG_ASSERT( team->t.t_argv );
-
- /* TODO clean the threads that are a part of this? */
-
- /* free stuff */
-
- __kmp_free_team_arrays( team );
- if ( team->t.t_argv != &team->t.t_inline_argv[0] )
- __kmp_free( (void*) team->t.t_argv );
- __kmp_free( team );
+kmp_team_t *__kmp_reap_team(kmp_team_t *team) {
+ kmp_team_t *next_pool = team->t.t_next_pool;
- KMP_MB();
- return next_pool;
+ KMP_DEBUG_ASSERT(team);
+ KMP_DEBUG_ASSERT(team->t.t_dispatch);
+ KMP_DEBUG_ASSERT(team->t.t_disp_buffer);
+ KMP_DEBUG_ASSERT(team->t.t_threads);
+ KMP_DEBUG_ASSERT(team->t.t_argv);
+
+ /* TODO clean the threads that are a part of this? */
+
+ /* free stuff */
+ __kmp_free_team_arrays(team);
+ if (team->t.t_argv != &team->t.t_inline_argv[0])
+ __kmp_free((void *)team->t.t_argv);
+ __kmp_free(team);
+
+ KMP_MB();
+ return next_pool;
}
-//
// Free the thread. Don't reap it, just place it on the pool of available
// threads.
//
@@ -5379,2343 +5388,2248 @@ __kmp_reap_team( kmp_team_t *team )
// grew and shrunk.
//
// Now, for single-level parallelism, the OMP tid is alway == gtid.
-//
-void
-__kmp_free_thread( kmp_info_t *this_th )
-{
- int gtid;
- kmp_info_t **scan;
-
- KA_TRACE( 20, ("__kmp_free_thread: T#%d putting T#%d back on free pool.\n",
- __kmp_get_gtid(), this_th->th.th_info.ds.ds_gtid ));
-
- KMP_DEBUG_ASSERT( this_th );
-
- // When moving thread to pool, switch thread to wait on own b_go flag, and uninitialized (NULL team).
- int b;
- kmp_balign_t *balign = this_th->th.th_bar;
- for (b=0; b<bs_last_barrier; ++b) {
- if (balign[b].bb.wait_flag == KMP_BARRIER_PARENT_FLAG)
- balign[b].bb.wait_flag = KMP_BARRIER_SWITCH_TO_OWN_FLAG;
- balign[b].bb.team = NULL;
- balign[b].bb.leaf_kids = 0;
- }
- this_th->th.th_task_state = 0;
-
- /* put thread back on the free pool */
- TCW_PTR(this_th->th.th_team, NULL);
- TCW_PTR(this_th->th.th_root, NULL);
- TCW_PTR(this_th->th.th_dispatch, NULL); /* NOT NEEDED */
-
- //
- // If the __kmp_thread_pool_insert_pt is already past the new insert
- // point, then we need to re-scan the entire list.
- //
- gtid = this_th->th.th_info.ds.ds_gtid;
- if ( __kmp_thread_pool_insert_pt != NULL ) {
- KMP_DEBUG_ASSERT( __kmp_thread_pool != NULL );
- if ( __kmp_thread_pool_insert_pt->th.th_info.ds.ds_gtid > gtid ) {
- __kmp_thread_pool_insert_pt = NULL;
- }
- }
+void __kmp_free_thread(kmp_info_t *this_th) {
+ int gtid;
+ kmp_info_t **scan;
+
+ KA_TRACE(20, ("__kmp_free_thread: T#%d putting T#%d back on free pool.\n",
+ __kmp_get_gtid(), this_th->th.th_info.ds.ds_gtid));
+
+ KMP_DEBUG_ASSERT(this_th);
+
+ // When moving thread to pool, switch thread to wait on own b_go flag, and
+ // uninitialized (NULL team).
+ int b;
+ kmp_balign_t *balign = this_th->th.th_bar;
+ for (b = 0; b < bs_last_barrier; ++b) {
+ if (balign[b].bb.wait_flag == KMP_BARRIER_PARENT_FLAG)
+ balign[b].bb.wait_flag = KMP_BARRIER_SWITCH_TO_OWN_FLAG;
+ balign[b].bb.team = NULL;
+ balign[b].bb.leaf_kids = 0;
+ }
+ this_th->th.th_task_state = 0;
+
+ /* put thread back on the free pool */
+ TCW_PTR(this_th->th.th_team, NULL);
+ TCW_PTR(this_th->th.th_root, NULL);
+ TCW_PTR(this_th->th.th_dispatch, NULL); /* NOT NEEDED */
+
+ // If the __kmp_thread_pool_insert_pt is already past the new insert
+ // point, then we need to re-scan the entire list.
+ gtid = this_th->th.th_info.ds.ds_gtid;
+ if (__kmp_thread_pool_insert_pt != NULL) {
+ KMP_DEBUG_ASSERT(__kmp_thread_pool != NULL);
+ if (__kmp_thread_pool_insert_pt->th.th_info.ds.ds_gtid > gtid) {
+ __kmp_thread_pool_insert_pt = NULL;
+ }
+ }
+
+ // Scan down the list to find the place to insert the thread.
+ // scan is the address of a link in the list, possibly the address of
+ // __kmp_thread_pool itself.
+ //
+ // In the absence of nested parallism, the for loop will have 0 iterations.
+ if (__kmp_thread_pool_insert_pt != NULL) {
+ scan = &(__kmp_thread_pool_insert_pt->th.th_next_pool);
+ } else {
+ scan = (kmp_info_t **)&__kmp_thread_pool;
+ }
+ for (; (*scan != NULL) && ((*scan)->th.th_info.ds.ds_gtid < gtid);
+ scan = &((*scan)->th.th_next_pool))
+ ;
+
+ // Insert the new element on the list, and set __kmp_thread_pool_insert_pt
+ // to its address.
+ TCW_PTR(this_th->th.th_next_pool, *scan);
+ __kmp_thread_pool_insert_pt = *scan = this_th;
+ KMP_DEBUG_ASSERT((this_th->th.th_next_pool == NULL) ||
+ (this_th->th.th_info.ds.ds_gtid <
+ this_th->th.th_next_pool->th.th_info.ds.ds_gtid));
+ TCW_4(this_th->th.th_in_pool, TRUE);
+ __kmp_thread_pool_nth++;
- //
- // Scan down the list to find the place to insert the thread.
- // scan is the address of a link in the list, possibly the address of
- // __kmp_thread_pool itself.
- //
- // In the absence of nested parallism, the for loop will have 0 iterations.
- //
- if ( __kmp_thread_pool_insert_pt != NULL ) {
- scan = &( __kmp_thread_pool_insert_pt->th.th_next_pool );
- }
- else {
- scan = (kmp_info_t **)&__kmp_thread_pool;
- }
- for (; ( *scan != NULL ) && ( (*scan)->th.th_info.ds.ds_gtid < gtid );
- scan = &( (*scan)->th.th_next_pool ) );
-
- //
- // Insert the new element on the list, and set __kmp_thread_pool_insert_pt
- // to its address.
- //
- TCW_PTR(this_th->th.th_next_pool, *scan);
- __kmp_thread_pool_insert_pt = *scan = this_th;
- KMP_DEBUG_ASSERT( ( this_th->th.th_next_pool == NULL )
- || ( this_th->th.th_info.ds.ds_gtid
- < this_th->th.th_next_pool->th.th_info.ds.ds_gtid ) );
- TCW_4(this_th->th.th_in_pool, TRUE);
- __kmp_thread_pool_nth++;
-
- TCW_4(__kmp_nth, __kmp_nth - 1);
+ TCW_4(__kmp_nth, __kmp_nth - 1);
#ifdef KMP_ADJUST_BLOCKTIME
- /* Adjust blocktime back to user setting or default if necessary */
- /* Middle initialization might never have occurred */
- if ( !__kmp_env_blocktime && ( __kmp_avail_proc > 0 ) ) {
- KMP_DEBUG_ASSERT( __kmp_avail_proc > 0 );
- if ( __kmp_nth <= __kmp_avail_proc ) {
- __kmp_zero_bt = FALSE;
- }
+ /* Adjust blocktime back to user setting or default if necessary */
+ /* Middle initialization might never have occurred */
+ if (!__kmp_env_blocktime && (__kmp_avail_proc > 0)) {
+ KMP_DEBUG_ASSERT(__kmp_avail_proc > 0);
+ if (__kmp_nth <= __kmp_avail_proc) {
+ __kmp_zero_bt = FALSE;
}
+ }
#endif /* KMP_ADJUST_BLOCKTIME */
- KMP_MB();
+ KMP_MB();
}
-
/* ------------------------------------------------------------------------ */
-void *
-__kmp_launch_thread( kmp_info_t *this_thr )
-{
- int gtid = this_thr->th.th_info.ds.ds_gtid;
-/* void *stack_data;*/
- kmp_team_t *(*volatile pteam);
+void *__kmp_launch_thread(kmp_info_t *this_thr) {
+ int gtid = this_thr->th.th_info.ds.ds_gtid;
+ /* void *stack_data;*/
+ kmp_team_t *(*volatile pteam);
- KMP_MB();
- KA_TRACE( 10, ("__kmp_launch_thread: T#%d start\n", gtid ) );
+ KMP_MB();
+ KA_TRACE(10, ("__kmp_launch_thread: T#%d start\n", gtid));
- if( __kmp_env_consistency_check ) {
- this_thr->th.th_cons = __kmp_allocate_cons_stack( gtid ); // ATT: Memory leak?
- }
+ if (__kmp_env_consistency_check) {
+ this_thr->th.th_cons = __kmp_allocate_cons_stack(gtid); // ATT: Memory leak?
+ }
#if OMPT_SUPPORT
- if (ompt_enabled) {
- this_thr->th.ompt_thread_info.state = ompt_state_overhead;
- this_thr->th.ompt_thread_info.wait_id = 0;
- this_thr->th.ompt_thread_info.idle_frame = __builtin_frame_address(0);
- if (ompt_callbacks.ompt_callback(ompt_event_thread_begin)) {
- __ompt_thread_begin(ompt_thread_worker, gtid);
- }
+ if (ompt_enabled) {
+ this_thr->th.ompt_thread_info.state = ompt_state_overhead;
+ this_thr->th.ompt_thread_info.wait_id = 0;
+ this_thr->th.ompt_thread_info.idle_frame = __builtin_frame_address(0);
+ if (ompt_callbacks.ompt_callback(ompt_event_thread_begin)) {
+ __ompt_thread_begin(ompt_thread_worker, gtid);
}
+ }
#endif
- /* This is the place where threads wait for work */
- while( ! TCR_4(__kmp_global.g.g_done) ) {
- KMP_DEBUG_ASSERT( this_thr == __kmp_threads[ gtid ] );
- KMP_MB();
+ /* This is the place where threads wait for work */
+ while (!TCR_4(__kmp_global.g.g_done)) {
+ KMP_DEBUG_ASSERT(this_thr == __kmp_threads[gtid]);
+ KMP_MB();
- /* wait for work to do */
- KA_TRACE( 20, ("__kmp_launch_thread: T#%d waiting for work\n", gtid ));
+ /* wait for work to do */
+ KA_TRACE(20, ("__kmp_launch_thread: T#%d waiting for work\n", gtid));
#if OMPT_SUPPORT
- if (ompt_enabled) {
- this_thr->th.ompt_thread_info.state = ompt_state_idle;
- }
+ if (ompt_enabled) {
+ this_thr->th.ompt_thread_info.state = ompt_state_idle;
+ }
#endif
- /* No tid yet since not part of a team */
- __kmp_fork_barrier( gtid, KMP_GTID_DNE );
+ /* No tid yet since not part of a team */
+ __kmp_fork_barrier(gtid, KMP_GTID_DNE);
#if OMPT_SUPPORT
- if (ompt_enabled) {
- this_thr->th.ompt_thread_info.state = ompt_state_overhead;
- }
+ if (ompt_enabled) {
+ this_thr->th.ompt_thread_info.state = ompt_state_overhead;
+ }
#endif
- pteam = (kmp_team_t *(*))(& this_thr->th.th_team);
+ pteam = (kmp_team_t * (*))(&this_thr->th.th_team);
- /* have we been allocated? */
- if ( TCR_SYNC_PTR(*pteam) && !TCR_4(__kmp_global.g.g_done) ) {
+ /* have we been allocated? */
+ if (TCR_SYNC_PTR(*pteam) && !TCR_4(__kmp_global.g.g_done)) {
#if OMPT_SUPPORT
- ompt_task_info_t *task_info;
- ompt_parallel_id_t my_parallel_id;
- if (ompt_enabled) {
- task_info = __ompt_get_taskinfo(0);
- my_parallel_id = (*pteam)->t.ompt_team_info.parallel_id;
- }
+ ompt_task_info_t *task_info;
+ ompt_parallel_id_t my_parallel_id;
+ if (ompt_enabled) {
+ task_info = __ompt_get_taskinfo(0);
+ my_parallel_id = (*pteam)->t.ompt_team_info.parallel_id;
+ }
#endif
- /* we were just woken up, so run our new task */
- if ( TCR_SYNC_PTR((*pteam)->t.t_pkfn) != NULL ) {
- int rc;
- KA_TRACE(20, ("__kmp_launch_thread: T#%d(%d:%d) invoke microtask = %p\n",
- gtid, (*pteam)->t.t_id, __kmp_tid_from_gtid(gtid), (*pteam)->t.t_pkfn));
+ /* we were just woken up, so run our new task */
+ if (TCR_SYNC_PTR((*pteam)->t.t_pkfn) != NULL) {
+ int rc;
+ KA_TRACE(20,
+ ("__kmp_launch_thread: T#%d(%d:%d) invoke microtask = %p\n",
+ gtid, (*pteam)->t.t_id, __kmp_tid_from_gtid(gtid),
+ (*pteam)->t.t_pkfn));
- updateHWFPControl (*pteam);
+ updateHWFPControl(*pteam);
#if OMPT_SUPPORT
- if (ompt_enabled) {
- this_thr->th.ompt_thread_info.state = ompt_state_work_parallel;
- // Initialize OMPT task id for implicit task.
- int tid = __kmp_tid_from_gtid(gtid);
- task_info->task_id = __ompt_task_id_new(tid);
- }
+ if (ompt_enabled) {
+ this_thr->th.ompt_thread_info.state = ompt_state_work_parallel;
+ // Initialize OMPT task id for implicit task.
+ int tid = __kmp_tid_from_gtid(gtid);
+ task_info->task_id = __ompt_task_id_new(tid);
+ }
#endif
- {
- KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
- KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
- rc = (*pteam)->t.t_invoke( gtid );
- }
- KMP_ASSERT( rc );
+ {
+ KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
+ KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
+ rc = (*pteam)->t.t_invoke(gtid);
+ }
+ KMP_ASSERT(rc);
#if OMPT_SUPPORT
- if (ompt_enabled) {
- /* no frame set while outside task */
- task_info->frame.exit_runtime_frame = NULL;
+ if (ompt_enabled) {
+ /* no frame set while outside task */
+ task_info->frame.exit_runtime_frame = NULL;
- this_thr->th.ompt_thread_info.state = ompt_state_overhead;
- }
+ this_thr->th.ompt_thread_info.state = ompt_state_overhead;
+ }
#endif
- KMP_MB();
- KA_TRACE(20, ("__kmp_launch_thread: T#%d(%d:%d) done microtask = %p\n",
- gtid, (*pteam)->t.t_id, __kmp_tid_from_gtid(gtid), (*pteam)->t.t_pkfn));
- }
- /* join barrier after parallel region */
- __kmp_join_barrier( gtid );
+ KMP_MB();
+ KA_TRACE(20, ("__kmp_launch_thread: T#%d(%d:%d) done microtask = %p\n",
+ gtid, (*pteam)->t.t_id, __kmp_tid_from_gtid(gtid),
+ (*pteam)->t.t_pkfn));
+ }
+ /* join barrier after parallel region */
+ __kmp_join_barrier(gtid);
#if OMPT_SUPPORT && OMPT_TRACE
- if (ompt_enabled) {
- if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
- // don't access *pteam here: it may have already been freed
- // by the master thread behind the barrier (possible race)
- ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
- my_parallel_id, task_info->task_id);
- }
- task_info->frame.exit_runtime_frame = NULL;
- task_info->task_id = 0;
- }
-#endif
+ if (ompt_enabled) {
+ if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
+ // don't access *pteam here: it may have already been freed
+ // by the master thread behind the barrier (possible race)
+ ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
+ my_parallel_id, task_info->task_id);
}
+ task_info->frame.exit_runtime_frame = NULL;
+ task_info->task_id = 0;
+ }
+#endif
}
- TCR_SYNC_PTR((intptr_t)__kmp_global.g.g_done);
+ }
+ TCR_SYNC_PTR((intptr_t)__kmp_global.g.g_done);
#if OMPT_SUPPORT
- if (ompt_enabled &&
- ompt_callbacks.ompt_callback(ompt_event_thread_end)) {
- __ompt_thread_end(ompt_thread_worker, gtid);
- }
+ if (ompt_enabled && ompt_callbacks.ompt_callback(ompt_event_thread_end)) {
+ __ompt_thread_end(ompt_thread_worker, gtid);
+ }
#endif
- this_thr->th.th_task_team = NULL;
- /* run the destructors for the threadprivate data for this thread */
- __kmp_common_destroy_gtid( gtid );
+ this_thr->th.th_task_team = NULL;
+ /* run the destructors for the threadprivate data for this thread */
+ __kmp_common_destroy_gtid(gtid);
- KA_TRACE( 10, ("__kmp_launch_thread: T#%d done\n", gtid ) );
- KMP_MB();
- return this_thr;
+ KA_TRACE(10, ("__kmp_launch_thread: T#%d done\n", gtid));
+ KMP_MB();
+ return this_thr;
}
/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
-void
-__kmp_internal_end_dest( void *specific_gtid )
-{
- #if KMP_COMPILER_ICC
- #pragma warning( push )
- #pragma warning( disable: 810 ) // conversion from "void *" to "int" may lose significant bits
- #endif
- // Make sure no significant bits are lost
- int gtid = (kmp_intptr_t)specific_gtid - 1;
- #if KMP_COMPILER_ICC
- #pragma warning( pop )
- #endif
-
- KA_TRACE( 30, ("__kmp_internal_end_dest: T#%d\n", gtid));
- /* NOTE: the gtid is stored as gitd+1 in the thread-local-storage
- * this is because 0 is reserved for the nothing-stored case */
-
- /* josh: One reason for setting the gtid specific data even when it is being
- destroyed by pthread is to allow gtid lookup through thread specific data
- (__kmp_gtid_get_specific). Some of the code, especially stat code,
- that gets executed in the call to __kmp_internal_end_thread, actually
- gets the gtid through the thread specific data. Setting it here seems
- rather inelegant and perhaps wrong, but allows __kmp_internal_end_thread
- to run smoothly.
- todo: get rid of this after we remove the dependence on
- __kmp_gtid_get_specific
- */
- if(gtid >= 0 && KMP_UBER_GTID(gtid))
- __kmp_gtid_set_specific( gtid );
- #ifdef KMP_TDATA_GTID
- __kmp_gtid = gtid;
- #endif
- __kmp_internal_end_thread( gtid );
+void __kmp_internal_end_dest(void *specific_gtid) {
+#if KMP_COMPILER_ICC
+#pragma warning(push)
+#pragma warning(disable : 810) // conversion from "void *" to "int" may lose
+// significant bits
+#endif
+ // Make sure no significant bits are lost
+ int gtid = (kmp_intptr_t)specific_gtid - 1;
+#if KMP_COMPILER_ICC
+#pragma warning(pop)
+#endif
+
+ KA_TRACE(30, ("__kmp_internal_end_dest: T#%d\n", gtid));
+ /* NOTE: the gtid is stored as gitd+1 in the thread-local-storage
+ * this is because 0 is reserved for the nothing-stored case */
+
+ /* josh: One reason for setting the gtid specific data even when it is being
+ destroyed by pthread is to allow gtid lookup through thread specific data
+ (__kmp_gtid_get_specific). Some of the code, especially stat code,
+ that gets executed in the call to __kmp_internal_end_thread, actually
+ gets the gtid through the thread specific data. Setting it here seems
+ rather inelegant and perhaps wrong, but allows __kmp_internal_end_thread
+ to run smoothly.
+ todo: get rid of this after we remove the dependence on
+ __kmp_gtid_get_specific */
+ if (gtid >= 0 && KMP_UBER_GTID(gtid))
+ __kmp_gtid_set_specific(gtid);
+#ifdef KMP_TDATA_GTID
+ __kmp_gtid = gtid;
+#endif
+ __kmp_internal_end_thread(gtid);
}
#if KMP_OS_UNIX && KMP_DYNAMIC_LIB
-// 2009-09-08 (lev): It looks the destructor does not work. In simple test cases destructors work
-// perfectly, but in real libomp.so I have no evidence it is ever called. However, -fini linker
-// option in makefile.mk works fine.
-
-__attribute__(( destructor ))
-void
-__kmp_internal_end_dtor( void )
-{
- __kmp_internal_end_atexit();
-}
-
-void
-__kmp_internal_end_fini( void )
-{
- __kmp_internal_end_atexit();
-}
+// 2009-09-08 (lev): It looks the destructor does not work. In simple test cases
+// destructors work perfectly, but in real libomp.so I have no evidence it is
+// ever called. However, -fini linker option in makefile.mk works fine.
+
+__attribute__((destructor)) void __kmp_internal_end_dtor(void) {
+ __kmp_internal_end_atexit();
+}
+
+void __kmp_internal_end_fini(void) { __kmp_internal_end_atexit(); }
#endif
-/* [Windows] josh: when the atexit handler is called, there may still be more than one thread alive */
-void
-__kmp_internal_end_atexit( void )
-{
- KA_TRACE( 30, ( "__kmp_internal_end_atexit\n" ) );
- /* [Windows]
- josh: ideally, we want to completely shutdown the library in this atexit handler, but
- stat code that depends on thread specific data for gtid fails because that data becomes
- unavailable at some point during the shutdown, so we call __kmp_internal_end_thread
- instead. We should eventually remove the dependency on __kmp_get_specific_gtid in the
- stat code and use __kmp_internal_end_library to cleanly shutdown the library.
-
-// TODO: Can some of this comment about GVS be removed?
- I suspect that the offending stat code is executed when the calling thread tries to
- clean up a dead root thread's data structures, resulting in GVS code trying to close
- the GVS structures for that thread, but since the stat code uses
- __kmp_get_specific_gtid to get the gtid with the assumption that the calling thread is
- cleaning up itself instead of another thread, it gets confused. This happens because
- allowing a thread to unregister and cleanup another thread is a recent modification for
- addressing an issue with Maxon Cinema4D. Based on the current design (20050722), a
- thread may end up trying to unregister another thread only if thread death does not
- trigger the calling of __kmp_internal_end_thread. For Linux* OS, there is the thread
- specific data destructor function to detect thread death. For Windows dynamic, there
- is DllMain(THREAD_DETACH). For Windows static, there is nothing. Thus, the
- workaround is applicable only for Windows static stat library.
- */
- __kmp_internal_end_library( -1 );
- #if KMP_OS_WINDOWS
- __kmp_close_console();
- #endif
+/* [Windows] josh: when the atexit handler is called, there may still be more
+ than one thread alive */
+void __kmp_internal_end_atexit(void) {
+ KA_TRACE(30, ("__kmp_internal_end_atexit\n"));
+ /* [Windows]
+ josh: ideally, we want to completely shutdown the library in this atexit
+ handler, but stat code that depends on thread specific data for gtid fails
+ because that data becomes unavailable at some point during the shutdown, so
+ we call __kmp_internal_end_thread instead. We should eventually remove the
+ dependency on __kmp_get_specific_gtid in the stat code and use
+ __kmp_internal_end_library to cleanly shutdown the library.
+
+ // TODO: Can some of this comment about GVS be removed?
+ I suspect that the offending stat code is executed when the calling thread
+ tries to clean up a dead root thread's data structures, resulting in GVS
+ code trying to close the GVS structures for that thread, but since the stat
+ code uses __kmp_get_specific_gtid to get the gtid with the assumption that
+ the calling thread is cleaning up itself instead of another thread, it get
+ confused. This happens because allowing a thread to unregister and cleanup
+ another thread is a recent modification for addressing an issue.
+ Based on the current design (20050722), a thread may end up
+ trying to unregister another thread only if thread death does not trigger
+ the calling of __kmp_internal_end_thread. For Linux* OS, there is the
+ thread specific data destructor function to detect thread death. For
+ Windows dynamic, there is DllMain(THREAD_DETACH). For Windows static, there
+ is nothing. Thus, the workaround is applicable only for Windows static
+ stat library. */
+ __kmp_internal_end_library(-1);
+#if KMP_OS_WINDOWS
+ __kmp_close_console();
+#endif
}
-static void
-__kmp_reap_thread(
- kmp_info_t * thread,
- int is_root
-) {
-
- // It is assumed __kmp_forkjoin_lock is acquired.
+static void __kmp_reap_thread(kmp_info_t *thread, int is_root) {
+ // It is assumed __kmp_forkjoin_lock is acquired.
- int gtid;
+ int gtid;
- KMP_DEBUG_ASSERT( thread != NULL );
+ KMP_DEBUG_ASSERT(thread != NULL);
- gtid = thread->th.th_info.ds.ds_gtid;
+ gtid = thread->th.th_info.ds.ds_gtid;
- if ( ! is_root ) {
+ if (!is_root) {
- if ( __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME ) {
- /* Assume the threads are at the fork barrier here */
- KA_TRACE( 20, ("__kmp_reap_thread: releasing T#%d from fork barrier for reap\n", gtid ) );
- /* Need release fence here to prevent seg faults for tree forkjoin barrier (GEH) */
- ANNOTATE_HAPPENS_BEFORE(thread);
- kmp_flag_64 flag(&thread->th.th_bar[ bs_forkjoin_barrier ].bb.b_go, thread);
- __kmp_release_64(&flag);
- }; // if
+ if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
+ /* Assume the threads are at the fork barrier here */
+ KA_TRACE(
+ 20, ("__kmp_reap_thread: releasing T#%d from fork barrier for reap\n",
+ gtid));
+ /* Need release fence here to prevent seg faults for tree forkjoin barrier
+ * (GEH) */
+ ANNOTATE_HAPPENS_BEFORE(thread);
+ kmp_flag_64 flag(&thread->th.th_bar[bs_forkjoin_barrier].bb.b_go, thread);
+ __kmp_release_64(&flag);
+ }; // if
- // Terminate OS thread.
- __kmp_reap_worker( thread );
+ // Terminate OS thread.
+ __kmp_reap_worker(thread);
- //
- // The thread was killed asynchronously. If it was actively
- // spinning in the thread pool, decrement the global count.
- //
- // There is a small timing hole here - if the worker thread was
- // just waking up after sleeping in the pool, had reset it's
- // th_active_in_pool flag but not decremented the global counter
- // __kmp_thread_pool_active_nth yet, then the global counter
- // might not get updated.
- //
- // Currently, this can only happen as the library is unloaded,
- // so there are no harmful side effects.
- //
- if ( thread->th.th_active_in_pool ) {
- thread->th.th_active_in_pool = FALSE;
- KMP_TEST_THEN_DEC32(
- (kmp_int32 *) &__kmp_thread_pool_active_nth );
- KMP_DEBUG_ASSERT( TCR_4(__kmp_thread_pool_active_nth) >= 0 );
- }
+ // The thread was killed asynchronously. If it was actively
+ // spinning in the thread pool, decrement the global count.
+ //
+ // There is a small timing hole here - if the worker thread was just waking
+ // up after sleeping in the pool, had reset it's th_active_in_pool flag but
+ // not decremented the global counter __kmp_thread_pool_active_nth yet, then
+ // the global counter might not get updated.
+ //
+ // Currently, this can only happen as the library is unloaded,
+ // so there are no harmful side effects.
+ if (thread->th.th_active_in_pool) {
+ thread->th.th_active_in_pool = FALSE;
+ KMP_TEST_THEN_DEC32((kmp_int32 *)&__kmp_thread_pool_active_nth);
+ KMP_DEBUG_ASSERT(TCR_4(__kmp_thread_pool_active_nth) >= 0);
+ }
- // Decrement # of [worker] threads in the pool.
- KMP_DEBUG_ASSERT( __kmp_thread_pool_nth > 0 );
- --__kmp_thread_pool_nth;
- }; // if
+ // Decrement # of [worker] threads in the pool.
+ KMP_DEBUG_ASSERT(__kmp_thread_pool_nth > 0);
+ --__kmp_thread_pool_nth;
+ }; // if
- __kmp_free_implicit_task(thread);
+ __kmp_free_implicit_task(thread);
- // Free the fast memory for tasking
- #if USE_FAST_MEMORY
- __kmp_free_fast_memory( thread );
- #endif /* USE_FAST_MEMORY */
+// Free the fast memory for tasking
+#if USE_FAST_MEMORY
+ __kmp_free_fast_memory(thread);
+#endif /* USE_FAST_MEMORY */
- __kmp_suspend_uninitialize_thread( thread );
+ __kmp_suspend_uninitialize_thread(thread);
- KMP_DEBUG_ASSERT( __kmp_threads[ gtid ] == thread );
- TCW_SYNC_PTR(__kmp_threads[gtid], NULL);
+ KMP_DEBUG_ASSERT(__kmp_threads[gtid] == thread);
+ TCW_SYNC_PTR(__kmp_threads[gtid], NULL);
- -- __kmp_all_nth;
- // __kmp_nth was decremented when thread is added to the pool.
+ --__kmp_all_nth;
+// __kmp_nth was decremented when thread is added to the pool.
#ifdef KMP_ADJUST_BLOCKTIME
- /* Adjust blocktime back to user setting or default if necessary */
- /* Middle initialization might never have occurred */
- if ( !__kmp_env_blocktime && ( __kmp_avail_proc > 0 ) ) {
- KMP_DEBUG_ASSERT( __kmp_avail_proc > 0 );
- if ( __kmp_nth <= __kmp_avail_proc ) {
- __kmp_zero_bt = FALSE;
- }
+ /* Adjust blocktime back to user setting or default if necessary */
+ /* Middle initialization might never have occurred */
+ if (!__kmp_env_blocktime && (__kmp_avail_proc > 0)) {
+ KMP_DEBUG_ASSERT(__kmp_avail_proc > 0);
+ if (__kmp_nth <= __kmp_avail_proc) {
+ __kmp_zero_bt = FALSE;
}
+ }
#endif /* KMP_ADJUST_BLOCKTIME */
- /* free the memory being used */
- if( __kmp_env_consistency_check ) {
- if ( thread->th.th_cons ) {
- __kmp_free_cons_stack( thread->th.th_cons );
- thread->th.th_cons = NULL;
- }; // if
- }
-
- if ( thread->th.th_pri_common != NULL ) {
- __kmp_free( thread->th.th_pri_common );
- thread->th.th_pri_common = NULL;
+ /* free the memory being used */
+ if (__kmp_env_consistency_check) {
+ if (thread->th.th_cons) {
+ __kmp_free_cons_stack(thread->th.th_cons);
+ thread->th.th_cons = NULL;
}; // if
+ }
- if (thread->th.th_task_state_memo_stack != NULL) {
- __kmp_free(thread->th.th_task_state_memo_stack);
- thread->th.th_task_state_memo_stack = NULL;
- }
-
- #if KMP_USE_BGET
- if ( thread->th.th_local.bget_data != NULL ) {
- __kmp_finalize_bget( thread );
- }; // if
- #endif
+ if (thread->th.th_pri_common != NULL) {
+ __kmp_free(thread->th.th_pri_common);
+ thread->th.th_pri_common = NULL;
+ }; // if
+
+ if (thread->th.th_task_state_memo_stack != NULL) {
+ __kmp_free(thread->th.th_task_state_memo_stack);
+ thread->th.th_task_state_memo_stack = NULL;
+ }
+
+#if KMP_USE_BGET
+ if (thread->th.th_local.bget_data != NULL) {
+ __kmp_finalize_bget(thread);
+ }; // if
+#endif
#if KMP_AFFINITY_SUPPORTED
- if ( thread->th.th_affin_mask != NULL ) {
- KMP_CPU_FREE( thread->th.th_affin_mask );
- thread->th.th_affin_mask = NULL;
- }; // if
+ if (thread->th.th_affin_mask != NULL) {
+ KMP_CPU_FREE(thread->th.th_affin_mask);
+ thread->th.th_affin_mask = NULL;
+ }; // if
#endif /* KMP_AFFINITY_SUPPORTED */
- __kmp_reap_team( thread->th.th_serial_team );
- thread->th.th_serial_team = NULL;
- __kmp_free( thread );
+ __kmp_reap_team(thread->th.th_serial_team);
+ thread->th.th_serial_team = NULL;
+ __kmp_free(thread);
- KMP_MB();
+ KMP_MB();
} // __kmp_reap_thread
-static void
-__kmp_internal_end(void)
-{
- int i;
+static void __kmp_internal_end(void) {
+ int i;
+
+ /* First, unregister the library */
+ __kmp_unregister_library();
- /* First, unregister the library */
- __kmp_unregister_library();
+#if KMP_OS_WINDOWS
+ /* In Win static library, we can't tell when a root actually dies, so we
+ reclaim the data structures for any root threads that have died but not
+ unregistered themselves, in order to shut down cleanly.
+ In Win dynamic library we also can't tell when a thread dies. */
+ __kmp_reclaim_dead_roots(); // AC: moved here to always clean resources of
+// dead roots
+#endif
- #if KMP_OS_WINDOWS
- /* In Win static library, we can't tell when a root actually dies, so we
- reclaim the data structures for any root threads that have died but not
- unregistered themselves, in order to shut down cleanly.
- In Win dynamic library we also can't tell when a thread dies.
- */
- __kmp_reclaim_dead_roots(); // AC: moved here to always clean resources of dead roots
- #endif
-
- for( i=0 ; i<__kmp_threads_capacity ; i++ )
- if( __kmp_root[i] )
- if( __kmp_root[i]->r.r_active )
- break;
- KMP_MB(); /* Flush all pending memory write invalidates. */
- TCW_SYNC_4(__kmp_global.g.g_done, TRUE);
+ for (i = 0; i < __kmp_threads_capacity; i++)
+ if (__kmp_root[i])
+ if (__kmp_root[i]->r.r_active)
+ break;
+ KMP_MB(); /* Flush all pending memory write invalidates. */
+ TCW_SYNC_4(__kmp_global.g.g_done, TRUE);
- if ( i < __kmp_threads_capacity ) {
+ if (i < __kmp_threads_capacity) {
#if KMP_USE_MONITOR
- // 2009-09-08 (lev): Other alive roots found. Why do we kill the monitor??
- KMP_MB(); /* Flush all pending memory write invalidates. */
+ // 2009-09-08 (lev): Other alive roots found. Why do we kill the monitor??
+ KMP_MB(); /* Flush all pending memory write invalidates. */
- //
- // Need to check that monitor was initialized before reaping it.
- // If we are called form __kmp_atfork_child (which sets
- // __kmp_init_parallel = 0), then __kmp_monitor will appear to
- // contain valid data, but it is only valid in the parent process,
- // not the child.
- //
- // New behavior (201008): instead of keying off of the flag
- // __kmp_init_parallel, the monitor thread creation is keyed off
- // of the new flag __kmp_init_monitor.
- //
- __kmp_acquire_bootstrap_lock( & __kmp_monitor_lock );
- if ( TCR_4( __kmp_init_monitor ) ) {
- __kmp_reap_monitor( & __kmp_monitor );
- TCW_4( __kmp_init_monitor, 0 );
- }
- __kmp_release_bootstrap_lock( & __kmp_monitor_lock );
- KA_TRACE( 10, ("__kmp_internal_end: monitor reaped\n" ) );
+// Need to check that monitor was initialized before reaping it. If we are
+// called form __kmp_atfork_child (which sets __kmp_init_parallel = 0), then
+// __kmp_monitor will appear to contain valid data, but it is only valid in the
+// parent process, not the child.
+ // New behavior (201008): instead of keying off of the flag
+ // __kmp_init_parallel, the monitor thread creation is keyed off
+ // of the new flag __kmp_init_monitor.
+ __kmp_acquire_bootstrap_lock(&__kmp_monitor_lock);
+ if (TCR_4(__kmp_init_monitor)) {
+ __kmp_reap_monitor(&__kmp_monitor);
+ TCW_4(__kmp_init_monitor, 0);
+ }
+ __kmp_release_bootstrap_lock(&__kmp_monitor_lock);
+ KA_TRACE(10, ("__kmp_internal_end: monitor reaped\n"));
#endif // KMP_USE_MONITOR
- } else {
- /* TODO move this to cleanup code */
- #ifdef KMP_DEBUG
- /* make sure that everything has properly ended */
- for ( i = 0; i < __kmp_threads_capacity; i++ ) {
- if( __kmp_root[i] ) {
-// KMP_ASSERT( ! KMP_UBER_GTID( i ) ); // AC: there can be uber threads alive here
- KMP_ASSERT( ! __kmp_root[i]->r.r_active ); // TODO: can they be active?
- }
- }
- #endif
-
- KMP_MB();
+ } else {
+/* TODO move this to cleanup code */
+#ifdef KMP_DEBUG
+ /* make sure that everything has properly ended */
+ for (i = 0; i < __kmp_threads_capacity; i++) {
+ if (__kmp_root[i]) {
+ // KMP_ASSERT( ! KMP_UBER_GTID( i ) ); // AC:
+ // there can be uber threads alive here
+ KMP_ASSERT(!__kmp_root[i]->r.r_active); // TODO: can they be active?
+ }
+ }
+#endif
- // Reap the worker threads.
- // This is valid for now, but be careful if threads are reaped sooner.
- while ( __kmp_thread_pool != NULL ) { // Loop thru all the thread in the pool.
- // Get the next thread from the pool.
- kmp_info_t * thread = (kmp_info_t *) __kmp_thread_pool;
- __kmp_thread_pool = thread->th.th_next_pool;
- // Reap it.
- KMP_DEBUG_ASSERT(thread->th.th_reap_state == KMP_SAFE_TO_REAP);
- thread->th.th_next_pool = NULL;
- thread->th.th_in_pool = FALSE;
- __kmp_reap_thread( thread, 0 );
- }; // while
- __kmp_thread_pool_insert_pt = NULL;
-
- // Reap teams.
- while ( __kmp_team_pool != NULL ) { // Loop thru all the teams in the pool.
- // Get the next team from the pool.
- kmp_team_t * team = (kmp_team_t *) __kmp_team_pool;
- __kmp_team_pool = team->t.t_next_pool;
- // Reap it.
- team->t.t_next_pool = NULL;
- __kmp_reap_team( team );
- }; // while
-
- __kmp_reap_task_teams( );
-
- for ( i = 0; i < __kmp_threads_capacity; ++ i ) {
- // TBD: Add some checking...
- // Something like KMP_DEBUG_ASSERT( __kmp_thread[ i ] == NULL );
- }
+ KMP_MB();
- /* Make sure all threadprivate destructors get run by joining with all worker
- threads before resetting this flag */
- TCW_SYNC_4(__kmp_init_common, FALSE);
+ // Reap the worker threads.
+ // This is valid for now, but be careful if threads are reaped sooner.
+ while (__kmp_thread_pool != NULL) { // Loop thru all the thread in the pool.
+ // Get the next thread from the pool.
+ kmp_info_t *thread = (kmp_info_t *)__kmp_thread_pool;
+ __kmp_thread_pool = thread->th.th_next_pool;
+ // Reap it.
+ KMP_DEBUG_ASSERT(thread->th.th_reap_state == KMP_SAFE_TO_REAP);
+ thread->th.th_next_pool = NULL;
+ thread->th.th_in_pool = FALSE;
+ __kmp_reap_thread(thread, 0);
+ }; // while
+ __kmp_thread_pool_insert_pt = NULL;
- KA_TRACE( 10, ("__kmp_internal_end: all workers reaped\n" ) );
- KMP_MB();
+ // Reap teams.
+ while (__kmp_team_pool != NULL) { // Loop thru all the teams in the pool.
+ // Get the next team from the pool.
+ kmp_team_t *team = (kmp_team_t *)__kmp_team_pool;
+ __kmp_team_pool = team->t.t_next_pool;
+ // Reap it.
+ team->t.t_next_pool = NULL;
+ __kmp_reap_team(team);
+ }; // while
-#if KMP_USE_MONITOR
- //
- // See note above: One of the possible fixes for CQ138434 / CQ140126
- //
- // FIXME: push both code fragments down and CSE them?
- // push them into __kmp_cleanup() ?
- //
- __kmp_acquire_bootstrap_lock( & __kmp_monitor_lock );
- if ( TCR_4( __kmp_init_monitor ) ) {
- __kmp_reap_monitor( & __kmp_monitor );
- TCW_4( __kmp_init_monitor, 0 );
- }
- __kmp_release_bootstrap_lock( & __kmp_monitor_lock );
- KA_TRACE( 10, ("__kmp_internal_end: monitor reaped\n" ) );
-#endif
- } /* else !__kmp_global.t_active */
- TCW_4(__kmp_init_gtid, FALSE);
- KMP_MB(); /* Flush all pending memory write invalidates. */
-
- __kmp_cleanup();
-#if OMPT_SUPPORT
- ompt_fini();
-#endif
-}
+ __kmp_reap_task_teams();
-void
-__kmp_internal_end_library( int gtid_req )
-{
- /* if we have already cleaned up, don't try again, it wouldn't be pretty */
- /* this shouldn't be a race condition because __kmp_internal_end() is the
- * only place to clear __kmp_serial_init */
- /* we'll check this later too, after we get the lock */
- // 2009-09-06: We do not set g_abort without setting g_done. This check looks redundaant,
- // because the next check will work in any case.
- if( __kmp_global.g.g_abort ) {
- KA_TRACE( 11, ("__kmp_internal_end_library: abort, exiting\n" ));
- /* TODO abort? */
- return;
- }
- if( TCR_4(__kmp_global.g.g_done) || !__kmp_init_serial ) {
- KA_TRACE( 10, ("__kmp_internal_end_library: already finished\n" ));
- return;
+ for (i = 0; i < __kmp_threads_capacity; ++i) {
+ // TBD: Add some checking...
+ // Something like KMP_DEBUG_ASSERT( __kmp_thread[ i ] == NULL );
}
+ /* Make sure all threadprivate destructors get run by joining with all
+ worker threads before resetting this flag */
+ TCW_SYNC_4(__kmp_init_common, FALSE);
- KMP_MB(); /* Flush all pending memory write invalidates. */
-
- /* find out who we are and what we should do */
- {
- int gtid = (gtid_req>=0) ? gtid_req : __kmp_gtid_get_specific();
- KA_TRACE( 10, ("__kmp_internal_end_library: enter T#%d (%d)\n", gtid, gtid_req ));
- if( gtid == KMP_GTID_SHUTDOWN ) {
- KA_TRACE( 10, ("__kmp_internal_end_library: !__kmp_init_runtime, system already shutdown\n" ));
- return;
- } else if( gtid == KMP_GTID_MONITOR ) {
- KA_TRACE( 10, ("__kmp_internal_end_library: monitor thread, gtid not registered, or system shutdown\n" ));
- return;
- } else if( gtid == KMP_GTID_DNE ) {
- KA_TRACE( 10, ("__kmp_internal_end_library: gtid not registered or system shutdown\n" ));
- /* we don't know who we are, but we may still shutdown the library */
- } else if( KMP_UBER_GTID( gtid )) {
- /* unregister ourselves as an uber thread. gtid is no longer valid */
- if( __kmp_root[gtid]->r.r_active ) {
- __kmp_global.g.g_abort = -1;
- TCW_SYNC_4(__kmp_global.g.g_done, TRUE);
- KA_TRACE( 10, ("__kmp_internal_end_library: root still active, abort T#%d\n", gtid ));
- return;
- } else {
- KA_TRACE( 10, ("__kmp_internal_end_library: unregistering sibling T#%d\n", gtid ));
- __kmp_unregister_root_current_thread( gtid );
- }
- } else {
- /* worker threads may call this function through the atexit handler, if they call exit() */
- /* For now, skip the usual subsequent processing and just dump the debug buffer.
- TODO: do a thorough shutdown instead
- */
- #ifdef DUMP_DEBUG_ON_EXIT
- if ( __kmp_debug_buf )
- __kmp_dump_debug_buffer( );
- #endif
- return;
- }
- }
- /* synchronize the termination process */
- __kmp_acquire_bootstrap_lock( &__kmp_initz_lock );
+ KA_TRACE(10, ("__kmp_internal_end: all workers reaped\n"));
+ KMP_MB();
- /* have we already finished */
- if( __kmp_global.g.g_abort ) {
- KA_TRACE( 10, ("__kmp_internal_end_library: abort, exiting\n" ));
- /* TODO abort? */
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
- return;
- }
- if( TCR_4(__kmp_global.g.g_done) || !__kmp_init_serial ) {
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
+#if KMP_USE_MONITOR
+ // See note above: One of the possible fixes for CQ138434 / CQ140126
+ //
+ // FIXME: push both code fragments down and CSE them?
+ // push them into __kmp_cleanup() ?
+ __kmp_acquire_bootstrap_lock(&__kmp_monitor_lock);
+ if (TCR_4(__kmp_init_monitor)) {
+ __kmp_reap_monitor(&__kmp_monitor);
+ TCW_4(__kmp_init_monitor, 0);
+ }
+ __kmp_release_bootstrap_lock(&__kmp_monitor_lock);
+ KA_TRACE(10, ("__kmp_internal_end: monitor reaped\n"));
+#endif
+ } /* else !__kmp_global.t_active */
+ TCW_4(__kmp_init_gtid, FALSE);
+ KMP_MB(); /* Flush all pending memory write invalidates. */
+
+ __kmp_cleanup();
+#if OMPT_SUPPORT
+ ompt_fini();
+#endif
+}
+
+void __kmp_internal_end_library(int gtid_req) {
+ /* if we have already cleaned up, don't try again, it wouldn't be pretty */
+ /* this shouldn't be a race condition because __kmp_internal_end() is the
+ only place to clear __kmp_serial_init */
+ /* we'll check this later too, after we get the lock */
+ // 2009-09-06: We do not set g_abort without setting g_done. This check looks
+ // redundaant, because the next check will work in any case.
+ if (__kmp_global.g.g_abort) {
+ KA_TRACE(11, ("__kmp_internal_end_library: abort, exiting\n"));
+ /* TODO abort? */
+ return;
+ }
+ if (TCR_4(__kmp_global.g.g_done) || !__kmp_init_serial) {
+ KA_TRACE(10, ("__kmp_internal_end_library: already finished\n"));
+ return;
+ }
+
+ KMP_MB(); /* Flush all pending memory write invalidates. */
+
+ /* find out who we are and what we should do */
+ {
+ int gtid = (gtid_req >= 0) ? gtid_req : __kmp_gtid_get_specific();
+ KA_TRACE(
+ 10, ("__kmp_internal_end_library: enter T#%d (%d)\n", gtid, gtid_req));
+ if (gtid == KMP_GTID_SHUTDOWN) {
+ KA_TRACE(10, ("__kmp_internal_end_library: !__kmp_init_runtime, system "
+ "already shutdown\n"));
+ return;
+ } else if (gtid == KMP_GTID_MONITOR) {
+ KA_TRACE(10, ("__kmp_internal_end_library: monitor thread, gtid not "
+ "registered, or system shutdown\n"));
+ return;
+ } else if (gtid == KMP_GTID_DNE) {
+ KA_TRACE(10, ("__kmp_internal_end_library: gtid not registered or system "
+ "shutdown\n"));
+ /* we don't know who we are, but we may still shutdown the library */
+ } else if (KMP_UBER_GTID(gtid)) {
+ /* unregister ourselves as an uber thread. gtid is no longer valid */
+ if (__kmp_root[gtid]->r.r_active) {
+ __kmp_global.g.g_abort = -1;
+ TCW_SYNC_4(__kmp_global.g.g_done, TRUE);
+ KA_TRACE(10,
+ ("__kmp_internal_end_library: root still active, abort T#%d\n",
+ gtid));
return;
+ } else {
+ KA_TRACE(
+ 10,
+ ("__kmp_internal_end_library: unregistering sibling T#%d\n", gtid));
+ __kmp_unregister_root_current_thread(gtid);
+ }
+ } else {
+/* worker threads may call this function through the atexit handler, if they
+ * call exit() */
+/* For now, skip the usual subsequent processing and just dump the debug buffer.
+ TODO: do a thorough shutdown instead */
+#ifdef DUMP_DEBUG_ON_EXIT
+ if (__kmp_debug_buf)
+ __kmp_dump_debug_buffer();
+#endif
+ return;
}
+ }
+ /* synchronize the termination process */
+ __kmp_acquire_bootstrap_lock(&__kmp_initz_lock);
+
+ /* have we already finished */
+ if (__kmp_global.g.g_abort) {
+ KA_TRACE(10, ("__kmp_internal_end_library: abort, exiting\n"));
+ /* TODO abort? */
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
+ return;
+ }
+ if (TCR_4(__kmp_global.g.g_done) || !__kmp_init_serial) {
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
+ return;
+ }
+
+ /* We need this lock to enforce mutex between this reading of
+ __kmp_threads_capacity and the writing by __kmp_register_root.
+ Alternatively, we can use a counter of roots that is atomically updated by
+ __kmp_get_global_thread_id_reg, __kmp_do_serial_initialize and
+ __kmp_internal_end_*. */
+ __kmp_acquire_bootstrap_lock(&__kmp_forkjoin_lock);
+
+ /* now we can safely conduct the actual termination */
+ __kmp_internal_end();
+
+ __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
+
+ KA_TRACE(10, ("__kmp_internal_end_library: exit\n"));
+
+#ifdef DUMP_DEBUG_ON_EXIT
+ if (__kmp_debug_buf)
+ __kmp_dump_debug_buffer();
+#endif
- /* We need this lock to enforce mutex between this reading of
- __kmp_threads_capacity and the writing by __kmp_register_root.
- Alternatively, we can use a counter of roots that is
- atomically updated by __kmp_get_global_thread_id_reg,
- __kmp_do_serial_initialize and __kmp_internal_end_*.
- */
- __kmp_acquire_bootstrap_lock( &__kmp_forkjoin_lock );
-
- /* now we can safely conduct the actual termination */
- __kmp_internal_end();
-
- __kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
-
- KA_TRACE( 10, ("__kmp_internal_end_library: exit\n" ) );
-
- #ifdef DUMP_DEBUG_ON_EXIT
- if ( __kmp_debug_buf )
- __kmp_dump_debug_buffer();
- #endif
-
- #if KMP_OS_WINDOWS
- __kmp_close_console();
- #endif
+#if KMP_OS_WINDOWS
+ __kmp_close_console();
+#endif
- __kmp_fini_allocator();
+ __kmp_fini_allocator();
} // __kmp_internal_end_library
-void
-__kmp_internal_end_thread( int gtid_req )
-{
- int i;
+void __kmp_internal_end_thread(int gtid_req) {
+ int i;
- /* if we have already cleaned up, don't try again, it wouldn't be pretty */
- /* this shouldn't be a race condition because __kmp_internal_end() is the
- * only place to clear __kmp_serial_init */
- /* we'll check this later too, after we get the lock */
- // 2009-09-06: We do not set g_abort without setting g_done. This check looks redundant,
- // because the next check will work in any case.
- if( __kmp_global.g.g_abort ) {
- KA_TRACE( 11, ("__kmp_internal_end_thread: abort, exiting\n" ));
- /* TODO abort? */
- return;
- }
- if( TCR_4(__kmp_global.g.g_done) || !__kmp_init_serial ) {
- KA_TRACE( 10, ("__kmp_internal_end_thread: already finished\n" ));
+ /* if we have already cleaned up, don't try again, it wouldn't be pretty */
+ /* this shouldn't be a race condition because __kmp_internal_end() is the
+ * only place to clear __kmp_serial_init */
+ /* we'll check this later too, after we get the lock */
+ // 2009-09-06: We do not set g_abort without setting g_done. This check looks
+ // redundant, because the next check will work in any case.
+ if (__kmp_global.g.g_abort) {
+ KA_TRACE(11, ("__kmp_internal_end_thread: abort, exiting\n"));
+ /* TODO abort? */
+ return;
+ }
+ if (TCR_4(__kmp_global.g.g_done) || !__kmp_init_serial) {
+ KA_TRACE(10, ("__kmp_internal_end_thread: already finished\n"));
+ return;
+ }
+
+ KMP_MB(); /* Flush all pending memory write invalidates. */
+
+ /* find out who we are and what we should do */
+ {
+ int gtid = (gtid_req >= 0) ? gtid_req : __kmp_gtid_get_specific();
+ KA_TRACE(10,
+ ("__kmp_internal_end_thread: enter T#%d (%d)\n", gtid, gtid_req));
+ if (gtid == KMP_GTID_SHUTDOWN) {
+ KA_TRACE(10, ("__kmp_internal_end_thread: !__kmp_init_runtime, system "
+ "already shutdown\n"));
+ return;
+ } else if (gtid == KMP_GTID_MONITOR) {
+ KA_TRACE(10, ("__kmp_internal_end_thread: monitor thread, gtid not "
+ "registered, or system shutdown\n"));
+ return;
+ } else if (gtid == KMP_GTID_DNE) {
+ KA_TRACE(10, ("__kmp_internal_end_thread: gtid not registered or system "
+ "shutdown\n"));
+ return;
+ /* we don't know who we are */
+ } else if (KMP_UBER_GTID(gtid)) {
+ /* unregister ourselves as an uber thread. gtid is no longer valid */
+ if (__kmp_root[gtid]->r.r_active) {
+ __kmp_global.g.g_abort = -1;
+ TCW_SYNC_4(__kmp_global.g.g_done, TRUE);
+ KA_TRACE(10,
+ ("__kmp_internal_end_thread: root still active, abort T#%d\n",
+ gtid));
return;
- }
+ } else {
+ KA_TRACE(10, ("__kmp_internal_end_thread: unregistering sibling T#%d\n",
+ gtid));
+ __kmp_unregister_root_current_thread(gtid);
+ }
+ } else {
+ /* just a worker thread, let's leave */
+ KA_TRACE(10, ("__kmp_internal_end_thread: worker thread T#%d\n", gtid));
- KMP_MB(); /* Flush all pending memory write invalidates. */
+ if (gtid >= 0) {
+ __kmp_threads[gtid]->th.th_task_team = NULL;
+ }
+
+ KA_TRACE(10,
+ ("__kmp_internal_end_thread: worker thread done, exiting T#%d\n",
+ gtid));
+ return;
+ }
+ }
+#if defined KMP_DYNAMIC_LIB
+ // AC: lets not shutdown the Linux* OS dynamic library at the exit of uber
+ // thread, because we will better shutdown later in the library destructor.
+ // The reason of this change is performance problem when non-openmp thread in
+ // a loop forks and joins many openmp threads. We can save a lot of time
+ // keeping worker threads alive until the program shutdown.
+ // OM: Removed Linux* OS restriction to fix the crash on OS X* (DPD200239966)
+ // and Windows(DPD200287443) that occurs when using critical sections from
+ // foreign threads.
+ KA_TRACE(10, ("__kmp_internal_end_thread: exiting T#%d\n", gtid_req));
+ return;
+#endif
+ /* synchronize the termination process */
+ __kmp_acquire_bootstrap_lock(&__kmp_initz_lock);
+
+ /* have we already finished */
+ if (__kmp_global.g.g_abort) {
+ KA_TRACE(10, ("__kmp_internal_end_thread: abort, exiting\n"));
+ /* TODO abort? */
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
+ return;
+ }
+ if (TCR_4(__kmp_global.g.g_done) || !__kmp_init_serial) {
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
+ return;
+ }
+
+ /* We need this lock to enforce mutex between this reading of
+ __kmp_threads_capacity and the writing by __kmp_register_root.
+ Alternatively, we can use a counter of roots that is atomically updated by
+ __kmp_get_global_thread_id_reg, __kmp_do_serial_initialize and
+ __kmp_internal_end_*. */
+
+ /* should we finish the run-time? are all siblings done? */
+ __kmp_acquire_bootstrap_lock(&__kmp_forkjoin_lock);
+
+ for (i = 0; i < __kmp_threads_capacity; ++i) {
+ if (KMP_UBER_GTID(i)) {
+ KA_TRACE(
+ 10,
+ ("__kmp_internal_end_thread: remaining sibling task: gtid==%d\n", i));
+ __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
+ return;
+ };
+ }
- /* find out who we are and what we should do */
- {
- int gtid = (gtid_req>=0) ? gtid_req : __kmp_gtid_get_specific();
- KA_TRACE( 10, ("__kmp_internal_end_thread: enter T#%d (%d)\n", gtid, gtid_req ));
- if( gtid == KMP_GTID_SHUTDOWN ) {
- KA_TRACE( 10, ("__kmp_internal_end_thread: !__kmp_init_runtime, system already shutdown\n" ));
- return;
- } else if( gtid == KMP_GTID_MONITOR ) {
- KA_TRACE( 10, ("__kmp_internal_end_thread: monitor thread, gtid not registered, or system shutdown\n" ));
- return;
- } else if( gtid == KMP_GTID_DNE ) {
- KA_TRACE( 10, ("__kmp_internal_end_thread: gtid not registered or system shutdown\n" ));
- return;
- /* we don't know who we are */
- } else if( KMP_UBER_GTID( gtid )) {
- /* unregister ourselves as an uber thread. gtid is no longer valid */
- if( __kmp_root[gtid]->r.r_active ) {
- __kmp_global.g.g_abort = -1;
- TCW_SYNC_4(__kmp_global.g.g_done, TRUE);
- KA_TRACE( 10, ("__kmp_internal_end_thread: root still active, abort T#%d\n", gtid ));
- return;
- } else {
- KA_TRACE( 10, ("__kmp_internal_end_thread: unregistering sibling T#%d\n", gtid ));
- __kmp_unregister_root_current_thread( gtid );
- }
- } else {
- /* just a worker thread, let's leave */
- KA_TRACE( 10, ("__kmp_internal_end_thread: worker thread T#%d\n", gtid ));
+ /* now we can safely conduct the actual termination */
- if ( gtid >= 0 ) {
- __kmp_threads[gtid]->th.th_task_team = NULL;
- }
+ __kmp_internal_end();
- KA_TRACE( 10, ("__kmp_internal_end_thread: worker thread done, exiting T#%d\n", gtid ));
- return;
- }
- }
- #if defined KMP_DYNAMIC_LIB
- // AC: lets not shutdown the Linux* OS dynamic library at the exit of uber thread,
- // because we will better shutdown later in the library destructor.
- // The reason of this change is performance problem when non-openmp thread
- // in a loop forks and joins many openmp threads. We can save a lot of time
- // keeping worker threads alive until the program shutdown.
- // OM: Removed Linux* OS restriction to fix the crash on OS X* (DPD200239966) and
- // Windows(DPD200287443) that occurs when using critical sections from foreign threads.
- KA_TRACE( 10, ("__kmp_internal_end_thread: exiting T#%d\n", gtid_req) );
- return;
- #endif
- /* synchronize the termination process */
- __kmp_acquire_bootstrap_lock( &__kmp_initz_lock );
-
- /* have we already finished */
- if( __kmp_global.g.g_abort ) {
- KA_TRACE( 10, ("__kmp_internal_end_thread: abort, exiting\n" ));
- /* TODO abort? */
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
- return;
- }
- if( TCR_4(__kmp_global.g.g_done) || !__kmp_init_serial ) {
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
- return;
- }
+ __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
- /* We need this lock to enforce mutex between this reading of
- __kmp_threads_capacity and the writing by __kmp_register_root.
- Alternatively, we can use a counter of roots that is
- atomically updated by __kmp_get_global_thread_id_reg,
- __kmp_do_serial_initialize and __kmp_internal_end_*.
- */
-
- /* should we finish the run-time? are all siblings done? */
- __kmp_acquire_bootstrap_lock( &__kmp_forkjoin_lock );
-
- for ( i = 0; i < __kmp_threads_capacity; ++ i ) {
- if ( KMP_UBER_GTID( i ) ) {
- KA_TRACE( 10, ("__kmp_internal_end_thread: remaining sibling task: gtid==%d\n", i ));
- __kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
- return;
- };
- }
-
- /* now we can safely conduct the actual termination */
-
- __kmp_internal_end();
-
- __kmp_release_bootstrap_lock( &__kmp_forkjoin_lock );
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
-
- KA_TRACE( 10, ("__kmp_internal_end_thread: exit T#%d\n", gtid_req ) );
-
- #ifdef DUMP_DEBUG_ON_EXIT
- if ( __kmp_debug_buf )
- __kmp_dump_debug_buffer();
- #endif
+ KA_TRACE(10, ("__kmp_internal_end_thread: exit T#%d\n", gtid_req));
+
+#ifdef DUMP_DEBUG_ON_EXIT
+ if (__kmp_debug_buf)
+ __kmp_dump_debug_buffer();
+#endif
} // __kmp_internal_end_thread
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// Library registration stuff.
-static long __kmp_registration_flag = 0;
- // Random value used to indicate library initialization.
-static char * __kmp_registration_str = NULL;
- // Value to be saved in env var __KMP_REGISTERED_LIB_<pid>.
+static long __kmp_registration_flag = 0;
+// Random value used to indicate library initialization.
+static char *__kmp_registration_str = NULL;
+// Value to be saved in env var __KMP_REGISTERED_LIB_<pid>.
+
+static inline char *__kmp_reg_status_name() {
+ /* On RHEL 3u5 if linked statically, getpid() returns different values in
+ each thread. If registration and unregistration go in different threads
+ (omp_misc_other_root_exit.cpp test case), the name of registered_lib_env
+ env var can not be found, because the name will contain different pid. */
+ return __kmp_str_format("__KMP_REGISTERED_LIB_%d", (int)getpid());
+} // __kmp_reg_status_get
+void __kmp_register_library_startup(void) {
-static inline
-char *
-__kmp_reg_status_name() {
- /*
- On RHEL 3u5 if linked statically, getpid() returns different values in each thread.
- If registration and unregistration go in different threads (omp_misc_other_root_exit.cpp test case),
- the name of registered_lib_env env var can not be found, because the name will contain different pid.
- */
- return __kmp_str_format( "__KMP_REGISTERED_LIB_%d", (int) getpid() );
-} // __kmp_reg_status_get
+ char *name = __kmp_reg_status_name(); // Name of the environment variable.
+ int done = 0;
+ union {
+ double dtime;
+ long ltime;
+ } time;
+#if KMP_ARCH_X86 || KMP_ARCH_X86_64
+ __kmp_initialize_system_tick();
+#endif
+ __kmp_read_system_time(&time.dtime);
+ __kmp_registration_flag = 0xCAFE0000L | (time.ltime & 0x0000FFFFL);
+ __kmp_registration_str =
+ __kmp_str_format("%p-%lx-%s", &__kmp_registration_flag,
+ __kmp_registration_flag, KMP_LIBRARY_FILE);
+ KA_TRACE(50, ("__kmp_register_library_startup: %s=\"%s\"\n", name,
+ __kmp_registration_str));
-void
-__kmp_register_library_startup(
- void
-) {
-
- char * name = __kmp_reg_status_name(); // Name of the environment variable.
- int done = 0;
- union {
- double dtime;
- long ltime;
- } time;
- #if KMP_ARCH_X86 || KMP_ARCH_X86_64
- __kmp_initialize_system_tick();
- #endif
- __kmp_read_system_time( & time.dtime );
- __kmp_registration_flag = 0xCAFE0000L | ( time.ltime & 0x0000FFFFL );
- __kmp_registration_str =
- __kmp_str_format(
- "%p-%lx-%s",
- & __kmp_registration_flag,
- __kmp_registration_flag,
- KMP_LIBRARY_FILE
- );
-
- KA_TRACE( 50, ( "__kmp_register_library_startup: %s=\"%s\"\n", name, __kmp_registration_str ) );
-
- while ( ! done ) {
-
- char * value = NULL; // Actual value of the environment variable.
-
- // Set environment variable, but do not overwrite if it is exist.
- __kmp_env_set( name, __kmp_registration_str, 0 );
- // Check the variable is written.
- value = __kmp_env_get( name );
- if ( value != NULL && strcmp( value, __kmp_registration_str ) == 0 ) {
+ while (!done) {
- done = 1; // Ok, environment variable set successfully, exit the loop.
+ char *value = NULL; // Actual value of the environment variable.
- } else {
+ // Set environment variable, but do not overwrite if it is exist.
+ __kmp_env_set(name, __kmp_registration_str, 0);
+ // Check the variable is written.
+ value = __kmp_env_get(name);
+ if (value != NULL && strcmp(value, __kmp_registration_str) == 0) {
+
+ done = 1; // Ok, environment variable set successfully, exit the loop.
- // Oops. Write failed. Another copy of OpenMP RTL is in memory.
- // Check whether it alive or dead.
- int neighbor = 0; // 0 -- unknown status, 1 -- alive, 2 -- dead.
- char * tail = value;
- char * flag_addr_str = NULL;
- char * flag_val_str = NULL;
- char const * file_name = NULL;
- __kmp_str_split( tail, '-', & flag_addr_str, & tail );
- __kmp_str_split( tail, '-', & flag_val_str, & tail );
- file_name = tail;
- if ( tail != NULL ) {
- long * flag_addr = 0;
- long flag_val = 0;
- KMP_SSCANF( flag_addr_str, "%p", & flag_addr );
- KMP_SSCANF( flag_val_str, "%lx", & flag_val );
- if ( flag_addr != 0 && flag_val != 0 && strcmp( file_name, "" ) != 0 ) {
- // First, check whether environment-encoded address is mapped into addr space.
- // If so, dereference it to see if it still has the right value.
-
- if ( __kmp_is_address_mapped( flag_addr ) && * flag_addr == flag_val ) {
- neighbor = 1;
- } else {
- // If not, then we know the other copy of the library is no longer running.
- neighbor = 2;
- }; // if
- }; // if
- }; // if
- switch ( neighbor ) {
- case 0 : // Cannot parse environment variable -- neighbor status unknown.
- // Assume it is the incompatible format of future version of the library.
- // Assume the other library is alive.
- // WARN( ... ); // TODO: Issue a warning.
- file_name = "unknown library";
- // Attention! Falling to the next case. That's intentional.
- case 1 : { // Neighbor is alive.
- // Check it is allowed.
- char * duplicate_ok = __kmp_env_get( "KMP_DUPLICATE_LIB_OK" );
- if ( ! __kmp_str_match_true( duplicate_ok ) ) {
- // That's not allowed. Issue fatal error.
- __kmp_msg(
- kmp_ms_fatal,
- KMP_MSG( DuplicateLibrary, KMP_LIBRARY_FILE, file_name ),
- KMP_HNT( DuplicateLibrary ),
- __kmp_msg_null
- );
- }; // if
- KMP_INTERNAL_FREE( duplicate_ok );
- __kmp_duplicate_library_ok = 1;
- done = 1; // Exit the loop.
- } break;
- case 2 : { // Neighbor is dead.
- // Clear the variable and try to register library again.
- __kmp_env_unset( name );
- } break;
- default : {
- KMP_DEBUG_ASSERT( 0 );
- } break;
- }; // switch
+ } else {
+ // Oops. Write failed. Another copy of OpenMP RTL is in memory.
+ // Check whether it alive or dead.
+ int neighbor = 0; // 0 -- unknown status, 1 -- alive, 2 -- dead.
+ char *tail = value;
+ char *flag_addr_str = NULL;
+ char *flag_val_str = NULL;
+ char const *file_name = NULL;
+ __kmp_str_split(tail, '-', &flag_addr_str, &tail);
+ __kmp_str_split(tail, '-', &flag_val_str, &tail);
+ file_name = tail;
+ if (tail != NULL) {
+ long *flag_addr = 0;
+ long flag_val = 0;
+ KMP_SSCANF(flag_addr_str, "%p", &flag_addr);
+ KMP_SSCANF(flag_val_str, "%lx", &flag_val);
+ if (flag_addr != 0 && flag_val != 0 && strcmp(file_name, "") != 0) {
+ // First, check whether environment-encoded address is mapped into
+ // addr space.
+ // If so, dereference it to see if it still has the right value.
+ if (__kmp_is_address_mapped(flag_addr) && *flag_addr == flag_val) {
+ neighbor = 1;
+ } else {
+ // If not, then we know the other copy of the library is no longer
+ // running.
+ neighbor = 2;
+ }; // if
+ }; // if
+ }; // if
+ switch (neighbor) {
+ case 0: // Cannot parse environment variable -- neighbor status unknown.
+ // Assume it is the incompatible format of future version of the
+ // library. Assume the other library is alive.
+ // WARN( ... ); // TODO: Issue a warning.
+ file_name = "unknown library";
+ // Attention! Falling to the next case. That's intentional.
+ case 1: { // Neighbor is alive.
+ // Check it is allowed.
+ char *duplicate_ok = __kmp_env_get("KMP_DUPLICATE_LIB_OK");
+ if (!__kmp_str_match_true(duplicate_ok)) {
+ // That's not allowed. Issue fatal error.
+ __kmp_msg(kmp_ms_fatal,
+ KMP_MSG(DuplicateLibrary, KMP_LIBRARY_FILE, file_name),
+ KMP_HNT(DuplicateLibrary), __kmp_msg_null);
}; // if
- KMP_INTERNAL_FREE( (void *) value );
+ KMP_INTERNAL_FREE(duplicate_ok);
+ __kmp_duplicate_library_ok = 1;
+ done = 1; // Exit the loop.
+ } break;
+ case 2: { // Neighbor is dead.
+ // Clear the variable and try to register library again.
+ __kmp_env_unset(name);
+ } break;
+ default: { KMP_DEBUG_ASSERT(0); } break;
+ }; // switch
- }; // while
- KMP_INTERNAL_FREE( (void *) name );
-
-} // func __kmp_register_library_startup
+ }; // if
+ KMP_INTERNAL_FREE((void *)value);
+ }; // while
+ KMP_INTERNAL_FREE((void *)name);
-void
-__kmp_unregister_library( void ) {
+} // func __kmp_register_library_startup
- char * name = __kmp_reg_status_name();
- char * value = __kmp_env_get( name );
+void __kmp_unregister_library(void) {
- KMP_DEBUG_ASSERT( __kmp_registration_flag != 0 );
- KMP_DEBUG_ASSERT( __kmp_registration_str != NULL );
- if ( value != NULL && strcmp( value, __kmp_registration_str ) == 0 ) {
- // Ok, this is our variable. Delete it.
- __kmp_env_unset( name );
- }; // if
+ char *name = __kmp_reg_status_name();
+ char *value = __kmp_env_get(name);
- KMP_INTERNAL_FREE( __kmp_registration_str );
- KMP_INTERNAL_FREE( value );
- KMP_INTERNAL_FREE( name );
+ KMP_DEBUG_ASSERT(__kmp_registration_flag != 0);
+ KMP_DEBUG_ASSERT(__kmp_registration_str != NULL);
+ if (value != NULL && strcmp(value, __kmp_registration_str) == 0) {
+ // Ok, this is our variable. Delete it.
+ __kmp_env_unset(name);
+ }; // if
+
+ KMP_INTERNAL_FREE(__kmp_registration_str);
+ KMP_INTERNAL_FREE(value);
+ KMP_INTERNAL_FREE(name);
- __kmp_registration_flag = 0;
- __kmp_registration_str = NULL;
+ __kmp_registration_flag = 0;
+ __kmp_registration_str = NULL;
} // __kmp_unregister_library
-
// End of Library registration stuff.
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
-static void __kmp_check_mic_type()
-{
- kmp_cpuid_t cpuid_state = {0};
- kmp_cpuid_t * cs_p = &cpuid_state;
- __kmp_x86_cpuid(1, 0, cs_p);
- // We don't support mic1 at the moment
- if( (cs_p->eax & 0xff0) == 0xB10 ) {
- __kmp_mic_type = mic2;
- } else if( (cs_p->eax & 0xf0ff0) == 0x50670 ) {
- __kmp_mic_type = mic3;
- } else {
- __kmp_mic_type = non_mic;
- }
+static void __kmp_check_mic_type() {
+ kmp_cpuid_t cpuid_state = {0};
+ kmp_cpuid_t *cs_p = &cpuid_state;
+ __kmp_x86_cpuid(1, 0, cs_p);
+ // We don't support mic1 at the moment
+ if ((cs_p->eax & 0xff0) == 0xB10) {
+ __kmp_mic_type = mic2;
+ } else if ((cs_p->eax & 0xf0ff0) == 0x50670) {
+ __kmp_mic_type = mic3;
+ } else {
+ __kmp_mic_type = non_mic;
+ }
}
#endif /* KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS) */
-static void
-__kmp_do_serial_initialize( void )
-{
- int i, gtid;
- int size;
+static void __kmp_do_serial_initialize(void) {
+ int i, gtid;
+ int size;
- KA_TRACE( 10, ("__kmp_do_serial_initialize: enter\n" ) );
+ KA_TRACE(10, ("__kmp_do_serial_initialize: enter\n"));
- KMP_DEBUG_ASSERT( sizeof( kmp_int32 ) == 4 );
- KMP_DEBUG_ASSERT( sizeof( kmp_uint32 ) == 4 );
- KMP_DEBUG_ASSERT( sizeof( kmp_int64 ) == 8 );
- KMP_DEBUG_ASSERT( sizeof( kmp_uint64 ) == 8 );
- KMP_DEBUG_ASSERT( sizeof( kmp_intptr_t ) == sizeof( void * ) );
+ KMP_DEBUG_ASSERT(sizeof(kmp_int32) == 4);
+ KMP_DEBUG_ASSERT(sizeof(kmp_uint32) == 4);
+ KMP_DEBUG_ASSERT(sizeof(kmp_int64) == 8);
+ KMP_DEBUG_ASSERT(sizeof(kmp_uint64) == 8);
+ KMP_DEBUG_ASSERT(sizeof(kmp_intptr_t) == sizeof(void *));
#if OMPT_SUPPORT
- ompt_pre_init();
+ ompt_pre_init();
#endif
- __kmp_validate_locks();
+ __kmp_validate_locks();
- /* Initialize internal memory allocator */
- __kmp_init_allocator();
+ /* Initialize internal memory allocator */
+ __kmp_init_allocator();
- /* Register the library startup via an environment variable
- and check to see whether another copy of the library is already
- registered. */
+ /* Register the library startup via an environment variable and check to see
+ whether another copy of the library is already registered. */
- __kmp_register_library_startup( );
+ __kmp_register_library_startup();
- /* TODO reinitialization of library */
- if( TCR_4(__kmp_global.g.g_done) ) {
- KA_TRACE( 10, ("__kmp_do_serial_initialize: reinitialization of library\n" ) );
- }
+ /* TODO reinitialization of library */
+ if (TCR_4(__kmp_global.g.g_done)) {
+ KA_TRACE(10, ("__kmp_do_serial_initialize: reinitialization of library\n"));
+ }
- __kmp_global.g.g_abort = 0;
- TCW_SYNC_4(__kmp_global.g.g_done, FALSE);
+ __kmp_global.g.g_abort = 0;
+ TCW_SYNC_4(__kmp_global.g.g_done, FALSE);
- /* initialize the locks */
+/* initialize the locks */
#if KMP_USE_ADAPTIVE_LOCKS
#if KMP_DEBUG_ADAPTIVE_LOCKS
- __kmp_init_speculative_stats();
+ __kmp_init_speculative_stats();
#endif
#endif
#if KMP_STATS_ENABLED
- __kmp_stats_init();
+ __kmp_stats_init();
#endif
- __kmp_init_lock( & __kmp_global_lock );
- __kmp_init_queuing_lock( & __kmp_dispatch_lock );
- __kmp_init_lock( & __kmp_debug_lock );
- __kmp_init_atomic_lock( & __kmp_atomic_lock );
- __kmp_init_atomic_lock( & __kmp_atomic_lock_1i );
- __kmp_init_atomic_lock( & __kmp_atomic_lock_2i );
- __kmp_init_atomic_lock( & __kmp_atomic_lock_4i );
- __kmp_init_atomic_lock( & __kmp_atomic_lock_4r );
- __kmp_init_atomic_lock( & __kmp_atomic_lock_8i );
- __kmp_init_atomic_lock( & __kmp_atomic_lock_8r );
- __kmp_init_atomic_lock( & __kmp_atomic_lock_8c );
- __kmp_init_atomic_lock( & __kmp_atomic_lock_10r );
- __kmp_init_atomic_lock( & __kmp_atomic_lock_16r );
- __kmp_init_atomic_lock( & __kmp_atomic_lock_16c );
- __kmp_init_atomic_lock( & __kmp_atomic_lock_20c );
- __kmp_init_atomic_lock( & __kmp_atomic_lock_32c );
- __kmp_init_bootstrap_lock( & __kmp_forkjoin_lock );
- __kmp_init_bootstrap_lock( & __kmp_exit_lock );
+ __kmp_init_lock(&__kmp_global_lock);
+ __kmp_init_queuing_lock(&__kmp_dispatch_lock);
+ __kmp_init_lock(&__kmp_debug_lock);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock_1i);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock_2i);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock_4i);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock_4r);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock_8i);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock_8r);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock_8c);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock_10r);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock_16r);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock_16c);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock_20c);
+ __kmp_init_atomic_lock(&__kmp_atomic_lock_32c);
+ __kmp_init_bootstrap_lock(&__kmp_forkjoin_lock);
+ __kmp_init_bootstrap_lock(&__kmp_exit_lock);
#if KMP_USE_MONITOR
- __kmp_init_bootstrap_lock( & __kmp_monitor_lock );
+ __kmp_init_bootstrap_lock(&__kmp_monitor_lock);
#endif
- __kmp_init_bootstrap_lock( & __kmp_tp_cached_lock );
+ __kmp_init_bootstrap_lock(&__kmp_tp_cached_lock);
- /* conduct initialization and initial setup of configuration */
+ /* conduct initialization and initial setup of configuration */
- __kmp_runtime_initialize();
+ __kmp_runtime_initialize();
#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
- __kmp_check_mic_type();
+ __kmp_check_mic_type();
#endif
- // Some global variable initialization moved here from kmp_env_initialize()
+// Some global variable initialization moved here from kmp_env_initialize()
#ifdef KMP_DEBUG
- kmp_diag = 0;
+ kmp_diag = 0;
#endif
- __kmp_abort_delay = 0;
-
- // From __kmp_init_dflt_team_nth()
- /* assume the entire machine will be used */
- __kmp_dflt_team_nth_ub = __kmp_xproc;
- if( __kmp_dflt_team_nth_ub < KMP_MIN_NTH ) {
- __kmp_dflt_team_nth_ub = KMP_MIN_NTH;
- }
- if( __kmp_dflt_team_nth_ub > __kmp_sys_max_nth ) {
- __kmp_dflt_team_nth_ub = __kmp_sys_max_nth;
- }
- __kmp_max_nth = __kmp_sys_max_nth;
+ __kmp_abort_delay = 0;
- // Three vars below moved here from __kmp_env_initialize() "KMP_BLOCKTIME" part
- __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
+ // From __kmp_init_dflt_team_nth()
+ /* assume the entire machine will be used */
+ __kmp_dflt_team_nth_ub = __kmp_xproc;
+ if (__kmp_dflt_team_nth_ub < KMP_MIN_NTH) {
+ __kmp_dflt_team_nth_ub = KMP_MIN_NTH;
+ }
+ if (__kmp_dflt_team_nth_ub > __kmp_sys_max_nth) {
+ __kmp_dflt_team_nth_ub = __kmp_sys_max_nth;
+ }
+ __kmp_max_nth = __kmp_sys_max_nth;
+
+ // Three vars below moved here from __kmp_env_initialize() "KMP_BLOCKTIME"
+ // part
+ __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
#if KMP_USE_MONITOR
- __kmp_monitor_wakeups = KMP_WAKEUPS_FROM_BLOCKTIME( __kmp_dflt_blocktime, __kmp_monitor_wakeups );
- __kmp_bt_intervals = KMP_INTERVALS_FROM_BLOCKTIME( __kmp_dflt_blocktime, __kmp_monitor_wakeups );
-#endif
- // From "KMP_LIBRARY" part of __kmp_env_initialize()
- __kmp_library = library_throughput;
- // From KMP_SCHEDULE initialization
- __kmp_static = kmp_sch_static_balanced;
- // AC: do not use analytical here, because it is non-monotonous
- //__kmp_guided = kmp_sch_guided_iterative_chunked;
- //__kmp_auto = kmp_sch_guided_analytical_chunked; // AC: it is the default, no need to repeate assignment
- // Barrier initialization. Moved here from __kmp_env_initialize() Barrier branch bit control and barrier method
- // control parts
- #if KMP_FAST_REDUCTION_BARRIER
- #define kmp_reduction_barrier_gather_bb ((int)1)
- #define kmp_reduction_barrier_release_bb ((int)1)
- #define kmp_reduction_barrier_gather_pat bp_hyper_bar
- #define kmp_reduction_barrier_release_pat bp_hyper_bar
- #endif // KMP_FAST_REDUCTION_BARRIER
- for ( i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
- __kmp_barrier_gather_branch_bits [ i ] = __kmp_barrier_gather_bb_dflt;
- __kmp_barrier_release_branch_bits[ i ] = __kmp_barrier_release_bb_dflt;
- __kmp_barrier_gather_pattern [ i ] = __kmp_barrier_gather_pat_dflt;
- __kmp_barrier_release_pattern[ i ] = __kmp_barrier_release_pat_dflt;
- #if KMP_FAST_REDUCTION_BARRIER
- if( i == bs_reduction_barrier ) { // tested and confirmed on ALTIX only ( lin_64 ): hyper,1
- __kmp_barrier_gather_branch_bits [ i ] = kmp_reduction_barrier_gather_bb;
- __kmp_barrier_release_branch_bits[ i ] = kmp_reduction_barrier_release_bb;
- __kmp_barrier_gather_pattern [ i ] = kmp_reduction_barrier_gather_pat;
- __kmp_barrier_release_pattern[ i ] = kmp_reduction_barrier_release_pat;
- }
- #endif // KMP_FAST_REDUCTION_BARRIER
+ __kmp_monitor_wakeups =
+ KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
+ __kmp_bt_intervals =
+ KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
+#endif
+ // From "KMP_LIBRARY" part of __kmp_env_initialize()
+ __kmp_library = library_throughput;
+ // From KMP_SCHEDULE initialization
+ __kmp_static = kmp_sch_static_balanced;
+// AC: do not use analytical here, because it is non-monotonous
+//__kmp_guided = kmp_sch_guided_iterative_chunked;
+//__kmp_auto = kmp_sch_guided_analytical_chunked; // AC: it is the default, no
+// need to repeat assignment
+// Barrier initialization. Moved here from __kmp_env_initialize() Barrier branch
+// bit control and barrier method control parts
+#if KMP_FAST_REDUCTION_BARRIER
+#define kmp_reduction_barrier_gather_bb ((int)1)
+#define kmp_reduction_barrier_release_bb ((int)1)
+#define kmp_reduction_barrier_gather_pat bp_hyper_bar
+#define kmp_reduction_barrier_release_pat bp_hyper_bar
+#endif // KMP_FAST_REDUCTION_BARRIER
+ for (i = bs_plain_barrier; i < bs_last_barrier; i++) {
+ __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
+ __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
+ __kmp_barrier_gather_pattern[i] = __kmp_barrier_gather_pat_dflt;
+ __kmp_barrier_release_pattern[i] = __kmp_barrier_release_pat_dflt;
+#if KMP_FAST_REDUCTION_BARRIER
+ if (i == bs_reduction_barrier) { // tested and confirmed on ALTIX only (
+ // lin_64 ): hyper,1
+ __kmp_barrier_gather_branch_bits[i] = kmp_reduction_barrier_gather_bb;
+ __kmp_barrier_release_branch_bits[i] = kmp_reduction_barrier_release_bb;
+ __kmp_barrier_gather_pattern[i] = kmp_reduction_barrier_gather_pat;
+ __kmp_barrier_release_pattern[i] = kmp_reduction_barrier_release_pat;
}
- #if KMP_FAST_REDUCTION_BARRIER
- #undef kmp_reduction_barrier_release_pat
- #undef kmp_reduction_barrier_gather_pat
- #undef kmp_reduction_barrier_release_bb
- #undef kmp_reduction_barrier_gather_bb
- #endif // KMP_FAST_REDUCTION_BARRIER
+#endif // KMP_FAST_REDUCTION_BARRIER
+ }
+#if KMP_FAST_REDUCTION_BARRIER
+#undef kmp_reduction_barrier_release_pat
+#undef kmp_reduction_barrier_gather_pat
+#undef kmp_reduction_barrier_release_bb
+#undef kmp_reduction_barrier_gather_bb
+#endif // KMP_FAST_REDUCTION_BARRIER
#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
- if (__kmp_mic_type == mic2) { // KNC
- // AC: plane=3,2, forkjoin=2,1 are optimal for 240 threads on KNC
- __kmp_barrier_gather_branch_bits [ bs_plain_barrier ] = 3; // plain gather
- __kmp_barrier_release_branch_bits[ bs_forkjoin_barrier ] = 1; // forkjoin release
- __kmp_barrier_gather_pattern [ bs_forkjoin_barrier ] = bp_hierarchical_bar;
- __kmp_barrier_release_pattern[ bs_forkjoin_barrier ] = bp_hierarchical_bar;
- }
+ if (__kmp_mic_type == mic2) { // KNC
+ // AC: plane=3,2, forkjoin=2,1 are optimal for 240 threads on KNC
+ __kmp_barrier_gather_branch_bits[bs_plain_barrier] = 3; // plain gather
+ __kmp_barrier_release_branch_bits[bs_forkjoin_barrier] =
+ 1; // forkjoin release
+ __kmp_barrier_gather_pattern[bs_forkjoin_barrier] = bp_hierarchical_bar;
+ __kmp_barrier_release_pattern[bs_forkjoin_barrier] = bp_hierarchical_bar;
+ }
#if KMP_FAST_REDUCTION_BARRIER
- if (__kmp_mic_type == mic2) { // KNC
- __kmp_barrier_gather_pattern [ bs_reduction_barrier ] = bp_hierarchical_bar;
- __kmp_barrier_release_pattern[ bs_reduction_barrier ] = bp_hierarchical_bar;
- }
+ if (__kmp_mic_type == mic2) { // KNC
+ __kmp_barrier_gather_pattern[bs_reduction_barrier] = bp_hierarchical_bar;
+ __kmp_barrier_release_pattern[bs_reduction_barrier] = bp_hierarchical_bar;
+ }
#endif
#endif
- // From KMP_CHECKS initialization
+// From KMP_CHECKS initialization
#ifdef KMP_DEBUG
- __kmp_env_checks = TRUE; /* development versions have the extra checks */
+ __kmp_env_checks = TRUE; /* development versions have the extra checks */
#else
- __kmp_env_checks = FALSE; /* port versions do not have the extra checks */
+ __kmp_env_checks = FALSE; /* port versions do not have the extra checks */
#endif
- // From "KMP_FOREIGN_THREADS_THREADPRIVATE" initialization
- __kmp_foreign_tp = TRUE;
+ // From "KMP_FOREIGN_THREADS_THREADPRIVATE" initialization
+ __kmp_foreign_tp = TRUE;
- __kmp_global.g.g_dynamic = FALSE;
- __kmp_global.g.g_dynamic_mode = dynamic_default;
+ __kmp_global.g.g_dynamic = FALSE;
+ __kmp_global.g.g_dynamic_mode = dynamic_default;
- __kmp_env_initialize( NULL );
-
- // Print all messages in message catalog for testing purposes.
- #ifdef KMP_DEBUG
- char const * val = __kmp_env_get( "KMP_DUMP_CATALOG" );
- if ( __kmp_str_match_true( val ) ) {
- kmp_str_buf_t buffer;
- __kmp_str_buf_init( & buffer );
- __kmp_i18n_dump_catalog( & buffer );
- __kmp_printf( "%s", buffer.str );
- __kmp_str_buf_free( & buffer );
- }; // if
- __kmp_env_free( & val );
- #endif
+ __kmp_env_initialize(NULL);
- __kmp_threads_capacity = __kmp_initial_threads_capacity( __kmp_dflt_team_nth_ub );
- // Moved here from __kmp_env_initialize() "KMP_ALL_THREADPRIVATE" part
- __kmp_tp_capacity = __kmp_default_tp_capacity(__kmp_dflt_team_nth_ub, __kmp_max_nth, __kmp_allThreadsSpecified);
-
- // If the library is shut down properly, both pools must be NULL. Just in case, set them
- // to NULL -- some memory may leak, but subsequent code will work even if pools are not freed.
- KMP_DEBUG_ASSERT( __kmp_thread_pool == NULL );
- KMP_DEBUG_ASSERT( __kmp_thread_pool_insert_pt == NULL );
- KMP_DEBUG_ASSERT( __kmp_team_pool == NULL );
- __kmp_thread_pool = NULL;
- __kmp_thread_pool_insert_pt = NULL;
- __kmp_team_pool = NULL;
+// Print all messages in message catalog for testing purposes.
+#ifdef KMP_DEBUG
+ char const *val = __kmp_env_get("KMP_DUMP_CATALOG");
+ if (__kmp_str_match_true(val)) {
+ kmp_str_buf_t buffer;
+ __kmp_str_buf_init(&buffer);
+ __kmp_i18n_dump_catalog(&buffer);
+ __kmp_printf("%s", buffer.str);
+ __kmp_str_buf_free(&buffer);
+ }; // if
+ __kmp_env_free(&val);
+#endif
+
+ __kmp_threads_capacity =
+ __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
+ // Moved here from __kmp_env_initialize() "KMP_ALL_THREADPRIVATE" part
+ __kmp_tp_capacity = __kmp_default_tp_capacity(
+ __kmp_dflt_team_nth_ub, __kmp_max_nth, __kmp_allThreadsSpecified);
+
+ // If the library is shut down properly, both pools must be NULL. Just in
+ // case, set them to NULL -- some memory may leak, but subsequent code will
+ // work even if pools are not freed.
+ KMP_DEBUG_ASSERT(__kmp_thread_pool == NULL);
+ KMP_DEBUG_ASSERT(__kmp_thread_pool_insert_pt == NULL);
+ KMP_DEBUG_ASSERT(__kmp_team_pool == NULL);
+ __kmp_thread_pool = NULL;
+ __kmp_thread_pool_insert_pt = NULL;
+ __kmp_team_pool = NULL;
+
+ /* Allocate all of the variable sized records */
+ /* NOTE: __kmp_threads_capacity entries are allocated, but the arrays are
+ * expandable */
+ /* Since allocation is cache-aligned, just add extra padding at the end */
+ size =
+ (sizeof(kmp_info_t *) + sizeof(kmp_root_t *)) * __kmp_threads_capacity +
+ CACHE_LINE;
+ __kmp_threads = (kmp_info_t **)__kmp_allocate(size);
+ __kmp_root = (kmp_root_t **)((char *)__kmp_threads +
+ sizeof(kmp_info_t *) * __kmp_threads_capacity);
+
+ /* init thread counts */
+ KMP_DEBUG_ASSERT(__kmp_all_nth ==
+ 0); // Asserts fail if the library is reinitializing and
+ KMP_DEBUG_ASSERT(__kmp_nth == 0); // something was wrong in termination.
+ __kmp_all_nth = 0;
+ __kmp_nth = 0;
+
+ /* setup the uber master thread and hierarchy */
+ gtid = __kmp_register_root(TRUE);
+ KA_TRACE(10, ("__kmp_do_serial_initialize T#%d\n", gtid));
+ KMP_ASSERT(KMP_UBER_GTID(gtid));
+ KMP_ASSERT(KMP_INITIAL_GTID(gtid));
- /* Allocate all of the variable sized records */
- /* NOTE: __kmp_threads_capacity entries are allocated, but the arrays are expandable */
- /* Since allocation is cache-aligned, just add extra padding at the end */
- size = (sizeof(kmp_info_t*) + sizeof(kmp_root_t*))*__kmp_threads_capacity + CACHE_LINE;
- __kmp_threads = (kmp_info_t**) __kmp_allocate( size );
- __kmp_root = (kmp_root_t**) ((char*)__kmp_threads + sizeof(kmp_info_t*) * __kmp_threads_capacity );
-
- /* init thread counts */
- KMP_DEBUG_ASSERT( __kmp_all_nth == 0 ); // Asserts fail if the library is reinitializing and
- KMP_DEBUG_ASSERT( __kmp_nth == 0 ); // something was wrong in termination.
- __kmp_all_nth = 0;
- __kmp_nth = 0;
-
- /* setup the uber master thread and hierarchy */
- gtid = __kmp_register_root( TRUE );
- KA_TRACE( 10, ("__kmp_do_serial_initialize T#%d\n", gtid ));
- KMP_ASSERT( KMP_UBER_GTID( gtid ) );
- KMP_ASSERT( KMP_INITIAL_GTID( gtid ) );
-
- KMP_MB(); /* Flush all pending memory write invalidates. */
-
- __kmp_common_initialize();
-
- #if KMP_OS_UNIX
- /* invoke the child fork handler */
- __kmp_register_atfork();
- #endif
+ KMP_MB(); /* Flush all pending memory write invalidates. */
- #if ! defined KMP_DYNAMIC_LIB
- {
- /* Invoke the exit handler when the program finishes, only for static library.
- For dynamic library, we already have _fini and DllMain.
- */
- int rc = atexit( __kmp_internal_end_atexit );
- if ( rc != 0 ) {
- __kmp_msg( kmp_ms_fatal, KMP_MSG( FunctionError, "atexit()" ), KMP_ERR( rc ), __kmp_msg_null );
- }; // if
- }
- #endif
+ __kmp_common_initialize();
+
+#if KMP_OS_UNIX
+ /* invoke the child fork handler */
+ __kmp_register_atfork();
+#endif
- #if KMP_HANDLE_SIGNALS
- #if KMP_OS_UNIX
- /* NOTE: make sure that this is called before the user installs
- * their own signal handlers so that the user handlers
- * are called first. this way they can return false,
- * not call our handler, avoid terminating the library,
- * and continue execution where they left off. */
- __kmp_install_signals( FALSE );
- #endif /* KMP_OS_UNIX */
- #if KMP_OS_WINDOWS
- __kmp_install_signals( TRUE );
- #endif /* KMP_OS_WINDOWS */
- #endif
-
- /* we have finished the serial initialization */
- __kmp_init_counter ++;
-
- __kmp_init_serial = TRUE;
+#if !defined KMP_DYNAMIC_LIB
+ {
+ /* Invoke the exit handler when the program finishes, only for static
+ library. For dynamic library, we already have _fini and DllMain. */
+ int rc = atexit(__kmp_internal_end_atexit);
+ if (rc != 0) {
+ __kmp_msg(kmp_ms_fatal, KMP_MSG(FunctionError, "atexit()"), KMP_ERR(rc),
+ __kmp_msg_null);
+ }; // if
+ }
+#endif
- if (__kmp_settings) {
- __kmp_env_print();
- }
+#if KMP_HANDLE_SIGNALS
+#if KMP_OS_UNIX
+ /* NOTE: make sure that this is called before the user installs their own
+ signal handlers so that the user handlers are called first. this way they
+ can return false, not call our handler, avoid terminating the library, and
+ continue execution where they left off. */
+ __kmp_install_signals(FALSE);
+#endif /* KMP_OS_UNIX */
+#if KMP_OS_WINDOWS
+ __kmp_install_signals(TRUE);
+#endif /* KMP_OS_WINDOWS */
+#endif
+
+ /* we have finished the serial initialization */
+ __kmp_init_counter++;
+
+ __kmp_init_serial = TRUE;
+
+ if (__kmp_settings) {
+ __kmp_env_print();
+ }
#if OMP_40_ENABLED
- if (__kmp_display_env || __kmp_display_env_verbose) {
- __kmp_env_print_2();
- }
+ if (__kmp_display_env || __kmp_display_env_verbose) {
+ __kmp_env_print_2();
+ }
#endif // OMP_40_ENABLED
#if OMPT_SUPPORT
- ompt_post_init();
+ ompt_post_init();
#endif
- KMP_MB();
+ KMP_MB();
- KA_TRACE( 10, ("__kmp_do_serial_initialize: exit\n" ) );
+ KA_TRACE(10, ("__kmp_do_serial_initialize: exit\n"));
}
-void
-__kmp_serial_initialize( void )
-{
- if ( __kmp_init_serial ) {
- return;
- }
- __kmp_acquire_bootstrap_lock( &__kmp_initz_lock );
- if ( __kmp_init_serial ) {
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
- return;
- }
- __kmp_do_serial_initialize();
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
+void __kmp_serial_initialize(void) {
+ if (__kmp_init_serial) {
+ return;
+ }
+ __kmp_acquire_bootstrap_lock(&__kmp_initz_lock);
+ if (__kmp_init_serial) {
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
+ return;
+ }
+ __kmp_do_serial_initialize();
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
}
-static void
-__kmp_do_middle_initialize( void )
-{
- int i, j;
- int prev_dflt_team_nth;
+static void __kmp_do_middle_initialize(void) {
+ int i, j;
+ int prev_dflt_team_nth;
- if( !__kmp_init_serial ) {
- __kmp_do_serial_initialize();
- }
+ if (!__kmp_init_serial) {
+ __kmp_do_serial_initialize();
+ }
- KA_TRACE( 10, ("__kmp_middle_initialize: enter\n" ) );
+ KA_TRACE(10, ("__kmp_middle_initialize: enter\n"));
- //
- // Save the previous value for the __kmp_dflt_team_nth so that
- // we can avoid some reinitialization if it hasn't changed.
- //
- prev_dflt_team_nth = __kmp_dflt_team_nth;
+ // Save the previous value for the __kmp_dflt_team_nth so that
+ // we can avoid some reinitialization if it hasn't changed.
+ prev_dflt_team_nth = __kmp_dflt_team_nth;
#if KMP_AFFINITY_SUPPORTED
- //
- // __kmp_affinity_initialize() will try to set __kmp_ncores to the
- // number of cores on the machine.
- //
- __kmp_affinity_initialize();
-
- //
- // Run through the __kmp_threads array and set the affinity mask
- // for each root thread that is currently registered with the RTL.
- //
- for ( i = 0; i < __kmp_threads_capacity; i++ ) {
- if ( TCR_PTR( __kmp_threads[ i ] ) != NULL ) {
- __kmp_affinity_set_init_mask( i, TRUE );
- }
+ // __kmp_affinity_initialize() will try to set __kmp_ncores to the
+ // number of cores on the machine.
+ __kmp_affinity_initialize();
+
+ // Run through the __kmp_threads array and set the affinity mask
+ // for each root thread that is currently registered with the RTL.
+ for (i = 0; i < __kmp_threads_capacity; i++) {
+ if (TCR_PTR(__kmp_threads[i]) != NULL) {
+ __kmp_affinity_set_init_mask(i, TRUE);
}
+ }
#endif /* KMP_AFFINITY_SUPPORTED */
- KMP_ASSERT( __kmp_xproc > 0 );
- if ( __kmp_avail_proc == 0 ) {
- __kmp_avail_proc = __kmp_xproc;
- }
-
- // If there were empty places in num_threads list (OMP_NUM_THREADS=,,2,3), correct them now
- j = 0;
- while ( ( j < __kmp_nested_nth.used ) && ! __kmp_nested_nth.nth[ j ] ) {
- __kmp_nested_nth.nth[ j ] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub = __kmp_avail_proc;
- j++;
- }
+ KMP_ASSERT(__kmp_xproc > 0);
+ if (__kmp_avail_proc == 0) {
+ __kmp_avail_proc = __kmp_xproc;
+ }
+
+ // If there were empty places in num_threads list (OMP_NUM_THREADS=,,2,3),
+ // correct them now
+ j = 0;
+ while ((j < __kmp_nested_nth.used) && !__kmp_nested_nth.nth[j]) {
+ __kmp_nested_nth.nth[j] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
+ __kmp_avail_proc;
+ j++;
+ }
- if ( __kmp_dflt_team_nth == 0 ) {
+ if (__kmp_dflt_team_nth == 0) {
#ifdef KMP_DFLT_NTH_CORES
- //
- // Default #threads = #cores
- //
- __kmp_dflt_team_nth = __kmp_ncores;
- KA_TRACE( 20, ("__kmp_middle_initialize: setting __kmp_dflt_team_nth = __kmp_ncores (%d)\n",
- __kmp_dflt_team_nth ) );
+ // Default #threads = #cores
+ __kmp_dflt_team_nth = __kmp_ncores;
+ KA_TRACE(20, ("__kmp_middle_initialize: setting __kmp_dflt_team_nth = "
+ "__kmp_ncores (%d)\n",
+ __kmp_dflt_team_nth));
#else
- //
- // Default #threads = #available OS procs
- //
- __kmp_dflt_team_nth = __kmp_avail_proc;
- KA_TRACE( 20, ("__kmp_middle_initialize: setting __kmp_dflt_team_nth = __kmp_avail_proc(%d)\n",
- __kmp_dflt_team_nth ) );
+ // Default #threads = #available OS procs
+ __kmp_dflt_team_nth = __kmp_avail_proc;
+ KA_TRACE(20, ("__kmp_middle_initialize: setting __kmp_dflt_team_nth = "
+ "__kmp_avail_proc(%d)\n",
+ __kmp_dflt_team_nth));
#endif /* KMP_DFLT_NTH_CORES */
- }
-
- if ( __kmp_dflt_team_nth < KMP_MIN_NTH ) {
- __kmp_dflt_team_nth = KMP_MIN_NTH;
- }
- if( __kmp_dflt_team_nth > __kmp_sys_max_nth ) {
- __kmp_dflt_team_nth = __kmp_sys_max_nth;
- }
+ }
- //
- // There's no harm in continuing if the following check fails,
- // but it indicates an error in the previous logic.
- //
- KMP_DEBUG_ASSERT( __kmp_dflt_team_nth <= __kmp_dflt_team_nth_ub );
-
- if ( __kmp_dflt_team_nth != prev_dflt_team_nth ) {
- //
- // Run through the __kmp_threads array and set the num threads icv
- // for each root thread that is currently registered with the RTL
- // (which has not already explicitly set its nthreads-var with a
- // call to omp_set_num_threads()).
- //
- for ( i = 0; i < __kmp_threads_capacity; i++ ) {
- kmp_info_t *thread = __kmp_threads[ i ];
- if ( thread == NULL ) continue;
- if ( thread->th.th_current_task->td_icvs.nproc != 0 ) continue;
-
- set__nproc( __kmp_threads[ i ], __kmp_dflt_team_nth );
- }
- }
- KA_TRACE( 20, ("__kmp_middle_initialize: final value for __kmp_dflt_team_nth = %d\n",
- __kmp_dflt_team_nth) );
+ if (__kmp_dflt_team_nth < KMP_MIN_NTH) {
+ __kmp_dflt_team_nth = KMP_MIN_NTH;
+ }
+ if (__kmp_dflt_team_nth > __kmp_sys_max_nth) {
+ __kmp_dflt_team_nth = __kmp_sys_max_nth;
+ }
+
+ // There's no harm in continuing if the following check fails,
+ // but it indicates an error in the previous logic.
+ KMP_DEBUG_ASSERT(__kmp_dflt_team_nth <= __kmp_dflt_team_nth_ub);
+
+ if (__kmp_dflt_team_nth != prev_dflt_team_nth) {
+ // Run through the __kmp_threads array and set the num threads icv for each
+ // root thread that is currently registered with the RTL (which has not
+ // already explicitly set its nthreads-var with a call to
+ // omp_set_num_threads()).
+ for (i = 0; i < __kmp_threads_capacity; i++) {
+ kmp_info_t *thread = __kmp_threads[i];
+ if (thread == NULL)
+ continue;
+ if (thread->th.th_current_task->td_icvs.nproc != 0)
+ continue;
+
+ set__nproc(__kmp_threads[i], __kmp_dflt_team_nth);
+ }
+ }
+ KA_TRACE(
+ 20,
+ ("__kmp_middle_initialize: final value for __kmp_dflt_team_nth = %d\n",
+ __kmp_dflt_team_nth));
#ifdef KMP_ADJUST_BLOCKTIME
- /* Adjust blocktime to zero if necessary */
- /* now that __kmp_avail_proc is set */
- if ( !__kmp_env_blocktime && ( __kmp_avail_proc > 0 ) ) {
- KMP_DEBUG_ASSERT( __kmp_avail_proc > 0 );
- if ( __kmp_nth > __kmp_avail_proc ) {
- __kmp_zero_bt = TRUE;
- }
+ /* Adjust blocktime to zero if necessary now that __kmp_avail_proc is set */
+ if (!__kmp_env_blocktime && (__kmp_avail_proc > 0)) {
+ KMP_DEBUG_ASSERT(__kmp_avail_proc > 0);
+ if (__kmp_nth > __kmp_avail_proc) {
+ __kmp_zero_bt = TRUE;
}
+ }
#endif /* KMP_ADJUST_BLOCKTIME */
- /* we have finished middle initialization */
- TCW_SYNC_4(__kmp_init_middle, TRUE);
-
- KA_TRACE( 10, ("__kmp_do_middle_initialize: exit\n" ) );
-}
+ /* we have finished middle initialization */
+ TCW_SYNC_4(__kmp_init_middle, TRUE);
-void
-__kmp_middle_initialize( void )
-{
- if ( __kmp_init_middle ) {
- return;
- }
- __kmp_acquire_bootstrap_lock( &__kmp_initz_lock );
- if ( __kmp_init_middle ) {
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
- return;
- }
- __kmp_do_middle_initialize();
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
+ KA_TRACE(10, ("__kmp_do_middle_initialize: exit\n"));
}
-void
-__kmp_parallel_initialize( void )
-{
- int gtid = __kmp_entry_gtid(); // this might be a new root
-
- /* synchronize parallel initialization (for sibling) */
- if( TCR_4(__kmp_init_parallel) ) return;
- __kmp_acquire_bootstrap_lock( &__kmp_initz_lock );
- if( TCR_4(__kmp_init_parallel) ) { __kmp_release_bootstrap_lock( &__kmp_initz_lock ); return; }
-
- /* TODO reinitialization after we have already shut down */
- if( TCR_4(__kmp_global.g.g_done) ) {
- KA_TRACE( 10, ("__kmp_parallel_initialize: attempt to init while shutting down\n" ) );
- __kmp_infinite_loop();
- }
+void __kmp_middle_initialize(void) {
+ if (__kmp_init_middle) {
+ return;
+ }
+ __kmp_acquire_bootstrap_lock(&__kmp_initz_lock);
+ if (__kmp_init_middle) {
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
+ return;
+ }
+ __kmp_do_middle_initialize();
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
+}
+
+void __kmp_parallel_initialize(void) {
+ int gtid = __kmp_entry_gtid(); // this might be a new root
+
+ /* synchronize parallel initialization (for sibling) */
+ if (TCR_4(__kmp_init_parallel))
+ return;
+ __kmp_acquire_bootstrap_lock(&__kmp_initz_lock);
+ if (TCR_4(__kmp_init_parallel)) {
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
+ return;
+ }
+
+ /* TODO reinitialization after we have already shut down */
+ if (TCR_4(__kmp_global.g.g_done)) {
+ KA_TRACE(
+ 10,
+ ("__kmp_parallel_initialize: attempt to init while shutting down\n"));
+ __kmp_infinite_loop();
+ }
- /* jc: The lock __kmp_initz_lock is already held, so calling __kmp_serial_initialize
- would cause a deadlock. So we call __kmp_do_serial_initialize directly.
- */
- if( !__kmp_init_middle ) {
- __kmp_do_middle_initialize();
- }
+ /* jc: The lock __kmp_initz_lock is already held, so calling
+ __kmp_serial_initialize would cause a deadlock. So we call
+ __kmp_do_serial_initialize directly. */
+ if (!__kmp_init_middle) {
+ __kmp_do_middle_initialize();
+ }
- /* begin initialization */
- KA_TRACE( 10, ("__kmp_parallel_initialize: enter\n" ) );
- KMP_ASSERT( KMP_UBER_GTID( gtid ) );
+ /* begin initialization */
+ KA_TRACE(10, ("__kmp_parallel_initialize: enter\n"));
+ KMP_ASSERT(KMP_UBER_GTID(gtid));
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
- //
- // Save the FP control regs.
- // Worker threads will set theirs to these values at thread startup.
- //
- __kmp_store_x87_fpu_control_word( &__kmp_init_x87_fpu_control_word );
- __kmp_store_mxcsr( &__kmp_init_mxcsr );
- __kmp_init_mxcsr &= KMP_X86_MXCSR_MASK;
+ // Save the FP control regs.
+ // Worker threads will set theirs to these values at thread startup.
+ __kmp_store_x87_fpu_control_word(&__kmp_init_x87_fpu_control_word);
+ __kmp_store_mxcsr(&__kmp_init_mxcsr);
+ __kmp_init_mxcsr &= KMP_X86_MXCSR_MASK;
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
#if KMP_OS_UNIX
-# if KMP_HANDLE_SIGNALS
- /* must be after __kmp_serial_initialize */
- __kmp_install_signals( TRUE );
-# endif
+#if KMP_HANDLE_SIGNALS
+ /* must be after __kmp_serial_initialize */
+ __kmp_install_signals(TRUE);
+#endif
#endif
- __kmp_suspend_initialize();
+ __kmp_suspend_initialize();
#if defined(USE_LOAD_BALANCE)
- if ( __kmp_global.g.g_dynamic_mode == dynamic_default ) {
- __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
- }
+ if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
+ __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
+ }
#else
- if ( __kmp_global.g.g_dynamic_mode == dynamic_default ) {
- __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
- }
+ if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
+ __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
+ }
#endif
- if ( __kmp_version ) {
- __kmp_print_version_2();
- }
+ if (__kmp_version) {
+ __kmp_print_version_2();
+ }
- /* we have finished parallel initialization */
- TCW_SYNC_4(__kmp_init_parallel, TRUE);
+ /* we have finished parallel initialization */
+ TCW_SYNC_4(__kmp_init_parallel, TRUE);
- KMP_MB();
- KA_TRACE( 10, ("__kmp_parallel_initialize: exit\n" ) );
+ KMP_MB();
+ KA_TRACE(10, ("__kmp_parallel_initialize: exit\n"));
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
}
-
/* ------------------------------------------------------------------------ */
-void
-__kmp_run_before_invoked_task( int gtid, int tid, kmp_info_t *this_thr,
- kmp_team_t *team )
-{
- kmp_disp_t *dispatch;
+void __kmp_run_before_invoked_task(int gtid, int tid, kmp_info_t *this_thr,
+ kmp_team_t *team) {
+ kmp_disp_t *dispatch;
- KMP_MB();
+ KMP_MB();
- /* none of the threads have encountered any constructs, yet. */
- this_thr->th.th_local.this_construct = 0;
+ /* none of the threads have encountered any constructs, yet. */
+ this_thr->th.th_local.this_construct = 0;
#if KMP_CACHE_MANAGE
- KMP_CACHE_PREFETCH( &this_thr->th.th_bar[ bs_forkjoin_barrier ].bb.b_arrived );
+ KMP_CACHE_PREFETCH(&this_thr->th.th_bar[bs_forkjoin_barrier].bb.b_arrived);
#endif /* KMP_CACHE_MANAGE */
- dispatch = (kmp_disp_t *)TCR_PTR(this_thr->th.th_dispatch);
- KMP_DEBUG_ASSERT( dispatch );
- KMP_DEBUG_ASSERT( team->t.t_dispatch );
- //KMP_DEBUG_ASSERT( this_thr->th.th_dispatch == &team->t.t_dispatch[ this_thr->th.th_info.ds.ds_tid ] );
+ dispatch = (kmp_disp_t *)TCR_PTR(this_thr->th.th_dispatch);
+ KMP_DEBUG_ASSERT(dispatch);
+ KMP_DEBUG_ASSERT(team->t.t_dispatch);
+ // KMP_DEBUG_ASSERT( this_thr->th.th_dispatch == &team->t.t_dispatch[
+ // this_thr->th.th_info.ds.ds_tid ] );
- dispatch->th_disp_index = 0; /* reset the dispatch buffer counter */
+ dispatch->th_disp_index = 0; /* reset the dispatch buffer counter */
#if OMP_45_ENABLED
- dispatch->th_doacross_buf_idx = 0; /* reset the doacross dispatch buffer counter */
+ dispatch->th_doacross_buf_idx =
+ 0; /* reset the doacross dispatch buffer counter */
#endif
- if( __kmp_env_consistency_check )
- __kmp_push_parallel( gtid, team->t.t_ident );
+ if (__kmp_env_consistency_check)
+ __kmp_push_parallel(gtid, team->t.t_ident);
- KMP_MB(); /* Flush all pending memory write invalidates. */
+ KMP_MB(); /* Flush all pending memory write invalidates. */
}
-void
-__kmp_run_after_invoked_task( int gtid, int tid, kmp_info_t *this_thr,
- kmp_team_t *team )
-{
- if( __kmp_env_consistency_check )
- __kmp_pop_parallel( gtid, team->t.t_ident );
+void __kmp_run_after_invoked_task(int gtid, int tid, kmp_info_t *this_thr,
+ kmp_team_t *team) {
+ if (__kmp_env_consistency_check)
+ __kmp_pop_parallel(gtid, team->t.t_ident);
- __kmp_finish_implicit_task(this_thr);
+ __kmp_finish_implicit_task(this_thr);
}
-int
-__kmp_invoke_task_func( int gtid )
-{
- int rc;
- int tid = __kmp_tid_from_gtid( gtid );
- kmp_info_t *this_thr = __kmp_threads[ gtid ];
- kmp_team_t *team = this_thr->th.th_team;
+int __kmp_invoke_task_func(int gtid) {
+ int rc;
+ int tid = __kmp_tid_from_gtid(gtid);
+ kmp_info_t *this_thr = __kmp_threads[gtid];
+ kmp_team_t *team = this_thr->th.th_team;
- __kmp_run_before_invoked_task( gtid, tid, this_thr, team );
+ __kmp_run_before_invoked_task(gtid, tid, this_thr, team);
#if USE_ITT_BUILD
- if ( __itt_stack_caller_create_ptr ) {
- __kmp_itt_stack_callee_enter( (__itt_caller)team->t.t_stack_id ); // inform ittnotify about entering user's code
- }
+ if (__itt_stack_caller_create_ptr) {
+ __kmp_itt_stack_callee_enter(
+ (__itt_caller)
+ team->t.t_stack_id); // inform ittnotify about entering user's code
+ }
#endif /* USE_ITT_BUILD */
#if INCLUDE_SSC_MARKS
- SSC_MARK_INVOKING();
+ SSC_MARK_INVOKING();
#endif
#if OMPT_SUPPORT
- void *dummy;
- void **exit_runtime_p;
- ompt_task_id_t my_task_id;
- ompt_parallel_id_t my_parallel_id;
+ void *dummy;
+ void **exit_runtime_p;
+ ompt_task_id_t my_task_id;
+ ompt_parallel_id_t my_parallel_id;
- if (ompt_enabled) {
- exit_runtime_p = &(team->t.t_implicit_task_taskdata[tid].
- ompt_task_info.frame.exit_runtime_frame);
- } else {
- exit_runtime_p = &dummy;
- }
+ if (ompt_enabled) {
+ exit_runtime_p = &(team->t.t_implicit_task_taskdata[tid]
+ .ompt_task_info.frame.exit_runtime_frame);
+ } else {
+ exit_runtime_p = &dummy;
+ }
#if OMPT_TRACE
- my_task_id = team->t.t_implicit_task_taskdata[tid].ompt_task_info.task_id;
- my_parallel_id = team->t.ompt_team_info.parallel_id;
- if (ompt_enabled &&
- ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
- ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(
- my_parallel_id, my_task_id);
- }
+ my_task_id = team->t.t_implicit_task_taskdata[tid].ompt_task_info.task_id;
+ my_parallel_id = team->t.ompt_team_info.parallel_id;
+ if (ompt_enabled &&
+ ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)) {
+ ompt_callbacks.ompt_callback(ompt_event_implicit_task_begin)(my_parallel_id,
+ my_task_id);
+ }
#endif
#endif
- {
- KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
- KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
- rc = __kmp_invoke_microtask( (microtask_t) TCR_SYNC_PTR(team->t.t_pkfn),
- gtid, tid, (int) team->t.t_argc, (void **) team->t.t_argv
+ {
+ KMP_TIME_PARTITIONED_BLOCK(OMP_parallel);
+ KMP_SET_THREAD_STATE_BLOCK(IMPLICIT_TASK);
+ rc =
+ __kmp_invoke_microtask((microtask_t)TCR_SYNC_PTR(team->t.t_pkfn), gtid,
+ tid, (int)team->t.t_argc, (void **)team->t.t_argv
#if OMPT_SUPPORT
- , exit_runtime_p
+ ,
+ exit_runtime_p
#endif
- );
+ );
#if OMPT_SUPPORT
- *exit_runtime_p = NULL;
+ *exit_runtime_p = NULL;
#endif
- }
+ }
#if USE_ITT_BUILD
- if ( __itt_stack_caller_create_ptr ) {
- __kmp_itt_stack_callee_leave( (__itt_caller)team->t.t_stack_id ); // inform ittnotify about leaving user's code
- }
+ if (__itt_stack_caller_create_ptr) {
+ __kmp_itt_stack_callee_leave(
+ (__itt_caller)
+ team->t.t_stack_id); // inform ittnotify about leaving user's code
+ }
#endif /* USE_ITT_BUILD */
- __kmp_run_after_invoked_task( gtid, tid, this_thr, team );
+ __kmp_run_after_invoked_task(gtid, tid, this_thr, team);
- return rc;
+ return rc;
}
#if OMP_40_ENABLED
-void
-__kmp_teams_master( int gtid )
-{
- // This routine is called by all master threads in teams construct
- kmp_info_t *thr = __kmp_threads[ gtid ];
- kmp_team_t *team = thr->th.th_team;
- ident_t *loc = team->t.t_ident;
- thr->th.th_set_nproc = thr->th.th_teams_size.nth;
- KMP_DEBUG_ASSERT( thr->th.th_teams_microtask );
- KMP_DEBUG_ASSERT( thr->th.th_set_nproc );
- KA_TRACE( 20, ("__kmp_teams_master: T#%d, Tid %d, microtask %p\n",
- gtid, __kmp_tid_from_gtid( gtid ), thr->th.th_teams_microtask ) );
- // Launch league of teams now, but not let workers execute
- // (they hang on fork barrier until next parallel)
+void __kmp_teams_master(int gtid) {
+ // This routine is called by all master threads in teams construct
+ kmp_info_t *thr = __kmp_threads[gtid];
+ kmp_team_t *team = thr->th.th_team;
+ ident_t *loc = team->t.t_ident;
+ thr->th.th_set_nproc = thr->th.th_teams_size.nth;
+ KMP_DEBUG_ASSERT(thr->th.th_teams_microtask);
+ KMP_DEBUG_ASSERT(thr->th.th_set_nproc);
+ KA_TRACE(20, ("__kmp_teams_master: T#%d, Tid %d, microtask %p\n", gtid,
+ __kmp_tid_from_gtid(gtid), thr->th.th_teams_microtask));
+// Launch league of teams now, but not let workers execute
+// (they hang on fork barrier until next parallel)
#if INCLUDE_SSC_MARKS
- SSC_MARK_FORKING();
+ SSC_MARK_FORKING();
#endif
- __kmp_fork_call( loc, gtid, fork_context_intel,
- team->t.t_argc,
+ __kmp_fork_call(loc, gtid, fork_context_intel, team->t.t_argc,
#if OMPT_SUPPORT
- (void *)thr->th.th_teams_microtask, // "unwrapped" task
+ (void *)thr->th.th_teams_microtask, // "unwrapped" task
#endif
- (microtask_t)thr->th.th_teams_microtask, // "wrapped" task
- VOLATILE_CAST(launch_t) __kmp_invoke_task_func,
- NULL );
+ (microtask_t)thr->th.th_teams_microtask, // "wrapped" task
+ VOLATILE_CAST(launch_t) __kmp_invoke_task_func, NULL);
#if INCLUDE_SSC_MARKS
- SSC_MARK_JOINING();
+ SSC_MARK_JOINING();
#endif
- // AC: last parameter "1" eliminates join barrier which won't work because
- // worker threads are in a fork barrier waiting for more parallel regions
- __kmp_join_call( loc, gtid
-#if OMPT_SUPPORT
- , fork_context_intel
-#endif
- , 1 );
-}
-
-int
-__kmp_invoke_teams_master( int gtid )
-{
- kmp_info_t *this_thr = __kmp_threads[ gtid ];
- kmp_team_t *team = this_thr->th.th_team;
- #if KMP_DEBUG
- if ( !__kmp_threads[gtid]-> th.th_team->t.t_serialized )
- KMP_DEBUG_ASSERT( (void*)__kmp_threads[gtid]-> th.th_team->t.t_pkfn == (void*)__kmp_teams_master );
- #endif
- __kmp_run_before_invoked_task( gtid, 0, this_thr, team );
- __kmp_teams_master( gtid );
- __kmp_run_after_invoked_task( gtid, 0, this_thr, team );
- return 1;
+ // AC: last parameter "1" eliminates join barrier which won't work because
+ // worker threads are in a fork barrier waiting for more parallel regions
+ __kmp_join_call(loc, gtid
+#if OMPT_SUPPORT
+ ,
+ fork_context_intel
+#endif
+ ,
+ 1);
+}
+
+int __kmp_invoke_teams_master(int gtid) {
+ kmp_info_t *this_thr = __kmp_threads[gtid];
+ kmp_team_t *team = this_thr->th.th_team;
+#if KMP_DEBUG
+ if (!__kmp_threads[gtid]->th.th_team->t.t_serialized)
+ KMP_DEBUG_ASSERT((void *)__kmp_threads[gtid]->th.th_team->t.t_pkfn ==
+ (void *)__kmp_teams_master);
+#endif
+ __kmp_run_before_invoked_task(gtid, 0, this_thr, team);
+ __kmp_teams_master(gtid);
+ __kmp_run_after_invoked_task(gtid, 0, this_thr, team);
+ return 1;
}
#endif /* OMP_40_ENABLED */
/* this sets the requested number of threads for the next parallel region
- * encountered by this team */
-/* since this should be enclosed in the forkjoin critical section it
- * should avoid race conditions with assymmetrical nested parallelism */
-
-void
-__kmp_push_num_threads( ident_t *id, int gtid, int num_threads )
-{
- kmp_info_t *thr = __kmp_threads[gtid];
+ encountered by this team. since this should be enclosed in the forkjoin
+ critical section it should avoid race conditions with assymmetrical nested
+ parallelism */
- if( num_threads > 0 )
- thr->th.th_set_nproc = num_threads;
+void __kmp_push_num_threads(ident_t *id, int gtid, int num_threads) {
+ kmp_info_t *thr = __kmp_threads[gtid];
+
+ if (num_threads > 0)
+ thr->th.th_set_nproc = num_threads;
}
#if OMP_40_ENABLED
/* this sets the requested number of teams for the teams region and/or
- * the number of threads for the next parallel region encountered */
-void
-__kmp_push_num_teams( ident_t *id, int gtid, int num_teams, int num_threads )
-{
- kmp_info_t *thr = __kmp_threads[gtid];
- KMP_DEBUG_ASSERT(num_teams >= 0);
- KMP_DEBUG_ASSERT(num_threads >= 0);
-
- if( num_teams == 0 )
- num_teams = 1; // default number of teams is 1.
- if( num_teams > __kmp_max_nth ) { // if too many teams requested?
- if ( !__kmp_reserve_warn ) {
- __kmp_reserve_warn = 1;
- __kmp_msg(
- kmp_ms_warning,
- KMP_MSG( CantFormThrTeam, num_teams, __kmp_max_nth ),
- KMP_HNT( Unset_ALL_THREADS ),
- __kmp_msg_null
- );
- }
- num_teams = __kmp_max_nth;
- }
- // Set number of teams (number of threads in the outer "parallel" of the teams)
- thr->th.th_set_nproc = thr->th.th_teams_size.nteams = num_teams;
-
- // Remember the number of threads for inner parallel regions
- if( num_threads == 0 ) {
- if( !TCR_4(__kmp_init_middle) )
- __kmp_middle_initialize(); // get __kmp_avail_proc calculated
- num_threads = __kmp_avail_proc / num_teams;
- if( num_teams * num_threads > __kmp_max_nth ) {
- // adjust num_threads w/o warning as it is not user setting
- num_threads = __kmp_max_nth / num_teams;
- }
- } else {
- if( num_teams * num_threads > __kmp_max_nth ) {
- int new_threads = __kmp_max_nth / num_teams;
- if ( !__kmp_reserve_warn ) { // user asked for too many threads
- __kmp_reserve_warn = 1; // that conflicts with OMP_THREAD_LIMIT
- __kmp_msg(
- kmp_ms_warning,
- KMP_MSG( CantFormThrTeam, num_threads, new_threads ),
- KMP_HNT( Unset_ALL_THREADS ),
- __kmp_msg_null
- );
- }
- num_threads = new_threads;
- }
+ the number of threads for the next parallel region encountered */
+void __kmp_push_num_teams(ident_t *id, int gtid, int num_teams,
+ int num_threads) {
+ kmp_info_t *thr = __kmp_threads[gtid];
+ KMP_DEBUG_ASSERT(num_teams >= 0);
+ KMP_DEBUG_ASSERT(num_threads >= 0);
+
+ if (num_teams == 0)
+ num_teams = 1; // default number of teams is 1.
+ if (num_teams > __kmp_max_nth) { // if too many teams requested?
+ if (!__kmp_reserve_warn) {
+ __kmp_reserve_warn = 1;
+ __kmp_msg(kmp_ms_warning,
+ KMP_MSG(CantFormThrTeam, num_teams, __kmp_max_nth),
+ KMP_HNT(Unset_ALL_THREADS), __kmp_msg_null);
+ }
+ num_teams = __kmp_max_nth;
+ }
+ // Set number of teams (number of threads in the outer "parallel" of the
+ // teams)
+ thr->th.th_set_nproc = thr->th.th_teams_size.nteams = num_teams;
+
+ // Remember the number of threads for inner parallel regions
+ if (num_threads == 0) {
+ if (!TCR_4(__kmp_init_middle))
+ __kmp_middle_initialize(); // get __kmp_avail_proc calculated
+ num_threads = __kmp_avail_proc / num_teams;
+ if (num_teams * num_threads > __kmp_max_nth) {
+ // adjust num_threads w/o warning as it is not user setting
+ num_threads = __kmp_max_nth / num_teams;
+ }
+ } else {
+ if (num_teams * num_threads > __kmp_max_nth) {
+ int new_threads = __kmp_max_nth / num_teams;
+ if (!__kmp_reserve_warn) { // user asked for too many threads
+ __kmp_reserve_warn = 1; // that conflicts with OMP_THREAD_LIMIT
+ __kmp_msg(kmp_ms_warning,
+ KMP_MSG(CantFormThrTeam, num_threads, new_threads),
+ KMP_HNT(Unset_ALL_THREADS), __kmp_msg_null);
+ }
+ num_threads = new_threads;
}
- thr->th.th_teams_size.nth = num_threads;
+ }
+ thr->th.th_teams_size.nth = num_threads;
}
-
-//
// Set the proc_bind var to use in the following parallel region.
-//
-void
-__kmp_push_proc_bind( ident_t *id, int gtid, kmp_proc_bind_t proc_bind )
-{
- kmp_info_t *thr = __kmp_threads[gtid];
- thr->th.th_set_proc_bind = proc_bind;
+void __kmp_push_proc_bind(ident_t *id, int gtid, kmp_proc_bind_t proc_bind) {
+ kmp_info_t *thr = __kmp_threads[gtid];
+ thr->th.th_set_proc_bind = proc_bind;
}
#endif /* OMP_40_ENABLED */
/* Launch the worker threads into the microtask. */
-void
-__kmp_internal_fork( ident_t *id, int gtid, kmp_team_t *team )
-{
- kmp_info_t *this_thr = __kmp_threads[gtid];
+void __kmp_internal_fork(ident_t *id, int gtid, kmp_team_t *team) {
+ kmp_info_t *this_thr = __kmp_threads[gtid];
#ifdef KMP_DEBUG
- int f;
+ int f;
#endif /* KMP_DEBUG */
- KMP_DEBUG_ASSERT( team );
- KMP_DEBUG_ASSERT( this_thr->th.th_team == team );
- KMP_ASSERT( KMP_MASTER_GTID(gtid) );
- KMP_MB(); /* Flush all pending memory write invalidates. */
-
- team->t.t_construct = 0; /* no single directives seen yet */
- team->t.t_ordered.dt.t_value = 0; /* thread 0 enters the ordered section first */
-
- /* Reset the identifiers on the dispatch buffer */
- KMP_DEBUG_ASSERT( team->t.t_disp_buffer );
- if ( team->t.t_max_nproc > 1 ) {
- int i;
- for (i = 0; i < __kmp_dispatch_num_buffers; ++i) {
- team->t.t_disp_buffer[ i ].buffer_index = i;
+ KMP_DEBUG_ASSERT(team);
+ KMP_DEBUG_ASSERT(this_thr->th.th_team == team);
+ KMP_ASSERT(KMP_MASTER_GTID(gtid));
+ KMP_MB(); /* Flush all pending memory write invalidates. */
+
+ team->t.t_construct = 0; /* no single directives seen yet */
+ team->t.t_ordered.dt.t_value =
+ 0; /* thread 0 enters the ordered section first */
+
+ /* Reset the identifiers on the dispatch buffer */
+ KMP_DEBUG_ASSERT(team->t.t_disp_buffer);
+ if (team->t.t_max_nproc > 1) {
+ int i;
+ for (i = 0; i < __kmp_dispatch_num_buffers; ++i) {
+ team->t.t_disp_buffer[i].buffer_index = i;
#if OMP_45_ENABLED
- team->t.t_disp_buffer[i].doacross_buf_idx = i;
+ team->t.t_disp_buffer[i].doacross_buf_idx = i;
#endif
- }
- } else {
- team->t.t_disp_buffer[ 0 ].buffer_index = 0;
+ }
+ } else {
+ team->t.t_disp_buffer[0].buffer_index = 0;
#if OMP_45_ENABLED
- team->t.t_disp_buffer[0].doacross_buf_idx = 0;
+ team->t.t_disp_buffer[0].doacross_buf_idx = 0;
#endif
- }
+ }
- KMP_MB(); /* Flush all pending memory write invalidates. */
- KMP_ASSERT( this_thr->th.th_team == team );
+ KMP_MB(); /* Flush all pending memory write invalidates. */
+ KMP_ASSERT(this_thr->th.th_team == team);
#ifdef KMP_DEBUG
- for( f=0 ; f<team->t.t_nproc ; f++ ) {
- KMP_DEBUG_ASSERT( team->t.t_threads[f] &&
- team->t.t_threads[f]->th.th_team_nproc == team->t.t_nproc );
- }
+ for (f = 0; f < team->t.t_nproc; f++) {
+ KMP_DEBUG_ASSERT(team->t.t_threads[f] &&
+ team->t.t_threads[f]->th.th_team_nproc == team->t.t_nproc);
+ }
#endif /* KMP_DEBUG */
- /* release the worker threads so they may begin working */
- __kmp_fork_barrier( gtid, 0 );
+ /* release the worker threads so they may begin working */
+ __kmp_fork_barrier(gtid, 0);
}
+void __kmp_internal_join(ident_t *id, int gtid, kmp_team_t *team) {
+ kmp_info_t *this_thr = __kmp_threads[gtid];
-void
-__kmp_internal_join( ident_t *id, int gtid, kmp_team_t *team )
-{
- kmp_info_t *this_thr = __kmp_threads[gtid];
-
- KMP_DEBUG_ASSERT( team );
- KMP_DEBUG_ASSERT( this_thr->th.th_team == team );
- KMP_ASSERT( KMP_MASTER_GTID(gtid) );
- KMP_MB(); /* Flush all pending memory write invalidates. */
+ KMP_DEBUG_ASSERT(team);
+ KMP_DEBUG_ASSERT(this_thr->th.th_team == team);
+ KMP_ASSERT(KMP_MASTER_GTID(gtid));
+ KMP_MB(); /* Flush all pending memory write invalidates. */
- /* Join barrier after fork */
+/* Join barrier after fork */
#ifdef KMP_DEBUG
- if (__kmp_threads[gtid] && __kmp_threads[gtid]->th.th_team_nproc != team->t.t_nproc ) {
- __kmp_printf("GTID: %d, __kmp_threads[%d]=%p\n",gtid, gtid, __kmp_threads[gtid]);
- __kmp_printf("__kmp_threads[%d]->th.th_team_nproc=%d, TEAM: %p, team->t.t_nproc=%d\n",
- gtid, __kmp_threads[gtid]->th.th_team_nproc, team, team->t.t_nproc);
- __kmp_print_structure();
- }
- KMP_DEBUG_ASSERT( __kmp_threads[gtid] &&
- __kmp_threads[gtid]->th.th_team_nproc == team->t.t_nproc );
+ if (__kmp_threads[gtid] &&
+ __kmp_threads[gtid]->th.th_team_nproc != team->t.t_nproc) {
+ __kmp_printf("GTID: %d, __kmp_threads[%d]=%p\n", gtid, gtid,
+ __kmp_threads[gtid]);
+ __kmp_printf("__kmp_threads[%d]->th.th_team_nproc=%d, TEAM: %p, "
+ "team->t.t_nproc=%d\n",
+ gtid, __kmp_threads[gtid]->th.th_team_nproc, team,
+ team->t.t_nproc);
+ __kmp_print_structure();
+ }
+ KMP_DEBUG_ASSERT(__kmp_threads[gtid] &&
+ __kmp_threads[gtid]->th.th_team_nproc == team->t.t_nproc);
#endif /* KMP_DEBUG */
- __kmp_join_barrier( gtid ); /* wait for everyone */
+ __kmp_join_barrier(gtid); /* wait for everyone */
- KMP_MB(); /* Flush all pending memory write invalidates. */
- KMP_ASSERT( this_thr->th.th_team == team );
+ KMP_MB(); /* Flush all pending memory write invalidates. */
+ KMP_ASSERT(this_thr->th.th_team == team);
}
-
-/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
#ifdef USE_LOAD_BALANCE
-//
// Return the worker threads actively spinning in the hot team, if we
// are at the outermost level of parallelism. Otherwise, return 0.
-//
-static int
-__kmp_active_hot_team_nproc( kmp_root_t *root )
-{
- int i;
- int retval;
- kmp_team_t *hot_team;
-
- if ( root->r.r_active ) {
- return 0;
- }
- hot_team = root->r.r_hot_team;
- if ( __kmp_dflt_blocktime == KMP_MAX_BLOCKTIME ) {
- return hot_team->t.t_nproc - 1; // Don't count master thread
- }
-
- //
- // Skip the master thread - it is accounted for elsewhere.
- //
- retval = 0;
- for ( i = 1; i < hot_team->t.t_nproc; i++ ) {
- if ( hot_team->t.t_threads[i]->th.th_active ) {
- retval++;
- }
+static int __kmp_active_hot_team_nproc(kmp_root_t *root) {
+ int i;
+ int retval;
+ kmp_team_t *hot_team;
+
+ if (root->r.r_active) {
+ return 0;
+ }
+ hot_team = root->r.r_hot_team;
+ if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME) {
+ return hot_team->t.t_nproc - 1; // Don't count master thread
+ }
+
+ // Skip the master thread - it is accounted for elsewhere.
+ retval = 0;
+ for (i = 1; i < hot_team->t.t_nproc; i++) {
+ if (hot_team->t.t_threads[i]->th.th_active) {
+ retval++;
}
- return retval;
+ }
+ return retval;
}
-//
// Perform an automatic adjustment to the number of
// threads used by the next parallel region.
-//
-static int
-__kmp_load_balance_nproc( kmp_root_t *root, int set_nproc )
-{
- int retval;
- int pool_active;
- int hot_team_active;
- int team_curr_active;
- int system_active;
-
- KB_TRACE( 20, ("__kmp_load_balance_nproc: called root:%p set_nproc:%d\n",
- root, set_nproc ) );
- KMP_DEBUG_ASSERT( root );
- KMP_DEBUG_ASSERT( root->r.r_root_team->t.t_threads[0]->th.th_current_task->td_icvs.dynamic == TRUE );
- KMP_DEBUG_ASSERT( set_nproc > 1 );
-
- if ( set_nproc == 1) {
- KB_TRACE( 20, ("__kmp_load_balance_nproc: serial execution.\n" ) );
- return 1;
- }
-
- //
- // Threads that are active in the thread pool, active in the hot team
- // for this particular root (if we are at the outer par level), and
- // the currently executing thread (to become the master) are available
- // to add to the new team, but are currently contributing to the system
- // load, and must be accounted for.
- //
- pool_active = TCR_4(__kmp_thread_pool_active_nth);
- hot_team_active = __kmp_active_hot_team_nproc( root );
- team_curr_active = pool_active + hot_team_active + 1;
-
- //
- // Check the system load.
- //
- system_active = __kmp_get_load_balance( __kmp_avail_proc + team_curr_active );
- KB_TRACE( 30, ("__kmp_load_balance_nproc: system active = %d pool active = %d hot team active = %d\n",
- system_active, pool_active, hot_team_active ) );
-
- if ( system_active < 0 ) {
- //
- // There was an error reading the necessary info from /proc,
- // so use the thread limit algorithm instead. Once we set
- // __kmp_global.g.g_dynamic_mode = dynamic_thread_limit,
- // we shouldn't wind up getting back here.
- //
- __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
- KMP_WARNING( CantLoadBalUsing, "KMP_DYNAMIC_MODE=thread limit" );
-
- //
- // Make this call behave like the thread limit algorithm.
- //
- retval = __kmp_avail_proc - __kmp_nth + (root->r.r_active ? 1
- : root->r.r_hot_team->t.t_nproc);
- if ( retval > set_nproc ) {
- retval = set_nproc;
- }
- if ( retval < KMP_MIN_NTH ) {
- retval = KMP_MIN_NTH;
- }
+static int __kmp_load_balance_nproc(kmp_root_t *root, int set_nproc) {
+ int retval;
+ int pool_active;
+ int hot_team_active;
+ int team_curr_active;
+ int system_active;
+
+ KB_TRACE(20, ("__kmp_load_balance_nproc: called root:%p set_nproc:%d\n", root,
+ set_nproc));
+ KMP_DEBUG_ASSERT(root);
+ KMP_DEBUG_ASSERT(root->r.r_root_team->t.t_threads[0]
+ ->th.th_current_task->td_icvs.dynamic == TRUE);
+ KMP_DEBUG_ASSERT(set_nproc > 1);
- KB_TRACE( 20, ("__kmp_load_balance_nproc: thread limit exit. retval:%d\n", retval ) );
- return retval;
- }
+ if (set_nproc == 1) {
+ KB_TRACE(20, ("__kmp_load_balance_nproc: serial execution.\n"));
+ return 1;
+ }
- //
- // There is a slight delay in the load balance algorithm in detecting
- // new running procs. The real system load at this instant should be
- // at least as large as the #active omp thread that are available to
- // add to the team.
- //
- if ( system_active < team_curr_active ) {
- system_active = team_curr_active;
- }
- retval = __kmp_avail_proc - system_active + team_curr_active;
- if ( retval > set_nproc ) {
- retval = set_nproc;
+ // Threads that are active in the thread pool, active in the hot team for this
+ // particular root (if we are at the outer par level), and the currently
+ // executing thread (to become the master) are available to add to the new
+ // team, but are currently contributing to the system load, and must be
+ // accounted for.
+ pool_active = TCR_4(__kmp_thread_pool_active_nth);
+ hot_team_active = __kmp_active_hot_team_nproc(root);
+ team_curr_active = pool_active + hot_team_active + 1;
+
+ // Check the system load.
+ system_active = __kmp_get_load_balance(__kmp_avail_proc + team_curr_active);
+ KB_TRACE(30, ("__kmp_load_balance_nproc: system active = %d pool active = %d "
+ "hot team active = %d\n",
+ system_active, pool_active, hot_team_active));
+
+ if (system_active < 0) {
+ // There was an error reading the necessary info from /proc, so use the
+ // thread limit algorithm instead. Once we set __kmp_global.g.g_dynamic_mode
+ // = dynamic_thread_limit, we shouldn't wind up getting back here.
+ __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
+ KMP_WARNING(CantLoadBalUsing, "KMP_DYNAMIC_MODE=thread limit");
+
+ // Make this call behave like the thread limit algorithm.
+ retval = __kmp_avail_proc - __kmp_nth +
+ (root->r.r_active ? 1 : root->r.r_hot_team->t.t_nproc);
+ if (retval > set_nproc) {
+ retval = set_nproc;
}
- if ( retval < KMP_MIN_NTH ) {
- retval = KMP_MIN_NTH;
+ if (retval < KMP_MIN_NTH) {
+ retval = KMP_MIN_NTH;
}
- KB_TRACE( 20, ("__kmp_load_balance_nproc: exit. retval:%d\n", retval ) );
+ KB_TRACE(20, ("__kmp_load_balance_nproc: thread limit exit. retval:%d\n",
+ retval));
return retval;
+ }
+
+ // There is a slight delay in the load balance algorithm in detecting new
+ // running procs. The real system load at this instant should be at least as
+ // large as the #active omp thread that are available to add to the team.
+ if (system_active < team_curr_active) {
+ system_active = team_curr_active;
+ }
+ retval = __kmp_avail_proc - system_active + team_curr_active;
+ if (retval > set_nproc) {
+ retval = set_nproc;
+ }
+ if (retval < KMP_MIN_NTH) {
+ retval = KMP_MIN_NTH;
+ }
+
+ KB_TRACE(20, ("__kmp_load_balance_nproc: exit. retval:%d\n", retval));
+ return retval;
} // __kmp_load_balance_nproc()
#endif /* USE_LOAD_BALANCE */
/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
/* NOTE: this is called with the __kmp_init_lock held */
-void
-__kmp_cleanup( void )
-{
- int f;
+void __kmp_cleanup(void) {
+ int f;
- KA_TRACE( 10, ("__kmp_cleanup: enter\n" ) );
+ KA_TRACE(10, ("__kmp_cleanup: enter\n"));
- if (TCR_4(__kmp_init_parallel)) {
+ if (TCR_4(__kmp_init_parallel)) {
#if KMP_HANDLE_SIGNALS
- __kmp_remove_signals();
+ __kmp_remove_signals();
#endif
- TCW_4(__kmp_init_parallel, FALSE);
- }
+ TCW_4(__kmp_init_parallel, FALSE);
+ }
- if (TCR_4(__kmp_init_middle)) {
+ if (TCR_4(__kmp_init_middle)) {
#if KMP_AFFINITY_SUPPORTED
- __kmp_affinity_uninitialize();
+ __kmp_affinity_uninitialize();
#endif /* KMP_AFFINITY_SUPPORTED */
- __kmp_cleanup_hierarchy();
- TCW_4(__kmp_init_middle, FALSE);
- }
-
- KA_TRACE( 10, ("__kmp_cleanup: go serial cleanup\n" ) );
-
- if (__kmp_init_serial) {
- __kmp_runtime_destroy();
- __kmp_init_serial = FALSE;
- }
-
- for ( f = 0; f < __kmp_threads_capacity; f++ ) {
- if ( __kmp_root[ f ] != NULL ) {
- __kmp_free( __kmp_root[ f ] );
- __kmp_root[ f ] = NULL;
- }
- }
- __kmp_free( __kmp_threads );
- // __kmp_threads and __kmp_root were allocated at once, as single block, so there is no need in
- // freeing __kmp_root.
- __kmp_threads = NULL;
- __kmp_root = NULL;
- __kmp_threads_capacity = 0;
+ __kmp_cleanup_hierarchy();
+ TCW_4(__kmp_init_middle, FALSE);
+ }
+
+ KA_TRACE(10, ("__kmp_cleanup: go serial cleanup\n"));
+
+ if (__kmp_init_serial) {
+ __kmp_runtime_destroy();
+ __kmp_init_serial = FALSE;
+ }
+
+ for (f = 0; f < __kmp_threads_capacity; f++) {
+ if (__kmp_root[f] != NULL) {
+ __kmp_free(__kmp_root[f]);
+ __kmp_root[f] = NULL;
+ }
+ }
+ __kmp_free(__kmp_threads);
+ // __kmp_threads and __kmp_root were allocated at once, as single block, so
+ // there is no need in freeing __kmp_root.
+ __kmp_threads = NULL;
+ __kmp_root = NULL;
+ __kmp_threads_capacity = 0;
#if KMP_USE_DYNAMIC_LOCK
- __kmp_cleanup_indirect_user_locks();
+ __kmp_cleanup_indirect_user_locks();
#else
- __kmp_cleanup_user_locks();
+ __kmp_cleanup_user_locks();
#endif
- #if KMP_AFFINITY_SUPPORTED
- KMP_INTERNAL_FREE( (void *) __kmp_cpuinfo_file );
- __kmp_cpuinfo_file = NULL;
- #endif /* KMP_AFFINITY_SUPPORTED */
-
- #if KMP_USE_ADAPTIVE_LOCKS
- #if KMP_DEBUG_ADAPTIVE_LOCKS
- __kmp_print_speculative_stats();
- #endif
- #endif
- KMP_INTERNAL_FREE( __kmp_nested_nth.nth );
- __kmp_nested_nth.nth = NULL;
- __kmp_nested_nth.size = 0;
- __kmp_nested_nth.used = 0;
- KMP_INTERNAL_FREE( __kmp_nested_proc_bind.bind_types );
- __kmp_nested_proc_bind.bind_types = NULL;
- __kmp_nested_proc_bind.size = 0;
- __kmp_nested_proc_bind.used = 0;
+#if KMP_AFFINITY_SUPPORTED
+ KMP_INTERNAL_FREE((void *)__kmp_cpuinfo_file);
+ __kmp_cpuinfo_file = NULL;
+#endif /* KMP_AFFINITY_SUPPORTED */
+
+#if KMP_USE_ADAPTIVE_LOCKS
+#if KMP_DEBUG_ADAPTIVE_LOCKS
+ __kmp_print_speculative_stats();
+#endif
+#endif
+ KMP_INTERNAL_FREE(__kmp_nested_nth.nth);
+ __kmp_nested_nth.nth = NULL;
+ __kmp_nested_nth.size = 0;
+ __kmp_nested_nth.used = 0;
+ KMP_INTERNAL_FREE(__kmp_nested_proc_bind.bind_types);
+ __kmp_nested_proc_bind.bind_types = NULL;
+ __kmp_nested_proc_bind.size = 0;
+ __kmp_nested_proc_bind.used = 0;
- __kmp_i18n_catclose();
+ __kmp_i18n_catclose();
#if KMP_STATS_ENABLED
- __kmp_stats_fini();
+ __kmp_stats_fini();
#endif
- KA_TRACE( 10, ("__kmp_cleanup: exit\n" ) );
+ KA_TRACE(10, ("__kmp_cleanup: exit\n"));
}
/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
-
-int
-__kmp_ignore_mppbeg( void )
-{
- char *env;
-
- if ((env = getenv( "KMP_IGNORE_MPPBEG" )) != NULL) {
- if (__kmp_str_match_false( env ))
- return FALSE;
- }
- // By default __kmpc_begin() is no-op.
- return TRUE;
-}
-
-int
-__kmp_ignore_mppend( void )
-{
- char *env;
-
- if ((env = getenv( "KMP_IGNORE_MPPEND" )) != NULL) {
- if (__kmp_str_match_false( env ))
- return FALSE;
- }
- // By default __kmpc_end() is no-op.
- return TRUE;
-}
-void
-__kmp_internal_begin( void )
-{
- int gtid;
- kmp_root_t *root;
+int __kmp_ignore_mppbeg(void) {
+ char *env;
- /* this is a very important step as it will register new sibling threads
- * and assign these new uber threads a new gtid */
- gtid = __kmp_entry_gtid();
- root = __kmp_threads[ gtid ]->th.th_root;
- KMP_ASSERT( KMP_UBER_GTID( gtid ));
-
- if( root->r.r_begin ) return;
- __kmp_acquire_lock( &root->r.r_begin_lock, gtid );
- if( root->r.r_begin ) {
- __kmp_release_lock( & root->r.r_begin_lock, gtid );
- return;
- }
+ if ((env = getenv("KMP_IGNORE_MPPBEG")) != NULL) {
+ if (__kmp_str_match_false(env))
+ return FALSE;
+ }
+ // By default __kmpc_begin() is no-op.
+ return TRUE;
+}
+
+int __kmp_ignore_mppend(void) {
+ char *env;
+
+ if ((env = getenv("KMP_IGNORE_MPPEND")) != NULL) {
+ if (__kmp_str_match_false(env))
+ return FALSE;
+ }
+ // By default __kmpc_end() is no-op.
+ return TRUE;
+}
+
+void __kmp_internal_begin(void) {
+ int gtid;
+ kmp_root_t *root;
+
+ /* this is a very important step as it will register new sibling threads
+ and assign these new uber threads a new gtid */
+ gtid = __kmp_entry_gtid();
+ root = __kmp_threads[gtid]->th.th_root;
+ KMP_ASSERT(KMP_UBER_GTID(gtid));
+
+ if (root->r.r_begin)
+ return;
+ __kmp_acquire_lock(&root->r.r_begin_lock, gtid);
+ if (root->r.r_begin) {
+ __kmp_release_lock(&root->r.r_begin_lock, gtid);
+ return;
+ }
- root->r.r_begin = TRUE;
+ root->r.r_begin = TRUE;
- __kmp_release_lock( & root->r.r_begin_lock, gtid );
+ __kmp_release_lock(&root->r.r_begin_lock, gtid);
}
-
/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
-
-void
-__kmp_user_set_library (enum library_type arg)
-{
- int gtid;
- kmp_root_t *root;
- kmp_info_t *thread;
-
- /* first, make sure we are initialized so we can get our gtid */
-
- gtid = __kmp_entry_gtid();
- thread = __kmp_threads[ gtid ];
-
- root = thread->th.th_root;
-
- KA_TRACE( 20, ("__kmp_user_set_library: enter T#%d, arg: %d, %d\n", gtid, arg, library_serial ));
- if (root->r.r_in_parallel) { /* Must be called in serial section of top-level thread */
- KMP_WARNING( SetLibraryIncorrectCall );
- return;
- }
-
- switch ( arg ) {
- case library_serial :
- thread->th.th_set_nproc = 0;
- set__nproc( thread, 1 );
- break;
- case library_turnaround :
- thread->th.th_set_nproc = 0;
- set__nproc( thread, __kmp_dflt_team_nth ? __kmp_dflt_team_nth : __kmp_dflt_team_nth_ub );
- break;
- case library_throughput :
- thread->th.th_set_nproc = 0;
- set__nproc( thread, __kmp_dflt_team_nth ? __kmp_dflt_team_nth : __kmp_dflt_team_nth_ub );
- break;
- default:
- KMP_FATAL( UnknownLibraryType, arg );
- }
-
- __kmp_aux_set_library ( arg );
-}
-void
-__kmp_aux_set_stacksize( size_t arg )
-{
- if (! __kmp_init_serial)
- __kmp_serial_initialize();
+void __kmp_user_set_library(enum library_type arg) {
+ int gtid;
+ kmp_root_t *root;
+ kmp_info_t *thread;
+
+ /* first, make sure we are initialized so we can get our gtid */
+
+ gtid = __kmp_entry_gtid();
+ thread = __kmp_threads[gtid];
+
+ root = thread->th.th_root;
+
+ KA_TRACE(20, ("__kmp_user_set_library: enter T#%d, arg: %d, %d\n", gtid, arg,
+ library_serial));
+ if (root->r.r_in_parallel) { /* Must be called in serial section of top-level
+ thread */
+ KMP_WARNING(SetLibraryIncorrectCall);
+ return;
+ }
+
+ switch (arg) {
+ case library_serial:
+ thread->th.th_set_nproc = 0;
+ set__nproc(thread, 1);
+ break;
+ case library_turnaround:
+ thread->th.th_set_nproc = 0;
+ set__nproc(thread, __kmp_dflt_team_nth ? __kmp_dflt_team_nth
+ : __kmp_dflt_team_nth_ub);
+ break;
+ case library_throughput:
+ thread->th.th_set_nproc = 0;
+ set__nproc(thread, __kmp_dflt_team_nth ? __kmp_dflt_team_nth
+ : __kmp_dflt_team_nth_ub);
+ break;
+ default:
+ KMP_FATAL(UnknownLibraryType, arg);
+ }
+
+ __kmp_aux_set_library(arg);
+}
+
+void __kmp_aux_set_stacksize(size_t arg) {
+ if (!__kmp_init_serial)
+ __kmp_serial_initialize();
#if KMP_OS_DARWIN
- if (arg & (0x1000 - 1)) {
- arg &= ~(0x1000 - 1);
- if(arg + 0x1000) /* check for overflow if we round up */
- arg += 0x1000;
- }
+ if (arg & (0x1000 - 1)) {
+ arg &= ~(0x1000 - 1);
+ if (arg + 0x1000) /* check for overflow if we round up */
+ arg += 0x1000;
+ }
#endif
- __kmp_acquire_bootstrap_lock( &__kmp_initz_lock );
+ __kmp_acquire_bootstrap_lock(&__kmp_initz_lock);
- /* only change the default stacksize before the first parallel region */
- if (! TCR_4(__kmp_init_parallel)) {
- size_t value = arg; /* argument is in bytes */
+ /* only change the default stacksize before the first parallel region */
+ if (!TCR_4(__kmp_init_parallel)) {
+ size_t value = arg; /* argument is in bytes */
- if (value < __kmp_sys_min_stksize )
- value = __kmp_sys_min_stksize ;
- else if (value > KMP_MAX_STKSIZE)
- value = KMP_MAX_STKSIZE;
+ if (value < __kmp_sys_min_stksize)
+ value = __kmp_sys_min_stksize;
+ else if (value > KMP_MAX_STKSIZE)
+ value = KMP_MAX_STKSIZE;
- __kmp_stksize = value;
+ __kmp_stksize = value;
- __kmp_env_stksize = TRUE; /* was KMP_STACKSIZE specified? */
- }
+ __kmp_env_stksize = TRUE; /* was KMP_STACKSIZE specified? */
+ }
- __kmp_release_bootstrap_lock( &__kmp_initz_lock );
+ __kmp_release_bootstrap_lock(&__kmp_initz_lock);
}
/* set the behaviour of the runtime library */
/* TODO this can cause some odd behaviour with sibling parallelism... */
-void
-__kmp_aux_set_library (enum library_type arg)
-{
- __kmp_library = arg;
+void __kmp_aux_set_library(enum library_type arg) {
+ __kmp_library = arg;
- switch ( __kmp_library ) {
- case library_serial :
- {
- KMP_INFORM( LibraryIsSerial );
- (void) __kmp_change_library( TRUE );
- }
- break;
- case library_turnaround :
- (void) __kmp_change_library( TRUE );
- break;
- case library_throughput :
- (void) __kmp_change_library( FALSE );
- break;
- default:
- KMP_FATAL( UnknownLibraryType, arg );
- }
+ switch (__kmp_library) {
+ case library_serial: {
+ KMP_INFORM(LibraryIsSerial);
+ (void)__kmp_change_library(TRUE);
+ } break;
+ case library_turnaround:
+ (void)__kmp_change_library(TRUE);
+ break;
+ case library_throughput:
+ (void)__kmp_change_library(FALSE);
+ break;
+ default:
+ KMP_FATAL(UnknownLibraryType, arg);
+ }
}
/* ------------------------------------------------------------------------ */
-/* ------------------------------------------------------------------------ */
-void
-__kmp_aux_set_blocktime (int arg, kmp_info_t *thread, int tid)
-{
- int blocktime = arg; /* argument is in milliseconds */
+void __kmp_aux_set_blocktime(int arg, kmp_info_t *thread, int tid) {
+ int blocktime = arg; /* argument is in milliseconds */
#if KMP_USE_MONITOR
- int bt_intervals;
+ int bt_intervals;
#endif
- int bt_set;
+ int bt_set;
- __kmp_save_internal_controls( thread );
+ __kmp_save_internal_controls(thread);
- /* Normalize and set blocktime for the teams */
- if (blocktime < KMP_MIN_BLOCKTIME)
- blocktime = KMP_MIN_BLOCKTIME;
- else if (blocktime > KMP_MAX_BLOCKTIME)
- blocktime = KMP_MAX_BLOCKTIME;
+ /* Normalize and set blocktime for the teams */
+ if (blocktime < KMP_MIN_BLOCKTIME)
+ blocktime = KMP_MIN_BLOCKTIME;
+ else if (blocktime > KMP_MAX_BLOCKTIME)
+ blocktime = KMP_MAX_BLOCKTIME;
- set__blocktime_team( thread->th.th_team, tid, blocktime );
- set__blocktime_team( thread->th.th_serial_team, 0, blocktime );
+ set__blocktime_team(thread->th.th_team, tid, blocktime);
+ set__blocktime_team(thread->th.th_serial_team, 0, blocktime);
#if KMP_USE_MONITOR
- /* Calculate and set blocktime intervals for the teams */
- bt_intervals = KMP_INTERVALS_FROM_BLOCKTIME(blocktime, __kmp_monitor_wakeups);
+ /* Calculate and set blocktime intervals for the teams */
+ bt_intervals = KMP_INTERVALS_FROM_BLOCKTIME(blocktime, __kmp_monitor_wakeups);
- set__bt_intervals_team( thread->th.th_team, tid, bt_intervals );
- set__bt_intervals_team( thread->th.th_serial_team, 0, bt_intervals );
+ set__bt_intervals_team(thread->th.th_team, tid, bt_intervals);
+ set__bt_intervals_team(thread->th.th_serial_team, 0, bt_intervals);
#endif
- /* Set whether blocktime has been set to "TRUE" */
- bt_set = TRUE;
+ /* Set whether blocktime has been set to "TRUE" */
+ bt_set = TRUE;
- set__bt_set_team( thread->th.th_team, tid, bt_set );
- set__bt_set_team( thread->th.th_serial_team, 0, bt_set );
+ set__bt_set_team(thread->th.th_team, tid, bt_set);
+ set__bt_set_team(thread->th.th_serial_team, 0, bt_set);
#if KMP_USE_MONITOR
- KF_TRACE(10, ("kmp_set_blocktime: T#%d(%d:%d), blocktime=%d, "
- "bt_intervals=%d, monitor_updates=%d\n",
- __kmp_gtid_from_tid(tid, thread->th.th_team),
- thread->th.th_team->t.t_id, tid, blocktime, bt_intervals,
- __kmp_monitor_wakeups));
+ KF_TRACE(10, ("kmp_set_blocktime: T#%d(%d:%d), blocktime=%d, "
+ "bt_intervals=%d, monitor_updates=%d\n",
+ __kmp_gtid_from_tid(tid, thread->th.th_team),
+ thread->th.th_team->t.t_id, tid, blocktime, bt_intervals,
+ __kmp_monitor_wakeups));
#else
- KF_TRACE(10, ("kmp_set_blocktime: T#%d(%d:%d), blocktime=%d\n",
- __kmp_gtid_from_tid(tid, thread->th.th_team),
- thread->th.th_team->t.t_id, tid, blocktime));
+ KF_TRACE(10, ("kmp_set_blocktime: T#%d(%d:%d), blocktime=%d\n",
+ __kmp_gtid_from_tid(tid, thread->th.th_team),
+ thread->th.th_team->t.t_id, tid, blocktime));
#endif
}
-void
-__kmp_aux_set_defaults(
- char const * str,
- int len
-) {
- if ( ! __kmp_init_serial ) {
- __kmp_serial_initialize();
- };
- __kmp_env_initialize( str );
+void __kmp_aux_set_defaults(char const *str, int len) {
+ if (!__kmp_init_serial) {
+ __kmp_serial_initialize();
+ };
+ __kmp_env_initialize(str);
- if (__kmp_settings
+ if (__kmp_settings
#if OMP_40_ENABLED
- || __kmp_display_env || __kmp_display_env_verbose
+ || __kmp_display_env || __kmp_display_env_verbose
#endif // OMP_40_ENABLED
- ) {
- __kmp_env_print();
- }
+ ) {
+ __kmp_env_print();
+ }
} // __kmp_aux_set_defaults
/* ------------------------------------------------------------------------ */
-
-/*
- * internal fast reduction routines
- */
+/* internal fast reduction routines */
PACKED_REDUCTION_METHOD_T
-__kmp_determine_reduction_method( ident_t *loc, kmp_int32 global_tid,
- kmp_int32 num_vars, size_t reduce_size, void *reduce_data, void (*reduce_func)(void *lhs_data, void *rhs_data),
- kmp_critical_name *lck )
-{
-
- // Default reduction method: critical construct ( lck != NULL, like in current PAROPT )
- // If ( reduce_data!=NULL && reduce_func!=NULL ): the tree-reduction method can be selected by RTL
- // If loc->flags contains KMP_IDENT_ATOMIC_REDUCE, the atomic reduce method can be selected by RTL
- // Finally, it's up to OpenMP RTL to make a decision on which method to select among generated by PAROPT.
+__kmp_determine_reduction_method(
+ ident_t *loc, kmp_int32 global_tid, kmp_int32 num_vars, size_t reduce_size,
+ void *reduce_data, void (*reduce_func)(void *lhs_data, void *rhs_data),
+ kmp_critical_name *lck) {
- PACKED_REDUCTION_METHOD_T retval;
+ // Default reduction method: critical construct ( lck != NULL, like in current
+ // PAROPT )
+ // If ( reduce_data!=NULL && reduce_func!=NULL ): the tree-reduction method
+ // can be selected by RTL
+ // If loc->flags contains KMP_IDENT_ATOMIC_REDUCE, the atomic reduce method
+ // can be selected by RTL
+ // Finally, it's up to OpenMP RTL to make a decision on which method to select
+ // among generated by PAROPT.
- int team_size;
+ PACKED_REDUCTION_METHOD_T retval;
- KMP_DEBUG_ASSERT( loc ); // it would be nice to test ( loc != 0 )
- KMP_DEBUG_ASSERT( lck ); // it would be nice to test ( lck != 0 )
+ int team_size;
- #define FAST_REDUCTION_ATOMIC_METHOD_GENERATED ( ( loc->flags & ( KMP_IDENT_ATOMIC_REDUCE ) ) == ( KMP_IDENT_ATOMIC_REDUCE ) )
- #define FAST_REDUCTION_TREE_METHOD_GENERATED ( ( reduce_data ) && ( reduce_func ) )
+ KMP_DEBUG_ASSERT(loc); // it would be nice to test ( loc != 0 )
+ KMP_DEBUG_ASSERT(lck); // it would be nice to test ( lck != 0 )
- retval = critical_reduce_block;
+#define FAST_REDUCTION_ATOMIC_METHOD_GENERATED \
+ ((loc->flags & (KMP_IDENT_ATOMIC_REDUCE)) == (KMP_IDENT_ATOMIC_REDUCE))
+#define FAST_REDUCTION_TREE_METHOD_GENERATED ((reduce_data) && (reduce_func))
- team_size = __kmp_get_team_num_threads( global_tid ); // another choice of getting a team size ( with 1 dynamic deference ) is slower
+ retval = critical_reduce_block;
- if( team_size == 1 ) {
+ // another choice of getting a team size (with 1 dynamic deference) is slower
+ team_size = __kmp_get_team_num_threads(global_tid);
+ if (team_size == 1) {
- retval = empty_reduce_block;
+ retval = empty_reduce_block;
- } else {
+ } else {
- int atomic_available = FAST_REDUCTION_ATOMIC_METHOD_GENERATED;
- int tree_available = FAST_REDUCTION_TREE_METHOD_GENERATED;
+ int atomic_available = FAST_REDUCTION_ATOMIC_METHOD_GENERATED;
+ int tree_available = FAST_REDUCTION_TREE_METHOD_GENERATED;
- #if KMP_ARCH_X86_64 || KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS64
+#if KMP_ARCH_X86_64 || KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS64
- #if KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN
+#if KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_WINDOWS || \
+ KMP_OS_DARWIN
- int teamsize_cutoff = 4;
+ int teamsize_cutoff = 4;
#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
- if( __kmp_mic_type != non_mic ) {
- teamsize_cutoff = 8;
- }
+ if (__kmp_mic_type != non_mic) {
+ teamsize_cutoff = 8;
+ }
#endif
- if( tree_available ) {
- if( team_size <= teamsize_cutoff ) {
- if ( atomic_available ) {
- retval = atomic_reduce_block;
- }
- } else {
- retval = TREE_REDUCE_BLOCK_WITH_REDUCTION_BARRIER;
- }
- } else if ( atomic_available ) {
- retval = atomic_reduce_block;
- }
- #else
- #error "Unknown or unsupported OS"
- #endif // KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN
-
- #elif KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_AARCH || KMP_ARCH_MIPS
-
- #if KMP_OS_LINUX || KMP_OS_WINDOWS
-
- // basic tuning
-
- if( atomic_available ) {
- if( num_vars <= 2 ) { // && ( team_size <= 8 ) due to false-sharing ???
- retval = atomic_reduce_block;
- }
- } // otherwise: use critical section
-
- #elif KMP_OS_DARWIN
-
- if( atomic_available && ( num_vars <= 3 ) ) {
- retval = atomic_reduce_block;
- } else if( tree_available ) {
- if( ( reduce_size > ( 9 * sizeof( kmp_real64 ) ) ) && ( reduce_size < ( 2000 * sizeof( kmp_real64 ) ) ) ) {
- retval = TREE_REDUCE_BLOCK_WITH_PLAIN_BARRIER;
- }
- } // otherwise: use critical section
-
- #else
- #error "Unknown or unsupported OS"
- #endif
-
- #else
- #error "Unknown or unsupported architecture"
- #endif
-
+ if (tree_available) {
+ if (team_size <= teamsize_cutoff) {
+ if (atomic_available) {
+ retval = atomic_reduce_block;
+ }
+ } else {
+ retval = TREE_REDUCE_BLOCK_WITH_REDUCTION_BARRIER;
+ }
+ } else if (atomic_available) {
+ retval = atomic_reduce_block;
}
+#else
+#error "Unknown or unsupported OS"
+#endif // KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_WINDOWS ||
+// KMP_OS_DARWIN
+
+#elif KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_AARCH || KMP_ARCH_MIPS
+
+#if KMP_OS_LINUX || KMP_OS_WINDOWS
+
+ // basic tuning
+
+ if (atomic_available) {
+ if (num_vars <= 2) { // && ( team_size <= 8 ) due to false-sharing ???
+ retval = atomic_reduce_block;
+ }
+ } // otherwise: use critical section
+
+#elif KMP_OS_DARWIN
+
+ if (atomic_available && (num_vars <= 3)) {
+ retval = atomic_reduce_block;
+ } else if (tree_available) {
+ if ((reduce_size > (9 * sizeof(kmp_real64))) &&
+ (reduce_size < (2000 * sizeof(kmp_real64)))) {
+ retval = TREE_REDUCE_BLOCK_WITH_PLAIN_BARRIER;
+ }
+ } // otherwise: use critical section
- // KMP_FORCE_REDUCTION
-
- // If the team is serialized (team_size == 1), ignore the forced reduction
- // method and stay with the unsynchronized method (empty_reduce_block)
- if( __kmp_force_reduction_method != reduction_method_not_defined && team_size != 1) {
-
- PACKED_REDUCTION_METHOD_T forced_retval = critical_reduce_block;
+#else
+#error "Unknown or unsupported OS"
+#endif
- int atomic_available, tree_available;
+#else
+#error "Unknown or unsupported architecture"
+#endif
+ }
- switch( ( forced_retval = __kmp_force_reduction_method ) )
- {
- case critical_reduce_block:
- KMP_ASSERT( lck ); // lck should be != 0
- break;
-
- case atomic_reduce_block:
- atomic_available = FAST_REDUCTION_ATOMIC_METHOD_GENERATED;
- if( ! atomic_available ) {
- KMP_WARNING(RedMethodNotSupported, "atomic");
- forced_retval = critical_reduce_block;
- }
- break;
-
- case tree_reduce_block:
- tree_available = FAST_REDUCTION_TREE_METHOD_GENERATED;
- if( ! tree_available ) {
- KMP_WARNING(RedMethodNotSupported, "tree");
- forced_retval = critical_reduce_block;
- } else {
- #if KMP_FAST_REDUCTION_BARRIER
- forced_retval = TREE_REDUCE_BLOCK_WITH_REDUCTION_BARRIER;
- #endif
- }
- break;
+ // KMP_FORCE_REDUCTION
- default:
- KMP_ASSERT( 0 ); // "unsupported method specified"
- }
+ // If the team is serialized (team_size == 1), ignore the forced reduction
+ // method and stay with the unsynchronized method (empty_reduce_block)
+ if (__kmp_force_reduction_method != reduction_method_not_defined &&
+ team_size != 1) {
+
+ PACKED_REDUCTION_METHOD_T forced_retval = critical_reduce_block;
+
+ int atomic_available, tree_available;
+
+ switch ((forced_retval = __kmp_force_reduction_method)) {
+ case critical_reduce_block:
+ KMP_ASSERT(lck); // lck should be != 0
+ break;
+
+ case atomic_reduce_block:
+ atomic_available = FAST_REDUCTION_ATOMIC_METHOD_GENERATED;
+ if (!atomic_available) {
+ KMP_WARNING(RedMethodNotSupported, "atomic");
+ forced_retval = critical_reduce_block;
+ }
+ break;
+
+ case tree_reduce_block:
+ tree_available = FAST_REDUCTION_TREE_METHOD_GENERATED;
+ if (!tree_available) {
+ KMP_WARNING(RedMethodNotSupported, "tree");
+ forced_retval = critical_reduce_block;
+ } else {
+#if KMP_FAST_REDUCTION_BARRIER
+ forced_retval = TREE_REDUCE_BLOCK_WITH_REDUCTION_BARRIER;
+#endif
+ }
+ break;
- retval = forced_retval;
+ default:
+ KMP_ASSERT(0); // "unsupported method specified"
}
- KA_TRACE(10, ( "reduction method selected=%08x\n", retval ) );
+ retval = forced_retval;
+ }
+
+ KA_TRACE(10, ("reduction method selected=%08x\n", retval));
- #undef FAST_REDUCTION_TREE_METHOD_GENERATED
- #undef FAST_REDUCTION_ATOMIC_METHOD_GENERATED
+#undef FAST_REDUCTION_TREE_METHOD_GENERATED
+#undef FAST_REDUCTION_ATOMIC_METHOD_GENERATED
- return ( retval );
+ return (retval);
}
// this function is for testing set/get/determine reduce method
-kmp_int32
-__kmp_get_reduce_method( void ) {
- return ( ( __kmp_entry_thread()->th.th_local.packed_reduction_method ) >> 8 );
+kmp_int32 __kmp_get_reduce_method(void) {
+ return ((__kmp_entry_thread()->th.th_local.packed_reduction_method) >> 8);
}
-
-/* ------------------------------------------------------------------------ */
Modified: openmp/trunk/runtime/src/kmp_safe_c_api.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_safe_c_api.h?rev=302929&r1=302928&r2=302929&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_safe_c_api.h (original)
+++ openmp/trunk/runtime/src/kmp_safe_c_api.h Fri May 12 13:01:32 2017
@@ -12,50 +12,49 @@
#ifndef KMP_SAFE_C_API_H
#define KMP_SAFE_C_API_H
-//
// Replacement for banned C API
-//
// Not every unsafe call listed here is handled now, but keeping everything
// in one place should be handy for future maintenance.
#if KMP_OS_WINDOWS
-# define RSIZE_MAX_STR ( 4UL << 10 ) // 4KB
+#define RSIZE_MAX_STR (4UL << 10) // 4KB
// _malloca was suggested, but it is not a drop-in replacement for _alloca
-# define KMP_ALLOCA _alloca
+#define KMP_ALLOCA _alloca
-# define KMP_MEMCPY_S memcpy_s
-# define KMP_SNPRINTF sprintf_s
-# define KMP_SSCANF sscanf_s
-# define KMP_STRCPY_S strcpy_s
-# define KMP_STRNCPY_S strncpy_s
+#define KMP_MEMCPY_S memcpy_s
+#define KMP_SNPRINTF sprintf_s
+#define KMP_SSCANF sscanf_s
+#define KMP_STRCPY_S strcpy_s
+#define KMP_STRNCPY_S strncpy_s
// Use this only when buffer size is unknown
-# define KMP_MEMCPY(dst, src, cnt) memcpy_s(dst, cnt, src, cnt)
+#define KMP_MEMCPY(dst, src, cnt) memcpy_s(dst, cnt, src, cnt)
-# define KMP_STRLEN(str) strnlen_s(str, RSIZE_MAX_STR)
+#define KMP_STRLEN(str) strnlen_s(str, RSIZE_MAX_STR)
// Use this only when buffer size is unknown
-# define KMP_STRNCPY(dst, src, cnt) strncpy_s(dst, cnt, src, cnt)
+#define KMP_STRNCPY(dst, src, cnt) strncpy_s(dst, cnt, src, cnt)
// _TRUNCATE insures buffer size > max string to print.
-# define KMP_VSNPRINTF(dst, cnt, fmt, arg) vsnprintf_s(dst, cnt, _TRUNCATE, fmt, arg)
+#define KMP_VSNPRINTF(dst, cnt, fmt, arg) \
+ vsnprintf_s(dst, cnt, _TRUNCATE, fmt, arg)
#else // KMP_OS_WINDOWS
// For now, these macros use the existing API.
-# define KMP_ALLOCA alloca
-# define KMP_MEMCPY_S(dst, bsz, src, cnt) memcpy(dst, src, cnt)
-# define KMP_SNPRINTF snprintf
-# define KMP_SSCANF sscanf
-# define KMP_STRCPY_S(dst, bsz, src) strcpy(dst, src)
-# define KMP_STRNCPY_S(dst, bsz, src, cnt) strncpy(dst, src, cnt)
-# define KMP_VSNPRINTF vsnprintf
-# define KMP_STRNCPY strncpy
-# define KMP_STRLEN strlen
-# define KMP_MEMCPY memcpy
+#define KMP_ALLOCA alloca
+#define KMP_MEMCPY_S(dst, bsz, src, cnt) memcpy(dst, src, cnt)
+#define KMP_SNPRINTF snprintf
+#define KMP_SSCANF sscanf
+#define KMP_STRCPY_S(dst, bsz, src) strcpy(dst, src)
+#define KMP_STRNCPY_S(dst, bsz, src, cnt) strncpy(dst, src, cnt)
+#define KMP_VSNPRINTF vsnprintf
+#define KMP_STRNCPY strncpy
+#define KMP_STRLEN strlen
+#define KMP_MEMCPY memcpy
#endif // KMP_OS_WINDOWS
Modified: openmp/trunk/runtime/src/kmp_sched.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_sched.cpp?rev=302929&r1=302928&r2=302929&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_sched.cpp (original)
+++ openmp/trunk/runtime/src/kmp_sched.cpp Fri May 12 13:01:32 2017
@@ -13,21 +13,18 @@
//===----------------------------------------------------------------------===//
-/*
- * Static scheduling initialization.
- *
- * NOTE: team->t.t_nproc is a constant inside of any dispatch loop, however
- * it may change values between parallel regions. __kmp_max_nth
- * is the largest value __kmp_nth may take, 1 is the smallest.
- *
- */
+/* Static scheduling initialization.
+
+ NOTE: team->t.t_nproc is a constant inside of any dispatch loop, however
+ it may change values between parallel regions. __kmp_max_nth
+ is the largest value __kmp_nth may take, 1 is the smallest. */
#include "kmp.h"
-#include "kmp_i18n.h"
-#include "kmp_str.h"
#include "kmp_error.h"
-#include "kmp_stats.h"
+#include "kmp_i18n.h"
#include "kmp_itt.h"
+#include "kmp_stats.h"
+#include "kmp_str.h"
#if OMPT_SUPPORT
#include "ompt-specific.h"
@@ -36,699 +33,694 @@
#ifdef KMP_DEBUG
//-------------------------------------------------------------------------
// template for debug prints specification ( d, u, lld, llu )
- char const * traits_t< int >::spec = "d";
- char const * traits_t< unsigned int >::spec = "u";
- char const * traits_t< long long >::spec = "lld";
- char const * traits_t< unsigned long long >::spec = "llu";
+char const *traits_t<int>::spec = "d";
+char const *traits_t<unsigned int>::spec = "u";
+char const *traits_t<long long>::spec = "lld";
+char const *traits_t<unsigned long long>::spec = "llu";
//-------------------------------------------------------------------------
#endif
-template< typename T >
-static void
-__kmp_for_static_init(
- ident_t *loc,
- kmp_int32 global_tid,
- kmp_int32 schedtype,
- kmp_int32 *plastiter,
- T *plower,
- T *pupper,
- typename traits_t< T >::signed_t *pstride,
- typename traits_t< T >::signed_t incr,
- typename traits_t< T >::signed_t chunk
-) {
- KMP_COUNT_BLOCK(OMP_FOR_static);
- KMP_TIME_PARTITIONED_BLOCK(FOR_static_scheduling);
-
- typedef typename traits_t< T >::unsigned_t UT;
- typedef typename traits_t< T >::signed_t ST;
- /* this all has to be changed back to TID and such.. */
- register kmp_int32 gtid = global_tid;
- register kmp_uint32 tid;
- register kmp_uint32 nth;
- register UT trip_count;
- register kmp_team_t *team;
- register kmp_info_t *th = __kmp_threads[ gtid ];
+template <typename T>
+static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
+ kmp_int32 schedtype, kmp_int32 *plastiter,
+ T *plower, T *pupper,
+ typename traits_t<T>::signed_t *pstride,
+ typename traits_t<T>::signed_t incr,
+ typename traits_t<T>::signed_t chunk) {
+ KMP_COUNT_BLOCK(OMP_FOR_static);
+ KMP_TIME_PARTITIONED_BLOCK(FOR_static_scheduling);
+
+ typedef typename traits_t<T>::unsigned_t UT;
+ typedef typename traits_t<T>::signed_t ST;
+ /* this all has to be changed back to TID and such.. */
+ register kmp_int32 gtid = global_tid;
+ register kmp_uint32 tid;
+ register kmp_uint32 nth;
+ register UT trip_count;
+ register kmp_team_t *team;
+ register kmp_info_t *th = __kmp_threads[gtid];
#if OMPT_SUPPORT && OMPT_TRACE
- ompt_team_info_t *team_info = NULL;
- ompt_task_info_t *task_info = NULL;
+ ompt_team_info_t *team_info = NULL;
+ ompt_task_info_t *task_info = NULL;
- if (ompt_enabled) {
- // Only fully initialize variables needed by OMPT if OMPT is enabled.
- team_info = __ompt_get_teaminfo(0, NULL);
- task_info = __ompt_get_taskinfo(0);
- }
+ if (ompt_enabled) {
+ // Only fully initialize variables needed by OMPT if OMPT is enabled.
+ team_info = __ompt_get_teaminfo(0, NULL);
+ task_info = __ompt_get_taskinfo(0);
+ }
+#endif
+
+ KMP_DEBUG_ASSERT(plastiter && plower && pupper && pstride);
+ KE_TRACE(10, ("__kmpc_for_static_init called (%d)\n", global_tid));
+#ifdef KMP_DEBUG
+ {
+ const char *buff;
+ // create format specifiers before the debug output
+ buff = __kmp_str_format(
+ "__kmpc_for_static_init: T#%%d sched=%%d liter=%%d iter=(%%%s,"
+ " %%%s, %%%s) incr=%%%s chunk=%%%s signed?<%s>\n",
+ traits_t<T>::spec, traits_t<T>::spec, traits_t<ST>::spec,
+ traits_t<ST>::spec, traits_t<ST>::spec, traits_t<T>::spec);
+ KD_TRACE(100, (buff, global_tid, schedtype, *plastiter, *plower, *pupper,
+ *pstride, incr, chunk));
+ __kmp_str_free(&buff);
+ }
#endif
- KMP_DEBUG_ASSERT( plastiter && plower && pupper && pstride );
- KE_TRACE( 10, ("__kmpc_for_static_init called (%d)\n", global_tid));
- #ifdef KMP_DEBUG
+ if (__kmp_env_consistency_check) {
+ __kmp_push_workshare(global_tid, ct_pdo, loc);
+ if (incr == 0) {
+ __kmp_error_construct(kmp_i18n_msg_CnsLoopIncrZeroProhibited, ct_pdo,
+ loc);
+ }
+ }
+ /* special handling for zero-trip loops */
+ if (incr > 0 ? (*pupper < *plower) : (*plower < *pupper)) {
+ if (plastiter != NULL)
+ *plastiter = FALSE;
+ /* leave pupper and plower set to entire iteration space */
+ *pstride = incr; /* value should never be used */
+// *plower = *pupper - incr;
+// let compiler bypass the illegal loop (like for(i=1;i<10;i--))
+// THE LINE COMMENTED ABOVE CAUSED shape2F/h_tests_1.f TO HAVE A FAILURE
+// ON A ZERO-TRIP LOOP (lower=1, upper=0,stride=1) - JPH June 23, 2009.
+#ifdef KMP_DEBUG
{
- const char * buff;
- // create format specifiers before the debug output
- buff = __kmp_str_format(
- "__kmpc_for_static_init: T#%%d sched=%%d liter=%%d iter=(%%%s," \
- " %%%s, %%%s) incr=%%%s chunk=%%%s signed?<%s>\n",
- traits_t< T >::spec, traits_t< T >::spec, traits_t< ST >::spec,
- traits_t< ST >::spec, traits_t< ST >::spec, traits_t< T >::spec );
- KD_TRACE(100, ( buff, global_tid, schedtype, *plastiter,
- *plower, *pupper, *pstride, incr, chunk ) );
- __kmp_str_free( &buff );
- }
- #endif
-
- if ( __kmp_env_consistency_check ) {
- __kmp_push_workshare( global_tid, ct_pdo, loc );
- if ( incr == 0 ) {
- __kmp_error_construct( kmp_i18n_msg_CnsLoopIncrZeroProhibited, ct_pdo, loc );
- }
+ const char *buff;
+ // create format specifiers before the debug output
+ buff = __kmp_str_format("__kmpc_for_static_init:(ZERO TRIP) liter=%%d "
+ "lower=%%%s upper=%%%s stride = %%%s "
+ "signed?<%s>, loc = %%s\n",
+ traits_t<T>::spec, traits_t<T>::spec,
+ traits_t<ST>::spec, traits_t<T>::spec);
+ KD_TRACE(100,
+ (buff, *plastiter, *plower, *pupper, *pstride, loc->psource));
+ __kmp_str_free(&buff);
}
- /* special handling for zero-trip loops */
- if ( incr > 0 ? (*pupper < *plower) : (*plower < *pupper) ) {
- if( plastiter != NULL )
- *plastiter = FALSE;
- /* leave pupper and plower set to entire iteration space */
- *pstride = incr; /* value should never be used */
- // *plower = *pupper - incr; // let compiler bypass the illegal loop (like for(i=1;i<10;i--)) THIS LINE CAUSED shape2F/h_tests_1.f TO HAVE A FAILURE ON A ZERO-TRIP LOOP (lower=1,\
- upper=0,stride=1) - JPH June 23, 2009.
- #ifdef KMP_DEBUG
- {
- const char * buff;
- // create format specifiers before the debug output
- buff = __kmp_str_format(
- "__kmpc_for_static_init:(ZERO TRIP) liter=%%d lower=%%%s upper=%%%s stride = %%%s signed?<%s>, loc = %%s\n",
- traits_t< T >::spec, traits_t< T >::spec, traits_t< ST >::spec, traits_t< T >::spec );
- KD_TRACE(100, ( buff, *plastiter, *plower, *pupper, *pstride, loc->psource ) );
- __kmp_str_free( &buff );
- }
- #endif
- KE_TRACE( 10, ("__kmpc_for_static_init: T#%d return\n", global_tid ) );
+#endif
+ KE_TRACE(10, ("__kmpc_for_static_init: T#%d return\n", global_tid));
#if OMPT_SUPPORT && OMPT_TRACE
- if (ompt_enabled &&
- ompt_callbacks.ompt_callback(ompt_event_loop_begin)) {
- ompt_callbacks.ompt_callback(ompt_event_loop_begin)(
- team_info->parallel_id, task_info->task_id,
- team_info->microtask);
- }
-#endif
- KMP_COUNT_VALUE (FOR_static_iterations, 0);
- return;
+ if (ompt_enabled && ompt_callbacks.ompt_callback(ompt_event_loop_begin)) {
+ ompt_callbacks.ompt_callback(ompt_event_loop_begin)(
+ team_info->parallel_id, task_info->task_id, team_info->microtask);
}
+#endif
+ KMP_COUNT_VALUE(FOR_static_iterations, 0);
+ return;
+ }
+
+#if OMP_40_ENABLED
+ // Although there are schedule enumerations above kmp_ord_upper which are not
+ // schedules for "distribute", the only ones which are useful are dynamic, so
+ // cannot be seen here, since this codepath is only executed for static
+ // schedules.
+ if (schedtype > kmp_ord_upper) {
+ // we are in DISTRIBUTE construct
+ schedtype += kmp_sch_static -
+ kmp_distribute_static; // AC: convert to usual schedule type
+ tid = th->th.th_team->t.t_master_tid;
+ team = th->th.th_team->t.t_parent;
+ } else
+#endif
+ {
+ tid = __kmp_tid_from_gtid(global_tid);
+ team = th->th.th_team;
+ }
- #if OMP_40_ENABLED
- // Although there are schedule enumerations above kmp_ord_upper which are not schedules for "distribute",
- // the only ones which are useful are dynamic, so cannot be seen here, since this codepath is only executed
- // for static schedules.
- if ( schedtype > kmp_ord_upper ) {
- // we are in DISTRIBUTE construct
- schedtype += kmp_sch_static - kmp_distribute_static; // AC: convert to usual schedule type
- tid = th->th.th_team->t.t_master_tid;
- team = th->th.th_team->t.t_parent;
- } else
- #endif
+ /* determine if "for" loop is an active worksharing construct */
+ if (team->t.t_serialized) {
+ /* serialized parallel, each thread executes whole iteration space */
+ if (plastiter != NULL)
+ *plastiter = TRUE;
+ /* leave pupper and plower set to entire iteration space */
+ *pstride =
+ (incr > 0) ? (*pupper - *plower + 1) : (-(*plower - *pupper + 1));
+
+#ifdef KMP_DEBUG
{
- tid = __kmp_tid_from_gtid( global_tid );
- team = th->th.th_team;
+ const char *buff;
+ // create format specifiers before the debug output
+ buff = __kmp_str_format("__kmpc_for_static_init: (serial) liter=%%d "
+ "lower=%%%s upper=%%%s stride = %%%s\n",
+ traits_t<T>::spec, traits_t<T>::spec,
+ traits_t<ST>::spec);
+ KD_TRACE(100, (buff, *plastiter, *plower, *pupper, *pstride));
+ __kmp_str_free(&buff);
}
-
- /* determine if "for" loop is an active worksharing construct */
- if ( team -> t.t_serialized ) {
- /* serialized parallel, each thread executes whole iteration space */
- if( plastiter != NULL )
- *plastiter = TRUE;
- /* leave pupper and plower set to entire iteration space */
- *pstride = (incr > 0) ? (*pupper - *plower + 1) : (-(*plower - *pupper + 1));
-
- #ifdef KMP_DEBUG
- {
- const char * buff;
- // create format specifiers before the debug output
- buff = __kmp_str_format(
- "__kmpc_for_static_init: (serial) liter=%%d lower=%%%s upper=%%%s stride = %%%s\n",
- traits_t< T >::spec, traits_t< T >::spec, traits_t< ST >::spec );
- KD_TRACE(100, ( buff, *plastiter, *plower, *pupper, *pstride ) );
- __kmp_str_free( &buff );
- }
- #endif
- KE_TRACE( 10, ("__kmpc_for_static_init: T#%d return\n", global_tid ) );
+#endif
+ KE_TRACE(10, ("__kmpc_for_static_init: T#%d return\n", global_tid));
#if OMPT_SUPPORT && OMPT_TRACE
- if (ompt_enabled &&
- ompt_callbacks.ompt_callback(ompt_event_loop_begin)) {
- ompt_callbacks.ompt_callback(ompt_event_loop_begin)(
- team_info->parallel_id, task_info->task_id,
- team_info->microtask);
- }
+ if (ompt_enabled && ompt_callbacks.ompt_callback(ompt_event_loop_begin)) {
+ ompt_callbacks.ompt_callback(ompt_event_loop_begin)(
+ team_info->parallel_id, task_info->task_id, team_info->microtask);
+ }
#endif
- return;
+ return;
+ }
+ nth = team->t.t_nproc;
+ if (nth == 1) {
+ if (plastiter != NULL)
+ *plastiter = TRUE;
+ *pstride =
+ (incr > 0) ? (*pupper - *plower + 1) : (-(*plower - *pupper + 1));
+#ifdef KMP_DEBUG
+ {
+ const char *buff;
+ // create format specifiers before the debug output
+ buff = __kmp_str_format("__kmpc_for_static_init: (serial) liter=%%d "
+ "lower=%%%s upper=%%%s stride = %%%s\n",
+ traits_t<T>::spec, traits_t<T>::spec,
+ traits_t<ST>::spec);
+ KD_TRACE(100, (buff, *plastiter, *plower, *pupper, *pstride));
+ __kmp_str_free(&buff);
}
- nth = team->t.t_nproc;
- if ( nth == 1 ) {
- if( plastiter != NULL )
- *plastiter = TRUE;
- *pstride = (incr > 0) ? (*pupper - *plower + 1) : (-(*plower - *pupper + 1));
- #ifdef KMP_DEBUG
- {
- const char * buff;
- // create format specifiers before the debug output
- buff = __kmp_str_format(
- "__kmpc_for_static_init: (serial) liter=%%d lower=%%%s upper=%%%s stride = %%%s\n",
- traits_t< T >::spec, traits_t< T >::spec, traits_t< ST >::spec );
- KD_TRACE(100, ( buff, *plastiter, *plower, *pupper, *pstride ) );
- __kmp_str_free( &buff );
- }
- #endif
- KE_TRACE( 10, ("__kmpc_for_static_init: T#%d return\n", global_tid ) );
+#endif
+ KE_TRACE(10, ("__kmpc_for_static_init: T#%d return\n", global_tid));
#if OMPT_SUPPORT && OMPT_TRACE
- if (ompt_enabled &&
- ompt_callbacks.ompt_callback(ompt_event_loop_begin)) {
- ompt_callbacks.ompt_callback(ompt_event_loop_begin)(
- team_info->parallel_id, task_info->task_id,
- team_info->microtask);
- }
-#endif
- return;
+ if (ompt_enabled && ompt_callbacks.ompt_callback(ompt_event_loop_begin)) {
+ ompt_callbacks.ompt_callback(ompt_event_loop_begin)(
+ team_info->parallel_id, task_info->task_id, team_info->microtask);
}
+#endif
+ return;
+ }
- /* compute trip count */
- if ( incr == 1 ) {
- trip_count = *pupper - *plower + 1;
- } else if (incr == -1) {
- trip_count = *plower - *pupper + 1;
- } else if ( incr > 0 ) {
- // upper-lower can exceed the limit of signed type
- trip_count = (UT)(*pupper - *plower) / incr + 1;
+ /* compute trip count */
+ if (incr == 1) {
+ trip_count = *pupper - *plower + 1;
+ } else if (incr == -1) {
+ trip_count = *plower - *pupper + 1;
+ } else if (incr > 0) {
+ // upper-lower can exceed the limit of signed type
+ trip_count = (UT)(*pupper - *plower) / incr + 1;
+ } else {
+ trip_count = (UT)(*plower - *pupper) / (-incr) + 1;
+ }
+
+ if (__kmp_env_consistency_check) {
+ /* tripcount overflow? */
+ if (trip_count == 0 && *pupper != *plower) {
+ __kmp_error_construct(kmp_i18n_msg_CnsIterationRangeTooLarge, ct_pdo,
+ loc);
+ }
+ }
+ KMP_COUNT_VALUE(FOR_static_iterations, trip_count);
+
+ /* compute remaining parameters */
+ switch (schedtype) {
+ case kmp_sch_static: {
+ if (trip_count < nth) {
+ KMP_DEBUG_ASSERT(
+ __kmp_static == kmp_sch_static_greedy ||
+ __kmp_static ==
+ kmp_sch_static_balanced); // Unknown static scheduling type.
+ if (tid < trip_count) {
+ *pupper = *plower = *plower + tid * incr;
+ } else {
+ *plower = *pupper + incr;
+ }
+ if (plastiter != NULL)
+ *plastiter = (tid == trip_count - 1);
} else {
- trip_count = (UT)(*plower - *pupper) / (-incr) + 1;
+ if (__kmp_static == kmp_sch_static_balanced) {
+ register UT small_chunk = trip_count / nth;
+ register UT extras = trip_count % nth;
+ *plower += incr * (tid * small_chunk + (tid < extras ? tid : extras));
+ *pupper = *plower + small_chunk * incr - (tid < extras ? 0 : incr);
+ if (plastiter != NULL)
+ *plastiter = (tid == nth - 1);
+ } else {
+ register T big_chunk_inc_count =
+ (trip_count / nth + ((trip_count % nth) ? 1 : 0)) * incr;
+ register T old_upper = *pupper;
+
+ KMP_DEBUG_ASSERT(__kmp_static == kmp_sch_static_greedy);
+ // Unknown static scheduling type.
+
+ *plower += tid * big_chunk_inc_count;
+ *pupper = *plower + big_chunk_inc_count - incr;
+ if (incr > 0) {
+ if (*pupper < *plower)
+ *pupper = traits_t<T>::max_value;
+ if (plastiter != NULL)
+ *plastiter = *plower <= old_upper && *pupper > old_upper - incr;
+ if (*pupper > old_upper)
+ *pupper = old_upper; // tracker C73258
+ } else {
+ if (*pupper > *plower)
+ *pupper = traits_t<T>::min_value;
+ if (plastiter != NULL)
+ *plastiter = *plower >= old_upper && *pupper < old_upper - incr;
+ if (*pupper < old_upper)
+ *pupper = old_upper; // tracker C73258
+ }
+ }
+ }
+ *pstride = trip_count;
+ break;
+ }
+ case kmp_sch_static_chunked: {
+ register ST span;
+ if (chunk < 1) {
+ chunk = 1;
}
+ span = chunk * incr;
+ *pstride = span * nth;
+ *plower = *plower + (span * tid);
+ *pupper = *plower + span - incr;
+ if (plastiter != NULL)
+ *plastiter = (tid == ((trip_count - 1) / (UT)chunk) % nth);
+ break;
+ }
+#if OMP_45_ENABLED
+ case kmp_sch_static_balanced_chunked: {
+ register T old_upper = *pupper;
+ // round up to make sure the chunk is enough to cover all iterations
+ register UT span = (trip_count + nth - 1) / nth;
- if ( __kmp_env_consistency_check ) {
- /* tripcount overflow? */
- if ( trip_count == 0 && *pupper != *plower ) {
- __kmp_error_construct( kmp_i18n_msg_CnsIterationRangeTooLarge, ct_pdo, loc );
- }
- }
- KMP_COUNT_VALUE (FOR_static_iterations, trip_count);
+ // perform chunk adjustment
+ chunk = (span + chunk - 1) & ~(chunk - 1);
- /* compute remaining parameters */
- switch ( schedtype ) {
- case kmp_sch_static:
- {
- if ( trip_count < nth ) {
- KMP_DEBUG_ASSERT(
- __kmp_static == kmp_sch_static_greedy || \
- __kmp_static == kmp_sch_static_balanced
- ); // Unknown static scheduling type.
- if ( tid < trip_count ) {
- *pupper = *plower = *plower + tid * incr;
- } else {
- *plower = *pupper + incr;
- }
- if( plastiter != NULL )
- *plastiter = ( tid == trip_count - 1 );
- } else {
- if ( __kmp_static == kmp_sch_static_balanced ) {
- register UT small_chunk = trip_count / nth;
- register UT extras = trip_count % nth;
- *plower += incr * ( tid * small_chunk + ( tid < extras ? tid : extras ) );
- *pupper = *plower + small_chunk * incr - ( tid < extras ? 0 : incr );
- if( plastiter != NULL )
- *plastiter = ( tid == nth - 1 );
- } else {
- register T big_chunk_inc_count = ( trip_count/nth +
- ( ( trip_count % nth ) ? 1 : 0) ) * incr;
- register T old_upper = *pupper;
-
- KMP_DEBUG_ASSERT( __kmp_static == kmp_sch_static_greedy );
- // Unknown static scheduling type.
-
- *plower += tid * big_chunk_inc_count;
- *pupper = *plower + big_chunk_inc_count - incr;
- if ( incr > 0 ) {
- if( *pupper < *plower )
- *pupper = traits_t<T>::max_value;
- if( plastiter != NULL )
- *plastiter = *plower <= old_upper && *pupper > old_upper - incr;
- if ( *pupper > old_upper ) *pupper = old_upper; // tracker C73258
- } else {
- if( *pupper > *plower )
- *pupper = traits_t<T>::min_value;
- if( plastiter != NULL )
- *plastiter = *plower >= old_upper && *pupper < old_upper - incr;
- if ( *pupper < old_upper ) *pupper = old_upper; // tracker C73258
- }
- }
- }
- *pstride = trip_count;
- break;
- }
- case kmp_sch_static_chunked:
- {
- register ST span;
- if ( chunk < 1 ) {
- chunk = 1;
- }
- span = chunk * incr;
- *pstride = span * nth;
- *plower = *plower + (span * tid);
- *pupper = *plower + span - incr;
- if( plastiter != NULL )
- *plastiter = (tid == ((trip_count - 1)/( UT )chunk) % nth);
- break;
- }
-#if OMP_45_ENABLED
- case kmp_sch_static_balanced_chunked:
- {
- register T old_upper = *pupper;
- // round up to make sure the chunk is enough to cover all iterations
- register UT span = (trip_count+nth-1) / nth;
-
- // perform chunk adjustment
- chunk = (span + chunk - 1) & ~(chunk-1);
-
- span = chunk * incr;
- *plower = *plower + (span * tid);
- *pupper = *plower + span - incr;
- if ( incr > 0 ) {
- if ( *pupper > old_upper ) *pupper = old_upper;
- } else
- if ( *pupper < old_upper ) *pupper = old_upper;
-
- if( plastiter != NULL )
- *plastiter = ( tid == ((trip_count - 1)/( UT )chunk) );
- break;
- }
+ span = chunk * incr;
+ *plower = *plower + (span * tid);
+ *pupper = *plower + span - incr;
+ if (incr > 0) {
+ if (*pupper > old_upper)
+ *pupper = old_upper;
+ } else if (*pupper < old_upper)
+ *pupper = old_upper;
+
+ if (plastiter != NULL)
+ *plastiter = (tid == ((trip_count - 1) / (UT)chunk));
+ break;
+ }
#endif
- default:
- KMP_ASSERT2( 0, "__kmpc_for_static_init: unknown scheduling type" );
- break;
- }
+ default:
+ KMP_ASSERT2(0, "__kmpc_for_static_init: unknown scheduling type");
+ break;
+ }
#if USE_ITT_BUILD
- // Report loop metadata
- if ( KMP_MASTER_TID(tid) && __itt_metadata_add_ptr && __kmp_forkjoin_frames_mode == 3 &&
+ // Report loop metadata
+ if (KMP_MASTER_TID(tid) && __itt_metadata_add_ptr &&
+ __kmp_forkjoin_frames_mode == 3 &&
#if OMP_40_ENABLED
- th->th.th_teams_microtask == NULL &&
+ th->th.th_teams_microtask == NULL &&
#endif
- team->t.t_active_level == 1 )
- {
- kmp_uint64 cur_chunk = chunk;
- // Calculate chunk in case it was not specified; it is specified for kmp_sch_static_chunked
- if ( schedtype == kmp_sch_static ) {
- cur_chunk = trip_count / nth + ( ( trip_count % nth ) ? 1 : 0);
- }
- // 0 - "static" schedule
- __kmp_itt_metadata_loop(loc, 0, trip_count, cur_chunk);
- }
+ team->t.t_active_level == 1) {
+ kmp_uint64 cur_chunk = chunk;
+ // Calculate chunk in case it was not specified; it is specified for
+ // kmp_sch_static_chunked
+ if (schedtype == kmp_sch_static) {
+ cur_chunk = trip_count / nth + ((trip_count % nth) ? 1 : 0);
+ }
+ // 0 - "static" schedule
+ __kmp_itt_metadata_loop(loc, 0, trip_count, cur_chunk);
+ }
#endif
- #ifdef KMP_DEBUG
- {
- const char * buff;
- // create format specifiers before the debug output
- buff = __kmp_str_format(
- "__kmpc_for_static_init: liter=%%d lower=%%%s upper=%%%s stride = %%%s signed?<%s>\n",
- traits_t< T >::spec, traits_t< T >::spec, traits_t< ST >::spec, traits_t< T >::spec );
- KD_TRACE(100, ( buff, *plastiter, *plower, *pupper, *pstride ) );
- __kmp_str_free( &buff );
- }
- #endif
- KE_TRACE( 10, ("__kmpc_for_static_init: T#%d return\n", global_tid ) );
+#ifdef KMP_DEBUG
+ {
+ const char *buff;
+ // create format specifiers before the debug output
+ buff = __kmp_str_format("__kmpc_for_static_init: liter=%%d lower=%%%s "
+ "upper=%%%s stride = %%%s signed?<%s>\n",
+ traits_t<T>::spec, traits_t<T>::spec,
+ traits_t<ST>::spec, traits_t<T>::spec);
+ KD_TRACE(100, (buff, *plastiter, *plower, *pupper, *pstride));
+ __kmp_str_free(&buff);
+ }
+#endif
+ KE_TRACE(10, ("__kmpc_for_static_init: T#%d return\n", global_tid));
#if OMPT_SUPPORT && OMPT_TRACE
- if (ompt_enabled &&
- ompt_callbacks.ompt_callback(ompt_event_loop_begin)) {
- ompt_callbacks.ompt_callback(ompt_event_loop_begin)(
- team_info->parallel_id, task_info->task_id, team_info->microtask);
- }
+ if (ompt_enabled && ompt_callbacks.ompt_callback(ompt_event_loop_begin)) {
+ ompt_callbacks.ompt_callback(ompt_event_loop_begin)(
+ team_info->parallel_id, task_info->task_id, team_info->microtask);
+ }
#endif
- return;
+ return;
}
-template< typename T >
-static void
-__kmp_dist_for_static_init(
- ident_t *loc,
- kmp_int32 gtid,
- kmp_int32 schedule,
- kmp_int32 *plastiter,
- T *plower,
- T *pupper,
- T *pupperDist,
- typename traits_t< T >::signed_t *pstride,
- typename traits_t< T >::signed_t incr,
- typename traits_t< T >::signed_t chunk
-) {
- KMP_COUNT_BLOCK(OMP_DISTRIBUTE);
- typedef typename traits_t< T >::unsigned_t UT;
- typedef typename traits_t< T >::signed_t ST;
- register kmp_uint32 tid;
- register kmp_uint32 nth;
- register kmp_uint32 team_id;
- register kmp_uint32 nteams;
- register UT trip_count;
- register kmp_team_t *team;
- kmp_info_t * th;
-
- KMP_DEBUG_ASSERT( plastiter && plower && pupper && pupperDist && pstride );
- KE_TRACE( 10, ("__kmpc_dist_for_static_init called (%d)\n", gtid));
- #ifdef KMP_DEBUG
- {
- const char * buff;
- // create format specifiers before the debug output
- buff = __kmp_str_format(
- "__kmpc_dist_for_static_init: T#%%d schedLoop=%%d liter=%%d "\
- "iter=(%%%s, %%%s, %%%s) chunk=%%%s signed?<%s>\n",
- traits_t< T >::spec, traits_t< T >::spec, traits_t< ST >::spec,
- traits_t< ST >::spec, traits_t< T >::spec );
- KD_TRACE(100, ( buff, gtid, schedule, *plastiter,
- *plower, *pupper, incr, chunk ) );
- __kmp_str_free( &buff );
- }
- #endif
-
- if( __kmp_env_consistency_check ) {
- __kmp_push_workshare( gtid, ct_pdo, loc );
- if( incr == 0 ) {
- __kmp_error_construct( kmp_i18n_msg_CnsLoopIncrZeroProhibited, ct_pdo, loc );
- }
- if( incr > 0 ? (*pupper < *plower) : (*plower < *pupper) ) {
- // The loop is illegal.
- // Some zero-trip loops maintained by compiler, e.g.:
- // for(i=10;i<0;++i) // lower >= upper - run-time check
- // for(i=0;i>10;--i) // lower <= upper - run-time check
- // for(i=0;i>10;++i) // incr > 0 - compile-time check
- // for(i=10;i<0;--i) // incr < 0 - compile-time check
- // Compiler does not check the following illegal loops:
- // for(i=0;i<10;i+=incr) // where incr<0
- // for(i=10;i>0;i-=incr) // where incr<0
- __kmp_error_construct( kmp_i18n_msg_CnsLoopIncrIllegal, ct_pdo, loc );
- }
+template <typename T>
+static void __kmp_dist_for_static_init(ident_t *loc, kmp_int32 gtid,
+ kmp_int32 schedule, kmp_int32 *plastiter,
+ T *plower, T *pupper, T *pupperDist,
+ typename traits_t<T>::signed_t *pstride,
+ typename traits_t<T>::signed_t incr,
+ typename traits_t<T>::signed_t chunk) {
+ KMP_COUNT_BLOCK(OMP_DISTRIBUTE);
+ typedef typename traits_t<T>::unsigned_t UT;
+ typedef typename traits_t<T>::signed_t ST;
+ register kmp_uint32 tid;
+ register kmp_uint32 nth;
+ register kmp_uint32 team_id;
+ register kmp_uint32 nteams;
+ register UT trip_count;
+ register kmp_team_t *team;
+ kmp_info_t *th;
+
+ KMP_DEBUG_ASSERT(plastiter && plower && pupper && pupperDist && pstride);
+ KE_TRACE(10, ("__kmpc_dist_for_static_init called (%d)\n", gtid));
+#ifdef KMP_DEBUG
+ {
+ const char *buff;
+ // create format specifiers before the debug output
+ buff = __kmp_str_format(
+ "__kmpc_dist_for_static_init: T#%%d schedLoop=%%d liter=%%d "
+ "iter=(%%%s, %%%s, %%%s) chunk=%%%s signed?<%s>\n",
+ traits_t<T>::spec, traits_t<T>::spec, traits_t<ST>::spec,
+ traits_t<ST>::spec, traits_t<T>::spec);
+ KD_TRACE(100,
+ (buff, gtid, schedule, *plastiter, *plower, *pupper, incr, chunk));
+ __kmp_str_free(&buff);
+ }
+#endif
+
+ if (__kmp_env_consistency_check) {
+ __kmp_push_workshare(gtid, ct_pdo, loc);
+ if (incr == 0) {
+ __kmp_error_construct(kmp_i18n_msg_CnsLoopIncrZeroProhibited, ct_pdo,
+ loc);
+ }
+ if (incr > 0 ? (*pupper < *plower) : (*plower < *pupper)) {
+ // The loop is illegal.
+ // Some zero-trip loops maintained by compiler, e.g.:
+ // for(i=10;i<0;++i) // lower >= upper - run-time check
+ // for(i=0;i>10;--i) // lower <= upper - run-time check
+ // for(i=0;i>10;++i) // incr > 0 - compile-time check
+ // for(i=10;i<0;--i) // incr < 0 - compile-time check
+ // Compiler does not check the following illegal loops:
+ // for(i=0;i<10;i+=incr) // where incr<0
+ // for(i=10;i>0;i-=incr) // where incr<0
+ __kmp_error_construct(kmp_i18n_msg_CnsLoopIncrIllegal, ct_pdo, loc);
+ }
+ }
+ tid = __kmp_tid_from_gtid(gtid);
+ th = __kmp_threads[gtid];
+ nth = th->th.th_team_nproc;
+ team = th->th.th_team;
+#if OMP_40_ENABLED
+ KMP_DEBUG_ASSERT(th->th.th_teams_microtask); // we are in the teams construct
+ nteams = th->th.th_teams_size.nteams;
+#endif
+ team_id = team->t.t_master_tid;
+ KMP_DEBUG_ASSERT(nteams == team->t.t_parent->t.t_nproc);
+
+ // compute global trip count
+ if (incr == 1) {
+ trip_count = *pupper - *plower + 1;
+ } else if (incr == -1) {
+ trip_count = *plower - *pupper + 1;
+ } else if (incr > 0) {
+ // upper-lower can exceed the limit of signed type
+ trip_count = (UT)(*pupper - *plower) / incr + 1;
+ } else {
+ trip_count = (UT)(*plower - *pupper) / (-incr) + 1;
+ }
+
+ *pstride = *pupper - *plower; // just in case (can be unused)
+ if (trip_count <= nteams) {
+ KMP_DEBUG_ASSERT(
+ __kmp_static == kmp_sch_static_greedy ||
+ __kmp_static ==
+ kmp_sch_static_balanced); // Unknown static scheduling type.
+ // only masters of some teams get single iteration, other threads get
+ // nothing
+ if (team_id < trip_count && tid == 0) {
+ *pupper = *pupperDist = *plower = *plower + team_id * incr;
+ } else {
+ *pupperDist = *pupper;
+ *plower = *pupper + incr; // compiler should skip loop body
}
- tid = __kmp_tid_from_gtid( gtid );
- th = __kmp_threads[gtid];
- nth = th->th.th_team_nproc;
- team = th->th.th_team;
- #if OMP_40_ENABLED
- KMP_DEBUG_ASSERT(th->th.th_teams_microtask); // we are in the teams construct
- nteams = th->th.th_teams_size.nteams;
- #endif
- team_id = team->t.t_master_tid;
- KMP_DEBUG_ASSERT(nteams == team->t.t_parent->t.t_nproc);
-
- // compute global trip count
- if( incr == 1 ) {
- trip_count = *pupper - *plower + 1;
- } else if(incr == -1) {
- trip_count = *plower - *pupper + 1;
- } else if ( incr > 0 ) {
- // upper-lower can exceed the limit of signed type
- trip_count = (UT)(*pupper - *plower) / incr + 1;
+ if (plastiter != NULL)
+ *plastiter = (tid == 0 && team_id == trip_count - 1);
+ } else {
+ // Get the team's chunk first (each team gets at most one chunk)
+ if (__kmp_static == kmp_sch_static_balanced) {
+ register UT chunkD = trip_count / nteams;
+ register UT extras = trip_count % nteams;
+ *plower +=
+ incr * (team_id * chunkD + (team_id < extras ? team_id : extras));
+ *pupperDist = *plower + chunkD * incr - (team_id < extras ? 0 : incr);
+ if (plastiter != NULL)
+ *plastiter = (team_id == nteams - 1);
+ } else {
+ register T chunk_inc_count =
+ (trip_count / nteams + ((trip_count % nteams) ? 1 : 0)) * incr;
+ register T upper = *pupper;
+ KMP_DEBUG_ASSERT(__kmp_static == kmp_sch_static_greedy);
+ // Unknown static scheduling type.
+ *plower += team_id * chunk_inc_count;
+ *pupperDist = *plower + chunk_inc_count - incr;
+ // Check/correct bounds if needed
+ if (incr > 0) {
+ if (*pupperDist < *plower)
+ *pupperDist = traits_t<T>::max_value;
+ if (plastiter != NULL)
+ *plastiter = *plower <= upper && *pupperDist > upper - incr;
+ if (*pupperDist > upper)
+ *pupperDist = upper; // tracker C73258
+ if (*plower > *pupperDist) {
+ *pupper = *pupperDist; // no iterations available for the team
+ goto end;
+ }
+ } else {
+ if (*pupperDist > *plower)
+ *pupperDist = traits_t<T>::min_value;
+ if (plastiter != NULL)
+ *plastiter = *plower >= upper && *pupperDist < upper - incr;
+ if (*pupperDist < upper)
+ *pupperDist = upper; // tracker C73258
+ if (*plower < *pupperDist) {
+ *pupper = *pupperDist; // no iterations available for the team
+ goto end;
+ }
+ }
+ }
+ // Get the parallel loop chunk now (for thread)
+ // compute trip count for team's chunk
+ if (incr == 1) {
+ trip_count = *pupperDist - *plower + 1;
+ } else if (incr == -1) {
+ trip_count = *plower - *pupperDist + 1;
+ } else if (incr > 1) {
+ // upper-lower can exceed the limit of signed type
+ trip_count = (UT)(*pupperDist - *plower) / incr + 1;
} else {
- trip_count = (UT)(*plower - *pupper) / (-incr) + 1;
+ trip_count = (UT)(*plower - *pupperDist) / (-incr) + 1;
}
-
- *pstride = *pupper - *plower; // just in case (can be unused)
- if( trip_count <= nteams ) {
+ KMP_DEBUG_ASSERT(trip_count);
+ switch (schedule) {
+ case kmp_sch_static: {
+ if (trip_count <= nth) {
KMP_DEBUG_ASSERT(
- __kmp_static == kmp_sch_static_greedy || \
- __kmp_static == kmp_sch_static_balanced
- ); // Unknown static scheduling type.
- // only masters of some teams get single iteration, other threads get nothing
- if( team_id < trip_count && tid == 0 ) {
- *pupper = *pupperDist = *plower = *plower + team_id * incr;
- } else {
- *pupperDist = *pupper;
- *plower = *pupper + incr; // compiler should skip loop body
- }
- if( plastiter != NULL )
- *plastiter = ( tid == 0 && team_id == trip_count - 1 );
- } else {
- // Get the team's chunk first (each team gets at most one chunk)
- if( __kmp_static == kmp_sch_static_balanced ) {
- register UT chunkD = trip_count / nteams;
- register UT extras = trip_count % nteams;
- *plower += incr * ( team_id * chunkD + ( team_id < extras ? team_id : extras ) );
- *pupperDist = *plower + chunkD * incr - ( team_id < extras ? 0 : incr );
- if( plastiter != NULL )
- *plastiter = ( team_id == nteams - 1 );
+ __kmp_static == kmp_sch_static_greedy ||
+ __kmp_static ==
+ kmp_sch_static_balanced); // Unknown static scheduling type.
+ if (tid < trip_count)
+ *pupper = *plower = *plower + tid * incr;
+ else
+ *plower = *pupper + incr; // no iterations available
+ if (plastiter != NULL)
+ if (*plastiter != 0 && !(tid == trip_count - 1))
+ *plastiter = 0;
+ } else {
+ if (__kmp_static == kmp_sch_static_balanced) {
+ register UT chunkL = trip_count / nth;
+ register UT extras = trip_count % nth;
+ *plower += incr * (tid * chunkL + (tid < extras ? tid : extras));
+ *pupper = *plower + chunkL * incr - (tid < extras ? 0 : incr);
+ if (plastiter != NULL)
+ if (*plastiter != 0 && !(tid == nth - 1))
+ *plastiter = 0;
} else {
- register T chunk_inc_count =
- ( trip_count / nteams + ( ( trip_count % nteams ) ? 1 : 0) ) * incr;
- register T upper = *pupper;
- KMP_DEBUG_ASSERT( __kmp_static == kmp_sch_static_greedy );
- // Unknown static scheduling type.
- *plower += team_id * chunk_inc_count;
- *pupperDist = *plower + chunk_inc_count - incr;
- // Check/correct bounds if needed
- if( incr > 0 ) {
- if( *pupperDist < *plower )
- *pupperDist = traits_t<T>::max_value;
- if( plastiter != NULL )
- *plastiter = *plower <= upper && *pupperDist > upper - incr;
- if( *pupperDist > upper )
- *pupperDist = upper; // tracker C73258
- if( *plower > *pupperDist ) {
- *pupper = *pupperDist; // no iterations available for the team
- goto end;
- }
- } else {
- if( *pupperDist > *plower )
- *pupperDist = traits_t<T>::min_value;
- if( plastiter != NULL )
- *plastiter = *plower >= upper && *pupperDist < upper - incr;
- if( *pupperDist < upper )
- *pupperDist = upper; // tracker C73258
- if( *plower < *pupperDist ) {
- *pupper = *pupperDist; // no iterations available for the team
- goto end;
- }
- }
- }
- // Get the parallel loop chunk now (for thread)
- // compute trip count for team's chunk
- if( incr == 1 ) {
- trip_count = *pupperDist - *plower + 1;
- } else if(incr == -1) {
- trip_count = *plower - *pupperDist + 1;
- } else if ( incr > 1 ) {
- // upper-lower can exceed the limit of signed type
- trip_count = (UT)(*pupperDist - *plower) / incr + 1;
- } else {
- trip_count = (UT)(*plower - *pupperDist) / (-incr) + 1;
- }
- KMP_DEBUG_ASSERT( trip_count );
- switch( schedule ) {
- case kmp_sch_static:
- {
- if( trip_count <= nth ) {
- KMP_DEBUG_ASSERT(
- __kmp_static == kmp_sch_static_greedy || \
- __kmp_static == kmp_sch_static_balanced
- ); // Unknown static scheduling type.
- if( tid < trip_count )
- *pupper = *plower = *plower + tid * incr;
- else
- *plower = *pupper + incr; // no iterations available
- if( plastiter != NULL )
- if( *plastiter != 0 && !( tid == trip_count - 1 ) )
- *plastiter = 0;
- } else {
- if( __kmp_static == kmp_sch_static_balanced ) {
- register UT chunkL = trip_count / nth;
- register UT extras = trip_count % nth;
- *plower += incr * (tid * chunkL + (tid < extras ? tid : extras));
- *pupper = *plower + chunkL * incr - (tid < extras ? 0 : incr);
- if( plastiter != NULL )
- if( *plastiter != 0 && !( tid == nth - 1 ) )
- *plastiter = 0;
- } else {
- register T chunk_inc_count =
- ( trip_count / nth + ( ( trip_count % nth ) ? 1 : 0) ) * incr;
- register T upper = *pupperDist;
- KMP_DEBUG_ASSERT( __kmp_static == kmp_sch_static_greedy );
- // Unknown static scheduling type.
- *plower += tid * chunk_inc_count;
- *pupper = *plower + chunk_inc_count - incr;
- if( incr > 0 ) {
- if( *pupper < *plower )
- *pupper = traits_t<T>::max_value;
- if( plastiter != NULL )
- if( *plastiter != 0 && !(*plower <= upper && *pupper > upper - incr) )
- *plastiter = 0;
- if( *pupper > upper )
- *pupper = upper;//tracker C73258
- } else {
- if( *pupper > *plower )
- *pupper = traits_t<T>::min_value;
- if( plastiter != NULL )
- if( *plastiter != 0 && !(*plower >= upper && *pupper < upper - incr) )
- *plastiter = 0;
- if( *pupper < upper )
- *pupper = upper;//tracker C73258
- }
- }
- }
- break;
- }
- case kmp_sch_static_chunked:
- {
- register ST span;
- if( chunk < 1 )
- chunk = 1;
- span = chunk * incr;
- *pstride = span * nth;
- *plower = *plower + (span * tid);
- *pupper = *plower + span - incr;
- if( plastiter != NULL )
- if( *plastiter != 0 && !(tid == ((trip_count - 1) / ( UT )chunk) % nth) )
- *plastiter = 0;
- break;
- }
- default:
- KMP_ASSERT2( 0, "__kmpc_dist_for_static_init: unknown loop scheduling type" );
- break;
- }
+ register T chunk_inc_count =
+ (trip_count / nth + ((trip_count % nth) ? 1 : 0)) * incr;
+ register T upper = *pupperDist;
+ KMP_DEBUG_ASSERT(__kmp_static == kmp_sch_static_greedy);
+ // Unknown static scheduling type.
+ *plower += tid * chunk_inc_count;
+ *pupper = *plower + chunk_inc_count - incr;
+ if (incr > 0) {
+ if (*pupper < *plower)
+ *pupper = traits_t<T>::max_value;
+ if (plastiter != NULL)
+ if (*plastiter != 0 &&
+ !(*plower <= upper && *pupper > upper - incr))
+ *plastiter = 0;
+ if (*pupper > upper)
+ *pupper = upper; // tracker C73258
+ } else {
+ if (*pupper > *plower)
+ *pupper = traits_t<T>::min_value;
+ if (plastiter != NULL)
+ if (*plastiter != 0 &&
+ !(*plower >= upper && *pupper < upper - incr))
+ *plastiter = 0;
+ if (*pupper < upper)
+ *pupper = upper; // tracker C73258
+ }
+ }
+ }
+ break;
+ }
+ case kmp_sch_static_chunked: {
+ register ST span;
+ if (chunk < 1)
+ chunk = 1;
+ span = chunk * incr;
+ *pstride = span * nth;
+ *plower = *plower + (span * tid);
+ *pupper = *plower + span - incr;
+ if (plastiter != NULL)
+ if (*plastiter != 0 && !(tid == ((trip_count - 1) / (UT)chunk) % nth))
+ *plastiter = 0;
+ break;
}
- end:;
- #ifdef KMP_DEBUG
- {
- const char * buff;
- // create format specifiers before the debug output
- buff = __kmp_str_format(
- "__kmpc_dist_for_static_init: last=%%d lo=%%%s up=%%%s upDist=%%%s "\
- "stride=%%%s signed?<%s>\n",
- traits_t< T >::spec, traits_t< T >::spec, traits_t< T >::spec,
- traits_t< ST >::spec, traits_t< T >::spec );
- KD_TRACE(100, ( buff, *plastiter, *plower, *pupper, *pupperDist, *pstride ) );
- __kmp_str_free( &buff );
+ default:
+ KMP_ASSERT2(0,
+ "__kmpc_dist_for_static_init: unknown loop scheduling type");
+ break;
}
- #endif
- KE_TRACE( 10, ("__kmpc_dist_for_static_init: T#%d return\n", gtid ) );
- return;
+ }
+end:;
+#ifdef KMP_DEBUG
+ {
+ const char *buff;
+ // create format specifiers before the debug output
+ buff = __kmp_str_format(
+ "__kmpc_dist_for_static_init: last=%%d lo=%%%s up=%%%s upDist=%%%s "
+ "stride=%%%s signed?<%s>\n",
+ traits_t<T>::spec, traits_t<T>::spec, traits_t<T>::spec,
+ traits_t<ST>::spec, traits_t<T>::spec);
+ KD_TRACE(100, (buff, *plastiter, *plower, *pupper, *pupperDist, *pstride));
+ __kmp_str_free(&buff);
+ }
+#endif
+ KE_TRACE(10, ("__kmpc_dist_for_static_init: T#%d return\n", gtid));
+ return;
}
-template< typename T >
-static void
-__kmp_team_static_init(
- ident_t *loc,
- kmp_int32 gtid,
- kmp_int32 *p_last,
- T *p_lb,
- T *p_ub,
- typename traits_t< T >::signed_t *p_st,
- typename traits_t< T >::signed_t incr,
- typename traits_t< T >::signed_t chunk
-) {
- // The routine returns the first chunk distributed to the team and
- // stride for next chunks calculation.
- // Last iteration flag set for the team that will execute
- // the last iteration of the loop.
- // The routine is called for dist_schedue(static,chunk) only.
- typedef typename traits_t< T >::unsigned_t UT;
- typedef typename traits_t< T >::signed_t ST;
- kmp_uint32 team_id;
- kmp_uint32 nteams;
- UT trip_count;
- T lower;
- T upper;
- ST span;
- kmp_team_t *team;
- kmp_info_t *th;
-
- KMP_DEBUG_ASSERT( p_last && p_lb && p_ub && p_st );
- KE_TRACE( 10, ("__kmp_team_static_init called (%d)\n", gtid));
- #ifdef KMP_DEBUG
- {
- const char * buff;
- // create format specifiers before the debug output
- buff = __kmp_str_format( "__kmp_team_static_init enter: T#%%d liter=%%d "\
- "iter=(%%%s, %%%s, %%%s) chunk %%%s; signed?<%s>\n",
- traits_t< T >::spec, traits_t< T >::spec, traits_t< ST >::spec,
- traits_t< ST >::spec, traits_t< T >::spec );
- KD_TRACE(100, ( buff, gtid, *p_last, *p_lb, *p_ub, *p_st, chunk ) );
- __kmp_str_free( &buff );
- }
- #endif
-
- lower = *p_lb;
- upper = *p_ub;
- if( __kmp_env_consistency_check ) {
- if( incr == 0 ) {
- __kmp_error_construct( kmp_i18n_msg_CnsLoopIncrZeroProhibited, ct_pdo, loc );
- }
- if( incr > 0 ? (upper < lower) : (lower < upper) ) {
- // The loop is illegal.
- // Some zero-trip loops maintained by compiler, e.g.:
- // for(i=10;i<0;++i) // lower >= upper - run-time check
- // for(i=0;i>10;--i) // lower <= upper - run-time check
- // for(i=0;i>10;++i) // incr > 0 - compile-time check
- // for(i=10;i<0;--i) // incr < 0 - compile-time check
- // Compiler does not check the following illegal loops:
- // for(i=0;i<10;i+=incr) // where incr<0
- // for(i=10;i>0;i-=incr) // where incr<0
- __kmp_error_construct( kmp_i18n_msg_CnsLoopIncrIllegal, ct_pdo, loc );
- }
- }
- th = __kmp_threads[gtid];
- team = th->th.th_team;
- #if OMP_40_ENABLED
- KMP_DEBUG_ASSERT(th->th.th_teams_microtask); // we are in the teams construct
- nteams = th->th.th_teams_size.nteams;
- #endif
- team_id = team->t.t_master_tid;
- KMP_DEBUG_ASSERT(nteams == team->t.t_parent->t.t_nproc);
-
- // compute trip count
- if( incr == 1 ) {
- trip_count = upper - lower + 1;
- } else if(incr == -1) {
- trip_count = lower - upper + 1;
- } else if ( incr > 0 ) {
- // upper-lower can exceed the limit of signed type
- trip_count = (UT)(upper - lower) / incr + 1;
- } else {
- trip_count = (UT)(lower - upper) / (-incr) + 1;
- }
- if( chunk < 1 )
- chunk = 1;
- span = chunk * incr;
- *p_st = span * nteams;
- *p_lb = lower + (span * team_id);
- *p_ub = *p_lb + span - incr;
- if ( p_last != NULL )
- *p_last = (team_id == ((trip_count - 1)/(UT)chunk) % nteams);
- // Correct upper bound if needed
- if( incr > 0 ) {
- if( *p_ub < *p_lb ) // overflow?
- *p_ub = traits_t<T>::max_value;
- if( *p_ub > upper )
- *p_ub = upper; // tracker C73258
- } else { // incr < 0
- if( *p_ub > *p_lb )
- *p_ub = traits_t<T>::min_value;
- if( *p_ub < upper )
- *p_ub = upper; // tracker C73258
- }
- #ifdef KMP_DEBUG
- {
- const char * buff;
- // create format specifiers before the debug output
- buff = __kmp_str_format( "__kmp_team_static_init exit: T#%%d team%%u liter=%%d "\
- "iter=(%%%s, %%%s, %%%s) chunk %%%s\n",
- traits_t< T >::spec, traits_t< T >::spec, traits_t< ST >::spec,
- traits_t< ST >::spec );
- KD_TRACE(100, ( buff, gtid, team_id, *p_last, *p_lb, *p_ub, *p_st, chunk ) );
- __kmp_str_free( &buff );
- }
- #endif
+template <typename T>
+static void __kmp_team_static_init(ident_t *loc, kmp_int32 gtid,
+ kmp_int32 *p_last, T *p_lb, T *p_ub,
+ typename traits_t<T>::signed_t *p_st,
+ typename traits_t<T>::signed_t incr,
+ typename traits_t<T>::signed_t chunk) {
+ // The routine returns the first chunk distributed to the team and
+ // stride for next chunks calculation.
+ // Last iteration flag set for the team that will execute
+ // the last iteration of the loop.
+ // The routine is called for dist_schedue(static,chunk) only.
+ typedef typename traits_t<T>::unsigned_t UT;
+ typedef typename traits_t<T>::signed_t ST;
+ kmp_uint32 team_id;
+ kmp_uint32 nteams;
+ UT trip_count;
+ T lower;
+ T upper;
+ ST span;
+ kmp_team_t *team;
+ kmp_info_t *th;
+
+ KMP_DEBUG_ASSERT(p_last && p_lb && p_ub && p_st);
+ KE_TRACE(10, ("__kmp_team_static_init called (%d)\n", gtid));
+#ifdef KMP_DEBUG
+ {
+ const char *buff;
+ // create format specifiers before the debug output
+ buff = __kmp_str_format("__kmp_team_static_init enter: T#%%d liter=%%d "
+ "iter=(%%%s, %%%s, %%%s) chunk %%%s; signed?<%s>\n",
+ traits_t<T>::spec, traits_t<T>::spec,
+ traits_t<ST>::spec, traits_t<ST>::spec,
+ traits_t<T>::spec);
+ KD_TRACE(100, (buff, gtid, *p_last, *p_lb, *p_ub, *p_st, chunk));
+ __kmp_str_free(&buff);
+ }
+#endif
+
+ lower = *p_lb;
+ upper = *p_ub;
+ if (__kmp_env_consistency_check) {
+ if (incr == 0) {
+ __kmp_error_construct(kmp_i18n_msg_CnsLoopIncrZeroProhibited, ct_pdo,
+ loc);
+ }
+ if (incr > 0 ? (upper < lower) : (lower < upper)) {
+ // The loop is illegal.
+ // Some zero-trip loops maintained by compiler, e.g.:
+ // for(i=10;i<0;++i) // lower >= upper - run-time check
+ // for(i=0;i>10;--i) // lower <= upper - run-time check
+ // for(i=0;i>10;++i) // incr > 0 - compile-time check
+ // for(i=10;i<0;--i) // incr < 0 - compile-time check
+ // Compiler does not check the following illegal loops:
+ // for(i=0;i<10;i+=incr) // where incr<0
+ // for(i=10;i>0;i-=incr) // where incr<0
+ __kmp_error_construct(kmp_i18n_msg_CnsLoopIncrIllegal, ct_pdo, loc);
+ }
+ }
+ th = __kmp_threads[gtid];
+ team = th->th.th_team;
+#if OMP_40_ENABLED
+ KMP_DEBUG_ASSERT(th->th.th_teams_microtask); // we are in the teams construct
+ nteams = th->th.th_teams_size.nteams;
+#endif
+ team_id = team->t.t_master_tid;
+ KMP_DEBUG_ASSERT(nteams == team->t.t_parent->t.t_nproc);
+
+ // compute trip count
+ if (incr == 1) {
+ trip_count = upper - lower + 1;
+ } else if (incr == -1) {
+ trip_count = lower - upper + 1;
+ } else if (incr > 0) {
+ // upper-lower can exceed the limit of signed type
+ trip_count = (UT)(upper - lower) / incr + 1;
+ } else {
+ trip_count = (UT)(lower - upper) / (-incr) + 1;
+ }
+ if (chunk < 1)
+ chunk = 1;
+ span = chunk * incr;
+ *p_st = span * nteams;
+ *p_lb = lower + (span * team_id);
+ *p_ub = *p_lb + span - incr;
+ if (p_last != NULL)
+ *p_last = (team_id == ((trip_count - 1) / (UT)chunk) % nteams);
+ // Correct upper bound if needed
+ if (incr > 0) {
+ if (*p_ub < *p_lb) // overflow?
+ *p_ub = traits_t<T>::max_value;
+ if (*p_ub > upper)
+ *p_ub = upper; // tracker C73258
+ } else { // incr < 0
+ if (*p_ub > *p_lb)
+ *p_ub = traits_t<T>::min_value;
+ if (*p_ub < upper)
+ *p_ub = upper; // tracker C73258
+ }
+#ifdef KMP_DEBUG
+ {
+ const char *buff;
+ // create format specifiers before the debug output
+ buff =
+ __kmp_str_format("__kmp_team_static_init exit: T#%%d team%%u liter=%%d "
+ "iter=(%%%s, %%%s, %%%s) chunk %%%s\n",
+ traits_t<T>::spec, traits_t<T>::spec,
+ traits_t<ST>::spec, traits_t<ST>::spec);
+ KD_TRACE(100, (buff, gtid, team_id, *p_last, *p_lb, *p_ub, *p_st, chunk));
+ __kmp_str_free(&buff);
+ }
+#endif
}
-//--------------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
extern "C" {
-
/*!
@ingroup WORK_SHARING
@param loc Source code location
@@ -743,55 +735,54 @@ extern "C" {
Each of the four functions here are identical apart from the argument types.
-The functions compute the upper and lower bounds and stride to be used for the set of iterations
-to be executed by the current thread from the statically scheduled loop that is described by the
-initial values of the bounds, stride, increment and chunk size.
+The functions compute the upper and lower bounds and stride to be used for the
+set of iterations to be executed by the current thread from the statically
+scheduled loop that is described by the initial values of the bounds, stride,
+increment and chunk size.
@{
*/
-void
-__kmpc_for_static_init_4( ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype, kmp_int32 *plastiter,
- kmp_int32 *plower, kmp_int32 *pupper,
- kmp_int32 *pstride, kmp_int32 incr, kmp_int32 chunk )
-{
- __kmp_for_static_init< kmp_int32 >(
- loc, gtid, schedtype, plastiter, plower, pupper, pstride, incr, chunk );
+void __kmpc_for_static_init_4(ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype,
+ kmp_int32 *plastiter, kmp_int32 *plower,
+ kmp_int32 *pupper, kmp_int32 *pstride,
+ kmp_int32 incr, kmp_int32 chunk) {
+ __kmp_for_static_init<kmp_int32>(loc, gtid, schedtype, plastiter, plower,
+ pupper, pstride, incr, chunk);
}
/*!
See @ref __kmpc_for_static_init_4
*/
-void
-__kmpc_for_static_init_4u( ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype, kmp_int32 *plastiter,
- kmp_uint32 *plower, kmp_uint32 *pupper,
- kmp_int32 *pstride, kmp_int32 incr, kmp_int32 chunk )
-{
- __kmp_for_static_init< kmp_uint32 >(
- loc, gtid, schedtype, plastiter, plower, pupper, pstride, incr, chunk );
+void __kmpc_for_static_init_4u(ident_t *loc, kmp_int32 gtid,
+ kmp_int32 schedtype, kmp_int32 *plastiter,
+ kmp_uint32 *plower, kmp_uint32 *pupper,
+ kmp_int32 *pstride, kmp_int32 incr,
+ kmp_int32 chunk) {
+ __kmp_for_static_init<kmp_uint32>(loc, gtid, schedtype, plastiter, plower,
+ pupper, pstride, incr, chunk);
}
/*!
See @ref __kmpc_for_static_init_4
*/
-void
-__kmpc_for_static_init_8( ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype, kmp_int32 *plastiter,
- kmp_int64 *plower, kmp_int64 *pupper,
- kmp_int64 *pstride, kmp_int64 incr, kmp_int64 chunk )
-{
- __kmp_for_static_init< kmp_int64 >(
- loc, gtid, schedtype, plastiter, plower, pupper, pstride, incr, chunk );
+void __kmpc_for_static_init_8(ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype,
+ kmp_int32 *plastiter, kmp_int64 *plower,
+ kmp_int64 *pupper, kmp_int64 *pstride,
+ kmp_int64 incr, kmp_int64 chunk) {
+ __kmp_for_static_init<kmp_int64>(loc, gtid, schedtype, plastiter, plower,
+ pupper, pstride, incr, chunk);
}
/*!
See @ref __kmpc_for_static_init_4
*/
-void
-__kmpc_for_static_init_8u( ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype, kmp_int32 *plastiter,
- kmp_uint64 *plower, kmp_uint64 *pupper,
- kmp_int64 *pstride, kmp_int64 incr, kmp_int64 chunk )
-{
- __kmp_for_static_init< kmp_uint64 >(
- loc, gtid, schedtype, plastiter, plower, pupper, pstride, incr, chunk );
+void __kmpc_for_static_init_8u(ident_t *loc, kmp_int32 gtid,
+ kmp_int32 schedtype, kmp_int32 *plastiter,
+ kmp_uint64 *plower, kmp_uint64 *pupper,
+ kmp_int64 *pstride, kmp_int64 incr,
+ kmp_int64 chunk) {
+ __kmp_for_static_init<kmp_uint64>(loc, gtid, schedtype, plastiter, plower,
+ pupper, pstride, incr, chunk);
}
/*!
@}
@@ -812,66 +803,62 @@ __kmpc_for_static_init_8u( ident_t *loc,
Each of the four functions here are identical apart from the argument types.
-The functions compute the upper and lower bounds and strides to be used for the set of iterations
-to be executed by the current thread from the statically scheduled loop that is described by the
-initial values of the bounds, strides, increment and chunks for parallel loop and distribute
-constructs.
+The functions compute the upper and lower bounds and strides to be used for the
+set of iterations to be executed by the current thread from the statically
+scheduled loop that is described by the initial values of the bounds, strides,
+increment and chunks for parallel loop and distribute constructs.
@{
*/
-void
-__kmpc_dist_for_static_init_4(
- ident_t *loc, kmp_int32 gtid, kmp_int32 schedule, kmp_int32 *plastiter,
- kmp_int32 *plower, kmp_int32 *pupper, kmp_int32 *pupperD,
- kmp_int32 *pstride, kmp_int32 incr, kmp_int32 chunk )
-{
- __kmp_dist_for_static_init< kmp_int32 >(
- loc, gtid, schedule, plastiter, plower, pupper, pupperD, pstride, incr, chunk );
+void __kmpc_dist_for_static_init_4(ident_t *loc, kmp_int32 gtid,
+ kmp_int32 schedule, kmp_int32 *plastiter,
+ kmp_int32 *plower, kmp_int32 *pupper,
+ kmp_int32 *pupperD, kmp_int32 *pstride,
+ kmp_int32 incr, kmp_int32 chunk) {
+ __kmp_dist_for_static_init<kmp_int32>(loc, gtid, schedule, plastiter, plower,
+ pupper, pupperD, pstride, incr, chunk);
}
/*!
See @ref __kmpc_dist_for_static_init_4
*/
-void
-__kmpc_dist_for_static_init_4u(
- ident_t *loc, kmp_int32 gtid, kmp_int32 schedule, kmp_int32 *plastiter,
- kmp_uint32 *plower, kmp_uint32 *pupper, kmp_uint32 *pupperD,
- kmp_int32 *pstride, kmp_int32 incr, kmp_int32 chunk )
-{
- __kmp_dist_for_static_init< kmp_uint32 >(
- loc, gtid, schedule, plastiter, plower, pupper, pupperD, pstride, incr, chunk );
+void __kmpc_dist_for_static_init_4u(ident_t *loc, kmp_int32 gtid,
+ kmp_int32 schedule, kmp_int32 *plastiter,
+ kmp_uint32 *plower, kmp_uint32 *pupper,
+ kmp_uint32 *pupperD, kmp_int32 *pstride,
+ kmp_int32 incr, kmp_int32 chunk) {
+ __kmp_dist_for_static_init<kmp_uint32>(loc, gtid, schedule, plastiter, plower,
+ pupper, pupperD, pstride, incr, chunk);
}
/*!
See @ref __kmpc_dist_for_static_init_4
*/
-void
-__kmpc_dist_for_static_init_8(
- ident_t *loc, kmp_int32 gtid, kmp_int32 schedule, kmp_int32 *plastiter,
- kmp_int64 *plower, kmp_int64 *pupper, kmp_int64 *pupperD,
- kmp_int64 *pstride, kmp_int64 incr, kmp_int64 chunk )
-{
- __kmp_dist_for_static_init< kmp_int64 >(
- loc, gtid, schedule, plastiter, plower, pupper, pupperD, pstride, incr, chunk );
+void __kmpc_dist_for_static_init_8(ident_t *loc, kmp_int32 gtid,
+ kmp_int32 schedule, kmp_int32 *plastiter,
+ kmp_int64 *plower, kmp_int64 *pupper,
+ kmp_int64 *pupperD, kmp_int64 *pstride,
+ kmp_int64 incr, kmp_int64 chunk) {
+ __kmp_dist_for_static_init<kmp_int64>(loc, gtid, schedule, plastiter, plower,
+ pupper, pupperD, pstride, incr, chunk);
}
/*!
See @ref __kmpc_dist_for_static_init_4
*/
-void
-__kmpc_dist_for_static_init_8u(
- ident_t *loc, kmp_int32 gtid, kmp_int32 schedule, kmp_int32 *plastiter,
- kmp_uint64 *plower, kmp_uint64 *pupper, kmp_uint64 *pupperD,
- kmp_int64 *pstride, kmp_int64 incr, kmp_int64 chunk )
-{
- __kmp_dist_for_static_init< kmp_uint64 >(
- loc, gtid, schedule, plastiter, plower, pupper, pupperD, pstride, incr, chunk );
+void __kmpc_dist_for_static_init_8u(ident_t *loc, kmp_int32 gtid,
+ kmp_int32 schedule, kmp_int32 *plastiter,
+ kmp_uint64 *plower, kmp_uint64 *pupper,
+ kmp_uint64 *pupperD, kmp_int64 *pstride,
+ kmp_int64 incr, kmp_int64 chunk) {
+ __kmp_dist_for_static_init<kmp_uint64>(loc, gtid, schedule, plastiter, plower,
+ pupper, pupperD, pstride, incr, chunk);
}
/*!
@}
*/
-//-----------------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
// Auxiliary routines for Distribute Parallel Loop construct implementation
// Transfer call to template< type T >
// __kmp_team_static_init( ident_t *loc, int gtid,
@@ -889,60 +876,60 @@ __kmpc_dist_for_static_init_8u(
@param incr Loop increment
@param chunk The chunk size to block with
-The functions compute the upper and lower bounds and stride to be used for the set of iterations
-to be executed by the current team from the statically scheduled loop that is described by the
-initial values of the bounds, stride, increment and chunk for the distribute construct as part of
-composite distribute parallel loop construct.
-These functions are all identical apart from the types of the arguments.
+The functions compute the upper and lower bounds and stride to be used for the
+set of iterations to be executed by the current team from the statically
+scheduled loop that is described by the initial values of the bounds, stride,
+increment and chunk for the distribute construct as part of composite distribute
+parallel loop construct. These functions are all identical apart from the types
+of the arguments.
*/
-void
-__kmpc_team_static_init_4(
- ident_t *loc, kmp_int32 gtid, kmp_int32 *p_last,
- kmp_int32 *p_lb, kmp_int32 *p_ub, kmp_int32 *p_st, kmp_int32 incr, kmp_int32 chunk )
-{
- KMP_DEBUG_ASSERT( __kmp_init_serial );
- __kmp_team_static_init< kmp_int32 >( loc, gtid, p_last, p_lb, p_ub, p_st, incr, chunk );
+void __kmpc_team_static_init_4(ident_t *loc, kmp_int32 gtid, kmp_int32 *p_last,
+ kmp_int32 *p_lb, kmp_int32 *p_ub,
+ kmp_int32 *p_st, kmp_int32 incr,
+ kmp_int32 chunk) {
+ KMP_DEBUG_ASSERT(__kmp_init_serial);
+ __kmp_team_static_init<kmp_int32>(loc, gtid, p_last, p_lb, p_ub, p_st, incr,
+ chunk);
}
/*!
See @ref __kmpc_team_static_init_4
*/
-void
-__kmpc_team_static_init_4u(
- ident_t *loc, kmp_int32 gtid, kmp_int32 *p_last,
- kmp_uint32 *p_lb, kmp_uint32 *p_ub, kmp_int32 *p_st, kmp_int32 incr, kmp_int32 chunk )
-{
- KMP_DEBUG_ASSERT( __kmp_init_serial );
- __kmp_team_static_init< kmp_uint32 >( loc, gtid, p_last, p_lb, p_ub, p_st, incr, chunk );
+void __kmpc_team_static_init_4u(ident_t *loc, kmp_int32 gtid, kmp_int32 *p_last,
+ kmp_uint32 *p_lb, kmp_uint32 *p_ub,
+ kmp_int32 *p_st, kmp_int32 incr,
+ kmp_int32 chunk) {
+ KMP_DEBUG_ASSERT(__kmp_init_serial);
+ __kmp_team_static_init<kmp_uint32>(loc, gtid, p_last, p_lb, p_ub, p_st, incr,
+ chunk);
}
/*!
See @ref __kmpc_team_static_init_4
*/
-void
-__kmpc_team_static_init_8(
- ident_t *loc, kmp_int32 gtid, kmp_int32 *p_last,
- kmp_int64 *p_lb, kmp_int64 *p_ub, kmp_int64 *p_st, kmp_int64 incr, kmp_int64 chunk )
-{
- KMP_DEBUG_ASSERT( __kmp_init_serial );
- __kmp_team_static_init< kmp_int64 >( loc, gtid, p_last, p_lb, p_ub, p_st, incr, chunk );
+void __kmpc_team_static_init_8(ident_t *loc, kmp_int32 gtid, kmp_int32 *p_last,
+ kmp_int64 *p_lb, kmp_int64 *p_ub,
+ kmp_int64 *p_st, kmp_int64 incr,
+ kmp_int64 chunk) {
+ KMP_DEBUG_ASSERT(__kmp_init_serial);
+ __kmp_team_static_init<kmp_int64>(loc, gtid, p_last, p_lb, p_ub, p_st, incr,
+ chunk);
}
/*!
See @ref __kmpc_team_static_init_4
*/
-void
-__kmpc_team_static_init_8u(
- ident_t *loc, kmp_int32 gtid, kmp_int32 *p_last,
- kmp_uint64 *p_lb, kmp_uint64 *p_ub, kmp_int64 *p_st, kmp_int64 incr, kmp_int64 chunk )
-{
- KMP_DEBUG_ASSERT( __kmp_init_serial );
- __kmp_team_static_init< kmp_uint64 >( loc, gtid, p_last, p_lb, p_ub, p_st, incr, chunk );
+void __kmpc_team_static_init_8u(ident_t *loc, kmp_int32 gtid, kmp_int32 *p_last,
+ kmp_uint64 *p_lb, kmp_uint64 *p_ub,
+ kmp_int64 *p_st, kmp_int64 incr,
+ kmp_int64 chunk) {
+ KMP_DEBUG_ASSERT(__kmp_init_serial);
+ __kmp_team_static_init<kmp_uint64>(loc, gtid, p_last, p_lb, p_ub, p_st, incr,
+ chunk);
}
/*!
@}
*/
} // extern "C"
-
Modified: openmp/trunk/runtime/src/kmp_settings.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_settings.cpp?rev=302929&r1=302928&r2=302929&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_settings.cpp (original)
+++ openmp/trunk/runtime/src/kmp_settings.cpp Fri May 12 13:01:32 2017
@@ -14,84 +14,80 @@
#include "kmp.h"
-#include "kmp_wrapper_getpid.h"
-#include "kmp_environment.h"
+#include "kmp_affinity.h"
#include "kmp_atomic.h"
-#include "kmp_itt.h"
-#include "kmp_str.h"
-#include "kmp_settings.h"
+#include "kmp_environment.h"
#include "kmp_i18n.h"
-#include "kmp_lock.h"
#include "kmp_io.h"
-#include "kmp_affinity.h"
+#include "kmp_itt.h"
+#include "kmp_lock.h"
+#include "kmp_settings.h"
+#include "kmp_str.h"
+#include "kmp_wrapper_getpid.h"
#include <ctype.h> // toupper()
-static int __kmp_env_toPrint( char const * name, int flag );
+static int __kmp_env_toPrint(char const *name, int flag);
bool __kmp_env_format = 0; // 0 - old format; 1 - new format
-// -------------------------------------------------------------------------------------------------
+
+// -----------------------------------------------------------------------------
// Helper string functions. Subject to move to kmp_str.
-// -------------------------------------------------------------------------------------------------
-static double
-__kmp_convert_to_double( char const * s )
-{
- double result;
+static double __kmp_convert_to_double(char const *s) {
+ double result;
- if ( KMP_SSCANF( s, "%lf", &result ) < 1 ) {
- result = 0.0;
- }
+ if (KMP_SSCANF(s, "%lf", &result) < 1) {
+ result = 0.0;
+ }
- return result;
+ return result;
}
#ifdef KMP_DEBUG
-static unsigned int
-__kmp_readstr_with_sentinel(char *dest, char const * src, size_t len, char sentinel) {
- unsigned int i;
- for (i = 0; i < len; i++) {
- if ((*src == '\0') || (*src == sentinel)) {
- break;
- }
- *(dest++) = *(src++);
+static unsigned int __kmp_readstr_with_sentinel(char *dest, char const *src,
+ size_t len, char sentinel) {
+ unsigned int i;
+ for (i = 0; i < len; i++) {
+ if ((*src == '\0') || (*src == sentinel)) {
+ break;
}
- *dest = '\0';
- return i;
+ *(dest++) = *(src++);
+ }
+ *dest = '\0';
+ return i;
}
#endif
-static int
-__kmp_match_with_sentinel( char const * a, char const * b, size_t len, char sentinel ) {
- size_t l = 0;
-
- if(a == NULL)
- a = "";
- if(b == NULL)
- b = "";
- while(*a && *b && *b != sentinel) {
- char ca = *a, cb = *b;
-
- if(ca >= 'a' && ca <= 'z')
- ca -= 'a' - 'A';
- if(cb >= 'a' && cb <= 'z')
- cb -= 'a' - 'A';
- if(ca != cb)
- return FALSE;
- ++l;
- ++a;
- ++b;
- }
- return l >= len;
+static int __kmp_match_with_sentinel(char const *a, char const *b, size_t len,
+ char sentinel) {
+ size_t l = 0;
+
+ if (a == NULL)
+ a = "";
+ if (b == NULL)
+ b = "";
+ while (*a && *b && *b != sentinel) {
+ char ca = *a, cb = *b;
+
+ if (ca >= 'a' && ca <= 'z')
+ ca -= 'a' - 'A';
+ if (cb >= 'a' && cb <= 'z')
+ cb -= 'a' - 'A';
+ if (ca != cb)
+ return FALSE;
+ ++l;
+ ++a;
+ ++b;
+ }
+ return l >= len;
}
-//
// Expected usage:
// token is the token to check for.
// buf is the string being parsed.
// *end returns the char after the end of the token.
// it is not modified unless a match occurs.
//
-//
// Example 1:
//
// if (__kmp_match_str("token", buf, *end) {
@@ -108,2405 +104,2295 @@ __kmp_match_with_sentinel( char const *
// **end = save;
// buf = end;
// }
-//
-static int
-__kmp_match_str( char const *token, char const *buf, const char **end) {
+static int __kmp_match_str(char const *token, char const *buf,
+ const char **end) {
- KMP_ASSERT(token != NULL);
- KMP_ASSERT(buf != NULL);
- KMP_ASSERT(end != NULL);
-
- while (*token && *buf) {
- char ct = *token, cb = *buf;
-
- if(ct >= 'a' && ct <= 'z')
- ct -= 'a' - 'A';
- if(cb >= 'a' && cb <= 'z')
- cb -= 'a' - 'A';
- if (ct != cb)
- return FALSE;
- ++token;
- ++buf;
- }
- if (*token) {
- return FALSE;
- }
- *end = buf;
- return TRUE;
+ KMP_ASSERT(token != NULL);
+ KMP_ASSERT(buf != NULL);
+ KMP_ASSERT(end != NULL);
+
+ while (*token && *buf) {
+ char ct = *token, cb = *buf;
+
+ if (ct >= 'a' && ct <= 'z')
+ ct -= 'a' - 'A';
+ if (cb >= 'a' && cb <= 'z')
+ cb -= 'a' - 'A';
+ if (ct != cb)
+ return FALSE;
+ ++token;
+ ++buf;
+ }
+ if (*token) {
+ return FALSE;
+ }
+ *end = buf;
+ return TRUE;
}
-
-static size_t
-__kmp_round4k( size_t size ) {
- size_t _4k = 4 * 1024;
- if ( size & ( _4k - 1 ) ) {
- size &= ~ ( _4k - 1 );
- if ( size <= KMP_SIZE_T_MAX - _4k ) {
- size += _4k; // Round up if there is no overflow.
- }; // if
+static size_t __kmp_round4k(size_t size) {
+ size_t _4k = 4 * 1024;
+ if (size & (_4k - 1)) {
+ size &= ~(_4k - 1);
+ if (size <= KMP_SIZE_T_MAX - _4k) {
+ size += _4k; // Round up if there is no overflow.
}; // if
- return size;
+ }; // if
+ return size;
} // __kmp_round4k
-
-/*
- Here, multipliers are like __kmp_convert_to_seconds, but floating-point
- values are allowed, and the return value is in milliseconds. The default
- multiplier is milliseconds. Returns INT_MAX only if the value specified
- matches "infinit*". Returns -1 if specified string is invalid.
-*/
-int
-__kmp_convert_to_milliseconds( char const * data )
-{
- int ret, nvalues, factor;
- char mult, extra;
- double value;
-
- if (data == NULL) return (-1);
- if ( __kmp_str_match( "infinit", -1, data)) return (INT_MAX);
- value = (double) 0.0;
+/* Here, multipliers are like __kmp_convert_to_seconds, but floating-point
+ values are allowed, and the return value is in milliseconds. The default
+ multiplier is milliseconds. Returns INT_MAX only if the value specified
+ matches "infinit*". Returns -1 if specified string is invalid. */
+int __kmp_convert_to_milliseconds(char const *data) {
+ int ret, nvalues, factor;
+ char mult, extra;
+ double value;
+
+ if (data == NULL)
+ return (-1);
+ if (__kmp_str_match("infinit", -1, data))
+ return (INT_MAX);
+ value = (double)0.0;
+ mult = '\0';
+ nvalues = KMP_SSCANF(data, "%lf%c%c", &value, &mult, &extra);
+ if (nvalues < 1)
+ return (-1);
+ if (nvalues == 1)
mult = '\0';
- nvalues = KMP_SSCANF (data, "%lf%c%c", &value, &mult, &extra);
- if (nvalues < 1) return (-1);
- if (nvalues == 1) mult = '\0';
- if (nvalues == 3) return (-1);
-
- if (value < 0) return (-1);
-
- switch (mult) {
- case '\0':
- /* default is milliseconds */
- factor = 1;
- break;
- case 's': case 'S':
- factor = 1000;
- break;
- case 'm': case 'M':
- factor = 1000 * 60;
- break;
- case 'h': case 'H':
- factor = 1000 * 60 * 60;
- break;
- case 'd': case 'D':
- factor = 1000 * 24 * 60 * 60;
- break;
- default:
- return (-1);
- }
+ if (nvalues == 3)
+ return (-1);
- if ( value >= ( (INT_MAX-1) / factor) )
- ret = INT_MAX-1; /* Don't allow infinite value here */
- else
- ret = (int) (value * (double) factor); /* truncate to int */
+ if (value < 0)
+ return (-1);
- return ret;
-}
+ switch (mult) {
+ case '\0':
+ /* default is milliseconds */
+ factor = 1;
+ break;
+ case 's':
+ case 'S':
+ factor = 1000;
+ break;
+ case 'm':
+ case 'M':
+ factor = 1000 * 60;
+ break;
+ case 'h':
+ case 'H':
+ factor = 1000 * 60 * 60;
+ break;
+ case 'd':
+ case 'D':
+ factor = 1000 * 24 * 60 * 60;
+ break;
+ default:
+ return (-1);
+ }
+ if (value >= ((INT_MAX - 1) / factor))
+ ret = INT_MAX - 1; /* Don't allow infinite value here */
+ else
+ ret = (int)(value * (double)factor); /* truncate to int */
-static int
-__kmp_strcasecmp_with_sentinel( char const * a, char const * b, char sentinel ) {
- if(a == NULL)
- a = "";
- if(b == NULL)
- b = "";
- while(*a && *b && *b != sentinel) {
- char ca = *a, cb = *b;
-
- if(ca >= 'a' && ca <= 'z')
- ca -= 'a' - 'A';
- if(cb >= 'a' && cb <= 'z')
- cb -= 'a' - 'A';
- if(ca != cb)
- return (int)(unsigned char)*a - (int)(unsigned char)*b;
- ++a;
- ++b;
- }
- return *a ?
- (*b && *b != sentinel) ? (int)(unsigned char)*a - (int)(unsigned char)*b : 1 :
- (*b && *b != sentinel) ? -1 : 0;
+ return ret;
}
+static int __kmp_strcasecmp_with_sentinel(char const *a, char const *b,
+ char sentinel) {
+ if (a == NULL)
+ a = "";
+ if (b == NULL)
+ b = "";
+ while (*a && *b && *b != sentinel) {
+ char ca = *a, cb = *b;
+
+ if (ca >= 'a' && ca <= 'z')
+ ca -= 'a' - 'A';
+ if (cb >= 'a' && cb <= 'z')
+ cb -= 'a' - 'A';
+ if (ca != cb)
+ return (int)(unsigned char)*a - (int)(unsigned char)*b;
+ ++a;
+ ++b;
+ }
+ return *a
+ ? (*b && *b != sentinel)
+ ? (int)(unsigned char)*a - (int)(unsigned char)*b
+ : 1
+ : (*b && *b != sentinel) ? -1 : 0;
+}
-// =================================================================================================
+// =============================================================================
// Table structures and helper functions.
-// =================================================================================================
-typedef struct __kmp_setting kmp_setting_t;
-typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
-typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
-typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
-
-typedef void ( * kmp_stg_parse_func_t )( char const * name, char const * value, void * data );
-typedef void ( * kmp_stg_print_func_t )( kmp_str_buf_t * buffer, char const * name, void * data );
+typedef struct __kmp_setting kmp_setting_t;
+typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
+typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
+typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;
+
+typedef void (*kmp_stg_parse_func_t)(char const *name, char const *value,
+ void *data);
+typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer, char const *name,
+ void *data);
struct __kmp_setting {
- char const * name; // Name of setting (environment variable).
- kmp_stg_parse_func_t parse; // Parser function.
- kmp_stg_print_func_t print; // Print function.
- void * data; // Data passed to parser and printer.
- int set; // Variable set during this "session"
- // (__kmp_env_initialize() or kmp_set_defaults() call).
- int defined; // Variable set in any "session".
+ char const *name; // Name of setting (environment variable).
+ kmp_stg_parse_func_t parse; // Parser function.
+ kmp_stg_print_func_t print; // Print function.
+ void *data; // Data passed to parser and printer.
+ int set; // Variable set during this "session"
+ // (__kmp_env_initialize() or kmp_set_defaults() call).
+ int defined; // Variable set in any "session".
}; // struct __kmp_setting
struct __kmp_stg_ss_data {
- size_t factor; // Default factor: 1 for KMP_STACKSIZE, 1024 for others.
- kmp_setting_t * * rivals; // Array of pointers to rivals (including itself).
+ size_t factor; // Default factor: 1 for KMP_STACKSIZE, 1024 for others.
+ kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
}; // struct __kmp_stg_ss_data
struct __kmp_stg_wp_data {
- int omp; // 0 -- KMP_LIBRARY, 1 -- OMP_WAIT_POLICY.
- kmp_setting_t * * rivals; // Array of pointers to rivals (including itself).
+ int omp; // 0 -- KMP_LIBRARY, 1 -- OMP_WAIT_POLICY.
+ kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
}; // struct __kmp_stg_wp_data
struct __kmp_stg_fr_data {
- int force; // 0 -- KMP_DETERMINISTIC_REDUCTION, 1 -- KMP_FORCE_REDUCTION.
- kmp_setting_t * * rivals; // Array of pointers to rivals (including itself).
+ int force; // 0 -- KMP_DETERMINISTIC_REDUCTION, 1 -- KMP_FORCE_REDUCTION.
+ kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
}; // struct __kmp_stg_fr_data
-static int
-__kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
- char const * name, // Name of variable.
- char const * value, // Value of the variable.
- kmp_setting_t * * rivals // List of rival settings (the list must include current one).
-);
-
+static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
+ char const *name, // Name of variable.
+ char const *value, // Value of the variable.
+ kmp_setting_t **rivals // List of rival settings (must include current one).
+ );
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// Helper parse functions.
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_bool(
- char const * name,
- char const * value,
- int * out
-) {
- if ( __kmp_str_match_true( value ) ) {
- * out = TRUE;
- } else if (__kmp_str_match_false( value ) ) {
- * out = FALSE;
- } else {
- __kmp_msg(
- kmp_ms_warning,
- KMP_MSG( BadBoolValue, name, value ),
- KMP_HNT( ValidBoolValues ),
- __kmp_msg_null
- );
- }; // if
+static void __kmp_stg_parse_bool(char const *name, char const *value,
+ int *out) {
+ if (__kmp_str_match_true(value)) {
+ *out = TRUE;
+ } else if (__kmp_str_match_false(value)) {
+ *out = FALSE;
+ } else {
+ __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
+ KMP_HNT(ValidBoolValues), __kmp_msg_null);
+ }; // if
} // __kmp_stg_parse_bool
-static void
-__kmp_stg_parse_size(
- char const * name,
- char const * value,
- size_t size_min,
- size_t size_max,
- int * is_specified,
- size_t * out,
- size_t factor
-) {
- char const * msg = NULL;
- #if KMP_OS_DARWIN
- size_min = __kmp_round4k( size_min );
- size_max = __kmp_round4k( size_max );
- #endif // KMP_OS_DARWIN
- if ( value ) {
- if ( is_specified != NULL ) {
- * is_specified = 1;
- }; // if
- __kmp_str_to_size( value, out, factor, & msg );
- if ( msg == NULL ) {
- if ( * out > size_max ) {
- * out = size_max;
- msg = KMP_I18N_STR( ValueTooLarge );
- } else if ( * out < size_min ) {
- * out = size_min;
- msg = KMP_I18N_STR( ValueTooSmall );
- } else {
- #if KMP_OS_DARWIN
- size_t round4k = __kmp_round4k( * out );
- if ( * out != round4k ) {
- * out = round4k;
- msg = KMP_I18N_STR( NotMultiple4K );
- }; // if
- #endif
- }; // if
- } else {
- // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to size_max silently.
- if ( * out < size_min ) {
- * out = size_max;
- }
- else if ( * out > size_max ) {
- * out = size_max;
- }; // if
- }; // if
- if ( msg != NULL ) {
- // Message is not empty. Print warning.
- kmp_str_buf_t buf;
- __kmp_str_buf_init( & buf );
- __kmp_str_buf_print_size( & buf, * out );
- KMP_WARNING( ParseSizeIntWarn, name, value, msg );
- KMP_INFORM( Using_str_Value, name, buf.str );
- __kmp_str_buf_free( & buf );
+static void __kmp_stg_parse_size(char const *name, char const *value,
+ size_t size_min, size_t size_max,
+ int *is_specified, size_t *out,
+ size_t factor) {
+ char const *msg = NULL;
+#if KMP_OS_DARWIN
+ size_min = __kmp_round4k(size_min);
+ size_max = __kmp_round4k(size_max);
+#endif // KMP_OS_DARWIN
+ if (value) {
+ if (is_specified != NULL) {
+ *is_specified = 1;
+ }; // if
+ __kmp_str_to_size(value, out, factor, &msg);
+ if (msg == NULL) {
+ if (*out > size_max) {
+ *out = size_max;
+ msg = KMP_I18N_STR(ValueTooLarge);
+ } else if (*out < size_min) {
+ *out = size_min;
+ msg = KMP_I18N_STR(ValueTooSmall);
+ } else {
+#if KMP_OS_DARWIN
+ size_t round4k = __kmp_round4k(*out);
+ if (*out != round4k) {
+ *out = round4k;
+ msg = KMP_I18N_STR(NotMultiple4K);
}; // if
+#endif
+ }; // if
+ } else {
+ // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to
+ // size_max silently.
+ if (*out < size_min) {
+ *out = size_max;
+ } else if (*out > size_max) {
+ *out = size_max;
+ }; // if
+ }; // if
+ if (msg != NULL) {
+ // Message is not empty. Print warning.
+ kmp_str_buf_t buf;
+ __kmp_str_buf_init(&buf);
+ __kmp_str_buf_print_size(&buf, *out);
+ KMP_WARNING(ParseSizeIntWarn, name, value, msg);
+ KMP_INFORM(Using_str_Value, name, buf.str);
+ __kmp_str_buf_free(&buf);
}; // if
+ }; // if
} // __kmp_stg_parse_size
#if KMP_AFFINITY_SUPPORTED
-static void
-__kmp_stg_parse_str(
- char const * name,
- char const * value,
- char const * * out
-) {
- __kmp_str_free(out);
- * out = __kmp_str_format( "%s", value );
+static void __kmp_stg_parse_str(char const *name, char const *value,
+ char const **out) {
+ __kmp_str_free(out);
+ *out = __kmp_str_format("%s", value);
} // __kmp_stg_parse_str
#endif
-static void
-__kmp_stg_parse_int(
- char const * name, // I: Name of environment variable (used in warning messages).
- char const * value, // I: Value of environment variable to parse.
- int min, // I: Miminal allowed value.
- int max, // I: Maximum allowed value.
- int * out // O: Output (parsed) value.
-) {
- char const * msg = NULL;
- kmp_uint64 uint = * out;
- __kmp_str_to_uint( value, & uint, & msg );
- if ( msg == NULL ) {
- if ( uint < (unsigned int)min ) {
- msg = KMP_I18N_STR( ValueTooSmall );
- uint = min;
- } else if ( uint > (unsigned int)max ) {
- msg = KMP_I18N_STR( ValueTooLarge );
- uint = max;
- }; // if
- } else {
- // If overflow occurred msg contains error message and uint is very big. Cut tmp it
- // to INT_MAX.
- if ( uint < (unsigned int)min ) {
- uint = min;
- }
- else if ( uint > (unsigned int)max ) {
- uint = max;
- }; // if
+static void __kmp_stg_parse_int(
+ char const
+ *name, // I: Name of environment variable (used in warning messages).
+ char const *value, // I: Value of environment variable to parse.
+ int min, // I: Miminal allowed value.
+ int max, // I: Maximum allowed value.
+ int *out // O: Output (parsed) value.
+ ) {
+ char const *msg = NULL;
+ kmp_uint64 uint = *out;
+ __kmp_str_to_uint(value, &uint, &msg);
+ if (msg == NULL) {
+ if (uint < (unsigned int)min) {
+ msg = KMP_I18N_STR(ValueTooSmall);
+ uint = min;
+ } else if (uint > (unsigned int)max) {
+ msg = KMP_I18N_STR(ValueTooLarge);
+ uint = max;
}; // if
- if ( msg != NULL ) {
- // Message is not empty. Print warning.
- kmp_str_buf_t buf;
- KMP_WARNING( ParseSizeIntWarn, name, value, msg );
- __kmp_str_buf_init( & buf );
- __kmp_str_buf_print( &buf, "%" KMP_UINT64_SPEC "", uint );
- KMP_INFORM( Using_uint64_Value, name, buf.str );
- __kmp_str_buf_free( &buf );
+ } else {
+ // If overflow occurred msg contains error message and uint is very big. Cut
+ // tmp it to INT_MAX.
+ if (uint < (unsigned int)min) {
+ uint = min;
+ } else if (uint > (unsigned int)max) {
+ uint = max;
}; // if
- * out = uint;
+ }; // if
+ if (msg != NULL) {
+ // Message is not empty. Print warning.
+ kmp_str_buf_t buf;
+ KMP_WARNING(ParseSizeIntWarn, name, value, msg);
+ __kmp_str_buf_init(&buf);
+ __kmp_str_buf_print(&buf, "%" KMP_UINT64_SPEC "", uint);
+ KMP_INFORM(Using_uint64_Value, name, buf.str);
+ __kmp_str_buf_free(&buf);
+ }; // if
+ *out = uint;
} // __kmp_stg_parse_int
-
#if KMP_DEBUG_ADAPTIVE_LOCKS
-static void
-__kmp_stg_parse_file(
- char const * name,
- char const * value,
- char * suffix,
- char * * out
-) {
- char buffer[256];
- char *t;
- int hasSuffix;
- __kmp_str_free(out);
- t = (char *) strrchr(value, '.');
- hasSuffix = t && __kmp_str_eqf( t, suffix );
- t = __kmp_str_format( "%s%s", value, hasSuffix ? "" : suffix );
- __kmp_expand_file_name( buffer, sizeof(buffer), t);
- __kmp_str_free(&t);
- * out = __kmp_str_format( "%s", buffer );
+static void __kmp_stg_parse_file(char const *name, char const *value,
+ char *suffix, char **out) {
+ char buffer[256];
+ char *t;
+ int hasSuffix;
+ __kmp_str_free(out);
+ t = (char *)strrchr(value, '.');
+ hasSuffix = t && __kmp_str_eqf(t, suffix);
+ t = __kmp_str_format("%s%s", value, hasSuffix ? "" : suffix);
+ __kmp_expand_file_name(buffer, sizeof(buffer), t);
+ __kmp_str_free(&t);
+ *out = __kmp_str_format("%s", buffer);
} // __kmp_stg_parse_file
#endif
#ifdef KMP_DEBUG
-static char * par_range_to_print = NULL;
+static char *par_range_to_print = NULL;
-static void
-__kmp_stg_parse_par_range(
- char const * name,
- char const * value,
- int * out_range,
- char * out_routine,
- char * out_file,
- int * out_lb,
- int * out_ub
-) {
- size_t len = KMP_STRLEN( value + 1 );
- par_range_to_print = (char *) KMP_INTERNAL_MALLOC( len +1 );
- KMP_STRNCPY_S( par_range_to_print, len + 1, value, len + 1);
- __kmp_par_range = +1;
- __kmp_par_range_lb = 0;
- __kmp_par_range_ub = INT_MAX;
- for (;;) {
- unsigned int len;
- if (( value == NULL ) || ( *value == '\0' )) {
- break;
- }
- if ( ! __kmp_strcasecmp_with_sentinel( "routine", value, '=' )) {
- value = strchr( value, '=' ) + 1;
- len = __kmp_readstr_with_sentinel( out_routine,
- value, KMP_PAR_RANGE_ROUTINE_LEN - 1, ',' );
- if ( len == 0 ) {
- goto par_range_error;
- }
- value = strchr( value, ',' );
- if ( value != NULL ) {
- value++;
- }
- continue;
- }
- if ( ! __kmp_strcasecmp_with_sentinel( "filename", value, '=' )) {
- value = strchr( value, '=' ) + 1;
- len = __kmp_readstr_with_sentinel( out_file,
- value, KMP_PAR_RANGE_FILENAME_LEN - 1, ',' );
- if ( len == 0) {
- goto par_range_error;
- }
- value = strchr( value, ',' );
- if ( value != NULL ) {
- value++;
- }
- continue;
- }
- if (( ! __kmp_strcasecmp_with_sentinel( "range", value, '=' ))
- || ( ! __kmp_strcasecmp_with_sentinel( "incl_range", value, '=' ))) {
- value = strchr( value, '=' ) + 1;
- if ( KMP_SSCANF( value, "%d:%d", out_lb, out_ub ) != 2 ) {
- goto par_range_error;
- }
- *out_range = +1;
- value = strchr( value, ',' );
- if ( value != NULL ) {
- value++;
- }
- continue;
- }
- if ( ! __kmp_strcasecmp_with_sentinel( "excl_range", value, '=' )) {
- value = strchr( value, '=' ) + 1;
- if ( KMP_SSCANF( value, "%d:%d", out_lb, out_ub) != 2 ) {
- goto par_range_error;
- }
- *out_range = -1;
- value = strchr( value, ',' );
- if ( value != NULL ) {
- value++;
- }
- continue;
- }
- par_range_error:
- KMP_WARNING( ParRangeSyntax, name );
- __kmp_par_range = 0;
- break;
+static void __kmp_stg_parse_par_range(char const *name, char const *value,
+ int *out_range, char *out_routine,
+ char *out_file, int *out_lb,
+ int *out_ub) {
+ size_t len = KMP_STRLEN(value + 1);
+ par_range_to_print = (char *)KMP_INTERNAL_MALLOC(len + 1);
+ KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
+ __kmp_par_range = +1;
+ __kmp_par_range_lb = 0;
+ __kmp_par_range_ub = INT_MAX;
+ for (;;) {
+ unsigned int len;
+ if ((value == NULL) || (*value == '\0')) {
+ break;
+ }
+ if (!__kmp_strcasecmp_with_sentinel("routine", value, '=')) {
+ value = strchr(value, '=') + 1;
+ len = __kmp_readstr_with_sentinel(out_routine, value,
+ KMP_PAR_RANGE_ROUTINE_LEN - 1, ',');
+ if (len == 0) {
+ goto par_range_error;
+ }
+ value = strchr(value, ',');
+ if (value != NULL) {
+ value++;
+ }
+ continue;
+ }
+ if (!__kmp_strcasecmp_with_sentinel("filename", value, '=')) {
+ value = strchr(value, '=') + 1;
+ len = __kmp_readstr_with_sentinel(out_file, value,
+ KMP_PAR_RANGE_FILENAME_LEN - 1, ',');
+ if (len == 0) {
+ goto par_range_error;
+ }
+ value = strchr(value, ',');
+ if (value != NULL) {
+ value++;
+ }
+ continue;
+ }
+ if ((!__kmp_strcasecmp_with_sentinel("range", value, '=')) ||
+ (!__kmp_strcasecmp_with_sentinel("incl_range", value, '='))) {
+ value = strchr(value, '=') + 1;
+ if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
+ goto par_range_error;
+ }
+ *out_range = +1;
+ value = strchr(value, ',');
+ if (value != NULL) {
+ value++;
+ }
+ continue;
}
+ if (!__kmp_strcasecmp_with_sentinel("excl_range", value, '=')) {
+ value = strchr(value, '=') + 1;
+ if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
+ goto par_range_error;
+ }
+ *out_range = -1;
+ value = strchr(value, ',');
+ if (value != NULL) {
+ value++;
+ }
+ continue;
+ }
+ par_range_error:
+ KMP_WARNING(ParRangeSyntax, name);
+ __kmp_par_range = 0;
+ break;
+ }
} // __kmp_stg_parse_par_range
#endif
-int
-__kmp_initial_threads_capacity( int req_nproc )
-{
- int nth = 32;
-
- /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ), __kmp_max_nth) */
- if (nth < (4 * req_nproc))
- nth = (4 * req_nproc);
- if (nth < (4 * __kmp_xproc))
- nth = (4 * __kmp_xproc);
+int __kmp_initial_threads_capacity(int req_nproc) {
+ int nth = 32;
- if (nth > __kmp_max_nth)
- nth = __kmp_max_nth;
+ /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
+ * __kmp_max_nth) */
+ if (nth < (4 * req_nproc))
+ nth = (4 * req_nproc);
+ if (nth < (4 * __kmp_xproc))
+ nth = (4 * __kmp_xproc);
- return nth;
-}
+ if (nth > __kmp_max_nth)
+ nth = __kmp_max_nth;
+ return nth;
+}
-int
-__kmp_default_tp_capacity( int req_nproc, int max_nth, int all_threads_specified) {
- int nth = 128;
-
- if(all_threads_specified)
- return max_nth;
- /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ), __kmp_max_nth ) */
- if (nth < (4 * req_nproc))
- nth = (4 * req_nproc);
- if (nth < (4 * __kmp_xproc))
- nth = (4 * __kmp_xproc);
+int __kmp_default_tp_capacity(int req_nproc, int max_nth,
+ int all_threads_specified) {
+ int nth = 128;
+
+ if (all_threads_specified)
+ return max_nth;
+ /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
+ * __kmp_max_nth ) */
+ if (nth < (4 * req_nproc))
+ nth = (4 * req_nproc);
+ if (nth < (4 * __kmp_xproc))
+ nth = (4 * __kmp_xproc);
- if (nth > __kmp_max_nth)
- nth = __kmp_max_nth;
+ if (nth > __kmp_max_nth)
+ nth = __kmp_max_nth;
- return nth;
+ return nth;
}
-
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// Helper print functions.
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_print_bool( kmp_str_buf_t * buffer, char const * name, int value ) {
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_BOOL;
- } else {
- __kmp_str_buf_print( buffer, " %s=%s\n", name, value ? "true" : "false" );
- }
+static void __kmp_stg_print_bool(kmp_str_buf_t *buffer, char const *name,
+ int value) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_BOOL;
+ } else {
+ __kmp_str_buf_print(buffer, " %s=%s\n", name, value ? "true" : "false");
+ }
} // __kmp_stg_print_bool
-static void
-__kmp_stg_print_int( kmp_str_buf_t * buffer, char const * name, int value ) {
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_INT;
- } else {
- __kmp_str_buf_print( buffer, " %s=%d\n", name, value );
- }
+static void __kmp_stg_print_int(kmp_str_buf_t *buffer, char const *name,
+ int value) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_INT;
+ } else {
+ __kmp_str_buf_print(buffer, " %s=%d\n", name, value);
+ }
} // __kmp_stg_print_int
-static void
-__kmp_stg_print_uint64( kmp_str_buf_t * buffer, char const * name, kmp_uint64 value ) {
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_UINT64;
- } else {
- __kmp_str_buf_print( buffer, " %s=%" KMP_UINT64_SPEC "\n", name, value );
- }
+static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer, char const *name,
+ kmp_uint64 value) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_UINT64;
+ } else {
+ __kmp_str_buf_print(buffer, " %s=%" KMP_UINT64_SPEC "\n", name, value);
+ }
} // __kmp_stg_print_uint64
-static void
-__kmp_stg_print_str( kmp_str_buf_t * buffer, char const * name, char const * value ) {
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_STR;
- } else {
- __kmp_str_buf_print( buffer, " %s=%s\n", name, value );
- }
+static void __kmp_stg_print_str(kmp_str_buf_t *buffer, char const *name,
+ char const *value) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_STR;
+ } else {
+ __kmp_str_buf_print(buffer, " %s=%s\n", name, value);
+ }
} // __kmp_stg_print_str
-static void
-__kmp_stg_print_size( kmp_str_buf_t * buffer, char const * name, size_t value ) {
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME_EX(name);
- __kmp_str_buf_print_size( buffer, value );
- __kmp_str_buf_print( buffer, "'\n" );
- } else {
- __kmp_str_buf_print( buffer, " %s=", name );
- __kmp_str_buf_print_size( buffer, value );
- __kmp_str_buf_print( buffer, "\n" );
- return;
- }
+static void __kmp_stg_print_size(kmp_str_buf_t *buffer, char const *name,
+ size_t value) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME_EX(name);
+ __kmp_str_buf_print_size(buffer, value);
+ __kmp_str_buf_print(buffer, "'\n");
+ } else {
+ __kmp_str_buf_print(buffer, " %s=", name);
+ __kmp_str_buf_print_size(buffer, value);
+ __kmp_str_buf_print(buffer, "\n");
+ return;
+ }
} // __kmp_stg_print_size
-
-// =================================================================================================
+// =============================================================================
// Parse and print functions.
-// =================================================================================================
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_ALL_THREADS, KMP_MAX_THREADS, OMP_THREAD_LIMIT
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_all_threads( char const * name, char const * value, void * data ) {
+static void __kmp_stg_parse_all_threads(char const *name, char const *value,
+ void *data) {
- kmp_setting_t * * rivals = (kmp_setting_t * *) data;
- int rc;
- rc = __kmp_stg_check_rivals( name, value, rivals );
- if ( rc ) {
- return;
- }; // if
- if ( ! __kmp_strcasecmp_with_sentinel( "all", value, 0 ) ) {
- __kmp_max_nth = __kmp_xproc;
- __kmp_allThreadsSpecified = 1;
- } else {
- __kmp_stg_parse_int( name, value, 1, __kmp_sys_max_nth, & __kmp_max_nth );
- __kmp_allThreadsSpecified = 0;
- }
- K_DIAG( 1, ( "__kmp_max_nth == %d\n", __kmp_max_nth ) );
+ kmp_setting_t **rivals = (kmp_setting_t **)data;
+ int rc;
+ rc = __kmp_stg_check_rivals(name, value, rivals);
+ if (rc) {
+ return;
+ }; // if
+ if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
+ __kmp_max_nth = __kmp_xproc;
+ __kmp_allThreadsSpecified = 1;
+ } else {
+ __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
+ __kmp_allThreadsSpecified = 0;
+ }
+ K_DIAG(1, ("__kmp_max_nth == %d\n", __kmp_max_nth));
} // __kmp_stg_parse_all_threads
-static void
-__kmp_stg_print_all_threads( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_max_nth );
+static void __kmp_stg_print_all_threads(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_max_nth);
} // __kmp_stg_print_all_threads
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_BLOCKTIME
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_blocktime( char const * name, char const * value, void * data ) {
- __kmp_dflt_blocktime = __kmp_convert_to_milliseconds( value );
- if ( __kmp_dflt_blocktime < 0 ) {
- __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
- __kmp_msg( kmp_ms_warning, KMP_MSG( InvalidValue, name, value ), __kmp_msg_null );
- KMP_INFORM( Using_int_Value, name, __kmp_dflt_blocktime );
- __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
- } else {
- if ( __kmp_dflt_blocktime < KMP_MIN_BLOCKTIME ) {
- __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
- __kmp_msg( kmp_ms_warning, KMP_MSG( SmallValue, name, value ), __kmp_msg_null );
- KMP_INFORM( MinValueUsing, name, __kmp_dflt_blocktime );
- } else if ( __kmp_dflt_blocktime > KMP_MAX_BLOCKTIME ) {
- __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
- __kmp_msg( kmp_ms_warning, KMP_MSG( LargeValue, name, value ), __kmp_msg_null );
- KMP_INFORM( MaxValueUsing, name, __kmp_dflt_blocktime );
- }; // if
- __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
+static void __kmp_stg_parse_blocktime(char const *name, char const *value,
+ void *data) {
+ __kmp_dflt_blocktime = __kmp_convert_to_milliseconds(value);
+ if (__kmp_dflt_blocktime < 0) {
+ __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
+ __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
+ __kmp_msg_null);
+ KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime);
+ __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
+ } else {
+ if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
+ __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
+ __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
+ __kmp_msg_null);
+ KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime);
+ } else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
+ __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
+ __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
+ __kmp_msg_null);
+ KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime);
}; // if
+ __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
+ }; // if
#if KMP_USE_MONITOR
- // calculate number of monitor thread wakeup intervals corresponding to blocktime.
- __kmp_monitor_wakeups = KMP_WAKEUPS_FROM_BLOCKTIME( __kmp_dflt_blocktime, __kmp_monitor_wakeups );
- __kmp_bt_intervals = KMP_INTERVALS_FROM_BLOCKTIME( __kmp_dflt_blocktime, __kmp_monitor_wakeups );
-#endif
- K_DIAG( 1, ( "__kmp_env_blocktime == %d\n", __kmp_env_blocktime ) );
- if ( __kmp_env_blocktime ) {
- K_DIAG( 1, ( "__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime ) );
- }
+ // calculate number of monitor thread wakeup intervals corresponding to
+ // blocktime.
+ __kmp_monitor_wakeups =
+ KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
+ __kmp_bt_intervals =
+ KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
+#endif
+ K_DIAG(1, ("__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
+ if (__kmp_env_blocktime) {
+ K_DIAG(1, ("__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
+ }
} // __kmp_stg_parse_blocktime
-static void
-__kmp_stg_print_blocktime( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_dflt_blocktime );
+static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_dflt_blocktime);
} // __kmp_stg_print_blocktime
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_DUPLICATE_LIB_OK
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_duplicate_lib_ok( char const * name, char const * value, void * data ) {
- /* actually this variable is not supported,
- put here for compatibility with earlier builds and for static/dynamic combination */
- __kmp_stg_parse_bool( name, value, & __kmp_duplicate_library_ok );
+static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
+ char const *value, void *data) {
+ /* actually this variable is not supported, put here for compatibility with
+ earlier builds and for static/dynamic combination */
+ __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
} // __kmp_stg_parse_duplicate_lib_ok
-static void
-__kmp_stg_print_duplicate_lib_ok( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_duplicate_library_ok );
+static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
} // __kmp_stg_print_duplicate_lib_ok
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_INHERIT_FP_CONTROL
-// -------------------------------------------------------------------------------------------------
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
-static void
-__kmp_stg_parse_inherit_fp_control( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_bool( name, value, & __kmp_inherit_fp_control );
+static void __kmp_stg_parse_inherit_fp_control(char const *name,
+ char const *value, void *data) {
+ __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
} // __kmp_stg_parse_inherit_fp_control
-static void
-__kmp_stg_print_inherit_fp_control( kmp_str_buf_t * buffer, char const * name, void * data ) {
+static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
#if KMP_DEBUG
- __kmp_stg_print_bool( buffer, name, __kmp_inherit_fp_control );
+ __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
#endif /* KMP_DEBUG */
} // __kmp_stg_print_inherit_fp_control
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_LIBRARY, OMP_WAIT_POLICY
-// -------------------------------------------------------------------------------------------------
static char const *blocktime_str = NULL;
-static void
-__kmp_stg_parse_wait_policy( char const * name, char const * value, void * data ) {
+static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
+ void *data) {
- kmp_stg_wp_data_t * wait = (kmp_stg_wp_data_t *) data;
- int rc;
+ kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
+ int rc;
- rc = __kmp_stg_check_rivals( name, value, wait->rivals );
- if ( rc ) {
- return;
+ rc = __kmp_stg_check_rivals(name, value, wait->rivals);
+ if (rc) {
+ return;
+ }; // if
+
+ if (wait->omp) {
+ if (__kmp_str_match("ACTIVE", 1, value)) {
+ __kmp_library = library_turnaround;
+ if (blocktime_str == NULL) {
+ // KMP_BLOCKTIME not specified, so set default to "infinite".
+ __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
+ }
+ } else if (__kmp_str_match("PASSIVE", 1, value)) {
+ __kmp_library = library_throughput;
+ if (blocktime_str == NULL) {
+ // KMP_BLOCKTIME not specified, so set default to 0.
+ __kmp_dflt_blocktime = 0;
+ }
+ } else {
+ KMP_WARNING(StgInvalidValue, name, value);
}; // if
-
- if ( wait->omp ) {
- if ( __kmp_str_match( "ACTIVE", 1, value ) ) {
- __kmp_library = library_turnaround;
- if ( blocktime_str == NULL ) {
- // KMP_BLOCKTIME not specified, so set default to "infinite".
- __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
- }
- } else if ( __kmp_str_match( "PASSIVE", 1, value ) ) {
- __kmp_library = library_throughput;
- if ( blocktime_str == NULL ) {
- // KMP_BLOCKTIME not specified, so set default to 0.
- __kmp_dflt_blocktime = 0;
- }
- } else {
- KMP_WARNING( StgInvalidValue, name, value );
- }; // if
+ } else {
+ if (__kmp_str_match("serial", 1, value)) { /* S */
+ __kmp_library = library_serial;
+ } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
+ __kmp_library = library_throughput;
+ } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
+ __kmp_library = library_turnaround;
+ } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
+ __kmp_library = library_turnaround;
+ } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
+ __kmp_library = library_throughput;
} else {
- if ( __kmp_str_match( "serial", 1, value ) ) { /* S */
- __kmp_library = library_serial;
- } else if ( __kmp_str_match( "throughput", 2, value ) ) { /* TH */
- __kmp_library = library_throughput;
- } else if ( __kmp_str_match( "turnaround", 2, value ) ) { /* TU */
- __kmp_library = library_turnaround;
- } else if ( __kmp_str_match( "dedicated", 1, value ) ) { /* D */
- __kmp_library = library_turnaround;
- } else if ( __kmp_str_match( "multiuser", 1, value ) ) { /* M */
- __kmp_library = library_throughput;
- } else {
- KMP_WARNING( StgInvalidValue, name, value );
- }; // if
+ KMP_WARNING(StgInvalidValue, name, value);
}; // if
- __kmp_aux_set_library( __kmp_library );
+ }; // if
+ __kmp_aux_set_library(__kmp_library);
} // __kmp_stg_parse_wait_policy
-static void
-__kmp_stg_print_wait_policy( kmp_str_buf_t * buffer, char const * name, void * data ) {
+static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
- kmp_stg_wp_data_t * wait = (kmp_stg_wp_data_t *) data;
- char const * value = NULL;
+ kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
+ char const *value = NULL;
- if ( wait->omp ) {
- switch ( __kmp_library ) {
- case library_turnaround : {
- value = "ACTIVE";
- } break;
- case library_throughput : {
- value = "PASSIVE";
- } break;
- }; // switch
- } else {
- switch ( __kmp_library ) {
- case library_serial : {
- value = "serial";
- } break;
- case library_turnaround : {
- value = "turnaround";
- } break;
- case library_throughput : {
- value = "throughput";
- } break;
- }; // switch
- }; // if
- if ( value != NULL ) {
- __kmp_stg_print_str( buffer, name, value );
- }; // if
+ if (wait->omp) {
+ switch (__kmp_library) {
+ case library_turnaround: {
+ value = "ACTIVE";
+ } break;
+ case library_throughput: {
+ value = "PASSIVE";
+ } break;
+ }; // switch
+ } else {
+ switch (__kmp_library) {
+ case library_serial: {
+ value = "serial";
+ } break;
+ case library_turnaround: {
+ value = "turnaround";
+ } break;
+ case library_throughput: {
+ value = "throughput";
+ } break;
+ }; // switch
+ }; // if
+ if (value != NULL) {
+ __kmp_stg_print_str(buffer, name, value);
+ }; // if
} // __kmp_stg_print_wait_policy
#if KMP_USE_MONITOR
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_MONITOR_STACKSIZE
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_monitor_stacksize( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_size(
- name,
- value,
- __kmp_sys_min_stksize,
- KMP_MAX_STKSIZE,
- NULL,
- & __kmp_monitor_stksize,
- 1
- );
+static void __kmp_stg_parse_monitor_stacksize(char const *name,
+ char const *value, void *data) {
+ __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
+ NULL, &__kmp_monitor_stksize, 1);
} // __kmp_stg_parse_monitor_stacksize
-static void
-__kmp_stg_print_monitor_stacksize( kmp_str_buf_t * buffer, char const * name, void * data ) {
- if( __kmp_env_format ) {
- if ( __kmp_monitor_stksize > 0 )
- KMP_STR_BUF_PRINT_NAME_EX(name);
- else
- KMP_STR_BUF_PRINT_NAME;
- } else {
- __kmp_str_buf_print( buffer, " %s", name );
- }
- if ( __kmp_monitor_stksize > 0 ) {
- __kmp_str_buf_print_size( buffer, __kmp_monitor_stksize );
- } else {
- __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
- }
- if( __kmp_env_format && __kmp_monitor_stksize ) {
- __kmp_str_buf_print( buffer, "'\n");
- }
-
+static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ if (__kmp_env_format) {
+ if (__kmp_monitor_stksize > 0)
+ KMP_STR_BUF_PRINT_NAME_EX(name);
+ else
+ KMP_STR_BUF_PRINT_NAME;
+ } else {
+ __kmp_str_buf_print(buffer, " %s", name);
+ }
+ if (__kmp_monitor_stksize > 0) {
+ __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
+ } else {
+ __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
+ }
+ if (__kmp_env_format && __kmp_monitor_stksize) {
+ __kmp_str_buf_print(buffer, "'\n");
+ }
} // __kmp_stg_print_monitor_stacksize
#endif // KMP_USE_MONITOR
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_SETTINGS
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_settings( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_bool( name, value, & __kmp_settings );
+static void __kmp_stg_parse_settings(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_bool(name, value, &__kmp_settings);
} // __kmp_stg_parse_settings
-static void
-__kmp_stg_print_settings( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_settings );
+static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_settings);
} // __kmp_stg_print_settings
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_STACKPAD
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_stackpad( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_int(
- name, // Env var name
- value, // Env var value
- KMP_MIN_STKPADDING, // Min value
- KMP_MAX_STKPADDING, // Max value
- & __kmp_stkpadding // Var to initialize
- );
+static void __kmp_stg_parse_stackpad(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_int(name, // Env var name
+ value, // Env var value
+ KMP_MIN_STKPADDING, // Min value
+ KMP_MAX_STKPADDING, // Max value
+ &__kmp_stkpadding // Var to initialize
+ );
} // __kmp_stg_parse_stackpad
-static void
-__kmp_stg_print_stackpad( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_stkpadding );
+static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
} // __kmp_stg_print_stackpad
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_STACKOFFSET
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_stackoffset( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_size(
- name, // Env var name
- value, // Env var value
- KMP_MIN_STKOFFSET, // Min value
- KMP_MAX_STKOFFSET, // Max value
- NULL, //
- & __kmp_stkoffset, // Var to initialize
- 1
- );
+static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_size(name, // Env var name
+ value, // Env var value
+ KMP_MIN_STKOFFSET, // Min value
+ KMP_MAX_STKOFFSET, // Max value
+ NULL, //
+ &__kmp_stkoffset, // Var to initialize
+ 1);
} // __kmp_stg_parse_stackoffset
-static void
-__kmp_stg_print_stackoffset( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_size( buffer, name, __kmp_stkoffset );
+static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
} // __kmp_stg_print_stackoffset
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_stacksize( char const * name, char const * value, void * data ) {
+static void __kmp_stg_parse_stacksize(char const *name, char const *value,
+ void *data) {
- kmp_stg_ss_data_t * stacksize = (kmp_stg_ss_data_t *) data;
- int rc;
+ kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
+ int rc;
- rc = __kmp_stg_check_rivals( name, value, stacksize->rivals );
- if ( rc ) {
- return;
- }; // if
- __kmp_stg_parse_size(
- name, // Env var name
- value, // Env var value
- __kmp_sys_min_stksize, // Min value
- KMP_MAX_STKSIZE, // Max value
- & __kmp_env_stksize, //
- & __kmp_stksize, // Var to initialize
- stacksize->factor
- );
+ rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
+ if (rc) {
+ return;
+ }; // if
+ __kmp_stg_parse_size(name, // Env var name
+ value, // Env var value
+ __kmp_sys_min_stksize, // Min value
+ KMP_MAX_STKSIZE, // Max value
+ &__kmp_env_stksize, //
+ &__kmp_stksize, // Var to initialize
+ stacksize->factor);
} // __kmp_stg_parse_stacksize
-// This function is called for printing both KMP_STACKSIZE (factor is 1) and OMP_STACKSIZE (factor is 1024).
-// Currently it is not possible to print OMP_STACKSIZE value in bytes. We can consider adding this
-// possibility by a customer request in future.
-static void
-__kmp_stg_print_stacksize( kmp_str_buf_t * buffer, char const * name, void * data ) {
- kmp_stg_ss_data_t * stacksize = (kmp_stg_ss_data_t *) data;
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME_EX(name);
- __kmp_str_buf_print_size( buffer, (__kmp_stksize % 1024) ? __kmp_stksize / stacksize->factor : __kmp_stksize );
- __kmp_str_buf_print( buffer, "'\n" );
- } else {
- __kmp_str_buf_print( buffer, " %s=", name );
- __kmp_str_buf_print_size( buffer, (__kmp_stksize % 1024) ? __kmp_stksize / stacksize->factor : __kmp_stksize );
- __kmp_str_buf_print( buffer, "\n" );
- }
+// This function is called for printing both KMP_STACKSIZE (factor is 1) and
+// OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
+// OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
+// customer request in future.
+static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME_EX(name);
+ __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
+ ? __kmp_stksize / stacksize->factor
+ : __kmp_stksize);
+ __kmp_str_buf_print(buffer, "'\n");
+ } else {
+ __kmp_str_buf_print(buffer, " %s=", name);
+ __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
+ ? __kmp_stksize / stacksize->factor
+ : __kmp_stksize);
+ __kmp_str_buf_print(buffer, "\n");
+ }
} // __kmp_stg_print_stacksize
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_VERSION
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_version( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_bool( name, value, & __kmp_version );
+static void __kmp_stg_parse_version(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_bool(name, value, &__kmp_version);
} // __kmp_stg_parse_version
-static void
-__kmp_stg_print_version( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_version );
+static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_version);
} // __kmp_stg_print_version
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_WARNINGS
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_warnings( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_bool( name, value, & __kmp_generate_warnings );
- if (__kmp_generate_warnings != kmp_warnings_off) { // AC: we have only 0/1 values documented,
- __kmp_generate_warnings = kmp_warnings_explicit; // so reset it to explicit in order to
- } // distinguish from default setting
+static void __kmp_stg_parse_warnings(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
+ if (__kmp_generate_warnings != kmp_warnings_off) {
+ // AC: only 0/1 values documented, so reset to explicit to distinguish from
+ // default setting
+ __kmp_generate_warnings = kmp_warnings_explicit;
+ }
} // __kmp_env_parse_warnings
-static void
-__kmp_stg_print_warnings( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_generate_warnings ); // AC: TODO: change to print_int?
-} // __kmp_env_print_warnings // (needs documentation change)...
+static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_bool(
+ buffer, name, __kmp_generate_warnings); // AC: TODO: change to print_int?
+} // __kmp_env_print_warnings // (needs
+ // documentation change)...
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// OMP_NESTED, OMP_NUM_THREADS
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_nested( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_bool( name, value, & __kmp_dflt_nested );
+static void __kmp_stg_parse_nested(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_bool(name, value, &__kmp_dflt_nested);
} // __kmp_stg_parse_nested
-static void
-__kmp_stg_print_nested( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_dflt_nested );
+static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_dflt_nested);
} // __kmp_stg_print_nested
-static void
-__kmp_parse_nested_num_threads( const char *var, const char *env, kmp_nested_nthreads_t *nth_array )
-{
- const char *next = env;
- const char *scan = next;
-
- int total = 0; // Count elements that were set. It'll be used as an array size
- int prev_comma = FALSE; // For correct processing sequential commas
-
- // Count the number of values in the env. var string
- for ( ; ; ) {
- SKIP_WS( next );
+static void __kmp_parse_nested_num_threads(const char *var, const char *env,
+ kmp_nested_nthreads_t *nth_array) {
+ const char *next = env;
+ const char *scan = next;
+
+ int total = 0; // Count elements that were set. It'll be used as an array size
+ int prev_comma = FALSE; // For correct processing sequential commas
+
+ // Count the number of values in the env. var string
+ for (;;) {
+ SKIP_WS(next);
- if ( *next == '\0' ) {
- break;
- }
- // Next character is not an integer or not a comma => end of list
- if ( ( ( *next < '0' ) || ( *next > '9' ) ) && ( *next !=',') ) {
- KMP_WARNING( NthSyntaxError, var, env );
- return;
- }
- // The next character is ','
- if ( *next == ',' ) {
- // ',' is the fisrt character
- if ( total == 0 || prev_comma ) {
- total++;
- }
- prev_comma = TRUE;
- next++; //skip ','
- SKIP_WS( next );
- }
- // Next character is a digit
- if ( *next >= '0' && *next <= '9' ) {
- prev_comma = FALSE;
- SKIP_DIGITS( next );
- total++;
- const char *tmp = next;
- SKIP_WS( tmp );
- if ( ( *next == ' ' || *next == '\t' ) && ( *tmp >= '0' && *tmp <= '9' ) ) {
- KMP_WARNING( NthSpacesNotAllowed, var, env );
- return;
- }
- }
+ if (*next == '\0') {
+ break;
}
- KMP_DEBUG_ASSERT( total > 0 );
- if( total <= 0 ) {
- KMP_WARNING( NthSyntaxError, var, env );
+ // Next character is not an integer or not a comma => end of list
+ if (((*next < '0') || (*next > '9')) && (*next != ',')) {
+ KMP_WARNING(NthSyntaxError, var, env);
+ return;
+ }
+ // The next character is ','
+ if (*next == ',') {
+ // ',' is the fisrt character
+ if (total == 0 || prev_comma) {
+ total++;
+ }
+ prev_comma = TRUE;
+ next++; // skip ','
+ SKIP_WS(next);
+ }
+ // Next character is a digit
+ if (*next >= '0' && *next <= '9') {
+ prev_comma = FALSE;
+ SKIP_DIGITS(next);
+ total++;
+ const char *tmp = next;
+ SKIP_WS(tmp);
+ if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
+ KMP_WARNING(NthSpacesNotAllowed, var, env);
return;
+ }
}
+ }
+ KMP_DEBUG_ASSERT(total > 0);
+ if (total <= 0) {
+ KMP_WARNING(NthSyntaxError, var, env);
+ return;
+ }
- // Check if the nested nthreads array exists
- if ( ! nth_array->nth ) {
- // Allocate an array of double size
- nth_array->nth = ( int * )KMP_INTERNAL_MALLOC( sizeof( int ) * total * 2 );
- if ( nth_array->nth == NULL ) {
- KMP_FATAL( MemoryAllocFailed );
- }
- nth_array->size = total * 2;
- } else {
- if ( nth_array->size < total ) {
- // Increase the array size
- do {
- nth_array->size *= 2;
- } while ( nth_array->size < total );
-
- nth_array->nth = (int *) KMP_INTERNAL_REALLOC(
- nth_array->nth, sizeof( int ) * nth_array->size );
- if ( nth_array->nth == NULL ) {
- KMP_FATAL( MemoryAllocFailed );
- }
- }
+ // Check if the nested nthreads array exists
+ if (!nth_array->nth) {
+ // Allocate an array of double size
+ nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
+ if (nth_array->nth == NULL) {
+ KMP_FATAL(MemoryAllocFailed);
+ }
+ nth_array->size = total * 2;
+ } else {
+ if (nth_array->size < total) {
+ // Increase the array size
+ do {
+ nth_array->size *= 2;
+ } while (nth_array->size < total);
+
+ nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
+ nth_array->nth, sizeof(int) * nth_array->size);
+ if (nth_array->nth == NULL) {
+ KMP_FATAL(MemoryAllocFailed);
+ }
}
- nth_array->used = total;
- int i = 0;
+ }
+ nth_array->used = total;
+ int i = 0;
- prev_comma = FALSE;
- total = 0;
- // Save values in the array
- for ( ; ; ) {
- SKIP_WS( scan );
- if ( *scan == '\0' ) {
- break;
- }
- // The next character is ','
- if ( *scan == ',' ) {
- // ',' in the beginning of the list
- if ( total == 0 ) {
- // The value is supposed to be equal to __kmp_avail_proc but it is unknown at the moment.
- // So let's put a placeholder (#threads = 0) to correct it later.
- nth_array->nth[i++] = 0;
- total++;
- }else if ( prev_comma ) {
- // Num threads is inherited from the previous level
- nth_array->nth[i] = nth_array->nth[i - 1];
- i++;
- total++;
- }
- prev_comma = TRUE;
- scan++; //skip ','
- SKIP_WS( scan );
- }
- // Next character is a digit
- if ( *scan >= '0' && *scan <= '9' ) {
- int num;
- const char *buf = scan;
- char const * msg = NULL;
- prev_comma = FALSE;
- SKIP_DIGITS( scan );
- total++;
-
- num = __kmp_str_to_int( buf, *scan );
- if ( num < KMP_MIN_NTH ) {
- msg = KMP_I18N_STR( ValueTooSmall );
- num = KMP_MIN_NTH;
- } else if ( num > __kmp_sys_max_nth ) {
- msg = KMP_I18N_STR( ValueTooLarge );
- num = __kmp_sys_max_nth;
- }
- if ( msg != NULL ) {
- // Message is not empty. Print warning.
- KMP_WARNING( ParseSizeIntWarn, var, env, msg );
- KMP_INFORM( Using_int_Value, var, num );
- }
- nth_array->nth[i++] = num;
- }
+ prev_comma = FALSE;
+ total = 0;
+ // Save values in the array
+ for (;;) {
+ SKIP_WS(scan);
+ if (*scan == '\0') {
+ break;
+ }
+ // The next character is ','
+ if (*scan == ',') {
+ // ',' in the beginning of the list
+ if (total == 0) {
+ // The value is supposed to be equal to __kmp_avail_proc but it is
+ // unknown at the moment.
+ // So let's put a placeholder (#threads = 0) to correct it later.
+ nth_array->nth[i++] = 0;
+ total++;
+ } else if (prev_comma) {
+ // Num threads is inherited from the previous level
+ nth_array->nth[i] = nth_array->nth[i - 1];
+ i++;
+ total++;
+ }
+ prev_comma = TRUE;
+ scan++; // skip ','
+ SKIP_WS(scan);
+ }
+ // Next character is a digit
+ if (*scan >= '0' && *scan <= '9') {
+ int num;
+ const char *buf = scan;
+ char const *msg = NULL;
+ prev_comma = FALSE;
+ SKIP_DIGITS(scan);
+ total++;
+
+ num = __kmp_str_to_int(buf, *scan);
+ if (num < KMP_MIN_NTH) {
+ msg = KMP_I18N_STR(ValueTooSmall);
+ num = KMP_MIN_NTH;
+ } else if (num > __kmp_sys_max_nth) {
+ msg = KMP_I18N_STR(ValueTooLarge);
+ num = __kmp_sys_max_nth;
+ }
+ if (msg != NULL) {
+ // Message is not empty. Print warning.
+ KMP_WARNING(ParseSizeIntWarn, var, env, msg);
+ KMP_INFORM(Using_int_Value, var, num);
+ }
+ nth_array->nth[i++] = num;
}
+ }
}
-static void
-__kmp_stg_parse_num_threads( char const * name, char const * value, void * data ) {
- // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
- if ( ! __kmp_strcasecmp_with_sentinel( "all", value, 0 ) ) {
- // The array of 1 element
- __kmp_nested_nth.nth = ( int* )KMP_INTERNAL_MALLOC( sizeof( int ) );
- __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
- __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub = __kmp_xproc;
- } else {
- __kmp_parse_nested_num_threads( name, value, & __kmp_nested_nth );
- if ( __kmp_nested_nth.nth ) {
- __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
- if ( __kmp_dflt_team_nth_ub < __kmp_dflt_team_nth ) {
- __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
- }
- }
- }; // if
- K_DIAG( 1, ( "__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth ) );
+static void __kmp_stg_parse_num_threads(char const *name, char const *value,
+ void *data) {
+ // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
+ if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
+ // The array of 1 element
+ __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
+ __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
+ __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
+ __kmp_xproc;
+ } else {
+ __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
+ if (__kmp_nested_nth.nth) {
+ __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
+ if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
+ __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
+ }
+ }
+ }; // if
+ K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
} // __kmp_stg_parse_num_threads
-static void
-__kmp_stg_print_num_threads( kmp_str_buf_t * buffer, char const * name, void * data ) {
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME;
- } else {
- __kmp_str_buf_print( buffer, " %s", name );
- }
- if ( __kmp_nested_nth.used ) {
- kmp_str_buf_t buf;
- __kmp_str_buf_init( &buf );
- for ( int i = 0; i < __kmp_nested_nth.used; i++) {
- __kmp_str_buf_print( &buf, "%d", __kmp_nested_nth.nth[i] );
- if ( i < __kmp_nested_nth.used - 1 ) {
- __kmp_str_buf_print( &buf, "," );
- }
- }
- __kmp_str_buf_print( buffer, "='%s'\n", buf.str );
- __kmp_str_buf_free(&buf);
- } else {
- __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
+static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME;
+ } else {
+ __kmp_str_buf_print(buffer, " %s", name);
+ }
+ if (__kmp_nested_nth.used) {
+ kmp_str_buf_t buf;
+ __kmp_str_buf_init(&buf);
+ for (int i = 0; i < __kmp_nested_nth.used; i++) {
+ __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
+ if (i < __kmp_nested_nth.used - 1) {
+ __kmp_str_buf_print(&buf, ",");
+ }
}
+ __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
+ __kmp_str_buf_free(&buf);
+ } else {
+ __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
+ }
} // __kmp_stg_print_num_threads
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_tasking( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_int( name, value, 0, (int)tskm_max, (int *)&__kmp_tasking_mode );
+static void __kmp_stg_parse_tasking(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
+ (int *)&__kmp_tasking_mode);
} // __kmp_stg_parse_tasking
-static void
-__kmp_stg_print_tasking( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_tasking_mode );
+static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
} // __kmp_stg_print_tasking
-static void
-__kmp_stg_parse_task_stealing( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_int( name, value, 0, 1, (int *)&__kmp_task_stealing_constraint );
+static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_int(name, value, 0, 1,
+ (int *)&__kmp_task_stealing_constraint);
} // __kmp_stg_parse_task_stealing
-static void
-__kmp_stg_print_task_stealing( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_task_stealing_constraint );
+static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
} // __kmp_stg_print_task_stealing
-static void
-__kmp_stg_parse_max_active_levels( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_int( name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT, & __kmp_dflt_max_active_levels );
+static void __kmp_stg_parse_max_active_levels(char const *name,
+ char const *value, void *data) {
+ __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
+ &__kmp_dflt_max_active_levels);
} // __kmp_stg_parse_max_active_levels
-static void
-__kmp_stg_print_max_active_levels( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_dflt_max_active_levels );
+static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
} // __kmp_stg_print_max_active_levels
#if OMP_40_ENABLED
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// OpenMP 4.0: OMP_DEFAULT_DEVICE
-// -------------------------------------------------------------------------------------------------
-static void __kmp_stg_parse_default_device(char const *name, char const *value, void *data) {
- __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT, &__kmp_default_device);
+static void __kmp_stg_parse_default_device(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
+ &__kmp_default_device);
} // __kmp_stg_parse_default_device
-static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer, char const *name, void *data) {
+static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
__kmp_stg_print_int(buffer, name, __kmp_default_device);
} // __kmp_stg_print_default_device
#endif
#if OMP_45_ENABLED
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// OpenMP 4.5: OMP_MAX_TASK_PRIORITY
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_max_task_priority(char const *name, char const *value, void *data) {
- __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT, &__kmp_max_task_priority);
+static void __kmp_stg_parse_max_task_priority(char const *name,
+ char const *value, void *data) {
+ __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
+ &__kmp_max_task_priority);
} // __kmp_stg_parse_max_task_priority
-static void
-__kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer, char const *name, void *data) {
- __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
+static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
} // __kmp_stg_print_max_task_priority
#endif // OMP_45_ENABLED
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_DISP_NUM_BUFFERS
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_disp_buffers( char const * name, char const * value, void * data ) {
- if ( TCR_4(__kmp_init_serial) ) {
- KMP_WARNING( EnvSerialWarn, name );
- return;
- } // read value before serial initialization only
- __kmp_stg_parse_int( name, value, 1, KMP_MAX_NTH, & __kmp_dispatch_num_buffers );
+static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
+ void *data) {
+ if (TCR_4(__kmp_init_serial)) {
+ KMP_WARNING(EnvSerialWarn, name);
+ return;
+ } // read value before serial initialization only
+ __kmp_stg_parse_int(name, value, 1, KMP_MAX_NTH, &__kmp_dispatch_num_buffers);
} // __kmp_stg_parse_disp_buffers
-static void
-__kmp_stg_print_disp_buffers( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_dispatch_num_buffers );
+static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
} // __kmp_stg_print_disp_buffers
#if KMP_NESTED_HOT_TEAMS
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_hot_teams_level( char const * name, char const * value, void * data ) {
- if ( TCR_4(__kmp_init_parallel) ) {
- KMP_WARNING( EnvParallelWarn, name );
- return;
- } // read value before first parallel only
- __kmp_stg_parse_int( name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT, & __kmp_hot_teams_max_level );
+static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
+ void *data) {
+ if (TCR_4(__kmp_init_parallel)) {
+ KMP_WARNING(EnvParallelWarn, name);
+ return;
+ } // read value before first parallel only
+ __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
+ &__kmp_hot_teams_max_level);
} // __kmp_stg_parse_hot_teams_level
-static void
-__kmp_stg_print_hot_teams_level( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_hot_teams_max_level );
+static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
} // __kmp_stg_print_hot_teams_level
-static void
-__kmp_stg_parse_hot_teams_mode( char const * name, char const * value, void * data ) {
- if ( TCR_4(__kmp_init_parallel) ) {
- KMP_WARNING( EnvParallelWarn, name );
- return;
- } // read value before first parallel only
- __kmp_stg_parse_int( name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT, & __kmp_hot_teams_mode );
+static void __kmp_stg_parse_hot_teams_mode(char const *name, char const *value,
+ void *data) {
+ if (TCR_4(__kmp_init_parallel)) {
+ KMP_WARNING(EnvParallelWarn, name);
+ return;
+ } // read value before first parallel only
+ __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
+ &__kmp_hot_teams_mode);
} // __kmp_stg_parse_hot_teams_mode
-static void
-__kmp_stg_print_hot_teams_mode( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_hot_teams_mode );
+static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
} // __kmp_stg_print_hot_teams_mode
#endif // KMP_NESTED_HOT_TEAMS
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_HANDLE_SIGNALS
-// -------------------------------------------------------------------------------------------------
#if KMP_HANDLE_SIGNALS
-static void
-__kmp_stg_parse_handle_signals( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_bool( name, value, & __kmp_handle_signals );
+static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
} // __kmp_stg_parse_handle_signals
-static void
-__kmp_stg_print_handle_signals( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_handle_signals );
+static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
} // __kmp_stg_print_handle_signals
#endif // KMP_HANDLE_SIGNALS
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG
-// -------------------------------------------------------------------------------------------------
#ifdef KMP_DEBUG
-#define KMP_STG_X_DEBUG( x ) \
- static void __kmp_stg_parse_##x##_debug( char const * name, char const * value, void * data ) { \
- __kmp_stg_parse_int( name, value, 0, INT_MAX, & kmp_##x##_debug ); \
- } /* __kmp_stg_parse_x_debug */ \
- static void __kmp_stg_print_##x##_debug( kmp_str_buf_t * buffer, char const * name, void * data ) { \
- __kmp_stg_print_int( buffer, name, kmp_##x##_debug ); \
- } /* __kmp_stg_print_x_debug */
-
-KMP_STG_X_DEBUG( a )
-KMP_STG_X_DEBUG( b )
-KMP_STG_X_DEBUG( c )
-KMP_STG_X_DEBUG( d )
-KMP_STG_X_DEBUG( e )
-KMP_STG_X_DEBUG( f )
+#define KMP_STG_X_DEBUG(x) \
+ static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
+ void *data) { \
+ __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug); \
+ } /* __kmp_stg_parse_x_debug */ \
+ static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer, \
+ char const *name, void *data) { \
+ __kmp_stg_print_int(buffer, name, kmp_##x##_debug); \
+ } /* __kmp_stg_print_x_debug */
+
+KMP_STG_X_DEBUG(a)
+KMP_STG_X_DEBUG(b)
+KMP_STG_X_DEBUG(c)
+KMP_STG_X_DEBUG(d)
+KMP_STG_X_DEBUG(e)
+KMP_STG_X_DEBUG(f)
#undef KMP_STG_X_DEBUG
-static void
-__kmp_stg_parse_debug( char const * name, char const * value, void * data ) {
- int debug = 0;
- __kmp_stg_parse_int( name, value, 0, INT_MAX, & debug );
- if ( kmp_a_debug < debug ) {
- kmp_a_debug = debug;
- }; // if
- if ( kmp_b_debug < debug ) {
- kmp_b_debug = debug;
- }; // if
- if ( kmp_c_debug < debug ) {
- kmp_c_debug = debug;
- }; // if
- if ( kmp_d_debug < debug ) {
- kmp_d_debug = debug;
- }; // if
- if ( kmp_e_debug < debug ) {
- kmp_e_debug = debug;
- }; // if
- if ( kmp_f_debug < debug ) {
- kmp_f_debug = debug;
- }; // if
+static void __kmp_stg_parse_debug(char const *name, char const *value,
+ void *data) {
+ int debug = 0;
+ __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
+ if (kmp_a_debug < debug) {
+ kmp_a_debug = debug;
+ }; // if
+ if (kmp_b_debug < debug) {
+ kmp_b_debug = debug;
+ }; // if
+ if (kmp_c_debug < debug) {
+ kmp_c_debug = debug;
+ }; // if
+ if (kmp_d_debug < debug) {
+ kmp_d_debug = debug;
+ }; // if
+ if (kmp_e_debug < debug) {
+ kmp_e_debug = debug;
+ }; // if
+ if (kmp_f_debug < debug) {
+ kmp_f_debug = debug;
+ }; // if
} // __kmp_stg_parse_debug
-static void
-__kmp_stg_parse_debug_buf( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_bool( name, value, & __kmp_debug_buf );
- // !!! TODO: Move buffer initialization of of this file! It may works incorrectly if
- // KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or KMP_DEBUG_BUF_CHARS.
- if ( __kmp_debug_buf ) {
- int i;
- int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
-
- /* allocate and initialize all entries in debug buffer to empty */
- __kmp_debug_buffer = (char *) __kmp_page_allocate( elements * sizeof( char ) );
- for ( i = 0; i < elements; i += __kmp_debug_buf_chars )
- __kmp_debug_buffer[i] = '\0';
+static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
+ // !!! TODO: Move buffer initialization of of this file! It may works
+ // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
+ // KMP_DEBUG_BUF_CHARS.
+ if (__kmp_debug_buf) {
+ int i;
+ int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;
- __kmp_debug_count = 0;
- }
- K_DIAG( 1, ( "__kmp_debug_buf = %d\n", __kmp_debug_buf ) );
+ /* allocate and initialize all entries in debug buffer to empty */
+ __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
+ for (i = 0; i < elements; i += __kmp_debug_buf_chars)
+ __kmp_debug_buffer[i] = '\0';
+
+ __kmp_debug_count = 0;
+ }
+ K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
} // __kmp_stg_parse_debug_buf
-static void
-__kmp_stg_print_debug_buf( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_debug_buf );
+static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
} // __kmp_stg_print_debug_buf
-static void
-__kmp_stg_parse_debug_buf_atomic( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_bool( name, value, & __kmp_debug_buf_atomic );
+static void __kmp_stg_parse_debug_buf_atomic(char const *name,
+ char const *value, void *data) {
+ __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
} // __kmp_stg_parse_debug_buf_atomic
-static void
-__kmp_stg_print_debug_buf_atomic( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_debug_buf_atomic );
+static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
} // __kmp_stg_print_debug_buf_atomic
-static void
-__kmp_stg_parse_debug_buf_chars( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_int(
- name,
- value,
- KMP_DEBUG_BUF_CHARS_MIN,
- INT_MAX,
- & __kmp_debug_buf_chars
- );
+static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
+ &__kmp_debug_buf_chars);
} // __kmp_stg_debug_parse_buf_chars
-static void
-__kmp_stg_print_debug_buf_chars( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_debug_buf_chars );
+static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
} // __kmp_stg_print_debug_buf_chars
-static void
-__kmp_stg_parse_debug_buf_lines( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_int(
- name,
- value,
- KMP_DEBUG_BUF_LINES_MIN,
- INT_MAX,
- & __kmp_debug_buf_lines
- );
+static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
+ &__kmp_debug_buf_lines);
} // __kmp_stg_parse_debug_buf_lines
-static void
-__kmp_stg_print_debug_buf_lines( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_debug_buf_lines );
+static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
} // __kmp_stg_print_debug_buf_lines
-static void
-__kmp_stg_parse_diag( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_int( name, value, 0, INT_MAX, & kmp_diag );
+static void __kmp_stg_parse_diag(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
} // __kmp_stg_parse_diag
-static void
-__kmp_stg_print_diag( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, kmp_diag );
+static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_int(buffer, name, kmp_diag);
} // __kmp_stg_print_diag
#endif // KMP_DEBUG
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_ALIGN_ALLOC
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_align_alloc( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_size(
- name,
- value,
- CACHE_LINE,
- INT_MAX,
- NULL,
- & __kmp_align_alloc,
- 1
- );
+static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
+ &__kmp_align_alloc, 1);
} // __kmp_stg_parse_align_alloc
-static void
-__kmp_stg_print_align_alloc( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_size( buffer, name, __kmp_align_alloc );
+static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
} // __kmp_stg_print_align_alloc
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER
-// -------------------------------------------------------------------------------------------------
-// TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from parse and print
-// functions, pass required info through data argument.
+// TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
+// parse and print functions, pass required info through data argument.
-static void
-__kmp_stg_parse_barrier_branch_bit( char const * name, char const * value, void * data ) {
- const char *var;
-
- /* ---------- Barrier branch bit control ------------ */
- for ( int i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
- var = __kmp_barrier_branch_bit_env_name[ i ];
- if ( ( strcmp( var, name) == 0 ) && ( value != 0 ) ) {
- char *comma;
-
- comma = (char *) strchr( value, ',' );
- __kmp_barrier_gather_branch_bits[ i ] = ( kmp_uint32 ) __kmp_str_to_int( value, ',' );
- /* is there a specified release parameter? */
- if ( comma == NULL ) {
- __kmp_barrier_release_branch_bits[ i ] = __kmp_barrier_release_bb_dflt;
- } else {
- __kmp_barrier_release_branch_bits[ i ] = (kmp_uint32) __kmp_str_to_int( comma + 1, 0 );
-
- if ( __kmp_barrier_release_branch_bits[ i ] > KMP_MAX_BRANCH_BITS ) {
- __kmp_msg( kmp_ms_warning, KMP_MSG( BarrReleaseValueInvalid, name, comma + 1 ), __kmp_msg_null );
- __kmp_barrier_release_branch_bits[ i ] = __kmp_barrier_release_bb_dflt;
- }
- }
- if ( __kmp_barrier_gather_branch_bits[ i ] > KMP_MAX_BRANCH_BITS ) {
- KMP_WARNING( BarrGatherValueInvalid, name, value );
- KMP_INFORM( Using_uint_Value, name, __kmp_barrier_gather_bb_dflt );
- __kmp_barrier_gather_branch_bits[ i ] = __kmp_barrier_gather_bb_dflt;
- }
+static void __kmp_stg_parse_barrier_branch_bit(char const *name,
+ char const *value, void *data) {
+ const char *var;
+
+ /* ---------- Barrier branch bit control ------------ */
+ for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
+ var = __kmp_barrier_branch_bit_env_name[i];
+ if ((strcmp(var, name) == 0) && (value != 0)) {
+ char *comma;
+
+ comma = (char *)strchr(value, ',');
+ __kmp_barrier_gather_branch_bits[i] =
+ (kmp_uint32)__kmp_str_to_int(value, ',');
+ /* is there a specified release parameter? */
+ if (comma == NULL) {
+ __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
+ } else {
+ __kmp_barrier_release_branch_bits[i] =
+ (kmp_uint32)__kmp_str_to_int(comma + 1, 0);
+
+ if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
+ __kmp_msg(kmp_ms_warning,
+ KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
+ __kmp_msg_null);
+ __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
}
- K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[ i ], \
- __kmp_barrier_gather_branch_bits [ i ], \
- __kmp_barrier_release_branch_bits [ i ]))
+ }
+ if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
+ KMP_WARNING(BarrGatherValueInvalid, name, value);
+ KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
+ __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
+ }
}
+ K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
+ __kmp_barrier_gather_branch_bits[i],
+ __kmp_barrier_release_branch_bits[i]))
+ }
} // __kmp_stg_parse_barrier_branch_bit
-static void
-__kmp_stg_print_barrier_branch_bit( kmp_str_buf_t * buffer, char const * name, void * data ) {
- const char *var;
- for ( int i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
- var = __kmp_barrier_branch_bit_env_name[ i ];
- if ( strcmp( var, name) == 0 ) {
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[ i ]);
- } else {
- __kmp_str_buf_print( buffer, " %s='", __kmp_barrier_branch_bit_env_name[ i ] );
- }
- __kmp_str_buf_print( buffer, "%d,%d'\n", __kmp_barrier_gather_branch_bits [ i ], __kmp_barrier_release_branch_bits [ i ]);
- }
+static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ const char *var;
+ for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
+ var = __kmp_barrier_branch_bit_env_name[i];
+ if (strcmp(var, name) == 0) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
+ } else {
+ __kmp_str_buf_print(buffer, " %s='",
+ __kmp_barrier_branch_bit_env_name[i]);
+ }
+ __kmp_str_buf_print(buffer, "%d,%d'\n",
+ __kmp_barrier_gather_branch_bits[i],
+ __kmp_barrier_release_branch_bits[i]);
}
+ }
} // __kmp_stg_print_barrier_branch_bit
+// ----------------------------------------------------------------------------
+// KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN,
+// KMP_REDUCTION_BARRIER_PATTERN
+
+// TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and
+// print functions, pass required data to functions through data argument.
+
+static void __kmp_stg_parse_barrier_pattern(char const *name, char const *value,
+ void *data) {
+ const char *var;
+ /* ---------- Barrier method control ------------ */
+
+ for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
+ var = __kmp_barrier_pattern_env_name[i];
+
+ if ((strcmp(var, name) == 0) && (value != 0)) {
+ int j;
+ char *comma = (char *)strchr(value, ',');
+
+ /* handle first parameter: gather pattern */
+ for (j = bp_linear_bar; j < bp_last_bar; j++) {
+ if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
+ ',')) {
+ __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
+ break;
+ }
+ }
+ if (j == bp_last_bar) {
+ KMP_WARNING(BarrGatherValueInvalid, name, value);
+ KMP_INFORM(Using_str_Value, name,
+ __kmp_barrier_pattern_name[bp_linear_bar]);
+ }
-// -------------------------------------------------------------------------------------------------
-// KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN, KMP_REDUCTION_BARRIER_PATTERN
-// -------------------------------------------------------------------------------------------------
-
-// TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and print functions,
-// pass required data to functions through data argument.
-
-static void
-__kmp_stg_parse_barrier_pattern( char const * name, char const * value, void * data ) {
- const char *var;
- /* ---------- Barrier method control ------------ */
-
- for ( int i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
- var = __kmp_barrier_pattern_env_name[ i ];
-
- if ( ( strcmp ( var, name ) == 0 ) && ( value != 0 ) ) {
- int j;
- char *comma = (char *) strchr( value, ',' );
-
- /* handle first parameter: gather pattern */
- for ( j = bp_linear_bar; j<bp_last_bar; j++ ) {
- if (__kmp_match_with_sentinel( __kmp_barrier_pattern_name[j], value, 1, ',' )) {
- __kmp_barrier_gather_pattern[ i ] = (kmp_bar_pat_e) j;
- break;
- }
- }
- if ( j == bp_last_bar ) {
- KMP_WARNING( BarrGatherValueInvalid, name, value );
- KMP_INFORM( Using_str_Value, name, __kmp_barrier_pattern_name[ bp_linear_bar ] );
- }
-
- /* handle second parameter: release pattern */
- if ( comma != NULL ) {
- for ( j = bp_linear_bar; j < bp_last_bar; j++ ) {
- if ( __kmp_str_match( __kmp_barrier_pattern_name[j], 1, comma + 1 ) ) {
- __kmp_barrier_release_pattern[ i ] = (kmp_bar_pat_e) j;
- break;
- }
- }
- if (j == bp_last_bar) {
- __kmp_msg( kmp_ms_warning, KMP_MSG( BarrReleaseValueInvalid, name, comma + 1 ), __kmp_msg_null );
- KMP_INFORM( Using_str_Value, name, __kmp_barrier_pattern_name[ bp_linear_bar ] );
- }
- }
+ /* handle second parameter: release pattern */
+ if (comma != NULL) {
+ for (j = bp_linear_bar; j < bp_last_bar; j++) {
+ if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
+ __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
+ break;
+ }
+ }
+ if (j == bp_last_bar) {
+ __kmp_msg(kmp_ms_warning,
+ KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
+ __kmp_msg_null);
+ KMP_INFORM(Using_str_Value, name,
+ __kmp_barrier_pattern_name[bp_linear_bar]);
}
+ }
}
+ }
} // __kmp_stg_parse_barrier_pattern
-static void
-__kmp_stg_print_barrier_pattern( kmp_str_buf_t * buffer, char const * name, void * data ) {
- const char *var;
- for ( int i=bs_plain_barrier; i<bs_last_barrier; i++ ) {
- var = __kmp_barrier_pattern_env_name[ i ];
- if ( strcmp ( var, name ) == 0 ) {
- int j = __kmp_barrier_gather_pattern [ i ];
- int k = __kmp_barrier_release_pattern [ i ];
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[ i ]);
- } else {
- __kmp_str_buf_print( buffer, " %s='", __kmp_barrier_pattern_env_name[ i ] );
- }
- __kmp_str_buf_print( buffer, "%s,%s'\n", __kmp_barrier_pattern_name [ j ], __kmp_barrier_pattern_name [ k ]);
- }
+static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ const char *var;
+ for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
+ var = __kmp_barrier_pattern_env_name[i];
+ if (strcmp(var, name) == 0) {
+ int j = __kmp_barrier_gather_pattern[i];
+ int k = __kmp_barrier_release_pattern[i];
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
+ } else {
+ __kmp_str_buf_print(buffer, " %s='",
+ __kmp_barrier_pattern_env_name[i]);
+ }
+ __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
+ __kmp_barrier_pattern_name[k]);
}
+ }
} // __kmp_stg_print_barrier_pattern
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_ABORT_DELAY
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_abort_delay( char const * name, char const * value, void * data ) {
- // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is milliseconds.
- int delay = __kmp_abort_delay / 1000;
- __kmp_stg_parse_int( name, value, 0, INT_MAX / 1000, & delay );
- __kmp_abort_delay = delay * 1000;
+static void __kmp_stg_parse_abort_delay(char const *name, char const *value,
+ void *data) {
+ // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is
+ // milliseconds.
+ int delay = __kmp_abort_delay / 1000;
+ __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
+ __kmp_abort_delay = delay * 1000;
} // __kmp_stg_parse_abort_delay
-static void
-__kmp_stg_print_abort_delay( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_abort_delay );
+static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
} // __kmp_stg_print_abort_delay
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_CPUINFO_FILE
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_cpuinfo_file( char const * name, char const * value, void * data ) {
- #if KMP_AFFINITY_SUPPORTED
- __kmp_stg_parse_str( name, value, & __kmp_cpuinfo_file );
- K_DIAG( 1, ( "__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file ) );
- #endif
-} //__kmp_stg_parse_cpuinfo_file
+static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value,
+ void *data) {
+#if KMP_AFFINITY_SUPPORTED
+ __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
+ K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
+#endif
+} //__kmp_stg_parse_cpuinfo_file
-static void
-__kmp_stg_print_cpuinfo_file( kmp_str_buf_t * buffer, char const * name, void * data ) {
- #if KMP_AFFINITY_SUPPORTED
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME;
- } else {
- __kmp_str_buf_print( buffer, " %s", name );
- }
- if ( __kmp_cpuinfo_file ) {
- __kmp_str_buf_print( buffer, "='%s'\n", __kmp_cpuinfo_file );
- } else {
- __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
- }
- #endif
+static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+#if KMP_AFFINITY_SUPPORTED
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME;
+ } else {
+ __kmp_str_buf_print(buffer, " %s", name);
+ }
+ if (__kmp_cpuinfo_file) {
+ __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file);
+ } else {
+ __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
+ }
+#endif
} //__kmp_stg_print_cpuinfo_file
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION
-// -------------------------------------------------------------------------------------------------
-
-static void
-__kmp_stg_parse_force_reduction( char const * name, char const * value, void * data )
-{
- kmp_stg_fr_data_t * reduction = (kmp_stg_fr_data_t *) data;
- int rc;
- rc = __kmp_stg_check_rivals( name, value, reduction->rivals );
- if ( rc ) {
- return;
- }; // if
- if ( reduction->force ) {
- if( value != 0 ) {
- if( __kmp_str_match( "critical", 0, value ) )
- __kmp_force_reduction_method = critical_reduce_block;
- else if( __kmp_str_match( "atomic", 0, value ) )
- __kmp_force_reduction_method = atomic_reduce_block;
- else if( __kmp_str_match( "tree", 0, value ) )
- __kmp_force_reduction_method = tree_reduce_block;
- else {
- KMP_FATAL( UnknownForceReduction, name, value );
- }
- }
+static void __kmp_stg_parse_force_reduction(char const *name, char const *value,
+ void *data) {
+ kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
+ int rc;
+
+ rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
+ if (rc) {
+ return;
+ }; // if
+ if (reduction->force) {
+ if (value != 0) {
+ if (__kmp_str_match("critical", 0, value))
+ __kmp_force_reduction_method = critical_reduce_block;
+ else if (__kmp_str_match("atomic", 0, value))
+ __kmp_force_reduction_method = atomic_reduce_block;
+ else if (__kmp_str_match("tree", 0, value))
+ __kmp_force_reduction_method = tree_reduce_block;
+ else {
+ KMP_FATAL(UnknownForceReduction, name, value);
+ }
+ }
+ } else {
+ __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
+ if (__kmp_determ_red) {
+ __kmp_force_reduction_method = tree_reduce_block;
} else {
- __kmp_stg_parse_bool( name, value, & __kmp_determ_red );
- if( __kmp_determ_red ) {
- __kmp_force_reduction_method = tree_reduce_block;
- } else {
- __kmp_force_reduction_method = reduction_method_not_defined;
- }
+ __kmp_force_reduction_method = reduction_method_not_defined;
}
- K_DIAG( 1, ( "__kmp_force_reduction_method == %d\n", __kmp_force_reduction_method ) );
+ }
+ K_DIAG(1, ("__kmp_force_reduction_method == %d\n",
+ __kmp_force_reduction_method));
} // __kmp_stg_parse_force_reduction
-static void
-__kmp_stg_print_force_reduction( kmp_str_buf_t * buffer, char const * name, void * data ) {
+static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
- kmp_stg_fr_data_t * reduction = (kmp_stg_fr_data_t *) data;
- if ( reduction->force ) {
- if( __kmp_force_reduction_method == critical_reduce_block) {
- __kmp_stg_print_str( buffer, name, "critical");
- } else if ( __kmp_force_reduction_method == atomic_reduce_block ) {
- __kmp_stg_print_str( buffer, name, "atomic");
- } else if ( __kmp_force_reduction_method == tree_reduce_block ) {
- __kmp_stg_print_str( buffer, name, "tree");
- } else {
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME;
- } else {
- __kmp_str_buf_print( buffer, " %s", name );
- }
- __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
- }
+ kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
+ if (reduction->force) {
+ if (__kmp_force_reduction_method == critical_reduce_block) {
+ __kmp_stg_print_str(buffer, name, "critical");
+ } else if (__kmp_force_reduction_method == atomic_reduce_block) {
+ __kmp_stg_print_str(buffer, name, "atomic");
+ } else if (__kmp_force_reduction_method == tree_reduce_block) {
+ __kmp_stg_print_str(buffer, name, "tree");
} else {
- __kmp_stg_print_bool( buffer, name, __kmp_determ_red );
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME;
+ } else {
+ __kmp_str_buf_print(buffer, " %s", name);
+ }
+ __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
}
-
+ } else {
+ __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
+ }
} // __kmp_stg_print_force_reduction
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_STORAGE_MAP
-// -------------------------------------------------------------------------------------------------
-
-static void
-__kmp_stg_parse_storage_map( char const * name, char const * value, void * data ) {
- if ( __kmp_str_match( "verbose", 1, value ) ) {
- __kmp_storage_map = TRUE;
- __kmp_storage_map_verbose = TRUE;
- __kmp_storage_map_verbose_specified = TRUE;
- } else {
- __kmp_storage_map_verbose = FALSE;
- __kmp_stg_parse_bool( name, value, & __kmp_storage_map ); // !!!
- }; // if
+static void __kmp_stg_parse_storage_map(char const *name, char const *value,
+ void *data) {
+ if (__kmp_str_match("verbose", 1, value)) {
+ __kmp_storage_map = TRUE;
+ __kmp_storage_map_verbose = TRUE;
+ __kmp_storage_map_verbose_specified = TRUE;
+
+ } else {
+ __kmp_storage_map_verbose = FALSE;
+ __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!!
+ }; // if
} // __kmp_stg_parse_storage_map
-static void
-__kmp_stg_print_storage_map( kmp_str_buf_t * buffer, char const * name, void * data ) {
- if ( __kmp_storage_map_verbose || __kmp_storage_map_verbose_specified ) {
- __kmp_stg_print_str( buffer, name, "verbose" );
- } else {
- __kmp_stg_print_bool( buffer, name, __kmp_storage_map );
- }
+static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
+ __kmp_stg_print_str(buffer, name, "verbose");
+ } else {
+ __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
+ }
} // __kmp_stg_print_storage_map
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_ALL_THREADPRIVATE
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_all_threadprivate( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_int( name, value, __kmp_allThreadsSpecified ? __kmp_max_nth : 1, __kmp_max_nth,
- & __kmp_tp_capacity );
+static void __kmp_stg_parse_all_threadprivate(char const *name,
+ char const *value, void *data) {
+ __kmp_stg_parse_int(name, value,
+ __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
+ __kmp_max_nth, &__kmp_tp_capacity);
} // __kmp_stg_parse_all_threadprivate
-static void
-__kmp_stg_print_all_threadprivate( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_tp_capacity );
-
+static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
}
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_FOREIGN_THREADS_THREADPRIVATE
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_foreign_threads_threadprivate( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_bool( name, value, & __kmp_foreign_tp );
+static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name,
+ char const *value,
+ void *data) {
+ __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
} // __kmp_stg_parse_foreign_threads_threadprivate
-static void
-__kmp_stg_print_foreign_threads_threadprivate( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_foreign_tp );
+static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
+ char const *name,
+ void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
} // __kmp_stg_print_foreign_threads_threadprivate
-
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD
-// -------------------------------------------------------------------------------------------------
#if KMP_AFFINITY_SUPPORTED
-//
// Parse the proc id list. Return TRUE if successful, FALSE otherwise.
-//
-static int
-__kmp_parse_affinity_proc_id_list( const char *var, const char *env,
- const char **nextEnv, char **proclist )
-{
- const char *scan = env;
- const char *next = scan;
- int empty = TRUE;
+static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env,
+ const char **nextEnv,
+ char **proclist) {
+ const char *scan = env;
+ const char *next = scan;
+ int empty = TRUE;
- *proclist = NULL;
+ *proclist = NULL;
- for (;;) {
- int start, end, stride;
+ for (;;) {
+ int start, end, stride;
- SKIP_WS(scan);
- next = scan;
- if (*next == '\0') {
- break;
- }
+ SKIP_WS(scan);
+ next = scan;
+ if (*next == '\0') {
+ break;
+ }
- if (*next == '{') {
- int num;
- next++; // skip '{'
- SKIP_WS(next);
- scan = next;
-
- //
- // Read the first integer in the set.
- //
- if ((*next < '0') || (*next > '9')) {
- KMP_WARNING( AffSyntaxError, var );
- return FALSE;
- }
- SKIP_DIGITS(next);
- num = __kmp_str_to_int(scan, *next);
- KMP_ASSERT(num >= 0);
-
- for (;;) {
- //
- // Check for end of set.
- //
- SKIP_WS(next);
- if (*next == '}') {
- next++; // skip '}'
- break;
- }
-
- //
- // Skip optional comma.
- //
- if (*next == ',') {
- next++;
- }
- SKIP_WS(next);
-
- //
- // Read the next integer in the set.
- //
- scan = next;
- if ((*next < '0') || (*next > '9')) {
- KMP_WARNING( AffSyntaxError, var );
- return FALSE;
- }
-
- SKIP_DIGITS(next);
- num = __kmp_str_to_int(scan, *next);
- KMP_ASSERT(num >= 0);
- }
- empty = FALSE;
+ if (*next == '{') {
+ int num;
+ next++; // skip '{'
+ SKIP_WS(next);
+ scan = next;
+
+ // Read the first integer in the set.
+ if ((*next < '0') || (*next > '9')) {
+ KMP_WARNING(AffSyntaxError, var);
+ return FALSE;
+ }
+ SKIP_DIGITS(next);
+ num = __kmp_str_to_int(scan, *next);
+ KMP_ASSERT(num >= 0);
- SKIP_WS(next);
- if (*next == ',') {
- next++;
- }
- scan = next;
- continue;
+ for (;;) {
+ // Check for end of set.
+ SKIP_WS(next);
+ if (*next == '}') {
+ next++; // skip '}'
+ break;
}
- //
- // Next character is not an integer => end of list
- //
- if ((*next < '0') || (*next > '9')) {
- if (empty) {
- KMP_WARNING( AffSyntaxError, var );
- return FALSE;
- }
- break;
+ // Skip optional comma.
+ if (*next == ',') {
+ next++;
}
-
- //
- // Read the first integer.
- //
- SKIP_DIGITS(next);
- start = __kmp_str_to_int(scan, *next);
- KMP_ASSERT(start >= 0);
SKIP_WS(next);
- //
- // If this isn't a range, then go on.
- //
- if (*next != '-') {
- empty = FALSE;
-
- //
- // Skip optional comma.
- //
- if (*next == ',') {
- next++;
- }
- scan = next;
- continue;
- }
-
- //
- // This is a range. Skip over the '-' and read in the 2nd int.
- //
- next++; // skip '-'
- SKIP_WS(next);
+ // Read the next integer in the set.
scan = next;
if ((*next < '0') || (*next > '9')) {
- KMP_WARNING( AffSyntaxError, var );
- return FALSE;
+ KMP_WARNING(AffSyntaxError, var);
+ return FALSE;
}
+
SKIP_DIGITS(next);
- end = __kmp_str_to_int(scan, *next);
- KMP_ASSERT(end >= 0);
+ num = __kmp_str_to_int(scan, *next);
+ KMP_ASSERT(num >= 0);
+ }
+ empty = FALSE;
- //
- // Check for a stride parameter
- //
- stride = 1;
- SKIP_WS(next);
- if (*next == ':') {
- //
- // A stride is specified. Skip over the ':" and read the 3rd int.
- //
- int sign = +1;
- next++; // skip ':'
- SKIP_WS(next);
- scan = next;
- if (*next == '-') {
- sign = -1;
- next++;
- SKIP_WS(next);
- scan = next;
- }
- if ((*next < '0') || (*next > '9')) {
- KMP_WARNING( AffSyntaxError, var );
- return FALSE;
- }
- SKIP_DIGITS(next);
- stride = __kmp_str_to_int(scan, *next);
- KMP_ASSERT(stride >= 0);
- stride *= sign;
- }
+ SKIP_WS(next);
+ if (*next == ',') {
+ next++;
+ }
+ scan = next;
+ continue;
+ }
- //
- // Do some range checks.
- //
- if (stride == 0) {
- KMP_WARNING( AffZeroStride, var );
- return FALSE;
- }
- if (stride > 0) {
- if (start > end) {
- KMP_WARNING( AffStartGreaterEnd, var, start, end );
- return FALSE;
- }
- }
- else {
- if (start < end) {
- KMP_WARNING( AffStrideLessZero, var, start, end );
- return FALSE;
- }
- }
- if ((end - start) / stride > 65536 ) {
- KMP_WARNING( AffRangeTooBig, var, end, start, stride );
- return FALSE;
- }
+ // Next character is not an integer => end of list
+ if ((*next < '0') || (*next > '9')) {
+ if (empty) {
+ KMP_WARNING(AffSyntaxError, var);
+ return FALSE;
+ }
+ break;
+ }
- empty = FALSE;
+ // Read the first integer.
+ SKIP_DIGITS(next);
+ start = __kmp_str_to_int(scan, *next);
+ KMP_ASSERT(start >= 0);
+ SKIP_WS(next);
+
+ // If this isn't a range, then go on.
+ if (*next != '-') {
+ empty = FALSE;
+
+ // Skip optional comma.
+ if (*next == ',') {
+ next++;
+ }
+ scan = next;
+ continue;
+ }
- //
- // Skip optional comma.
- //
+ // This is a range. Skip over the '-' and read in the 2nd int.
+ next++; // skip '-'
+ SKIP_WS(next);
+ scan = next;
+ if ((*next < '0') || (*next > '9')) {
+ KMP_WARNING(AffSyntaxError, var);
+ return FALSE;
+ }
+ SKIP_DIGITS(next);
+ end = __kmp_str_to_int(scan, *next);
+ KMP_ASSERT(end >= 0);
+
+ // Check for a stride parameter
+ stride = 1;
+ SKIP_WS(next);
+ if (*next == ':') {
+ // A stride is specified. Skip over the ':" and read the 3rd int.
+ int sign = +1;
+ next++; // skip ':'
+ SKIP_WS(next);
+ scan = next;
+ if (*next == '-') {
+ sign = -1;
+ next++;
SKIP_WS(next);
- if (*next == ',') {
- next++;
- }
scan = next;
+ }
+ if ((*next < '0') || (*next > '9')) {
+ KMP_WARNING(AffSyntaxError, var);
+ return FALSE;
+ }
+ SKIP_DIGITS(next);
+ stride = __kmp_str_to_int(scan, *next);
+ KMP_ASSERT(stride >= 0);
+ stride *= sign;
}
- *nextEnv = next;
+ // Do some range checks.
+ if (stride == 0) {
+ KMP_WARNING(AffZeroStride, var);
+ return FALSE;
+ }
+ if (stride > 0) {
+ if (start > end) {
+ KMP_WARNING(AffStartGreaterEnd, var, start, end);
+ return FALSE;
+ }
+ } else {
+ if (start < end) {
+ KMP_WARNING(AffStrideLessZero, var, start, end);
+ return FALSE;
+ }
+ }
+ if ((end - start) / stride > 65536) {
+ KMP_WARNING(AffRangeTooBig, var, end, start, stride);
+ return FALSE;
+ }
+
+ empty = FALSE;
- {
- int len = next - env;
- char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
- KMP_MEMCPY_S(retlist, (len+1)*sizeof(char), env, len * sizeof(char));
- retlist[len] = '\0';
- *proclist = retlist;
+ // Skip optional comma.
+ SKIP_WS(next);
+ if (*next == ',') {
+ next++;
}
- return TRUE;
-}
+ scan = next;
+ }
+ *nextEnv = next;
+
+ {
+ int len = next - env;
+ char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
+ KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
+ retlist[len] = '\0';
+ *proclist = retlist;
+ }
+ return TRUE;
+}
-//
// If KMP_AFFINITY is specified without a type, then
// __kmp_affinity_notype should point to its setting.
-//
static kmp_setting_t *__kmp_affinity_notype = NULL;
-static void
-__kmp_parse_affinity_env( char const * name, char const * value,
- enum affinity_type * out_type,
- char ** out_proclist,
- int * out_verbose,
- int * out_warn,
- int * out_respect,
- enum affinity_gran * out_gran,
- int * out_gran_levels,
- int * out_dups,
- int * out_compact,
- int * out_offset
-)
-{
- char * buffer = NULL; // Copy of env var value.
- char * buf = NULL; // Buffer for strtok_r() function.
- char * next = NULL; // end of token / start of next.
- const char * start; // start of current token (for err msgs)
- int count = 0; // Counter of parsed integer numbers.
- int number[ 2 ]; // Parsed numbers.
-
- // Guards.
- int type = 0;
- int proclist = 0;
- int max_proclist = 0;
- int verbose = 0;
- int warnings = 0;
- int respect = 0;
- int gran = 0;
- int dups = 0;
-
- KMP_ASSERT( value != NULL );
-
- if ( TCR_4(__kmp_init_middle) ) {
- KMP_WARNING( EnvMiddleWarn, name );
- __kmp_env_toPrint( name, 0 );
- return;
- }
- __kmp_env_toPrint( name, 1 );
+static void __kmp_parse_affinity_env(char const *name, char const *value,
+ enum affinity_type *out_type,
+ char **out_proclist, int *out_verbose,
+ int *out_warn, int *out_respect,
+ enum affinity_gran *out_gran,
+ int *out_gran_levels, int *out_dups,
+ int *out_compact, int *out_offset) {
+ char *buffer = NULL; // Copy of env var value.
+ char *buf = NULL; // Buffer for strtok_r() function.
+ char *next = NULL; // end of token / start of next.
+ const char *start; // start of current token (for err msgs)
+ int count = 0; // Counter of parsed integer numbers.
+ int number[2]; // Parsed numbers.
+
+ // Guards.
+ int type = 0;
+ int proclist = 0;
+ int max_proclist = 0;
+ int verbose = 0;
+ int warnings = 0;
+ int respect = 0;
+ int gran = 0;
+ int dups = 0;
+
+ KMP_ASSERT(value != NULL);
+
+ if (TCR_4(__kmp_init_middle)) {
+ KMP_WARNING(EnvMiddleWarn, name);
+ __kmp_env_toPrint(name, 0);
+ return;
+ }
+ __kmp_env_toPrint(name, 1);
- buffer = __kmp_str_format( "%s", value ); // Copy env var to keep original intact.
- buf = buffer;
- SKIP_WS(buf);
+ buffer =
+ __kmp_str_format("%s", value); // Copy env var to keep original intact.
+ buf = buffer;
+ SKIP_WS(buf);
- // Helper macros.
+// Helper macros.
- //
- // If we see a parse error, emit a warning and scan to the next ",".
- //
- // FIXME - there's got to be a better way to print an error
- // message, hopefully without overwritting peices of buf.
- //
- #define EMIT_WARN(skip,errlist) \
- { \
- char ch; \
- if (skip) { \
- SKIP_TO(next, ','); \
- } \
- ch = *next; \
- *next = '\0'; \
- KMP_WARNING errlist; \
- *next = ch; \
- if (skip) { \
- if (ch == ',') next++; \
- } \
- buf = next; \
- }
-
- #define _set_param(_guard,_var,_val) \
- { \
- if ( _guard == 0 ) { \
- _var = _val; \
- } else { \
- EMIT_WARN( FALSE, ( AffParamDefined, name, start ) ); \
- }; \
- ++ _guard; \
- }
+// If we see a parse error, emit a warning and scan to the next ",".
+//
+// FIXME - there's got to be a better way to print an error
+// message, hopefully without overwritting peices of buf.
+#define EMIT_WARN(skip, errlist) \
+ { \
+ char ch; \
+ if (skip) { \
+ SKIP_TO(next, ','); \
+ } \
+ ch = *next; \
+ *next = '\0'; \
+ KMP_WARNING errlist; \
+ *next = ch; \
+ if (skip) { \
+ if (ch == ',') \
+ next++; \
+ } \
+ buf = next; \
+ }
- #define set_type(val) _set_param( type, *out_type, val )
- #define set_verbose(val) _set_param( verbose, *out_verbose, val )
- #define set_warnings(val) _set_param( warnings, *out_warn, val )
- #define set_respect(val) _set_param( respect, *out_respect, val )
- #define set_dups(val) _set_param( dups, *out_dups, val )
- #define set_proclist(val) _set_param( proclist, *out_proclist, val )
-
- #define set_gran(val,levels) \
- { \
- if ( gran == 0 ) { \
- *out_gran = val; \
- *out_gran_levels = levels; \
- } else { \
- EMIT_WARN( FALSE, ( AffParamDefined, name, start ) ); \
- }; \
- ++ gran; \
- }
+#define _set_param(_guard, _var, _val) \
+ { \
+ if (_guard == 0) { \
+ _var = _val; \
+ } else { \
+ EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
+ }; \
+ ++_guard; \
+ }
-# if OMP_40_ENABLED
- KMP_DEBUG_ASSERT( ( __kmp_nested_proc_bind.bind_types != NULL )
- && ( __kmp_nested_proc_bind.used > 0 ) );
-# endif
+#define set_type(val) _set_param(type, *out_type, val)
+#define set_verbose(val) _set_param(verbose, *out_verbose, val)
+#define set_warnings(val) _set_param(warnings, *out_warn, val)
+#define set_respect(val) _set_param(respect, *out_respect, val)
+#define set_dups(val) _set_param(dups, *out_dups, val)
+#define set_proclist(val) _set_param(proclist, *out_proclist, val)
+
+#define set_gran(val, levels) \
+ { \
+ if (gran == 0) { \
+ *out_gran = val; \
+ *out_gran_levels = levels; \
+ } else { \
+ EMIT_WARN(FALSE, (AffParamDefined, name, start)); \
+ }; \
+ ++gran; \
+ }
- while ( *buf != '\0' ) {
- start = next = buf;
+#if OMP_40_ENABLED
+ KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
+ (__kmp_nested_proc_bind.used > 0));
+#endif
- if (__kmp_match_str("none", buf, (const char **)&next)) {
- set_type( affinity_none );
-# if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
-# endif
- buf = next;
- } else if (__kmp_match_str("scatter", buf, (const char **)&next)) {
- set_type( affinity_scatter );
-# if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
-# endif
- buf = next;
- } else if (__kmp_match_str("compact", buf, (const char **)&next)) {
- set_type( affinity_compact );
-# if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
-# endif
- buf = next;
- } else if (__kmp_match_str("logical", buf, (const char **)&next)) {
- set_type( affinity_logical );
-# if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
-# endif
- buf = next;
- } else if (__kmp_match_str("physical", buf, (const char **)&next)) {
- set_type( affinity_physical );
-# if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
-# endif
- buf = next;
- } else if (__kmp_match_str("explicit", buf, (const char **)&next)) {
- set_type( affinity_explicit );
-# if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
-# endif
- buf = next;
- } else if (__kmp_match_str("balanced", buf, (const char **)&next)) {
- set_type( affinity_balanced );
-# if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
-# endif
- buf = next;
- } else if (__kmp_match_str("disabled", buf, (const char **)&next)) {
- set_type( affinity_disabled );
-# if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
-# endif
- buf = next;
- } else if (__kmp_match_str("verbose", buf, (const char **)&next)) {
- set_verbose( TRUE );
- buf = next;
- } else if (__kmp_match_str("noverbose", buf, (const char **)&next)) {
- set_verbose( FALSE );
- buf = next;
- } else if (__kmp_match_str("warnings", buf, (const char **)&next)) {
- set_warnings( TRUE );
- buf = next;
- } else if (__kmp_match_str("nowarnings", buf, (const char **)&next)) {
- set_warnings( FALSE );
- buf = next;
- } else if (__kmp_match_str("respect", buf, (const char **)&next)) {
- set_respect( TRUE );
- buf = next;
- } else if (__kmp_match_str("norespect", buf, (const char **)&next)) {
- set_respect( FALSE );
- buf = next;
- } else if (__kmp_match_str("duplicates", buf, (const char **)&next)
- || __kmp_match_str("dups", buf, (const char **)&next)) {
- set_dups( TRUE );
- buf = next;
- } else if (__kmp_match_str("noduplicates", buf, (const char **)&next)
- || __kmp_match_str("nodups", buf, (const char **)&next)) {
- set_dups( FALSE );
- buf = next;
- } else if (__kmp_match_str("granularity", buf, (const char **)&next)
- || __kmp_match_str("gran", buf, (const char **)&next)) {
- SKIP_WS(next);
- if (*next != '=') {
- EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
- continue;
- }
- next++; // skip '='
- SKIP_WS(next);
+ while (*buf != '\0') {
+ start = next = buf;
- buf = next;
- if (__kmp_match_str("fine", buf, (const char **)&next)) {
- set_gran( affinity_gran_fine, -1 );
- buf = next;
- } else if (__kmp_match_str("thread", buf, (const char **)&next)) {
- set_gran( affinity_gran_thread, -1 );
- buf = next;
- } else if (__kmp_match_str("core", buf, (const char **)&next)) {
- set_gran( affinity_gran_core, -1 );
- buf = next;
- } else if (__kmp_match_str("package", buf, (const char **)&next)) {
- set_gran( affinity_gran_package, -1 );
- buf = next;
- } else if (__kmp_match_str("node", buf, (const char **)&next)) {
- set_gran( affinity_gran_node, -1 );
- buf = next;
-# if KMP_GROUP_AFFINITY
- } else if (__kmp_match_str("group", buf, (const char **)&next)) {
- set_gran( affinity_gran_group, -1 );
- buf = next;
-# endif /* KMP_GROUP AFFINITY */
- } else if ((*buf >= '0') && (*buf <= '9')) {
- int n;
- next = buf;
- SKIP_DIGITS(next);
- n = __kmp_str_to_int( buf, *next );
- KMP_ASSERT(n >= 0);
- buf = next;
- set_gran( affinity_gran_default, n );
- } else {
- EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
- continue;
- }
- } else if (__kmp_match_str("proclist", buf, (const char **)&next)) {
- char *temp_proclist;
+ if (__kmp_match_str("none", buf, (const char **)&next)) {
+ set_type(affinity_none);
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
+#endif
+ buf = next;
+ } else if (__kmp_match_str("scatter", buf, (const char **)&next)) {
+ set_type(affinity_scatter);
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
+#endif
+ buf = next;
+ } else if (__kmp_match_str("compact", buf, (const char **)&next)) {
+ set_type(affinity_compact);
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
+#endif
+ buf = next;
+ } else if (__kmp_match_str("logical", buf, (const char **)&next)) {
+ set_type(affinity_logical);
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
+#endif
+ buf = next;
+ } else if (__kmp_match_str("physical", buf, (const char **)&next)) {
+ set_type(affinity_physical);
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
+#endif
+ buf = next;
+ } else if (__kmp_match_str("explicit", buf, (const char **)&next)) {
+ set_type(affinity_explicit);
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
+#endif
+ buf = next;
+ } else if (__kmp_match_str("balanced", buf, (const char **)&next)) {
+ set_type(affinity_balanced);
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
+#endif
+ buf = next;
+ } else if (__kmp_match_str("disabled", buf, (const char **)&next)) {
+ set_type(affinity_disabled);
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
+#endif
+ buf = next;
+ } else if (__kmp_match_str("verbose", buf, (const char **)&next)) {
+ set_verbose(TRUE);
+ buf = next;
+ } else if (__kmp_match_str("noverbose", buf, (const char **)&next)) {
+ set_verbose(FALSE);
+ buf = next;
+ } else if (__kmp_match_str("warnings", buf, (const char **)&next)) {
+ set_warnings(TRUE);
+ buf = next;
+ } else if (__kmp_match_str("nowarnings", buf, (const char **)&next)) {
+ set_warnings(FALSE);
+ buf = next;
+ } else if (__kmp_match_str("respect", buf, (const char **)&next)) {
+ set_respect(TRUE);
+ buf = next;
+ } else if (__kmp_match_str("norespect", buf, (const char **)&next)) {
+ set_respect(FALSE);
+ buf = next;
+ } else if (__kmp_match_str("duplicates", buf, (const char **)&next) ||
+ __kmp_match_str("dups", buf, (const char **)&next)) {
+ set_dups(TRUE);
+ buf = next;
+ } else if (__kmp_match_str("noduplicates", buf, (const char **)&next) ||
+ __kmp_match_str("nodups", buf, (const char **)&next)) {
+ set_dups(FALSE);
+ buf = next;
+ } else if (__kmp_match_str("granularity", buf, (const char **)&next) ||
+ __kmp_match_str("gran", buf, (const char **)&next)) {
+ SKIP_WS(next);
+ if (*next != '=') {
+ EMIT_WARN(TRUE, (AffInvalidParam, name, start));
+ continue;
+ }
+ next++; // skip '='
+ SKIP_WS(next);
- SKIP_WS(next);
- if (*next != '=') {
- EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
- continue;
- }
- next++; // skip '='
- SKIP_WS(next);
- if (*next != '[') {
- EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
- continue;
- }
- next++; // skip '['
- buf = next;
- if (! __kmp_parse_affinity_proc_id_list(name, buf,
- (const char **)&next, &temp_proclist)) {
- //
- // warning already emitted.
- //
- SKIP_TO(next, ']');
- if (*next == ']') next++;
- SKIP_TO(next, ',');
- if (*next == ',') next++;
- buf = next;
- continue;
- }
- if (*next != ']') {
- EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
- continue;
- }
- next++; // skip ']'
- set_proclist( temp_proclist );
- } else if ((*buf >= '0') && (*buf <= '9')) {
- // Parse integer numbers -- permute and offset.
- int n;
- next = buf;
- SKIP_DIGITS(next);
- n = __kmp_str_to_int( buf, *next );
- KMP_ASSERT(n >= 0);
- buf = next;
- if ( count < 2 ) {
- number[ count ] = n;
- } else {
- KMP_WARNING( AffManyParams, name, start );
- }; // if
- ++ count;
- } else {
- EMIT_WARN( TRUE, ( AffInvalidParam, name, start ) );
- continue;
- }
+ buf = next;
+ if (__kmp_match_str("fine", buf, (const char **)&next)) {
+ set_gran(affinity_gran_fine, -1);
+ buf = next;
+ } else if (__kmp_match_str("thread", buf, (const char **)&next)) {
+ set_gran(affinity_gran_thread, -1);
+ buf = next;
+ } else if (__kmp_match_str("core", buf, (const char **)&next)) {
+ set_gran(affinity_gran_core, -1);
+ buf = next;
+ } else if (__kmp_match_str("package", buf, (const char **)&next)) {
+ set_gran(affinity_gran_package, -1);
+ buf = next;
+ } else if (__kmp_match_str("node", buf, (const char **)&next)) {
+ set_gran(affinity_gran_node, -1);
+ buf = next;
+#if KMP_GROUP_AFFINITY
+ } else if (__kmp_match_str("group", buf, (const char **)&next)) {
+ set_gran(affinity_gran_group, -1);
+ buf = next;
+#endif /* KMP_GROUP AFFINITY */
+ } else if ((*buf >= '0') && (*buf <= '9')) {
+ int n;
+ next = buf;
+ SKIP_DIGITS(next);
+ n = __kmp_str_to_int(buf, *next);
+ KMP_ASSERT(n >= 0);
+ buf = next;
+ set_gran(affinity_gran_default, n);
+ } else {
+ EMIT_WARN(TRUE, (AffInvalidParam, name, start));
+ continue;
+ }
+ } else if (__kmp_match_str("proclist", buf, (const char **)&next)) {
+ char *temp_proclist;
- SKIP_WS(next);
- if (*next == ',') {
- next++;
- SKIP_WS(next);
- }
- else if (*next != '\0') {
- const char *temp = next;
- EMIT_WARN( TRUE, ( ParseExtraCharsWarn, name, temp ) );
- continue;
- }
+ SKIP_WS(next);
+ if (*next != '=') {
+ EMIT_WARN(TRUE, (AffInvalidParam, name, start));
+ continue;
+ }
+ next++; // skip '='
+ SKIP_WS(next);
+ if (*next != '[') {
+ EMIT_WARN(TRUE, (AffInvalidParam, name, start));
+ continue;
+ }
+ next++; // skip '['
+ buf = next;
+ if (!__kmp_parse_affinity_proc_id_list(name, buf, (const char **)&next,
+ &temp_proclist)) {
+ // warning already emitted.
+ SKIP_TO(next, ']');
+ if (*next == ']')
+ next++;
+ SKIP_TO(next, ',');
+ if (*next == ',')
+ next++;
buf = next;
- } // while
+ continue;
+ }
+ if (*next != ']') {
+ EMIT_WARN(TRUE, (AffInvalidParam, name, start));
+ continue;
+ }
+ next++; // skip ']'
+ set_proclist(temp_proclist);
+ } else if ((*buf >= '0') && (*buf <= '9')) {
+ // Parse integer numbers -- permute and offset.
+ int n;
+ next = buf;
+ SKIP_DIGITS(next);
+ n = __kmp_str_to_int(buf, *next);
+ KMP_ASSERT(n >= 0);
+ buf = next;
+ if (count < 2) {
+ number[count] = n;
+ } else {
+ KMP_WARNING(AffManyParams, name, start);
+ }; // if
+ ++count;
+ } else {
+ EMIT_WARN(TRUE, (AffInvalidParam, name, start));
+ continue;
+ }
- #undef EMIT_WARN
- #undef _set_param
- #undef set_type
- #undef set_verbose
- #undef set_warnings
- #undef set_respect
- #undef set_granularity
-
- __kmp_str_free((const char **) &buffer);
-
- if ( proclist ) {
- if ( ! type ) {
- KMP_WARNING( AffProcListNoType, name );
- *out_type = affinity_explicit;
-# if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
-# endif
- }
- else if ( *out_type != affinity_explicit ) {
- KMP_WARNING( AffProcListNotExplicit, name );
- KMP_ASSERT( *out_proclist != NULL );
- KMP_INTERNAL_FREE( *out_proclist );
- *out_proclist = NULL;
- }
+ SKIP_WS(next);
+ if (*next == ',') {
+ next++;
+ SKIP_WS(next);
+ } else if (*next != '\0') {
+ const char *temp = next;
+ EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
+ continue;
+ }
+ buf = next;
+ } // while
+
+#undef EMIT_WARN
+#undef _set_param
+#undef set_type
+#undef set_verbose
+#undef set_warnings
+#undef set_respect
+#undef set_granularity
+
+ __kmp_str_free((const char **)&buffer);
+
+ if (proclist) {
+ if (!type) {
+ KMP_WARNING(AffProcListNoType, name);
+ *out_type = affinity_explicit;
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
+#endif
+ } else if (*out_type != affinity_explicit) {
+ KMP_WARNING(AffProcListNotExplicit, name);
+ KMP_ASSERT(*out_proclist != NULL);
+ KMP_INTERNAL_FREE(*out_proclist);
+ *out_proclist = NULL;
}
- switch ( *out_type ) {
- case affinity_logical:
- case affinity_physical: {
- if ( count > 0 ) {
- *out_offset = number[ 0 ];
- }; // if
- if ( count > 1 ) {
- KMP_WARNING( AffManyParamsForLogic, name, number[ 1 ] );
- }; // if
- } break;
- case affinity_balanced: {
- if ( count > 0 ) {
- *out_compact = number[ 0 ];
- }; // if
- if ( count > 1 ) {
- *out_offset = number[ 1 ];
- }; // if
+ }
+ switch (*out_type) {
+ case affinity_logical:
+ case affinity_physical: {
+ if (count > 0) {
+ *out_offset = number[0];
+ }; // if
+ if (count > 1) {
+ KMP_WARNING(AffManyParamsForLogic, name, number[1]);
+ }; // if
+ } break;
+ case affinity_balanced: {
+ if (count > 0) {
+ *out_compact = number[0];
+ }; // if
+ if (count > 1) {
+ *out_offset = number[1];
+ }; // if
- if ( __kmp_affinity_gran == affinity_gran_default ) {
+ if (__kmp_affinity_gran == affinity_gran_default) {
#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
- if( __kmp_mic_type != non_mic ) {
- if( __kmp_affinity_verbose || __kmp_affinity_warnings ) {
- KMP_WARNING( AffGranUsing, "KMP_AFFINITY", "fine" );
- }
- __kmp_affinity_gran = affinity_gran_fine;
- } else
-#endif
- {
- if( __kmp_affinity_verbose || __kmp_affinity_warnings ) {
- KMP_WARNING( AffGranUsing, "KMP_AFFINITY", "core" );
- }
- __kmp_affinity_gran = affinity_gran_core;
- }
- }
- } break;
- case affinity_scatter:
- case affinity_compact: {
- if ( count > 0 ) {
- *out_compact = number[ 0 ];
- }; // if
- if ( count > 1 ) {
- *out_offset = number[ 1 ];
- }; // if
- } break;
- case affinity_explicit: {
- if ( *out_proclist == NULL ) {
- KMP_WARNING( AffNoProcList, name );
- __kmp_affinity_type = affinity_none;
- }
- if ( count > 0 ) {
- KMP_WARNING( AffNoParam, name, "explicit" );
- }
- } break;
- case affinity_none: {
- if ( count > 0 ) {
- KMP_WARNING( AffNoParam, name, "none" );
- }; // if
- } break;
- case affinity_disabled: {
- if ( count > 0 ) {
- KMP_WARNING( AffNoParam, name, "disabled" );
- }; // if
- } break;
- case affinity_default: {
- if ( count > 0 ) {
- KMP_WARNING( AffNoParam, name, "default" );
- }; // if
- } break;
- default: {
- KMP_ASSERT( 0 );
- };
- }; // switch
+ if (__kmp_mic_type != non_mic) {
+ if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
+ KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "fine");
+ }
+ __kmp_affinity_gran = affinity_gran_fine;
+ } else
+#endif
+ {
+ if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
+ KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "core");
+ }
+ __kmp_affinity_gran = affinity_gran_core;
+ }
+ }
+ } break;
+ case affinity_scatter:
+ case affinity_compact: {
+ if (count > 0) {
+ *out_compact = number[0];
+ }; // if
+ if (count > 1) {
+ *out_offset = number[1];
+ }; // if
+ } break;
+ case affinity_explicit: {
+ if (*out_proclist == NULL) {
+ KMP_WARNING(AffNoProcList, name);
+ __kmp_affinity_type = affinity_none;
+ }
+ if (count > 0) {
+ KMP_WARNING(AffNoParam, name, "explicit");
+ }
+ } break;
+ case affinity_none: {
+ if (count > 0) {
+ KMP_WARNING(AffNoParam, name, "none");
+ }; // if
+ } break;
+ case affinity_disabled: {
+ if (count > 0) {
+ KMP_WARNING(AffNoParam, name, "disabled");
+ }; // if
+ } break;
+ case affinity_default: {
+ if (count > 0) {
+ KMP_WARNING(AffNoParam, name, "default");
+ }; // if
+ } break;
+ default: { KMP_ASSERT(0); };
+ }; // switch
} // __kmp_parse_affinity_env
-static void
-__kmp_stg_parse_affinity( char const * name, char const * value, void * data )
-{
- kmp_setting_t **rivals = (kmp_setting_t **) data;
- int rc;
-
- rc = __kmp_stg_check_rivals( name, value, rivals );
- if ( rc ) {
- return;
- }
+static void __kmp_stg_parse_affinity(char const *name, char const *value,
+ void *data) {
+ kmp_setting_t **rivals = (kmp_setting_t **)data;
+ int rc;
+
+ rc = __kmp_stg_check_rivals(name, value, rivals);
+ if (rc) {
+ return;
+ }
- __kmp_parse_affinity_env( name, value, & __kmp_affinity_type,
- & __kmp_affinity_proclist, & __kmp_affinity_verbose,
- & __kmp_affinity_warnings, & __kmp_affinity_respect_mask,
- & __kmp_affinity_gran, & __kmp_affinity_gran_levels,
- & __kmp_affinity_dups, & __kmp_affinity_compact,
- & __kmp_affinity_offset );
+ __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
+ &__kmp_affinity_proclist, &__kmp_affinity_verbose,
+ &__kmp_affinity_warnings,
+ &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
+ &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
+ &__kmp_affinity_compact, &__kmp_affinity_offset);
} // __kmp_stg_parse_affinity
-static void
-__kmp_stg_print_affinity( kmp_str_buf_t * buffer, char const * name, void * data ) {
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME_EX(name);
+static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME_EX(name);
+ } else {
+ __kmp_str_buf_print(buffer, " %s='", name);
+ }
+ if (__kmp_affinity_verbose) {
+ __kmp_str_buf_print(buffer, "%s,", "verbose");
+ } else {
+ __kmp_str_buf_print(buffer, "%s,", "noverbose");
+ }
+ if (__kmp_affinity_warnings) {
+ __kmp_str_buf_print(buffer, "%s,", "warnings");
+ } else {
+ __kmp_str_buf_print(buffer, "%s,", "nowarnings");
+ }
+ if (KMP_AFFINITY_CAPABLE()) {
+ if (__kmp_affinity_respect_mask) {
+ __kmp_str_buf_print(buffer, "%s,", "respect");
} else {
- __kmp_str_buf_print( buffer, " %s='", name );
+ __kmp_str_buf_print(buffer, "%s,", "norespect");
}
- if ( __kmp_affinity_verbose ) {
- __kmp_str_buf_print( buffer, "%s,", "verbose");
- } else {
- __kmp_str_buf_print( buffer, "%s,", "noverbose");
+ switch (__kmp_affinity_gran) {
+ case affinity_gran_default:
+ __kmp_str_buf_print(buffer, "%s", "granularity=default,");
+ break;
+ case affinity_gran_fine:
+ __kmp_str_buf_print(buffer, "%s", "granularity=fine,");
+ break;
+ case affinity_gran_thread:
+ __kmp_str_buf_print(buffer, "%s", "granularity=thread,");
+ break;
+ case affinity_gran_core:
+ __kmp_str_buf_print(buffer, "%s", "granularity=core,");
+ break;
+ case affinity_gran_package:
+ __kmp_str_buf_print(buffer, "%s", "granularity=package,");
+ break;
+ case affinity_gran_node:
+ __kmp_str_buf_print(buffer, "%s", "granularity=node,");
+ break;
+#if KMP_GROUP_AFFINITY
+ case affinity_gran_group:
+ __kmp_str_buf_print(buffer, "%s", "granularity=group,");
+ break;
+#endif /* KMP_GROUP_AFFINITY */
}
- if ( __kmp_affinity_warnings ) {
- __kmp_str_buf_print( buffer, "%s,", "warnings");
+ if (__kmp_affinity_dups) {
+ __kmp_str_buf_print(buffer, "%s,", "duplicates");
} else {
- __kmp_str_buf_print( buffer, "%s,", "nowarnings");
+ __kmp_str_buf_print(buffer, "%s,", "noduplicates");
}
- if ( KMP_AFFINITY_CAPABLE() ) {
- if ( __kmp_affinity_respect_mask ) {
- __kmp_str_buf_print( buffer, "%s,", "respect");
- } else {
- __kmp_str_buf_print( buffer, "%s,", "norespect");
- }
- switch ( __kmp_affinity_gran ) {
- case affinity_gran_default:
- __kmp_str_buf_print( buffer, "%s", "granularity=default,");
- break;
- case affinity_gran_fine:
- __kmp_str_buf_print( buffer, "%s", "granularity=fine,");
- break;
- case affinity_gran_thread:
- __kmp_str_buf_print( buffer, "%s", "granularity=thread,");
- break;
- case affinity_gran_core:
- __kmp_str_buf_print( buffer, "%s", "granularity=core,");
- break;
- case affinity_gran_package:
- __kmp_str_buf_print( buffer, "%s", "granularity=package,");
- break;
- case affinity_gran_node:
- __kmp_str_buf_print( buffer, "%s", "granularity=node,");
- break;
-# if KMP_GROUP_AFFINITY
- case affinity_gran_group:
- __kmp_str_buf_print( buffer, "%s", "granularity=group,");
- break;
-# endif /* KMP_GROUP_AFFINITY */
- }
- if ( __kmp_affinity_dups ) {
- __kmp_str_buf_print( buffer, "%s,", "duplicates");
- } else {
- __kmp_str_buf_print( buffer, "%s,", "noduplicates");
- }
- }
- if ( ! KMP_AFFINITY_CAPABLE() ) {
- __kmp_str_buf_print( buffer, "%s", "disabled" );
- }
- else switch ( __kmp_affinity_type ){
- case affinity_none:
- __kmp_str_buf_print( buffer, "%s", "none");
- break;
- case affinity_physical:
- __kmp_str_buf_print( buffer, "%s,%d", "physical",
- __kmp_affinity_offset );
- break;
- case affinity_logical:
- __kmp_str_buf_print( buffer, "%s,%d", "logical",
- __kmp_affinity_offset );
- break;
- case affinity_compact:
- __kmp_str_buf_print( buffer, "%s,%d,%d", "compact",
- __kmp_affinity_compact, __kmp_affinity_offset );
- break;
- case affinity_scatter:
- __kmp_str_buf_print( buffer, "%s,%d,%d", "scatter",
- __kmp_affinity_compact, __kmp_affinity_offset );
- break;
- case affinity_explicit:
- __kmp_str_buf_print( buffer, "%s=[%s],%s", "proclist",
- __kmp_affinity_proclist, "explicit" );
- break;
- case affinity_balanced:
- __kmp_str_buf_print( buffer, "%s,%d,%d", "balanced",
- __kmp_affinity_compact, __kmp_affinity_offset );
- break;
- case affinity_disabled:
- __kmp_str_buf_print( buffer, "%s", "disabled");
- break;
- case affinity_default:
- __kmp_str_buf_print( buffer, "%s", "default");
- break;
- default:
- __kmp_str_buf_print( buffer, "%s", "<unknown>");
- break;
+ }
+ if (!KMP_AFFINITY_CAPABLE()) {
+ __kmp_str_buf_print(buffer, "%s", "disabled");
+ } else
+ switch (__kmp_affinity_type) {
+ case affinity_none:
+ __kmp_str_buf_print(buffer, "%s", "none");
+ break;
+ case affinity_physical:
+ __kmp_str_buf_print(buffer, "%s,%d", "physical", __kmp_affinity_offset);
+ break;
+ case affinity_logical:
+ __kmp_str_buf_print(buffer, "%s,%d", "logical", __kmp_affinity_offset);
+ break;
+ case affinity_compact:
+ __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", __kmp_affinity_compact,
+ __kmp_affinity_offset);
+ break;
+ case affinity_scatter:
+ __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", __kmp_affinity_compact,
+ __kmp_affinity_offset);
+ break;
+ case affinity_explicit:
+ __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist",
+ __kmp_affinity_proclist, "explicit");
+ break;
+ case affinity_balanced:
+ __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced",
+ __kmp_affinity_compact, __kmp_affinity_offset);
+ break;
+ case affinity_disabled:
+ __kmp_str_buf_print(buffer, "%s", "disabled");
+ break;
+ case affinity_default:
+ __kmp_str_buf_print(buffer, "%s", "default");
+ break;
+ default:
+ __kmp_str_buf_print(buffer, "%s", "<unknown>");
+ break;
}
- __kmp_str_buf_print( buffer, "'\n" );
+ __kmp_str_buf_print(buffer, "'\n");
} //__kmp_stg_print_affinity
-# ifdef KMP_GOMP_COMPAT
-
-static void
-__kmp_stg_parse_gomp_cpu_affinity( char const * name, char const * value, void * data )
-{
- const char * next = NULL;
- char * temp_proclist;
- kmp_setting_t **rivals = (kmp_setting_t **) data;
- int rc;
+#ifdef KMP_GOMP_COMPAT
- rc = __kmp_stg_check_rivals( name, value, rivals );
- if ( rc ) {
- return;
- }
+static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
+ char const *value, void *data) {
+ const char *next = NULL;
+ char *temp_proclist;
+ kmp_setting_t **rivals = (kmp_setting_t **)data;
+ int rc;
+
+ rc = __kmp_stg_check_rivals(name, value, rivals);
+ if (rc) {
+ return;
+ }
- if ( TCR_4(__kmp_init_middle) ) {
- KMP_WARNING( EnvMiddleWarn, name );
- __kmp_env_toPrint( name, 0 );
- return;
- }
+ if (TCR_4(__kmp_init_middle)) {
+ KMP_WARNING(EnvMiddleWarn, name);
+ __kmp_env_toPrint(name, 0);
+ return;
+ }
- __kmp_env_toPrint( name, 1 );
+ __kmp_env_toPrint(name, 1);
- if ( __kmp_parse_affinity_proc_id_list( name, value, &next,
- &temp_proclist )) {
- SKIP_WS(next);
- if (*next == '\0') {
- //
- // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
- //
- __kmp_affinity_proclist = temp_proclist;
- __kmp_affinity_type = affinity_explicit;
- __kmp_affinity_gran = affinity_gran_fine;
-# if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
-# endif
- }
- else {
- KMP_WARNING( AffSyntaxError, name );
- if (temp_proclist != NULL) {
- KMP_INTERNAL_FREE((void *)temp_proclist);
- }
- }
- }
- else {
- //
- // Warning already emitted
- //
- __kmp_affinity_type = affinity_none;
-# if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
-# endif
+ if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
+ SKIP_WS(next);
+ if (*next == '\0') {
+ // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
+ __kmp_affinity_proclist = temp_proclist;
+ __kmp_affinity_type = affinity_explicit;
+ __kmp_affinity_gran = affinity_gran_fine;
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
+#endif
+ } else {
+ KMP_WARNING(AffSyntaxError, name);
+ if (temp_proclist != NULL) {
+ KMP_INTERNAL_FREE((void *)temp_proclist);
+ }
}
+ } else {
+ // Warning already emitted
+ __kmp_affinity_type = affinity_none;
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
+#endif
+ }
} // __kmp_stg_parse_gomp_cpu_affinity
-# endif /* KMP_GOMP_COMPAT */
-
+#endif /* KMP_GOMP_COMPAT */
-# if OMP_40_ENABLED
+#if OMP_40_ENABLED
/*-----------------------------------------------------------------------------
-
The OMP_PLACES proc id list parser. Here is the grammar:
place_list := place
@@ -2524,1775 +2410,1654 @@ subplace := num : num : signed
signed := num
signed := + signed
signed := - signed
-
-----------------------------------------------------------------------------*/
-static int
-__kmp_parse_subplace_list( const char *var, const char **scan )
-{
- const char *next;
+static int __kmp_parse_subplace_list(const char *var, const char **scan) {
+ const char *next;
- for (;;) {
- int start, count, stride;
-
- //
- // Read in the starting proc id
- //
- SKIP_WS(*scan);
- if ((**scan < '0') || (**scan > '9')) {
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
- }
- next = *scan;
- SKIP_DIGITS(next);
- start = __kmp_str_to_int(*scan, *next);
- KMP_ASSERT(start >= 0);
- *scan = next;
-
- //
- // valid follow sets are ',' ':' and '}'
- //
- SKIP_WS(*scan);
- if (**scan == '}') {
- break;
- }
- if (**scan == ',') {
- (*scan)++; // skip ','
- continue;
- }
- if (**scan != ':') {
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
- }
- (*scan)++; // skip ':'
-
- //
- // Read count parameter
- //
- SKIP_WS(*scan);
- if ((**scan < '0') || (**scan > '9')) {
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
- }
- next = *scan;
- SKIP_DIGITS(next);
- count = __kmp_str_to_int(*scan, *next);
- KMP_ASSERT(count >= 0);
- *scan = next;
-
- //
- // valid follow sets are ',' ':' and '}'
- //
- SKIP_WS(*scan);
- if (**scan == '}') {
- break;
- }
- if (**scan == ',') {
- (*scan)++; // skip ','
- continue;
- }
- if (**scan != ':') {
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
- }
- (*scan)++; // skip ':'
-
- //
- // Read stride parameter
- //
- int sign = +1;
- for (;;) {
- SKIP_WS(*scan);
- if (**scan == '+') {
- (*scan)++; // skip '+'
- continue;
- }
- if (**scan == '-') {
- sign *= -1;
- (*scan)++; // skip '-'
- continue;
- }
- break;
- }
- SKIP_WS(*scan);
- if ((**scan < '0') || (**scan > '9')) {
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
- }
- next = *scan;
- SKIP_DIGITS(next);
- stride = __kmp_str_to_int(*scan, *next);
- KMP_ASSERT(stride >= 0);
- *scan = next;
- stride *= sign;
-
- //
- // valid follow sets are ',' and '}'
- //
- SKIP_WS(*scan);
- if (**scan == '}') {
- break;
- }
- if (**scan == ',') {
- (*scan)++; // skip ','
- continue;
- }
-
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
- }
- return TRUE;
-}
-
-static int
-__kmp_parse_place( const char *var, const char ** scan )
-{
- const char *next;
+ for (;;) {
+ int start, count, stride;
//
- // valid follow sets are '{' '!' and num
+ // Read in the starting proc id
//
SKIP_WS(*scan);
- if (**scan == '{') {
- (*scan)++; // skip '{'
- if (! __kmp_parse_subplace_list(var, scan)) {
- return FALSE;
- }
- if (**scan != '}') {
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
- }
- (*scan)++; // skip '}'
+ if ((**scan < '0') || (**scan > '9')) {
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
}
- else if (**scan == '!') {
- (*scan)++; // skip '!'
- return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
+ next = *scan;
+ SKIP_DIGITS(next);
+ start = __kmp_str_to_int(*scan, *next);
+ KMP_ASSERT(start >= 0);
+ *scan = next;
+
+ // valid follow sets are ',' ':' and '}'
+ SKIP_WS(*scan);
+ if (**scan == '}') {
+ break;
}
- else if ((**scan >= '0') && (**scan <= '9')) {
- next = *scan;
- SKIP_DIGITS(next);
- int proc = __kmp_str_to_int(*scan, *next);
- KMP_ASSERT(proc >= 0);
- *scan = next;
+ if (**scan == ',') {
+ (*scan)++; // skip ','
+ continue;
}
- else {
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
+ if (**scan != ':') {
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
}
- return TRUE;
-}
-
-static int
-__kmp_parse_place_list( const char *var, const char *env, char **place_list )
-{
- const char *scan = env;
- const char *next = scan;
-
- for (;;) {
- int start, count, stride;
-
- if (! __kmp_parse_place(var, &scan)) {
- return FALSE;
- }
-
- //
- // valid follow sets are ',' ':' and EOL
- //
- SKIP_WS(scan);
- if (*scan == '\0') {
- break;
- }
- if (*scan == ',') {
- scan++; // skip ','
- continue;
- }
- if (*scan != ':') {
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
- }
- scan++; // skip ':'
-
- //
- // Read count parameter
- //
- SKIP_WS(scan);
- if ((*scan < '0') || (*scan > '9')) {
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
- }
- next = scan;
- SKIP_DIGITS(next);
- count = __kmp_str_to_int(scan, *next);
- KMP_ASSERT(count >= 0);
- scan = next;
-
- //
- // valid follow sets are ',' ':' and EOL
- //
- SKIP_WS(scan);
- if (*scan == '\0') {
- break;
- }
- if (*scan == ',') {
- scan++; // skip ','
- continue;
- }
- if (*scan != ':') {
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
- }
- scan++; // skip ':'
+ (*scan)++; // skip ':'
- //
- // Read stride parameter
- //
- int sign = +1;
- for (;;) {
- SKIP_WS(scan);
- if (*scan == '+') {
- scan++; // skip '+'
- continue;
- }
- if (*scan == '-') {
- sign *= -1;
- scan++; // skip '-'
- continue;
- }
- break;
- }
- SKIP_WS(scan);
- if ((*scan < '0') || (*scan > '9')) {
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
- }
- next = scan;
- SKIP_DIGITS(next);
- stride = __kmp_str_to_int(scan, *next);
- KMP_ASSERT(stride >= 0);
- scan = next;
- stride *= sign;
+ // Read count parameter
+ SKIP_WS(*scan);
+ if ((**scan < '0') || (**scan > '9')) {
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
+ }
+ next = *scan;
+ SKIP_DIGITS(next);
+ count = __kmp_str_to_int(*scan, *next);
+ KMP_ASSERT(count >= 0);
+ *scan = next;
- //
- // valid follow sets are ',' and EOL
- //
- SKIP_WS(scan);
- if (*scan == '\0') {
- break;
- }
- if (*scan == ',') {
- scan++; // skip ','
- continue;
- }
+ // valid follow sets are ',' ':' and '}'
+ SKIP_WS(*scan);
+ if (**scan == '}') {
+ break;
+ }
+ if (**scan == ',') {
+ (*scan)++; // skip ','
+ continue;
+ }
+ if (**scan != ':') {
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
+ }
+ (*scan)++; // skip ':'
- KMP_WARNING( SyntaxErrorUsing, var, "\"threads\"" );
- return FALSE;
+ // Read stride parameter
+ int sign = +1;
+ for (;;) {
+ SKIP_WS(*scan);
+ if (**scan == '+') {
+ (*scan)++; // skip '+'
+ continue;
+ }
+ if (**scan == '-') {
+ sign *= -1;
+ (*scan)++; // skip '-'
+ continue;
+ }
+ break;
}
+ SKIP_WS(*scan);
+ if ((**scan < '0') || (**scan > '9')) {
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
+ }
+ next = *scan;
+ SKIP_DIGITS(next);
+ stride = __kmp_str_to_int(*scan, *next);
+ KMP_ASSERT(stride >= 0);
+ *scan = next;
+ stride *= sign;
- {
- int len = scan - env;
- char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
- KMP_MEMCPY_S(retlist, (len+1)*sizeof(char), env, len * sizeof(char));
- retlist[len] = '\0';
- *place_list = retlist;
+ // valid follow sets are ',' and '}'
+ SKIP_WS(*scan);
+ if (**scan == '}') {
+ break;
+ }
+ if (**scan == ',') {
+ (*scan)++; // skip ','
+ continue;
}
- return TRUE;
-}
-static void
-__kmp_stg_parse_places( char const * name, char const * value, void * data )
-{
- int count;
- const char *scan = value;
- const char *next = scan;
- const char *kind = "\"threads\"";
- kmp_setting_t **rivals = (kmp_setting_t **) data;
- int rc;
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
+ }
+ return TRUE;
+}
- rc = __kmp_stg_check_rivals( name, value, rivals );
- if ( rc ) {
- return;
- }
+static int __kmp_parse_place(const char *var, const char **scan) {
+ const char *next;
- //
- // If OMP_PROC_BIND is not specified but OMP_PLACES is,
- // then let OMP_PROC_BIND default to true.
- //
- if ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_default ) {
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
- }
+ // valid follow sets are '{' '!' and num
+ SKIP_WS(*scan);
+ if (**scan == '{') {
+ (*scan)++; // skip '{'
+ if (!__kmp_parse_subplace_list(var, scan)) {
+ return FALSE;
+ }
+ if (**scan != '}') {
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
+ }
+ (*scan)++; // skip '}'
+ } else if (**scan == '!') {
+ (*scan)++; // skip '!'
+ return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
+ } else if ((**scan >= '0') && (**scan <= '9')) {
+ next = *scan;
+ SKIP_DIGITS(next);
+ int proc = __kmp_str_to_int(*scan, *next);
+ KMP_ASSERT(proc >= 0);
+ *scan = next;
+ } else {
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
+ }
+ return TRUE;
+}
- //__kmp_affinity_num_places = 0;
+static int __kmp_parse_place_list(const char *var, const char *env,
+ char **place_list) {
+ const char *scan = env;
+ const char *next = scan;
- if ( __kmp_match_str( "threads", scan, &next ) ) {
- scan = next;
- __kmp_affinity_type = affinity_compact;
- __kmp_affinity_gran = affinity_gran_thread;
- __kmp_affinity_dups = FALSE;
- kind = "\"threads\"";
- }
- else if ( __kmp_match_str( "cores", scan, &next ) ) {
- scan = next;
- __kmp_affinity_type = affinity_compact;
- __kmp_affinity_gran = affinity_gran_core;
- __kmp_affinity_dups = FALSE;
- kind = "\"cores\"";
- }
- else if ( __kmp_match_str( "sockets", scan, &next ) ) {
- scan = next;
- __kmp_affinity_type = affinity_compact;
- __kmp_affinity_gran = affinity_gran_package;
- __kmp_affinity_dups = FALSE;
- kind = "\"sockets\"";
- }
- else {
- if ( __kmp_affinity_proclist != NULL ) {
- KMP_INTERNAL_FREE( (void *)__kmp_affinity_proclist );
- __kmp_affinity_proclist = NULL;
- }
- if ( __kmp_parse_place_list( name, value, &__kmp_affinity_proclist ) ) {
- __kmp_affinity_type = affinity_explicit;
- __kmp_affinity_gran = affinity_gran_fine;
- __kmp_affinity_dups = FALSE;
- if ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_default ) {
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
- }
- }
- return;
- }
+ for (;;) {
+ int start, count, stride;
- if ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_default ) {
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
+ if (!__kmp_parse_place(var, &scan)) {
+ return FALSE;
}
+ // valid follow sets are ',' ':' and EOL
SKIP_WS(scan);
- if ( *scan == '\0' ) {
- return;
+ if (*scan == '\0') {
+ break;
}
-
- //
- // Parse option count parameter in parentheses
- //
- if ( *scan != '(' ) {
- KMP_WARNING( SyntaxErrorUsing, name, kind );
- return;
+ if (*scan == ',') {
+ scan++; // skip ','
+ continue;
}
- scan++; // skip '('
+ if (*scan != ':') {
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
+ }
+ scan++; // skip ':'
+ // Read count parameter
SKIP_WS(scan);
+ if ((*scan < '0') || (*scan > '9')) {
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
+ }
next = scan;
SKIP_DIGITS(next);
count = __kmp_str_to_int(scan, *next);
KMP_ASSERT(count >= 0);
scan = next;
+ // valid follow sets are ',' ':' and EOL
SKIP_WS(scan);
- if ( *scan != ')' ) {
- KMP_WARNING( SyntaxErrorUsing, name, kind );
- return;
+ if (*scan == '\0') {
+ break;
}
- scan++; // skip ')'
-
- SKIP_WS(scan);
- if ( *scan != '\0' ) {
- KMP_WARNING( ParseExtraCharsWarn, name, scan );
+ if (*scan == ',') {
+ scan++; // skip ','
+ continue;
+ }
+ if (*scan != ':') {
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
}
- __kmp_affinity_num_places = count;
-}
+ scan++; // skip ':'
-static void
-__kmp_stg_print_places( kmp_str_buf_t * buffer, char const * name,
- void * data )
-{
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME;
- } else {
- __kmp_str_buf_print( buffer, " %s", name );
+ // Read stride parameter
+ int sign = +1;
+ for (;;) {
+ SKIP_WS(scan);
+ if (*scan == '+') {
+ scan++; // skip '+'
+ continue;
+ }
+ if (*scan == '-') {
+ sign *= -1;
+ scan++; // skip '-'
+ continue;
+ }
+ break;
}
- if ( ( __kmp_nested_proc_bind.used == 0 )
- || ( __kmp_nested_proc_bind.bind_types == NULL )
- || ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_false ) ) {
- __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
- }
- else if ( __kmp_affinity_type == affinity_explicit ) {
- if ( __kmp_affinity_proclist != NULL ) {
- __kmp_str_buf_print( buffer, "='%s'\n", __kmp_affinity_proclist );
- }
- else {
- __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
- }
+ SKIP_WS(scan);
+ if ((*scan < '0') || (*scan > '9')) {
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
}
- else if ( __kmp_affinity_type == affinity_compact ) {
- int num;
- if ( __kmp_affinity_num_masks > 0 ) {
- num = __kmp_affinity_num_masks;
- }
- else if ( __kmp_affinity_num_places > 0 ) {
- num = __kmp_affinity_num_places;
- }
- else {
- num = 0;
- }
- if ( __kmp_affinity_gran == affinity_gran_thread ) {
- if ( num > 0 ) {
- __kmp_str_buf_print( buffer, "='threads(%d)'\n", num );
- }
- else {
- __kmp_str_buf_print( buffer, "='threads'\n" );
- }
- }
- else if ( __kmp_affinity_gran == affinity_gran_core ) {
- if ( num > 0 ) {
- __kmp_str_buf_print( buffer, "='cores(%d)' \n", num );
- }
- else {
- __kmp_str_buf_print( buffer, "='cores'\n" );
- }
- }
- else if ( __kmp_affinity_gran == affinity_gran_package ) {
- if ( num > 0 ) {
- __kmp_str_buf_print( buffer, "='sockets(%d)'\n", num );
- }
- else {
- __kmp_str_buf_print( buffer, "='sockets'\n" );
- }
- }
- else {
- __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
- }
+ next = scan;
+ SKIP_DIGITS(next);
+ stride = __kmp_str_to_int(scan, *next);
+ KMP_ASSERT(stride >= 0);
+ scan = next;
+ stride *= sign;
+
+ // valid follow sets are ',' and EOL
+ SKIP_WS(scan);
+ if (*scan == '\0') {
+ break;
}
- else {
- __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
+ if (*scan == ',') {
+ scan++; // skip ','
+ continue;
}
+
+ KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
+ return FALSE;
+ }
+
+ {
+ int len = scan - env;
+ char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
+ KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
+ retlist[len] = '\0';
+ *place_list = retlist;
+ }
+ return TRUE;
}
-# endif /* OMP_40_ENABLED */
+static void __kmp_stg_parse_places(char const *name, char const *value,
+ void *data) {
+ int count;
+ const char *scan = value;
+ const char *next = scan;
+ const char *kind = "\"threads\"";
+ kmp_setting_t **rivals = (kmp_setting_t **)data;
+ int rc;
+
+ rc = __kmp_stg_check_rivals(name, value, rivals);
+ if (rc) {
+ return;
+ }
-# if (! OMP_40_ENABLED)
+ // If OMP_PROC_BIND is not specified but OMP_PLACES is,
+ // then let OMP_PROC_BIND default to true.
+ if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
+ }
-static void
-__kmp_stg_parse_proc_bind( char const * name, char const * value, void * data )
-{
- int enabled;
- kmp_setting_t **rivals = (kmp_setting_t **) data;
- int rc;
+ //__kmp_affinity_num_places = 0;
- rc = __kmp_stg_check_rivals( name, value, rivals );
- if ( rc ) {
- return;
+ if (__kmp_match_str("threads", scan, &next)) {
+ scan = next;
+ __kmp_affinity_type = affinity_compact;
+ __kmp_affinity_gran = affinity_gran_thread;
+ __kmp_affinity_dups = FALSE;
+ kind = "\"threads\"";
+ } else if (__kmp_match_str("cores", scan, &next)) {
+ scan = next;
+ __kmp_affinity_type = affinity_compact;
+ __kmp_affinity_gran = affinity_gran_core;
+ __kmp_affinity_dups = FALSE;
+ kind = "\"cores\"";
+ } else if (__kmp_match_str("sockets", scan, &next)) {
+ scan = next;
+ __kmp_affinity_type = affinity_compact;
+ __kmp_affinity_gran = affinity_gran_package;
+ __kmp_affinity_dups = FALSE;
+ kind = "\"sockets\"";
+ } else {
+ if (__kmp_affinity_proclist != NULL) {
+ KMP_INTERNAL_FREE((void *)__kmp_affinity_proclist);
+ __kmp_affinity_proclist = NULL;
+ }
+ if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
+ __kmp_affinity_type = affinity_explicit;
+ __kmp_affinity_gran = affinity_gran_fine;
+ __kmp_affinity_dups = FALSE;
+ if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
+ }
}
+ return;
+ }
- //
- // in OMP 3.1, OMP_PROC_BIND is strictly a boolean
- //
- __kmp_stg_parse_bool( name, value, & enabled );
- if ( enabled ) {
- //
- // OMP_PROC_BIND => granularity=fine,scatter on MIC
- // OMP_PROC_BIND => granularity=core,scatter elsewhere
- //
- __kmp_affinity_type = affinity_scatter;
-# if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
- if( __kmp_mic_type != non_mic )
- __kmp_affinity_gran = affinity_gran_fine;
- else
-# endif
- __kmp_affinity_gran = affinity_gran_core;
- }
- else {
- __kmp_affinity_type = affinity_none;
- }
-} // __kmp_parse_proc_bind
+ if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
+ }
+
+ SKIP_WS(scan);
+ if (*scan == '\0') {
+ return;
+ }
+
+ // Parse option count parameter in parentheses
+ if (*scan != '(') {
+ KMP_WARNING(SyntaxErrorUsing, name, kind);
+ return;
+ }
+ scan++; // skip '('
-# endif /* if (! OMP_40_ENABLED) */
+ SKIP_WS(scan);
+ next = scan;
+ SKIP_DIGITS(next);
+ count = __kmp_str_to_int(scan, *next);
+ KMP_ASSERT(count >= 0);
+ scan = next;
+
+ SKIP_WS(scan);
+ if (*scan != ')') {
+ KMP_WARNING(SyntaxErrorUsing, name, kind);
+ return;
+ }
+ scan++; // skip ')'
+ SKIP_WS(scan);
+ if (*scan != '\0') {
+ KMP_WARNING(ParseExtraCharsWarn, name, scan);
+ }
+ __kmp_affinity_num_places = count;
+}
-static void
-__kmp_stg_parse_topology_method( char const * name, char const * value,
- void * data ) {
- if ( __kmp_str_match( "all", 1, value ) ) {
- __kmp_affinity_top_method = affinity_top_method_all;
- }
-# if KMP_ARCH_X86 || KMP_ARCH_X86_64
- else if ( __kmp_str_match( "x2apic id", 9, value )
- || __kmp_str_match( "x2apic_id", 9, value )
- || __kmp_str_match( "x2apic-id", 9, value )
- || __kmp_str_match( "x2apicid", 8, value )
- || __kmp_str_match( "cpuid leaf 11", 13, value )
- || __kmp_str_match( "cpuid_leaf_11", 13, value )
- || __kmp_str_match( "cpuid-leaf-11", 13, value )
- || __kmp_str_match( "cpuid leaf11", 12, value )
- || __kmp_str_match( "cpuid_leaf11", 12, value )
- || __kmp_str_match( "cpuid-leaf11", 12, value )
- || __kmp_str_match( "cpuidleaf 11", 12, value )
- || __kmp_str_match( "cpuidleaf_11", 12, value )
- || __kmp_str_match( "cpuidleaf-11", 12, value )
- || __kmp_str_match( "cpuidleaf11", 11, value )
- || __kmp_str_match( "cpuid 11", 8, value )
- || __kmp_str_match( "cpuid_11", 8, value )
- || __kmp_str_match( "cpuid-11", 8, value )
- || __kmp_str_match( "cpuid11", 7, value )
- || __kmp_str_match( "leaf 11", 7, value )
- || __kmp_str_match( "leaf_11", 7, value )
- || __kmp_str_match( "leaf-11", 7, value )
- || __kmp_str_match( "leaf11", 6, value ) ) {
- __kmp_affinity_top_method = affinity_top_method_x2apicid;
- }
- else if ( __kmp_str_match( "apic id", 7, value )
- || __kmp_str_match( "apic_id", 7, value )
- || __kmp_str_match( "apic-id", 7, value )
- || __kmp_str_match( "apicid", 6, value )
- || __kmp_str_match( "cpuid leaf 4", 12, value )
- || __kmp_str_match( "cpuid_leaf_4", 12, value )
- || __kmp_str_match( "cpuid-leaf-4", 12, value )
- || __kmp_str_match( "cpuid leaf4", 11, value )
- || __kmp_str_match( "cpuid_leaf4", 11, value )
- || __kmp_str_match( "cpuid-leaf4", 11, value )
- || __kmp_str_match( "cpuidleaf 4", 11, value )
- || __kmp_str_match( "cpuidleaf_4", 11, value )
- || __kmp_str_match( "cpuidleaf-4", 11, value )
- || __kmp_str_match( "cpuidleaf4", 10, value )
- || __kmp_str_match( "cpuid 4", 7, value )
- || __kmp_str_match( "cpuid_4", 7, value )
- || __kmp_str_match( "cpuid-4", 7, value )
- || __kmp_str_match( "cpuid4", 6, value )
- || __kmp_str_match( "leaf 4", 6, value )
- || __kmp_str_match( "leaf_4", 6, value )
- || __kmp_str_match( "leaf-4", 6, value )
- || __kmp_str_match( "leaf4", 5, value ) ) {
- __kmp_affinity_top_method = affinity_top_method_apicid;
- }
-# endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
- else if ( __kmp_str_match( "/proc/cpuinfo", 2, value )
- || __kmp_str_match( "cpuinfo", 5, value )) {
- __kmp_affinity_top_method = affinity_top_method_cpuinfo;
- }
-# if KMP_GROUP_AFFINITY
- else if ( __kmp_str_match( "group", 1, value ) ) {
- __kmp_affinity_top_method = affinity_top_method_group;
- }
-# endif /* KMP_GROUP_AFFINITY */
- else if ( __kmp_str_match( "flat", 1, value ) ) {
- __kmp_affinity_top_method = affinity_top_method_flat;
+static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME;
+ } else {
+ __kmp_str_buf_print(buffer, " %s", name);
+ }
+ if ((__kmp_nested_proc_bind.used == 0) ||
+ (__kmp_nested_proc_bind.bind_types == NULL) ||
+ (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
+ __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
+ } else if (__kmp_affinity_type == affinity_explicit) {
+ if (__kmp_affinity_proclist != NULL) {
+ __kmp_str_buf_print(buffer, "='%s'\n", __kmp_affinity_proclist);
+ } else {
+ __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
}
-# if KMP_USE_HWLOC
- else if ( __kmp_str_match( "hwloc", 1, value) ) {
- __kmp_affinity_top_method = affinity_top_method_hwloc;
+ } else if (__kmp_affinity_type == affinity_compact) {
+ int num;
+ if (__kmp_affinity_num_masks > 0) {
+ num = __kmp_affinity_num_masks;
+ } else if (__kmp_affinity_num_places > 0) {
+ num = __kmp_affinity_num_places;
+ } else {
+ num = 0;
}
-# endif
- else {
- KMP_WARNING( StgInvalidValue, name, value );
+ if (__kmp_affinity_gran == affinity_gran_thread) {
+ if (num > 0) {
+ __kmp_str_buf_print(buffer, "='threads(%d)'\n", num);
+ } else {
+ __kmp_str_buf_print(buffer, "='threads'\n");
+ }
+ } else if (__kmp_affinity_gran == affinity_gran_core) {
+ if (num > 0) {
+ __kmp_str_buf_print(buffer, "='cores(%d)' \n", num);
+ } else {
+ __kmp_str_buf_print(buffer, "='cores'\n");
+ }
+ } else if (__kmp_affinity_gran == affinity_gran_package) {
+ if (num > 0) {
+ __kmp_str_buf_print(buffer, "='sockets(%d)'\n", num);
+ } else {
+ __kmp_str_buf_print(buffer, "='sockets'\n");
+ }
+ } else {
+ __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
}
-} // __kmp_stg_parse_topology_method
+ } else {
+ __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
+ }
+}
+
+#endif /* OMP_40_ENABLED */
+
+#if (!OMP_40_ENABLED)
+
+static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
+ void *data) {
+ int enabled;
+ kmp_setting_t **rivals = (kmp_setting_t **)data;
+ int rc;
+
+ rc = __kmp_stg_check_rivals(name, value, rivals);
+ if (rc) {
+ return;
+ }
+
+ // In OMP 3.1, OMP_PROC_BIND is strictly a boolean
+ __kmp_stg_parse_bool(name, value, &enabled);
+ if (enabled) {
+ // OMP_PROC_BIND => granularity=fine,scatter on MIC
+ // OMP_PROC_BIND => granularity=core,scatter elsewhere
+ __kmp_affinity_type = affinity_scatter;
+#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
+ if (__kmp_mic_type != non_mic)
+ __kmp_affinity_gran = affinity_gran_fine;
+ else
+#endif
+ __kmp_affinity_gran = affinity_gran_core;
+ } else {
+ __kmp_affinity_type = affinity_none;
+ }
+} // __kmp_parse_proc_bind
-static void
-__kmp_stg_print_topology_method( kmp_str_buf_t * buffer, char const * name,
- void * data ) {
-# if KMP_DEBUG
- char const * value = NULL;
-
- switch ( __kmp_affinity_top_method ) {
- case affinity_top_method_default:
- value = "default";
- break;
+#endif /* if (! OMP_40_ENABLED) */
- case affinity_top_method_all:
- value = "all";
- break;
+static void __kmp_stg_parse_topology_method(char const *name, char const *value,
+ void *data) {
+ if (__kmp_str_match("all", 1, value)) {
+ __kmp_affinity_top_method = affinity_top_method_all;
+ }
+#if KMP_ARCH_X86 || KMP_ARCH_X86_64
+ else if (__kmp_str_match("x2apic id", 9, value) ||
+ __kmp_str_match("x2apic_id", 9, value) ||
+ __kmp_str_match("x2apic-id", 9, value) ||
+ __kmp_str_match("x2apicid", 8, value) ||
+ __kmp_str_match("cpuid leaf 11", 13, value) ||
+ __kmp_str_match("cpuid_leaf_11", 13, value) ||
+ __kmp_str_match("cpuid-leaf-11", 13, value) ||
+ __kmp_str_match("cpuid leaf11", 12, value) ||
+ __kmp_str_match("cpuid_leaf11", 12, value) ||
+ __kmp_str_match("cpuid-leaf11", 12, value) ||
+ __kmp_str_match("cpuidleaf 11", 12, value) ||
+ __kmp_str_match("cpuidleaf_11", 12, value) ||
+ __kmp_str_match("cpuidleaf-11", 12, value) ||
+ __kmp_str_match("cpuidleaf11", 11, value) ||
+ __kmp_str_match("cpuid 11", 8, value) ||
+ __kmp_str_match("cpuid_11", 8, value) ||
+ __kmp_str_match("cpuid-11", 8, value) ||
+ __kmp_str_match("cpuid11", 7, value) ||
+ __kmp_str_match("leaf 11", 7, value) ||
+ __kmp_str_match("leaf_11", 7, value) ||
+ __kmp_str_match("leaf-11", 7, value) ||
+ __kmp_str_match("leaf11", 6, value)) {
+ __kmp_affinity_top_method = affinity_top_method_x2apicid;
+ } else if (__kmp_str_match("apic id", 7, value) ||
+ __kmp_str_match("apic_id", 7, value) ||
+ __kmp_str_match("apic-id", 7, value) ||
+ __kmp_str_match("apicid", 6, value) ||
+ __kmp_str_match("cpuid leaf 4", 12, value) ||
+ __kmp_str_match("cpuid_leaf_4", 12, value) ||
+ __kmp_str_match("cpuid-leaf-4", 12, value) ||
+ __kmp_str_match("cpuid leaf4", 11, value) ||
+ __kmp_str_match("cpuid_leaf4", 11, value) ||
+ __kmp_str_match("cpuid-leaf4", 11, value) ||
+ __kmp_str_match("cpuidleaf 4", 11, value) ||
+ __kmp_str_match("cpuidleaf_4", 11, value) ||
+ __kmp_str_match("cpuidleaf-4", 11, value) ||
+ __kmp_str_match("cpuidleaf4", 10, value) ||
+ __kmp_str_match("cpuid 4", 7, value) ||
+ __kmp_str_match("cpuid_4", 7, value) ||
+ __kmp_str_match("cpuid-4", 7, value) ||
+ __kmp_str_match("cpuid4", 6, value) ||
+ __kmp_str_match("leaf 4", 6, value) ||
+ __kmp_str_match("leaf_4", 6, value) ||
+ __kmp_str_match("leaf-4", 6, value) ||
+ __kmp_str_match("leaf4", 5, value)) {
+ __kmp_affinity_top_method = affinity_top_method_apicid;
+ }
+#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
+ else if (__kmp_str_match("/proc/cpuinfo", 2, value) ||
+ __kmp_str_match("cpuinfo", 5, value)) {
+ __kmp_affinity_top_method = affinity_top_method_cpuinfo;
+ }
+#if KMP_GROUP_AFFINITY
+ else if (__kmp_str_match("group", 1, value)) {
+ __kmp_affinity_top_method = affinity_top_method_group;
+ }
+#endif /* KMP_GROUP_AFFINITY */
+ else if (__kmp_str_match("flat", 1, value)) {
+ __kmp_affinity_top_method = affinity_top_method_flat;
+ }
+#if KMP_USE_HWLOC
+ else if (__kmp_str_match("hwloc", 1, value)) {
+ __kmp_affinity_top_method = affinity_top_method_hwloc;
+ }
+#endif
+ else {
+ KMP_WARNING(StgInvalidValue, name, value);
+ }
+} // __kmp_stg_parse_topology_method
-# if KMP_ARCH_X86 || KMP_ARCH_X86_64
- case affinity_top_method_x2apicid:
- value = "x2APIC id";
- break;
+static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+#if KMP_DEBUG
+ char const *value = NULL;
- case affinity_top_method_apicid:
- value = "APIC id";
- break;
-# endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
+ switch (__kmp_affinity_top_method) {
+ case affinity_top_method_default:
+ value = "default";
+ break;
+
+ case affinity_top_method_all:
+ value = "all";
+ break;
+
+#if KMP_ARCH_X86 || KMP_ARCH_X86_64
+ case affinity_top_method_x2apicid:
+ value = "x2APIC id";
+ break;
+
+ case affinity_top_method_apicid:
+ value = "APIC id";
+ break;
+#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
# if KMP_USE_HWLOC
- case affinity_top_method_hwloc:
- value = "hwloc";
- break;
+ case affinity_top_method_hwloc:
+ value = "hwloc";
+ break;
# endif
- case affinity_top_method_cpuinfo:
- value = "cpuinfo";
- break;
-
-# if KMP_GROUP_AFFINITY
- case affinity_top_method_group:
- value = "group";
- break;
-# endif /* KMP_GROUP_AFFINITY */
-
- case affinity_top_method_flat:
- value = "flat";
- break;
- }
+ case affinity_top_method_cpuinfo:
+ value = "cpuinfo";
+ break;
+
+#if KMP_GROUP_AFFINITY
+ case affinity_top_method_group:
+ value = "group";
+ break;
+#endif /* KMP_GROUP_AFFINITY */
+
+ case affinity_top_method_flat:
+ value = "flat";
+ break;
+ }
- if ( value != NULL ) {
- __kmp_stg_print_str( buffer, name, value );
- }
-# endif /* KMP_DEBUG */
+ if (value != NULL) {
+ __kmp_stg_print_str(buffer, name, value);
+ }
+#endif /* KMP_DEBUG */
} // __kmp_stg_print_topology_method
#endif /* KMP_AFFINITY_SUPPORTED */
-
#if OMP_40_ENABLED
-//
// OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
// OMP_PLACES / place-partition-var is not.
-//
-static void
-__kmp_stg_parse_proc_bind( char const * name, char const * value, void * data )
-{
- kmp_setting_t **rivals = (kmp_setting_t **) data;
- int rc;
-
- rc = __kmp_stg_check_rivals( name, value, rivals );
- if ( rc ) {
- return;
- }
+static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
+ void *data) {
+ kmp_setting_t **rivals = (kmp_setting_t **)data;
+ int rc;
+
+ rc = __kmp_stg_check_rivals(name, value, rivals);
+ if (rc) {
+ return;
+ }
- //
- // in OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
- //
- KMP_DEBUG_ASSERT( (__kmp_nested_proc_bind.bind_types != NULL)
- && ( __kmp_nested_proc_bind.used > 0 ) );
+ // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
+ KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
+ (__kmp_nested_proc_bind.used > 0));
+
+ const char *buf = value;
+ const char *next;
+ int num;
+ SKIP_WS(buf);
+ if ((*buf >= '0') && (*buf <= '9')) {
+ next = buf;
+ SKIP_DIGITS(next);
+ num = __kmp_str_to_int(buf, *next);
+ KMP_ASSERT(num >= 0);
+ buf = next;
+ SKIP_WS(buf);
+ } else {
+ num = -1;
+ }
- const char *buf = value;
- const char *next;
- int num;
- SKIP_WS( buf );
- if ( (*buf >= '0') && (*buf <= '9') ) {
- next = buf;
- SKIP_DIGITS( next );
- num = __kmp_str_to_int( buf, *next );
- KMP_ASSERT( num >= 0 );
- buf = next;
- SKIP_WS( buf );
+ next = buf;
+ if (__kmp_match_str("disabled", buf, &next)) {
+ buf = next;
+ SKIP_WS(buf);
+#if KMP_AFFINITY_SUPPORTED
+ __kmp_affinity_type = affinity_disabled;
+#endif /* KMP_AFFINITY_SUPPORTED */
+ __kmp_nested_proc_bind.used = 1;
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
+ } else if ((num == (int)proc_bind_false) ||
+ __kmp_match_str("false", buf, &next)) {
+ buf = next;
+ SKIP_WS(buf);
+#if KMP_AFFINITY_SUPPORTED
+ __kmp_affinity_type = affinity_none;
+#endif /* KMP_AFFINITY_SUPPORTED */
+ __kmp_nested_proc_bind.used = 1;
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
+ } else if ((num == (int)proc_bind_true) ||
+ __kmp_match_str("true", buf, &next)) {
+ buf = next;
+ SKIP_WS(buf);
+ __kmp_nested_proc_bind.used = 1;
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
+ } else {
+ // Count the number of values in the env var string
+ const char *scan;
+ int nelem = 1;
+ for (scan = buf; *scan != '\0'; scan++) {
+ if (*scan == ',') {
+ nelem++;
+ }
}
- else {
- num = -1;
+
+ // Create / expand the nested proc_bind array as needed
+ if (__kmp_nested_proc_bind.size < nelem) {
+ __kmp_nested_proc_bind.bind_types =
+ (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
+ __kmp_nested_proc_bind.bind_types,
+ sizeof(kmp_proc_bind_t) * nelem);
+ if (__kmp_nested_proc_bind.bind_types == NULL) {
+ KMP_FATAL(MemoryAllocFailed);
+ }
+ __kmp_nested_proc_bind.size = nelem;
}
+ __kmp_nested_proc_bind.used = nelem;
- next = buf;
- if ( __kmp_match_str( "disabled", buf, &next ) ) {
+ // Save values in the nested proc_bind array
+ int i = 0;
+ for (;;) {
+ enum kmp_proc_bind_t bind;
+
+ if ((num == (int)proc_bind_master) ||
+ __kmp_match_str("master", buf, &next)) {
buf = next;
- SKIP_WS( buf );
-# if KMP_AFFINITY_SUPPORTED
- __kmp_affinity_type = affinity_disabled;
-# endif /* KMP_AFFINITY_SUPPORTED */
- __kmp_nested_proc_bind.used = 1;
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
- }
- else if ( ( num == (int)proc_bind_false )
- || __kmp_match_str( "false", buf, &next ) ) {
+ SKIP_WS(buf);
+ bind = proc_bind_master;
+ } else if ((num == (int)proc_bind_close) ||
+ __kmp_match_str("close", buf, &next)) {
buf = next;
- SKIP_WS( buf );
-# if KMP_AFFINITY_SUPPORTED
- __kmp_affinity_type = affinity_none;
-# endif /* KMP_AFFINITY_SUPPORTED */
- __kmp_nested_proc_bind.used = 1;
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
- }
- else if ( ( num == (int)proc_bind_true )
- || __kmp_match_str( "true", buf, &next ) ) {
+ SKIP_WS(buf);
+ bind = proc_bind_close;
+ } else if ((num == (int)proc_bind_spread) ||
+ __kmp_match_str("spread", buf, &next)) {
buf = next;
- SKIP_WS( buf );
+ SKIP_WS(buf);
+ bind = proc_bind_spread;
+ } else {
+ KMP_WARNING(StgInvalidValue, name, value);
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
__kmp_nested_proc_bind.used = 1;
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
- }
- else {
- //
- // Count the number of values in the env var string
- //
- const char *scan;
- int nelem = 1;
- for ( scan = buf; *scan != '\0'; scan++ ) {
- if ( *scan == ',' ) {
- nelem++;
- }
- }
-
- //
- // Create / expand the nested proc_bind array as needed
- //
- if ( __kmp_nested_proc_bind.size < nelem ) {
- __kmp_nested_proc_bind.bind_types = (kmp_proc_bind_t *)
- KMP_INTERNAL_REALLOC( __kmp_nested_proc_bind.bind_types,
- sizeof(kmp_proc_bind_t) * nelem );
- if ( __kmp_nested_proc_bind.bind_types == NULL ) {
- KMP_FATAL( MemoryAllocFailed );
- }
- __kmp_nested_proc_bind.size = nelem;
- }
- __kmp_nested_proc_bind.used = nelem;
+ return;
+ }
- //
- // Save values in the nested proc_bind array
- //
- int i = 0;
- for (;;) {
- enum kmp_proc_bind_t bind;
-
- if ( ( num == (int)proc_bind_master )
- || __kmp_match_str( "master", buf, &next ) ) {
- buf = next;
- SKIP_WS( buf );
- bind = proc_bind_master;
- }
- else if ( ( num == (int)proc_bind_close )
- || __kmp_match_str( "close", buf, &next ) ) {
- buf = next;
- SKIP_WS( buf );
- bind = proc_bind_close;
- }
- else if ( ( num == (int)proc_bind_spread )
- || __kmp_match_str( "spread", buf, &next ) ) {
- buf = next;
- SKIP_WS( buf );
- bind = proc_bind_spread;
- }
- else {
- KMP_WARNING( StgInvalidValue, name, value );
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
- __kmp_nested_proc_bind.used = 1;
- return;
- }
+ __kmp_nested_proc_bind.bind_types[i++] = bind;
+ if (i >= nelem) {
+ break;
+ }
+ KMP_DEBUG_ASSERT(*buf == ',');
+ buf++;
+ SKIP_WS(buf);
- __kmp_nested_proc_bind.bind_types[i++] = bind;
- if ( i >= nelem ) {
- break;
- }
- KMP_DEBUG_ASSERT( *buf == ',' );
- buf++;
- SKIP_WS( buf );
-
- //
- // Read next value if it was specified as an integer
- //
- if ( (*buf >= '0') && (*buf <= '9') ) {
- next = buf;
- SKIP_DIGITS( next );
- num = __kmp_str_to_int( buf, *next );
- KMP_ASSERT( num >= 0 );
- buf = next;
- SKIP_WS( buf );
- }
- else {
- num = -1;
- }
- }
- SKIP_WS( buf );
- }
- if ( *buf != '\0' ) {
- KMP_WARNING( ParseExtraCharsWarn, name, buf );
+ // Read next value if it was specified as an integer
+ if ((*buf >= '0') && (*buf <= '9')) {
+ next = buf;
+ SKIP_DIGITS(next);
+ num = __kmp_str_to_int(buf, *next);
+ KMP_ASSERT(num >= 0);
+ buf = next;
+ SKIP_WS(buf);
+ } else {
+ num = -1;
+ }
}
+ SKIP_WS(buf);
+ }
+ if (*buf != '\0') {
+ KMP_WARNING(ParseExtraCharsWarn, name, buf);
+ }
}
+static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ int nelem = __kmp_nested_proc_bind.used;
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME;
+ } else {
+ __kmp_str_buf_print(buffer, " %s", name);
+ }
+ if (nelem == 0) {
+ __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
+ } else {
+ int i;
+ __kmp_str_buf_print(buffer, "='", name);
+ for (i = 0; i < nelem; i++) {
+ switch (__kmp_nested_proc_bind.bind_types[i]) {
+ case proc_bind_false:
+ __kmp_str_buf_print(buffer, "false");
+ break;
-static void
-__kmp_stg_print_proc_bind( kmp_str_buf_t * buffer, char const * name,
- void * data )
-{
- int nelem = __kmp_nested_proc_bind.used;
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME;
- } else {
- __kmp_str_buf_print( buffer, " %s", name );
- }
- if ( nelem == 0 ) {
- __kmp_str_buf_print( buffer, ": %s\n", KMP_I18N_STR( NotDefined ) );
- }
- else {
- int i;
- __kmp_str_buf_print( buffer, "='", name );
- for ( i = 0; i < nelem; i++ ) {
- switch ( __kmp_nested_proc_bind.bind_types[i] ) {
- case proc_bind_false:
- __kmp_str_buf_print( buffer, "false" );
- break;
-
- case proc_bind_true:
- __kmp_str_buf_print( buffer, "true" );
- break;
-
- case proc_bind_master:
- __kmp_str_buf_print( buffer, "master" );
- break;
-
- case proc_bind_close:
- __kmp_str_buf_print( buffer, "close" );
- break;
-
- case proc_bind_spread:
- __kmp_str_buf_print( buffer, "spread" );
- break;
-
- case proc_bind_intel:
- __kmp_str_buf_print( buffer, "intel" );
- break;
-
- case proc_bind_default:
- __kmp_str_buf_print( buffer, "default" );
- break;
- }
- if ( i < nelem - 1 ) {
- __kmp_str_buf_print( buffer, "," );
- }
- }
- __kmp_str_buf_print( buffer, "'\n" );
+ case proc_bind_true:
+ __kmp_str_buf_print(buffer, "true");
+ break;
+
+ case proc_bind_master:
+ __kmp_str_buf_print(buffer, "master");
+ break;
+
+ case proc_bind_close:
+ __kmp_str_buf_print(buffer, "close");
+ break;
+
+ case proc_bind_spread:
+ __kmp_str_buf_print(buffer, "spread");
+ break;
+
+ case proc_bind_intel:
+ __kmp_str_buf_print(buffer, "intel");
+ break;
+
+ case proc_bind_default:
+ __kmp_str_buf_print(buffer, "default");
+ break;
+ }
+ if (i < nelem - 1) {
+ __kmp_str_buf_print(buffer, ",");
+ }
}
+ __kmp_str_buf_print(buffer, "'\n");
+ }
}
#endif /* OMP_40_ENABLED */
-
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// OMP_DYNAMIC
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_omp_dynamic( char const * name, char const * value, void * data )
-{
- __kmp_stg_parse_bool( name, value, & (__kmp_global.g.g_dynamic) );
+static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
} // __kmp_stg_parse_omp_dynamic
-static void
-__kmp_stg_print_omp_dynamic( kmp_str_buf_t * buffer, char const * name, void * data )
-{
- __kmp_stg_print_bool( buffer, name, __kmp_global.g.g_dynamic );
+static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
} // __kmp_stg_print_omp_dynamic
-static void
-__kmp_stg_parse_kmp_dynamic_mode( char const * name, char const * value, void * data )
-{
- if ( TCR_4(__kmp_init_parallel) ) {
- KMP_WARNING( EnvParallelWarn, name );
- __kmp_env_toPrint( name, 0 );
- return;
- }
+static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
+ char const *value, void *data) {
+ if (TCR_4(__kmp_init_parallel)) {
+ KMP_WARNING(EnvParallelWarn, name);
+ __kmp_env_toPrint(name, 0);
+ return;
+ }
#ifdef USE_LOAD_BALANCE
- else if ( __kmp_str_match( "load balance", 2, value )
- || __kmp_str_match( "load_balance", 2, value )
- || __kmp_str_match( "load-balance", 2, value )
- || __kmp_str_match( "loadbalance", 2, value )
- || __kmp_str_match( "balance", 1, value ) ) {
- __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
- }
+ else if (__kmp_str_match("load balance", 2, value) ||
+ __kmp_str_match("load_balance", 2, value) ||
+ __kmp_str_match("load-balance", 2, value) ||
+ __kmp_str_match("loadbalance", 2, value) ||
+ __kmp_str_match("balance", 1, value)) {
+ __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
+ }
#endif /* USE_LOAD_BALANCE */
- else if ( __kmp_str_match( "thread limit", 1, value )
- || __kmp_str_match( "thread_limit", 1, value )
- || __kmp_str_match( "thread-limit", 1, value )
- || __kmp_str_match( "threadlimit", 1, value )
- || __kmp_str_match( "limit", 2, value ) ) {
- __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
- }
- else if ( __kmp_str_match( "random", 1, value ) ) {
- __kmp_global.g.g_dynamic_mode = dynamic_random;
- }
- else {
- KMP_WARNING( StgInvalidValue, name, value );
- }
+ else if (__kmp_str_match("thread limit", 1, value) ||
+ __kmp_str_match("thread_limit", 1, value) ||
+ __kmp_str_match("thread-limit", 1, value) ||
+ __kmp_str_match("threadlimit", 1, value) ||
+ __kmp_str_match("limit", 2, value)) {
+ __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
+ } else if (__kmp_str_match("random", 1, value)) {
+ __kmp_global.g.g_dynamic_mode = dynamic_random;
+ } else {
+ KMP_WARNING(StgInvalidValue, name, value);
+ }
} //__kmp_stg_parse_kmp_dynamic_mode
-static void
-__kmp_stg_print_kmp_dynamic_mode( kmp_str_buf_t * buffer, char const * name, void * data )
-{
+static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
#if KMP_DEBUG
- if ( __kmp_global.g.g_dynamic_mode == dynamic_default ) {
- __kmp_str_buf_print( buffer, " %s: %s \n", name, KMP_I18N_STR( NotDefined ) );
- }
-# ifdef USE_LOAD_BALANCE
- else if ( __kmp_global.g.g_dynamic_mode == dynamic_load_balance ) {
- __kmp_stg_print_str( buffer, name, "load balance" );
- }
-# endif /* USE_LOAD_BALANCE */
- else if ( __kmp_global.g.g_dynamic_mode == dynamic_thread_limit ) {
- __kmp_stg_print_str( buffer, name, "thread limit" );
- }
- else if ( __kmp_global.g.g_dynamic_mode == dynamic_random ) {
- __kmp_stg_print_str( buffer, name, "random" );
- }
- else {
- KMP_ASSERT(0);
- }
+ if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
+ __kmp_str_buf_print(buffer, " %s: %s \n", name, KMP_I18N_STR(NotDefined));
+ }
+#ifdef USE_LOAD_BALANCE
+ else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
+ __kmp_stg_print_str(buffer, name, "load balance");
+ }
+#endif /* USE_LOAD_BALANCE */
+ else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
+ __kmp_stg_print_str(buffer, name, "thread limit");
+ } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
+ __kmp_stg_print_str(buffer, name, "random");
+ } else {
+ KMP_ASSERT(0);
+ }
#endif /* KMP_DEBUG */
} // __kmp_stg_print_kmp_dynamic_mode
-
#ifdef USE_LOAD_BALANCE
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_LOAD_BALANCE_INTERVAL
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_ld_balance_interval( char const * name, char const * value, void * data )
-{
- double interval = __kmp_convert_to_double( value );
- if ( interval >= 0 ) {
- __kmp_load_balance_interval = interval;
- } else {
- KMP_WARNING( StgInvalidValue, name, value );
- }; // if
+static void __kmp_stg_parse_ld_balance_interval(char const *name,
+ char const *value, void *data) {
+ double interval = __kmp_convert_to_double(value);
+ if (interval >= 0) {
+ __kmp_load_balance_interval = interval;
+ } else {
+ KMP_WARNING(StgInvalidValue, name, value);
+ }; // if
} // __kmp_stg_parse_load_balance_interval
-static void
-__kmp_stg_print_ld_balance_interval( kmp_str_buf_t * buffer, char const * name, void * data ) {
+static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
#if KMP_DEBUG
- __kmp_str_buf_print( buffer, " %s=%8.6f\n", name, __kmp_load_balance_interval );
+ __kmp_str_buf_print(buffer, " %s=%8.6f\n", name,
+ __kmp_load_balance_interval);
#endif /* KMP_DEBUG */
} // __kmp_stg_print_load_balance_interval
#endif /* USE_LOAD_BALANCE */
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_INIT_AT_FORK
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_init_at_fork( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_bool( name, value, & __kmp_need_register_atfork );
- if ( __kmp_need_register_atfork ) {
- __kmp_need_register_atfork_specified = TRUE;
- };
+static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
+ if (__kmp_need_register_atfork) {
+ __kmp_need_register_atfork_specified = TRUE;
+ };
} // __kmp_stg_parse_init_at_fork
-static void
-__kmp_stg_print_init_at_fork( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_need_register_atfork_specified );
+static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
} // __kmp_stg_print_init_at_fork
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_SCHEDULE
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_schedule( char const * name, char const * value, void * data ) {
+static void __kmp_stg_parse_schedule(char const *name, char const *value,
+ void *data) {
- if ( value != NULL ) {
- size_t length = KMP_STRLEN( value );
- if ( length > INT_MAX ) {
- KMP_WARNING( LongValue, name );
- } else {
- char *semicolon;
- if( value[ length - 1 ] == '"' || value[ length -1 ] == '\'' )
- KMP_WARNING( UnbalancedQuotes, name );
- do {
- char sentinel;
-
- semicolon = (char *) strchr( value, ';' );
- if( *value && semicolon != value ) {
- char *comma = (char *) strchr( value, ',' );
-
- if ( comma ) {
- ++comma;
- sentinel = ',';
- } else
- sentinel = ';';
- if ( !__kmp_strcasecmp_with_sentinel( "static", value, sentinel ) ) {
- if( !__kmp_strcasecmp_with_sentinel( "greedy", comma, ';' ) ) {
- __kmp_static = kmp_sch_static_greedy;
- continue;
- } else if( !__kmp_strcasecmp_with_sentinel( "balanced", comma, ';' ) ) {
- __kmp_static = kmp_sch_static_balanced;
- continue;
- }
- } else if ( !__kmp_strcasecmp_with_sentinel( "guided", value, sentinel ) ) {
- if ( !__kmp_strcasecmp_with_sentinel( "iterative", comma, ';' ) ) {
- __kmp_guided = kmp_sch_guided_iterative_chunked;
- continue;
- } else if ( !__kmp_strcasecmp_with_sentinel( "analytical", comma, ';' ) ) {
- /* analytical not allowed for too many threads */
- __kmp_guided = kmp_sch_guided_analytical_chunked;
- continue;
- }
- }
- KMP_WARNING( InvalidClause, name, value );
- } else
- KMP_WARNING( EmptyClause, name );
- } while ( (value = semicolon ? semicolon + 1 : NULL) );
- }
- }; // if
+ if (value != NULL) {
+ size_t length = KMP_STRLEN(value);
+ if (length > INT_MAX) {
+ KMP_WARNING(LongValue, name);
+ } else {
+ char *semicolon;
+ if (value[length - 1] == '"' || value[length - 1] == '\'')
+ KMP_WARNING(UnbalancedQuotes, name);
+ do {
+ char sentinel;
+
+ semicolon = (char *)strchr(value, ';');
+ if (*value && semicolon != value) {
+ char *comma = (char *)strchr(value, ',');
+
+ if (comma) {
+ ++comma;
+ sentinel = ',';
+ } else
+ sentinel = ';';
+ if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
+ if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
+ __kmp_static = kmp_sch_static_greedy;
+ continue;
+ } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
+ ';')) {
+ __kmp_static = kmp_sch_static_balanced;
+ continue;
+ }
+ } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
+ sentinel)) {
+ if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
+ __kmp_guided = kmp_sch_guided_iterative_chunked;
+ continue;
+ } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
+ ';')) {
+ /* analytical not allowed for too many threads */
+ __kmp_guided = kmp_sch_guided_analytical_chunked;
+ continue;
+ }
+ }
+ KMP_WARNING(InvalidClause, name, value);
+ } else
+ KMP_WARNING(EmptyClause, name);
+ } while ((value = semicolon ? semicolon + 1 : NULL));
+ }
+ }; // if
} // __kmp_stg_parse__schedule
-static void
-__kmp_stg_print_schedule( kmp_str_buf_t * buffer, char const * name, void * data ) {
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME_EX(name);
- } else {
- __kmp_str_buf_print( buffer, " %s='", name );
- }
- if ( __kmp_static == kmp_sch_static_greedy ) {
- __kmp_str_buf_print( buffer, "%s", "static,greedy");
- } else if ( __kmp_static == kmp_sch_static_balanced ) {
- __kmp_str_buf_print ( buffer, "%s", "static,balanced");
- }
- if ( __kmp_guided == kmp_sch_guided_iterative_chunked ) {
- __kmp_str_buf_print( buffer, ";%s'\n", "guided,iterative");
- } else if ( __kmp_guided == kmp_sch_guided_analytical_chunked ) {
- __kmp_str_buf_print( buffer, ";%s'\n", "guided,analytical");
- }
+static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME_EX(name);
+ } else {
+ __kmp_str_buf_print(buffer, " %s='", name);
+ }
+ if (__kmp_static == kmp_sch_static_greedy) {
+ __kmp_str_buf_print(buffer, "%s", "static,greedy");
+ } else if (__kmp_static == kmp_sch_static_balanced) {
+ __kmp_str_buf_print(buffer, "%s", "static,balanced");
+ }
+ if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
+ __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
+ } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
+ __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
+ }
} // __kmp_stg_print_schedule
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// OMP_SCHEDULE
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_omp_schedule( char const * name, char const * value, void * data )
-{
- size_t length;
- if( value ) {
- length = KMP_STRLEN( value );
- if( length ) {
- char *comma = (char *) strchr( value, ',' );
- if( value[ length - 1 ] == '"' || value[ length -1 ] == '\'')
- KMP_WARNING( UnbalancedQuotes, name );
- /* get the specified scheduling style */
- if (!__kmp_strcasecmp_with_sentinel("dynamic", value, ',')) /* DYNAMIC */
- __kmp_sched = kmp_sch_dynamic_chunked;
- else if (!__kmp_strcasecmp_with_sentinel("guided", value, ',')) /* GUIDED */
- __kmp_sched = kmp_sch_guided_chunked;
-// AC: TODO: add AUTO schedule, and pprobably remove TRAPEZOIDAL (OMP 3.0 does not allow it)
- else if (!__kmp_strcasecmp_with_sentinel("auto", value, ',')) { /* AUTO */
- __kmp_sched = kmp_sch_auto;
- if( comma ) {
- __kmp_msg( kmp_ms_warning, KMP_MSG( IgnoreChunk, name, comma ), __kmp_msg_null );
- comma = NULL;
- }
- }
- else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", value, ',')) /* TRAPEZOIDAL */
- __kmp_sched = kmp_sch_trapezoidal;
- else if (!__kmp_strcasecmp_with_sentinel("static", value, ',')) /* STATIC */
- __kmp_sched = kmp_sch_static;
+static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
+ void *data) {
+ size_t length;
+ if (value) {
+ length = KMP_STRLEN(value);
+ if (length) {
+ char *comma = (char *)strchr(value, ',');
+ if (value[length - 1] == '"' || value[length - 1] == '\'')
+ KMP_WARNING(UnbalancedQuotes, name);
+ /* get the specified scheduling style */
+ if (!__kmp_strcasecmp_with_sentinel("dynamic", value, ',')) /* DYNAMIC */
+ __kmp_sched = kmp_sch_dynamic_chunked;
+ else if (!__kmp_strcasecmp_with_sentinel("guided", value,
+ ',')) /* GUIDED */
+ __kmp_sched = kmp_sch_guided_chunked;
+ // AC: TODO: add AUTO schedule, and pprobably remove TRAPEZOIDAL (OMP 3.0
+ // does not allow it)
+ else if (!__kmp_strcasecmp_with_sentinel("auto", value, ',')) { /* AUTO */
+ __kmp_sched = kmp_sch_auto;
+ if (comma) {
+ __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, comma),
+ __kmp_msg_null);
+ comma = NULL;
+ }
+ } else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", value,
+ ',')) /* TRAPEZOIDAL */
+ __kmp_sched = kmp_sch_trapezoidal;
+ else if (!__kmp_strcasecmp_with_sentinel("static", value,
+ ',')) /* STATIC */
+ __kmp_sched = kmp_sch_static;
#if KMP_STATIC_STEAL_ENABLED
- else if (!__kmp_strcasecmp_with_sentinel("static_steal", value, ','))
- __kmp_sched = kmp_sch_static_steal;
+ else if (!__kmp_strcasecmp_with_sentinel("static_steal", value, ','))
+ __kmp_sched = kmp_sch_static_steal;
#endif
- else {
- KMP_WARNING( StgInvalidValue, name, value );
- value = NULL; /* skip processing of comma */
- }
- if( value && comma ) {
- __kmp_env_chunk = TRUE;
+ else {
+ KMP_WARNING(StgInvalidValue, name, value);
+ value = NULL; /* skip processing of comma */
+ }
+ if (value && comma) {
+ __kmp_env_chunk = TRUE;
- if(__kmp_sched == kmp_sch_static)
- __kmp_sched = kmp_sch_static_chunked;
- ++comma;
- __kmp_chunk = __kmp_str_to_int( comma, 0 );
- if ( __kmp_chunk < 1 ) {
- __kmp_chunk = KMP_DEFAULT_CHUNK;
- __kmp_msg( kmp_ms_warning, KMP_MSG( InvalidChunk, name, comma ), __kmp_msg_null );
- KMP_INFORM( Using_int_Value, name, __kmp_chunk );
-// AC: next block commented out until KMP_DEFAULT_CHUNK != KMP_MIN_CHUNK (to improve code coverage :)
-// The default chunk size is 1 according to standard, thus making KMP_MIN_CHUNK not 1 we would introduce mess:
-// wrong chunk becomes 1, but it will be impossible to explicitely set 1, because it becomes KMP_MIN_CHUNK...
-// } else if ( __kmp_chunk < KMP_MIN_CHUNK ) {
-// __kmp_chunk = KMP_MIN_CHUNK;
- } else if ( __kmp_chunk > KMP_MAX_CHUNK ) {
- __kmp_chunk = KMP_MAX_CHUNK;
- __kmp_msg( kmp_ms_warning, KMP_MSG( LargeChunk, name, comma ), __kmp_msg_null );
- KMP_INFORM( Using_int_Value, name, __kmp_chunk );
- }
- } else
- __kmp_env_chunk = FALSE;
- } else
- KMP_WARNING( EmptyString, name );
- }
- K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
- K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
- K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
- K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
+ if (__kmp_sched == kmp_sch_static)
+ __kmp_sched = kmp_sch_static_chunked;
+ ++comma;
+ __kmp_chunk = __kmp_str_to_int(comma, 0);
+ if (__kmp_chunk < 1) {
+ __kmp_chunk = KMP_DEFAULT_CHUNK;
+ __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, comma),
+ __kmp_msg_null);
+ KMP_INFORM(Using_int_Value, name, __kmp_chunk);
+ // AC: next block commented out until KMP_DEFAULT_CHUNK !=
+ // KMP_MIN_CHUNK (to improve code coverage :)
+ // The default chunk size is 1 according to standard, thus making
+ // KMP_MIN_CHUNK not 1 we would introduce mess:
+ // wrong chunk becomes 1, but it will be impossible to explicitely
+ // set 1, because it becomes KMP_MIN_CHUNK...
+ // } else if ( __kmp_chunk < KMP_MIN_CHUNK ) {
+ // __kmp_chunk = KMP_MIN_CHUNK;
+ } else if (__kmp_chunk > KMP_MAX_CHUNK) {
+ __kmp_chunk = KMP_MAX_CHUNK;
+ __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, comma),
+ __kmp_msg_null);
+ KMP_INFORM(Using_int_Value, name, __kmp_chunk);
+ }
+ } else
+ __kmp_env_chunk = FALSE;
+ } else
+ KMP_WARNING(EmptyString, name);
+ }
+ K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
+ K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
+ K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
+ K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
} // __kmp_stg_parse_omp_schedule
-static void
-__kmp_stg_print_omp_schedule( kmp_str_buf_t * buffer, char const * name, void * data ) {
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME_EX(name);
- } else {
- __kmp_str_buf_print( buffer, " %s='", name );
+static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME_EX(name);
+ } else {
+ __kmp_str_buf_print(buffer, " %s='", name);
+ }
+ if (__kmp_chunk) {
+ switch (__kmp_sched) {
+ case kmp_sch_dynamic_chunked:
+ __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
+ break;
+ case kmp_sch_guided_iterative_chunked:
+ case kmp_sch_guided_analytical_chunked:
+ __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
+ break;
+ case kmp_sch_trapezoidal:
+ __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
+ break;
+ case kmp_sch_static:
+ case kmp_sch_static_chunked:
+ case kmp_sch_static_balanced:
+ case kmp_sch_static_greedy:
+ __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
+ break;
+ case kmp_sch_static_steal:
+ __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
+ break;
+ case kmp_sch_auto:
+ __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
+ break;
}
- if ( __kmp_chunk ) {
- switch ( __kmp_sched ) {
- case kmp_sch_dynamic_chunked:
- __kmp_str_buf_print( buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
- break;
- case kmp_sch_guided_iterative_chunked:
- case kmp_sch_guided_analytical_chunked:
- __kmp_str_buf_print( buffer, "%s,%d'\n", "guided", __kmp_chunk);
- break;
- case kmp_sch_trapezoidal:
- __kmp_str_buf_print( buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
- break;
- case kmp_sch_static:
- case kmp_sch_static_chunked:
- case kmp_sch_static_balanced:
- case kmp_sch_static_greedy:
- __kmp_str_buf_print( buffer, "%s,%d'\n", "static", __kmp_chunk);
- break;
- case kmp_sch_static_steal:
- __kmp_str_buf_print( buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
- break;
- case kmp_sch_auto:
- __kmp_str_buf_print( buffer, "%s,%d'\n", "auto", __kmp_chunk);
- break;
- }
- } else {
- switch ( __kmp_sched ) {
- case kmp_sch_dynamic_chunked:
- __kmp_str_buf_print( buffer, "%s'\n", "dynamic");
- break;
- case kmp_sch_guided_iterative_chunked:
- case kmp_sch_guided_analytical_chunked:
- __kmp_str_buf_print( buffer, "%s'\n", "guided");
- break;
- case kmp_sch_trapezoidal:
- __kmp_str_buf_print( buffer, "%s'\n", "trapezoidal");
- break;
- case kmp_sch_static:
- case kmp_sch_static_chunked:
- case kmp_sch_static_balanced:
- case kmp_sch_static_greedy:
- __kmp_str_buf_print( buffer, "%s'\n", "static");
- break;
- case kmp_sch_static_steal:
- __kmp_str_buf_print( buffer, "%s'\n", "static_steal");
- break;
- case kmp_sch_auto:
- __kmp_str_buf_print( buffer, "%s'\n", "auto");
- break;
- }
+ } else {
+ switch (__kmp_sched) {
+ case kmp_sch_dynamic_chunked:
+ __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
+ break;
+ case kmp_sch_guided_iterative_chunked:
+ case kmp_sch_guided_analytical_chunked:
+ __kmp_str_buf_print(buffer, "%s'\n", "guided");
+ break;
+ case kmp_sch_trapezoidal:
+ __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
+ break;
+ case kmp_sch_static:
+ case kmp_sch_static_chunked:
+ case kmp_sch_static_balanced:
+ case kmp_sch_static_greedy:
+ __kmp_str_buf_print(buffer, "%s'\n", "static");
+ break;
+ case kmp_sch_static_steal:
+ __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
+ break;
+ case kmp_sch_auto:
+ __kmp_str_buf_print(buffer, "%s'\n", "auto");
+ break;
}
+ }
} // __kmp_stg_print_omp_schedule
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_ATOMIC_MODE
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_atomic_mode( char const * name, char const * value, void * data ) {
- // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP compatibility mode.
- int mode = 0;
- int max = 1;
- #ifdef KMP_GOMP_COMPAT
- max = 2;
- #endif /* KMP_GOMP_COMPAT */
- __kmp_stg_parse_int( name, value, 0, max, & mode );
- // TODO; parse_int is not very suitable for this case. In case of overflow it is better to use
- // 0 rather that max value.
- if ( mode > 0 ) {
- __kmp_atomic_mode = mode;
- }; // if
+static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
+ void *data) {
+ // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
+ // compatibility mode.
+ int mode = 0;
+ int max = 1;
+#ifdef KMP_GOMP_COMPAT
+ max = 2;
+#endif /* KMP_GOMP_COMPAT */
+ __kmp_stg_parse_int(name, value, 0, max, &mode);
+ // TODO; parse_int is not very suitable for this case. In case of overflow it
+ // is better to use
+ // 0 rather that max value.
+ if (mode > 0) {
+ __kmp_atomic_mode = mode;
+ }; // if
} // __kmp_stg_parse_atomic_mode
-static void
-__kmp_stg_print_atomic_mode( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_atomic_mode );
+static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
} // __kmp_stg_print_atomic_mode
-
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_CONSISTENCY_CHECK
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_consistency_check( char const * name, char const * value, void * data ) {
- if ( ! __kmp_strcasecmp_with_sentinel( "all", value, 0 ) ) {
- // Note, this will not work from kmp_set_defaults because th_cons stack was not allocated
- // for existed thread(s) thus the first __kmp_push_<construct> will break with assertion.
- // TODO: allocate th_cons if called from kmp_set_defaults.
- __kmp_env_consistency_check = TRUE;
- } else if ( ! __kmp_strcasecmp_with_sentinel( "none", value, 0 ) ) {
- __kmp_env_consistency_check = FALSE;
- } else {
- KMP_WARNING( StgInvalidValue, name, value );
- }; // if
+static void __kmp_stg_parse_consistency_check(char const *name,
+ char const *value, void *data) {
+ if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
+ // Note, this will not work from kmp_set_defaults because th_cons stack was
+ // not allocated
+ // for existed thread(s) thus the first __kmp_push_<construct> will break
+ // with assertion.
+ // TODO: allocate th_cons if called from kmp_set_defaults.
+ __kmp_env_consistency_check = TRUE;
+ } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
+ __kmp_env_consistency_check = FALSE;
+ } else {
+ KMP_WARNING(StgInvalidValue, name, value);
+ }; // if
} // __kmp_stg_parse_consistency_check
-static void
-__kmp_stg_print_consistency_check( kmp_str_buf_t * buffer, char const * name, void * data ) {
+static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
#if KMP_DEBUG
- const char *value = NULL;
+ const char *value = NULL;
- if ( __kmp_env_consistency_check ) {
- value = "all";
- } else {
- value = "none";
- }
+ if (__kmp_env_consistency_check) {
+ value = "all";
+ } else {
+ value = "none";
+ }
- if ( value != NULL ) {
- __kmp_stg_print_str( buffer, name, value );
- }
+ if (value != NULL) {
+ __kmp_stg_print_str(buffer, name, value);
+ }
#endif /* KMP_DEBUG */
} // __kmp_stg_print_consistency_check
-
#if USE_ITT_BUILD
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_ITT_PREPARE_DELAY
-// -------------------------------------------------------------------------------------------------
#if USE_ITT_NOTIFY
-static void
-__kmp_stg_parse_itt_prepare_delay( char const * name, char const * value, void * data )
-{
- // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop iterations.
- int delay = 0;
- __kmp_stg_parse_int( name, value, 0, INT_MAX, & delay );
- __kmp_itt_prepare_delay = delay;
+static void __kmp_stg_parse_itt_prepare_delay(char const *name,
+ char const *value, void *data) {
+ // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
+ // iterations.
+ int delay = 0;
+ __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
+ __kmp_itt_prepare_delay = delay;
} // __kmp_str_parse_itt_prepare_delay
-static void
-__kmp_stg_print_itt_prepare_delay( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_uint64( buffer, name, __kmp_itt_prepare_delay );
+static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);
} // __kmp_str_print_itt_prepare_delay
#endif // USE_ITT_NOTIFY
#endif /* USE_ITT_BUILD */
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_MALLOC_POOL_INCR
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_malloc_pool_incr( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_size(
- name,
- value,
- KMP_MIN_MALLOC_POOL_INCR,
- KMP_MAX_MALLOC_POOL_INCR,
- NULL,
- & __kmp_malloc_pool_incr,
- 1
- );
+static void __kmp_stg_parse_malloc_pool_incr(char const *name,
+ char const *value, void *data) {
+ __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
+ KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
+ 1);
} // __kmp_stg_parse_malloc_pool_incr
-static void
-__kmp_stg_print_malloc_pool_incr( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_size( buffer, name, __kmp_malloc_pool_incr );
+static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);
} // _kmp_stg_print_malloc_pool_incr
-
#ifdef KMP_DEBUG
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_PAR_RANGE
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_par_range_env( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_par_range(
- name,
- value,
- & __kmp_par_range,
- __kmp_par_range_routine,
- __kmp_par_range_filename,
- & __kmp_par_range_lb,
- & __kmp_par_range_ub
- );
+static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
+ __kmp_par_range_routine, __kmp_par_range_filename,
+ &__kmp_par_range_lb, &__kmp_par_range_ub);
} // __kmp_stg_parse_par_range_env
-static void
-__kmp_stg_print_par_range_env( kmp_str_buf_t * buffer, char const * name, void * data ) {
- if (__kmp_par_range != 0) {
- __kmp_stg_print_str( buffer, name, par_range_to_print );
- }
+static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ if (__kmp_par_range != 0) {
+ __kmp_stg_print_str(buffer, name, par_range_to_print);
+ }
} // __kmp_stg_print_par_range_env
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_YIELD_CYCLE, KMP_YIELD_ON, KMP_YIELD_OFF
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_yield_cycle( char const * name, char const * value, void * data ) {
- int flag = __kmp_yield_cycle;
- __kmp_stg_parse_bool( name, value, & flag );
- __kmp_yield_cycle = flag;
+static void __kmp_stg_parse_yield_cycle(char const *name, char const *value,
+ void *data) {
+ int flag = __kmp_yield_cycle;
+ __kmp_stg_parse_bool(name, value, &flag);
+ __kmp_yield_cycle = flag;
} // __kmp_stg_parse_yield_cycle
-static void
-__kmp_stg_print_yield_cycle( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_yield_cycle );
+static void __kmp_stg_print_yield_cycle(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_yield_cycle);
} // __kmp_stg_print_yield_cycle
-static void
-__kmp_stg_parse_yield_on( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_int( name, value, 2, INT_MAX, & __kmp_yield_on_count );
+static void __kmp_stg_parse_yield_on(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_on_count);
} // __kmp_stg_parse_yield_on
-static void
-__kmp_stg_print_yield_on( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_yield_on_count );
+static void __kmp_stg_print_yield_on(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_yield_on_count);
} // __kmp_stg_print_yield_on
-static void
-__kmp_stg_parse_yield_off( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_int( name, value, 2, INT_MAX, & __kmp_yield_off_count );
+static void __kmp_stg_parse_yield_off(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_int(name, value, 2, INT_MAX, &__kmp_yield_off_count);
} // __kmp_stg_parse_yield_off
-static void
-__kmp_stg_print_yield_off( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_yield_off_count );
+static void __kmp_stg_print_yield_off(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_yield_off_count);
} // __kmp_stg_print_yield_off
#endif
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_INIT_WAIT, KMP_NEXT_WAIT
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_init_wait( char const * name, char const * value, void * data ) {
- int wait;
- KMP_ASSERT( ( __kmp_init_wait & 1 ) == 0 );
- wait = __kmp_init_wait / 2;
- __kmp_stg_parse_int( name, value, KMP_MIN_INIT_WAIT, KMP_MAX_INIT_WAIT, & wait );
- __kmp_init_wait = wait * 2;
- KMP_ASSERT( ( __kmp_init_wait & 1 ) == 0 );
- __kmp_yield_init = __kmp_init_wait;
+static void __kmp_stg_parse_init_wait(char const *name, char const *value,
+ void *data) {
+ int wait;
+ KMP_ASSERT((__kmp_init_wait & 1) == 0);
+ wait = __kmp_init_wait / 2;
+ __kmp_stg_parse_int(name, value, KMP_MIN_INIT_WAIT, KMP_MAX_INIT_WAIT, &wait);
+ __kmp_init_wait = wait * 2;
+ KMP_ASSERT((__kmp_init_wait & 1) == 0);
+ __kmp_yield_init = __kmp_init_wait;
} // __kmp_stg_parse_init_wait
-static void
-__kmp_stg_print_init_wait( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_init_wait );
+static void __kmp_stg_print_init_wait(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_init_wait);
} // __kmp_stg_print_init_wait
-static void
-__kmp_stg_parse_next_wait( char const * name, char const * value, void * data ) {
- int wait;
- KMP_ASSERT( ( __kmp_next_wait & 1 ) == 0 );
- wait = __kmp_next_wait / 2;
- __kmp_stg_parse_int( name, value, KMP_MIN_NEXT_WAIT, KMP_MAX_NEXT_WAIT, & wait );
- __kmp_next_wait = wait * 2;
- KMP_ASSERT( ( __kmp_next_wait & 1 ) == 0 );
- __kmp_yield_next = __kmp_next_wait;
+static void __kmp_stg_parse_next_wait(char const *name, char const *value,
+ void *data) {
+ int wait;
+ KMP_ASSERT((__kmp_next_wait & 1) == 0);
+ wait = __kmp_next_wait / 2;
+ __kmp_stg_parse_int(name, value, KMP_MIN_NEXT_WAIT, KMP_MAX_NEXT_WAIT, &wait);
+ __kmp_next_wait = wait * 2;
+ KMP_ASSERT((__kmp_next_wait & 1) == 0);
+ __kmp_yield_next = __kmp_next_wait;
} // __kmp_stg_parse_next_wait
-static void
-__kmp_stg_print_next_wait( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_next_wait );
+static void __kmp_stg_print_next_wait(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_next_wait);
} //__kmp_stg_print_next_wait
-
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_GTID_MODE
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_gtid_mode( char const * name, char const * value, void * data ) {
- //
- // Modes:
- // 0 -- do not change default
- // 1 -- sp search
- // 2 -- use "keyed" TLS var, i.e.
- // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
- // 3 -- __declspec(thread) TLS var in tdata section
- //
- int mode = 0;
- int max = 2;
- #ifdef KMP_TDATA_GTID
- max = 3;
- #endif /* KMP_TDATA_GTID */
- __kmp_stg_parse_int( name, value, 0, max, & mode );
- // TODO; parse_int is not very suitable for this case. In case of overflow it is better to use
- // 0 rather that max value.
- if ( mode == 0 ) {
- __kmp_adjust_gtid_mode = TRUE;
- }
- else {
- __kmp_gtid_mode = mode;
- __kmp_adjust_gtid_mode = FALSE;
- }; // if
+static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
+ void *data) {
+ // Modes:
+ // 0 -- do not change default
+ // 1 -- sp search
+ // 2 -- use "keyed" TLS var, i.e.
+ // pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
+ // 3 -- __declspec(thread) TLS var in tdata section
+ int mode = 0;
+ int max = 2;
+#ifdef KMP_TDATA_GTID
+ max = 3;
+#endif /* KMP_TDATA_GTID */
+ __kmp_stg_parse_int(name, value, 0, max, &mode);
+ // TODO; parse_int is not very suitable for this case. In case of overflow it
+ // is better to use 0 rather that max value.
+ if (mode == 0) {
+ __kmp_adjust_gtid_mode = TRUE;
+ } else {
+ __kmp_gtid_mode = mode;
+ __kmp_adjust_gtid_mode = FALSE;
+ }; // if
} // __kmp_str_parse_gtid_mode
-static void
-__kmp_stg_print_gtid_mode( kmp_str_buf_t * buffer, char const * name, void * data ) {
- if ( __kmp_adjust_gtid_mode ) {
- __kmp_stg_print_int( buffer, name, 0 );
- }
- else {
- __kmp_stg_print_int( buffer, name, __kmp_gtid_mode );
- }
+static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ if (__kmp_adjust_gtid_mode) {
+ __kmp_stg_print_int(buffer, name, 0);
+ } else {
+ __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
+ }
} // __kmp_stg_print_gtid_mode
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_NUM_LOCKS_IN_BLOCK
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_lock_block( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_int( name, value, 0, KMP_INT_MAX, & __kmp_num_locks_in_block );
+static void __kmp_stg_parse_lock_block(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
} // __kmp_str_parse_lock_block
-static void
-__kmp_stg_print_lock_block( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_num_locks_in_block );
+static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
} // __kmp_stg_print_lock_block
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_LOCK_KIND
-// -------------------------------------------------------------------------------------------------
#if KMP_USE_DYNAMIC_LOCK
-# define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
+#define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
#else
-# define KMP_STORE_LOCK_SEQ(a)
+#define KMP_STORE_LOCK_SEQ(a)
#endif
-static void
-__kmp_stg_parse_lock_kind( char const * name, char const * value, void * data ) {
- if ( __kmp_init_user_locks ) {
- KMP_WARNING( EnvLockWarn, name );
- return;
- }
+static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
+ void *data) {
+ if (__kmp_init_user_locks) {
+ KMP_WARNING(EnvLockWarn, name);
+ return;
+ }
- if ( __kmp_str_match( "tas", 2, value )
- || __kmp_str_match( "test and set", 2, value )
- || __kmp_str_match( "test_and_set", 2, value )
- || __kmp_str_match( "test-and-set", 2, value )
- || __kmp_str_match( "test andset", 2, value )
- || __kmp_str_match( "test_andset", 2, value )
- || __kmp_str_match( "test-andset", 2, value )
- || __kmp_str_match( "testand set", 2, value )
- || __kmp_str_match( "testand_set", 2, value )
- || __kmp_str_match( "testand-set", 2, value )
- || __kmp_str_match( "testandset", 2, value ) ) {
- __kmp_user_lock_kind = lk_tas;
- KMP_STORE_LOCK_SEQ(tas);
- }
+ if (__kmp_str_match("tas", 2, value) ||
+ __kmp_str_match("test and set", 2, value) ||
+ __kmp_str_match("test_and_set", 2, value) ||
+ __kmp_str_match("test-and-set", 2, value) ||
+ __kmp_str_match("test andset", 2, value) ||
+ __kmp_str_match("test_andset", 2, value) ||
+ __kmp_str_match("test-andset", 2, value) ||
+ __kmp_str_match("testand set", 2, value) ||
+ __kmp_str_match("testand_set", 2, value) ||
+ __kmp_str_match("testand-set", 2, value) ||
+ __kmp_str_match("testandset", 2, value)) {
+ __kmp_user_lock_kind = lk_tas;
+ KMP_STORE_LOCK_SEQ(tas);
+ }
#if KMP_USE_FUTEX
- else if ( __kmp_str_match( "futex", 1, value ) ) {
- if ( __kmp_futex_determine_capable() ) {
- __kmp_user_lock_kind = lk_futex;
- KMP_STORE_LOCK_SEQ(futex);
- }
- else {
- KMP_WARNING( FutexNotSupported, name, value );
- }
+ else if (__kmp_str_match("futex", 1, value)) {
+ if (__kmp_futex_determine_capable()) {
+ __kmp_user_lock_kind = lk_futex;
+ KMP_STORE_LOCK_SEQ(futex);
+ } else {
+ KMP_WARNING(FutexNotSupported, name, value);
}
+ }
#endif
- else if ( __kmp_str_match( "ticket", 2, value ) ) {
- __kmp_user_lock_kind = lk_ticket;
- KMP_STORE_LOCK_SEQ(ticket);
- }
- else if ( __kmp_str_match( "queuing", 1, value )
- || __kmp_str_match( "queue", 1, value ) ) {
- __kmp_user_lock_kind = lk_queuing;
- KMP_STORE_LOCK_SEQ(queuing);
- }
- else if ( __kmp_str_match( "drdpa ticket", 1, value )
- || __kmp_str_match( "drdpa_ticket", 1, value )
- || __kmp_str_match( "drdpa-ticket", 1, value )
- || __kmp_str_match( "drdpaticket", 1, value )
- || __kmp_str_match( "drdpa", 1, value ) ) {
- __kmp_user_lock_kind = lk_drdpa;
- KMP_STORE_LOCK_SEQ(drdpa);
- }
+ else if (__kmp_str_match("ticket", 2, value)) {
+ __kmp_user_lock_kind = lk_ticket;
+ KMP_STORE_LOCK_SEQ(ticket);
+ } else if (__kmp_str_match("queuing", 1, value) ||
+ __kmp_str_match("queue", 1, value)) {
+ __kmp_user_lock_kind = lk_queuing;
+ KMP_STORE_LOCK_SEQ(queuing);
+ } else if (__kmp_str_match("drdpa ticket", 1, value) ||
+ __kmp_str_match("drdpa_ticket", 1, value) ||
+ __kmp_str_match("drdpa-ticket", 1, value) ||
+ __kmp_str_match("drdpaticket", 1, value) ||
+ __kmp_str_match("drdpa", 1, value)) {
+ __kmp_user_lock_kind = lk_drdpa;
+ KMP_STORE_LOCK_SEQ(drdpa);
+ }
#if KMP_USE_ADAPTIVE_LOCKS
- else if ( __kmp_str_match( "adaptive", 1, value ) ) {
- if( __kmp_cpuinfo.rtm ) { // ??? Is cpuinfo available here?
- __kmp_user_lock_kind = lk_adaptive;
- KMP_STORE_LOCK_SEQ(adaptive);
- } else {
- KMP_WARNING( AdaptiveNotSupported, name, value );
- __kmp_user_lock_kind = lk_queuing;
- KMP_STORE_LOCK_SEQ(queuing);
- }
+ else if (__kmp_str_match("adaptive", 1, value)) {
+ if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here?
+ __kmp_user_lock_kind = lk_adaptive;
+ KMP_STORE_LOCK_SEQ(adaptive);
+ } else {
+ KMP_WARNING(AdaptiveNotSupported, name, value);
+ __kmp_user_lock_kind = lk_queuing;
+ KMP_STORE_LOCK_SEQ(queuing);
}
+ }
#endif // KMP_USE_ADAPTIVE_LOCKS
#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
- else if ( __kmp_str_match("rtm", 1, value) ) {
- if ( __kmp_cpuinfo.rtm ) {
- __kmp_user_lock_kind = lk_rtm;
- KMP_STORE_LOCK_SEQ(rtm);
- } else {
- KMP_WARNING( AdaptiveNotSupported, name, value );
- __kmp_user_lock_kind = lk_queuing;
- KMP_STORE_LOCK_SEQ(queuing);
- }
- }
- else if ( __kmp_str_match("hle", 1, value) ) {
- __kmp_user_lock_kind = lk_hle;
- KMP_STORE_LOCK_SEQ(hle);
- }
+ else if (__kmp_str_match("rtm", 1, value)) {
+ if (__kmp_cpuinfo.rtm) {
+ __kmp_user_lock_kind = lk_rtm;
+ KMP_STORE_LOCK_SEQ(rtm);
+ } else {
+ KMP_WARNING(AdaptiveNotSupported, name, value);
+ __kmp_user_lock_kind = lk_queuing;
+ KMP_STORE_LOCK_SEQ(queuing);
+ }
+ } else if (__kmp_str_match("hle", 1, value)) {
+ __kmp_user_lock_kind = lk_hle;
+ KMP_STORE_LOCK_SEQ(hle);
+ }
#endif
- else {
- KMP_WARNING( StgInvalidValue, name, value );
- }
+ else {
+ KMP_WARNING(StgInvalidValue, name, value);
+ }
}
-static void
-__kmp_stg_print_lock_kind( kmp_str_buf_t * buffer, char const * name, void * data ) {
- const char *value = NULL;
-
- switch ( __kmp_user_lock_kind ) {
- case lk_default:
- value = "default";
- break;
-
- case lk_tas:
- value = "tas";
- break;
+static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
+ void *data) {
+ const char *value = NULL;
+
+ switch (__kmp_user_lock_kind) {
+ case lk_default:
+ value = "default";
+ break;
+
+ case lk_tas:
+ value = "tas";
+ break;
#if KMP_USE_FUTEX
- case lk_futex:
- value = "futex";
- break;
+ case lk_futex:
+ value = "futex";
+ break;
#endif
#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
- case lk_rtm:
- value = "rtm";
- break;
-
- case lk_hle:
- value = "hle";
- break;
+ case lk_rtm:
+ value = "rtm";
+ break;
+
+ case lk_hle:
+ value = "hle";
+ break;
#endif
- case lk_ticket:
- value = "ticket";
- break;
-
- case lk_queuing:
- value = "queuing";
- break;
-
- case lk_drdpa:
- value = "drdpa";
- break;
+ case lk_ticket:
+ value = "ticket";
+ break;
+
+ case lk_queuing:
+ value = "queuing";
+ break;
+
+ case lk_drdpa:
+ value = "drdpa";
+ break;
#if KMP_USE_ADAPTIVE_LOCKS
- case lk_adaptive:
- value = "adaptive";
- break;
+ case lk_adaptive:
+ value = "adaptive";
+ break;
#endif
- }
+ }
- if ( value != NULL ) {
- __kmp_stg_print_str( buffer, name, value );
- }
+ if (value != NULL) {
+ __kmp_stg_print_str(buffer, name, value);
+ }
}
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_SPIN_BACKOFF_PARAMS
-// -------------------------------------------------------------------------------------------------
-
-// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick for machine pause)
-static void
-__kmp_stg_parse_spin_backoff_params(const char* name, const char* value, void* data)
-{
- const char *next = value;
-
- int total = 0; // Count elements that were set. It'll be used as an array size
- int prev_comma = FALSE; // For correct processing sequential commas
- int i;
- kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
- kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
-
- // Run only 3 iterations because it is enough to read two values or find a syntax error
- for ( i = 0; i < 3 ; i++) {
- SKIP_WS( next );
-
- if ( *next == '\0' ) {
- break;
- }
- // Next character is not an integer or not a comma OR number of values > 2 => end of list
- if ( ( ( *next < '0' || *next > '9' ) && *next !=',' ) || total > 2 ) {
- KMP_WARNING( EnvSyntaxError, name, value );
- return;
- }
- // The next character is ','
- if ( *next == ',' ) {
- // ',' is the fisrt character
- if ( total == 0 || prev_comma ) {
- total++;
- }
- prev_comma = TRUE;
- next++; //skip ','
- SKIP_WS( next );
- }
- // Next character is a digit
- if ( *next >= '0' && *next <= '9' ) {
- int num;
- const char *buf = next;
- char const * msg = NULL;
- prev_comma = FALSE;
- SKIP_DIGITS( next );
- total++;
-
- const char *tmp = next;
- SKIP_WS( tmp );
- if ( ( *next == ' ' || *next == '\t' ) && ( *tmp >= '0' && *tmp <= '9' ) ) {
- KMP_WARNING( EnvSpacesNotAllowed, name, value );
- return;
- }
+// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
+// for machine pause)
+static void __kmp_stg_parse_spin_backoff_params(const char *name,
+ const char *value, void *data) {
+ const char *next = value;
+
+ int total = 0; // Count elements that were set. It'll be used as an array size
+ int prev_comma = FALSE; // For correct processing sequential commas
+ int i;
+
+ kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
+ kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;
+
+ // Run only 3 iterations because it is enough to read two values or find a
+ // syntax error
+ for (i = 0; i < 3; i++) {
+ SKIP_WS(next);
- num = __kmp_str_to_int( buf, *next );
- if ( num <= 0 ) { // The number of retries should be > 0
- msg = KMP_I18N_STR( ValueTooSmall );
- num = 1;
- } else if ( num > KMP_INT_MAX ) {
- msg = KMP_I18N_STR( ValueTooLarge );
- num = KMP_INT_MAX;
- }
- if ( msg != NULL ) {
- // Message is not empty. Print warning.
- KMP_WARNING( ParseSizeIntWarn, name, value, msg );
- KMP_INFORM( Using_int_Value, name, num );
- }
- if( total == 1 ) {
- max_backoff = num;
- } else if( total == 2 ) {
- min_tick = num;
- }
- }
+ if (*next == '\0') {
+ break;
}
- KMP_DEBUG_ASSERT( total > 0 );
- if( total <= 0 ) {
- KMP_WARNING( EnvSyntaxError, name, value );
+ // Next character is not an integer or not a comma OR number of values > 2
+ // => end of list
+ if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
+ KMP_WARNING(EnvSyntaxError, name, value);
+ return;
+ }
+ // The next character is ','
+ if (*next == ',') {
+ // ',' is the fisrt character
+ if (total == 0 || prev_comma) {
+ total++;
+ }
+ prev_comma = TRUE;
+ next++; // skip ','
+ SKIP_WS(next);
+ }
+ // Next character is a digit
+ if (*next >= '0' && *next <= '9') {
+ int num;
+ const char *buf = next;
+ char const *msg = NULL;
+ prev_comma = FALSE;
+ SKIP_DIGITS(next);
+ total++;
+
+ const char *tmp = next;
+ SKIP_WS(tmp);
+ if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
+ KMP_WARNING(EnvSpacesNotAllowed, name, value);
return;
+ }
+
+ num = __kmp_str_to_int(buf, *next);
+ if (num <= 0) { // The number of retries should be > 0
+ msg = KMP_I18N_STR(ValueTooSmall);
+ num = 1;
+ } else if (num > KMP_INT_MAX) {
+ msg = KMP_I18N_STR(ValueTooLarge);
+ num = KMP_INT_MAX;
+ }
+ if (msg != NULL) {
+ // Message is not empty. Print warning.
+ KMP_WARNING(ParseSizeIntWarn, name, value, msg);
+ KMP_INFORM(Using_int_Value, name, num);
+ }
+ if (total == 1) {
+ max_backoff = num;
+ } else if (total == 2) {
+ min_tick = num;
+ }
}
- __kmp_spin_backoff_params.max_backoff = max_backoff;
- __kmp_spin_backoff_params.min_tick = min_tick;
+ }
+ KMP_DEBUG_ASSERT(total > 0);
+ if (total <= 0) {
+ KMP_WARNING(EnvSyntaxError, name, value);
+ return;
+ }
+ __kmp_spin_backoff_params.max_backoff = max_backoff;
+ __kmp_spin_backoff_params.min_tick = min_tick;
}
-static void
-__kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer, char const* name, void* data)
-{
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME_EX(name);
- } else {
- __kmp_str_buf_print( buffer, " %s='", name );
- }
- __kmp_str_buf_print( buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
- __kmp_spin_backoff_params.min_tick );
+static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME_EX(name);
+ } else {
+ __kmp_str_buf_print(buffer, " %s='", name);
+ }
+ __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
+ __kmp_spin_backoff_params.min_tick);
}
#if KMP_USE_ADAPTIVE_LOCKS
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE
-// -------------------------------------------------------------------------------------------------
// Parse out values for the tunable parameters from a string of the form
// KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
-static void
-__kmp_stg_parse_adaptive_lock_props( const char *name, const char *value, void *data )
-{
- int max_retries = 0;
- int max_badness = 0;
-
- const char *next = value;
-
- int total = 0; // Count elements that were set. It'll be used as an array size
- int prev_comma = FALSE; // For correct processing sequential commas
- int i;
-
- // Save values in the structure __kmp_speculative_backoff_params
- // Run only 3 iterations because it is enough to read two values or find a syntax error
- for ( i = 0; i < 3 ; i++) {
- SKIP_WS( next );
-
- if ( *next == '\0' ) {
- break;
- }
- // Next character is not an integer or not a comma OR number of values > 2 => end of list
- if ( ( ( *next < '0' || *next > '9' ) && *next !=',' ) || total > 2 ) {
- KMP_WARNING( EnvSyntaxError, name, value );
- return;
- }
- // The next character is ','
- if ( *next == ',' ) {
- // ',' is the fisrt character
- if ( total == 0 || prev_comma ) {
- total++;
- }
- prev_comma = TRUE;
- next++; //skip ','
- SKIP_WS( next );
- }
- // Next character is a digit
- if ( *next >= '0' && *next <= '9' ) {
- int num;
- const char *buf = next;
- char const * msg = NULL;
- prev_comma = FALSE;
- SKIP_DIGITS( next );
- total++;
-
- const char *tmp = next;
- SKIP_WS( tmp );
- if ( ( *next == ' ' || *next == '\t' ) && ( *tmp >= '0' && *tmp <= '9' ) ) {
- KMP_WARNING( EnvSpacesNotAllowed, name, value );
- return;
- }
+static void __kmp_stg_parse_adaptive_lock_props(const char *name,
+ const char *value, void *data) {
+ int max_retries = 0;
+ int max_badness = 0;
+
+ const char *next = value;
+
+ int total = 0; // Count elements that were set. It'll be used as an array size
+ int prev_comma = FALSE; // For correct processing sequential commas
+ int i;
+
+ // Save values in the structure __kmp_speculative_backoff_params
+ // Run only 3 iterations because it is enough to read two values or find a
+ // syntax error
+ for (i = 0; i < 3; i++) {
+ SKIP_WS(next);
- num = __kmp_str_to_int( buf, *next );
- if ( num < 0 ) { // The number of retries should be >= 0
- msg = KMP_I18N_STR( ValueTooSmall );
- num = 1;
- } else if ( num > KMP_INT_MAX ) {
- msg = KMP_I18N_STR( ValueTooLarge );
- num = KMP_INT_MAX;
- }
- if ( msg != NULL ) {
- // Message is not empty. Print warning.
- KMP_WARNING( ParseSizeIntWarn, name, value, msg );
- KMP_INFORM( Using_int_Value, name, num );
- }
- if( total == 1 ) {
- max_retries = num;
- } else if( total == 2 ) {
- max_badness = num;
- }
- }
+ if (*next == '\0') {
+ break;
}
- KMP_DEBUG_ASSERT( total > 0 );
- if( total <= 0 ) {
- KMP_WARNING( EnvSyntaxError, name, value );
+ // Next character is not an integer or not a comma OR number of values > 2
+ // => end of list
+ if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
+ KMP_WARNING(EnvSyntaxError, name, value);
+ return;
+ }
+ // The next character is ','
+ if (*next == ',') {
+ // ',' is the fisrt character
+ if (total == 0 || prev_comma) {
+ total++;
+ }
+ prev_comma = TRUE;
+ next++; // skip ','
+ SKIP_WS(next);
+ }
+ // Next character is a digit
+ if (*next >= '0' && *next <= '9') {
+ int num;
+ const char *buf = next;
+ char const *msg = NULL;
+ prev_comma = FALSE;
+ SKIP_DIGITS(next);
+ total++;
+
+ const char *tmp = next;
+ SKIP_WS(tmp);
+ if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
+ KMP_WARNING(EnvSpacesNotAllowed, name, value);
return;
+ }
+
+ num = __kmp_str_to_int(buf, *next);
+ if (num < 0) { // The number of retries should be >= 0
+ msg = KMP_I18N_STR(ValueTooSmall);
+ num = 1;
+ } else if (num > KMP_INT_MAX) {
+ msg = KMP_I18N_STR(ValueTooLarge);
+ num = KMP_INT_MAX;
+ }
+ if (msg != NULL) {
+ // Message is not empty. Print warning.
+ KMP_WARNING(ParseSizeIntWarn, name, value, msg);
+ KMP_INFORM(Using_int_Value, name, num);
+ }
+ if (total == 1) {
+ max_retries = num;
+ } else if (total == 2) {
+ max_badness = num;
+ }
}
- __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
- __kmp_adaptive_backoff_params.max_badness = max_badness;
+ }
+ KMP_DEBUG_ASSERT(total > 0);
+ if (total <= 0) {
+ KMP_WARNING(EnvSyntaxError, name, value);
+ return;
+ }
+ __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
+ __kmp_adaptive_backoff_params.max_badness = max_badness;
}
-
-static void
-__kmp_stg_print_adaptive_lock_props(kmp_str_buf_t * buffer, char const * name, void * data )
-{
- if( __kmp_env_format ) {
- KMP_STR_BUF_PRINT_NAME_EX(name);
- } else {
- __kmp_str_buf_print( buffer, " %s='", name );
- }
- __kmp_str_buf_print( buffer, "%d,%d'\n", __kmp_adaptive_backoff_params.max_soft_retries,
- __kmp_adaptive_backoff_params.max_badness );
+static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ if (__kmp_env_format) {
+ KMP_STR_BUF_PRINT_NAME_EX(name);
+ } else {
+ __kmp_str_buf_print(buffer, " %s='", name);
+ }
+ __kmp_str_buf_print(buffer, "%d,%d'\n",
+ __kmp_adaptive_backoff_params.max_soft_retries,
+ __kmp_adaptive_backoff_params.max_badness);
} // __kmp_stg_print_adaptive_lock_props
#if KMP_DEBUG_ADAPTIVE_LOCKS
-static void
-__kmp_stg_parse_speculative_statsfile( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_file( name, value, "", & __kmp_speculative_statsfile );
+static void __kmp_stg_parse_speculative_statsfile(char const *name,
+ char const *value,
+ void *data) {
+ __kmp_stg_parse_file(name, value, "", &__kmp_speculative_statsfile);
} // __kmp_stg_parse_speculative_statsfile
-static void
-__kmp_stg_print_speculative_statsfile( kmp_str_buf_t * buffer, char const * name, void * data ) {
- if ( __kmp_str_match( "-", 0, __kmp_speculative_statsfile ) ) {
- __kmp_stg_print_str( buffer, name, "stdout" );
- } else {
- __kmp_stg_print_str( buffer, name, __kmp_speculative_statsfile );
- }
+static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
+ char const *name,
+ void *data) {
+ if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
+ __kmp_stg_print_str(buffer, name, "stdout");
+ } else {
+ __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
+ }
} // __kmp_stg_print_speculative_statsfile
@@ -4300,9 +4065,8 @@ __kmp_stg_print_speculative_statsfile( k
#endif // KMP_USE_ADAPTIVE_LOCKS
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_HW_SUBSET (was KMP_PLACE_THREADS)
-// -------------------------------------------------------------------------------------------------
// The longest observable sequense of items is
// Socket-Node-Tile-Core-Thread
@@ -4310,8 +4074,8 @@ __kmp_stg_print_speculative_statsfile( k
// The input string is usually short enough, let's use 512 limit for now
#define MAX_T_LEVEL 5
#define MAX_STR_LEN 512
-static void
-__kmp_stg_parse_hw_subset( char const * name, char const * value, void * data ) {
+static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
+ void *data) {
// Value example: 1s,5c at 3,2T
// Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
static int parsed = 0;
@@ -4447,1076 +4211,1116 @@ err:
return;
}
-static void
-__kmp_stg_print_hw_subset( kmp_str_buf_t * buffer, char const * name, void * data ) {
- if (__kmp_hws_requested) {
- int comma = 0;
- kmp_str_buf_t buf;
- __kmp_str_buf_init(&buf);
- if(__kmp_env_format)
- KMP_STR_BUF_PRINT_NAME_EX(name);
- else
- __kmp_str_buf_print(buffer, " %s='", name);
- if (__kmp_hws_socket.num) {
- __kmp_str_buf_print(&buf, "%ds", __kmp_hws_socket.num);
- if (__kmp_hws_socket.offset)
- __kmp_str_buf_print(&buf, "@%d", __kmp_hws_socket.offset);
- comma = 1;
- }
- if (__kmp_hws_node.num) {
- __kmp_str_buf_print(&buf, "%s%dn", comma?",":"", __kmp_hws_node.num);
- if (__kmp_hws_node.offset)
- __kmp_str_buf_print(&buf, "@%d", __kmp_hws_node.offset);
- comma = 1;
- }
- if (__kmp_hws_tile.num) {
- __kmp_str_buf_print(&buf, "%s%dL2", comma?",":"", __kmp_hws_tile.num);
- if (__kmp_hws_tile.offset)
- __kmp_str_buf_print(&buf, "@%d", __kmp_hws_tile.offset);
- comma = 1;
- }
- if (__kmp_hws_core.num) {
- __kmp_str_buf_print(&buf, "%s%dc", comma?",":"", __kmp_hws_core.num);
- if (__kmp_hws_core.offset)
- __kmp_str_buf_print(&buf, "@%d", __kmp_hws_core.offset);
- comma = 1;
- }
- if (__kmp_hws_proc.num)
- __kmp_str_buf_print(&buf, "%s%dt", comma?",":"", __kmp_hws_proc.num);
- __kmp_str_buf_print(buffer, "%s'\n", buf.str );
- __kmp_str_buf_free(&buf);
- }
+static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
+ void *data ) {
+ if (__kmp_hws_requested) {
+ int comma = 0;
+ kmp_str_buf_t buf;
+ __kmp_str_buf_init(&buf);
+ if (__kmp_env_format)
+ KMP_STR_BUF_PRINT_NAME_EX(name);
+ else
+ __kmp_str_buf_print(buffer, " %s='", name);
+ if (__kmp_hws_socket.num) {
+ __kmp_str_buf_print(&buf, "%ds", __kmp_hws_socket.num);
+ if (__kmp_hws_socket.offset)
+ __kmp_str_buf_print(&buf, "@%d", __kmp_hws_socket.offset);
+ comma = 1;
+ }
+ if (__kmp_hws_node.num) {
+ __kmp_str_buf_print(&buf, "%s%dn", comma?",":"", __kmp_hws_node.num);
+ if (__kmp_hws_node.offset)
+ __kmp_str_buf_print(&buf, "@%d", __kmp_hws_node.offset);
+ comma = 1;
+ }
+ if (__kmp_hws_tile.num) {
+ __kmp_str_buf_print(&buf, "%s%dL2", comma?",":"", __kmp_hws_tile.num);
+ if (__kmp_hws_tile.offset)
+ __kmp_str_buf_print(&buf, "@%d", __kmp_hws_tile.offset);
+ comma = 1;
+ }
+ if (__kmp_hws_core.num) {
+ __kmp_str_buf_print(&buf, "%s%dc", comma?",":"", __kmp_hws_core.num);
+ if (__kmp_hws_core.offset)
+ __kmp_str_buf_print(&buf, "@%d", __kmp_hws_core.offset);
+ comma = 1;
+ }
+ if (__kmp_hws_proc.num)
+ __kmp_str_buf_print(&buf, "%s%dt", comma?",":"", __kmp_hws_proc.num);
+ __kmp_str_buf_print(buffer, "%s'\n", buf.str );
+ __kmp_str_buf_free(&buf);
+ }
}
#if USE_ITT_BUILD
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_FORKJOIN_FRAMES
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_forkjoin_frames( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_bool( name, value, & __kmp_forkjoin_frames );
+static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
+ void *data) {
+ __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
} // __kmp_stg_parse_forkjoin_frames
-static void
-__kmp_stg_print_forkjoin_frames( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_forkjoin_frames );
+static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
} // __kmp_stg_print_forkjoin_frames
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// KMP_FORKJOIN_FRAMES_MODE
-// -------------------------------------------------------------------------------------------------
-static void
-__kmp_stg_parse_forkjoin_frames_mode( char const * name, char const * value, void * data ) {
- __kmp_stg_parse_int( name, value, 0, 3, & __kmp_forkjoin_frames_mode );
+static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
+ char const *value,
+ void *data) {
+ __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
} // __kmp_stg_parse_forkjoin_frames
-static void
-__kmp_stg_print_forkjoin_frames_mode( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_int( buffer, name, __kmp_forkjoin_frames_mode );
+static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
} // __kmp_stg_print_forkjoin_frames
#endif /* USE_ITT_BUILD */
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// OMP_DISPLAY_ENV
-// -------------------------------------------------------------------------------------------------
#if OMP_40_ENABLED
-static void
-__kmp_stg_parse_omp_display_env( char const * name, char const * value, void * data )
-{
- if ( __kmp_str_match( "VERBOSE", 1, value ) )
- {
- __kmp_display_env_verbose = TRUE;
- } else {
- __kmp_stg_parse_bool( name, value, & __kmp_display_env );
- }
+static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
+ void *data) {
+ if (__kmp_str_match("VERBOSE", 1, value)) {
+ __kmp_display_env_verbose = TRUE;
+ } else {
+ __kmp_stg_parse_bool(name, value, &__kmp_display_env);
+ }
} // __kmp_stg_parse_omp_display_env
-static void
-__kmp_stg_print_omp_display_env( kmp_str_buf_t * buffer, char const * name, void * data )
-{
- if ( __kmp_display_env_verbose )
- {
- __kmp_stg_print_str( buffer, name, "VERBOSE" );
- } else {
- __kmp_stg_print_bool( buffer, name, __kmp_display_env );
- }
+static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ if (__kmp_display_env_verbose) {
+ __kmp_stg_print_str(buffer, name, "VERBOSE");
+ } else {
+ __kmp_stg_print_bool(buffer, name, __kmp_display_env);
+ }
} // __kmp_stg_print_omp_display_env
-static void
-__kmp_stg_parse_omp_cancellation( char const * name, char const * value, void * data ) {
- if ( TCR_4(__kmp_init_parallel) ) {
- KMP_WARNING( EnvParallelWarn, name );
- return;
- } // read value before first parallel only
- __kmp_stg_parse_bool( name, value, & __kmp_omp_cancellation );
+static void __kmp_stg_parse_omp_cancellation(char const *name,
+ char const *value, void *data) {
+ if (TCR_4(__kmp_init_parallel)) {
+ KMP_WARNING(EnvParallelWarn, name);
+ return;
+ } // read value before first parallel only
+ __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
} // __kmp_stg_parse_omp_cancellation
-static void
-__kmp_stg_print_omp_cancellation( kmp_str_buf_t * buffer, char const * name, void * data ) {
- __kmp_stg_print_bool( buffer, name, __kmp_omp_cancellation );
+static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
+ char const *name, void *data) {
+ __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
} // __kmp_stg_print_omp_cancellation
#endif
-// -------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// Table.
-// -------------------------------------------------------------------------------------------------
-
static kmp_setting_t __kmp_stg_table[] = {
- { "KMP_ALL_THREADS", __kmp_stg_parse_all_threads, __kmp_stg_print_all_threads, NULL, 0, 0 },
- { "KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime, NULL, 0, 0 },
- { "KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok, __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0 },
- { "KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy, NULL, 0, 0 },
- { "KMP_MAX_THREADS", __kmp_stg_parse_all_threads, NULL, NULL, 0, 0 }, // For backward compatibility
+ {"KMP_ALL_THREADS", __kmp_stg_parse_all_threads,
+ __kmp_stg_print_all_threads, NULL, 0, 0},
+ {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
+ NULL, 0, 0},
+ {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
+ __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
+ {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
+ NULL, 0, 0},
+ {"KMP_MAX_THREADS", __kmp_stg_parse_all_threads, NULL, NULL, 0,
+ 0}, // For backward compatibility
#if KMP_USE_MONITOR
- { "KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize, __kmp_stg_print_monitor_stacksize, NULL, 0, 0 },
+ {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
+ __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
#endif
- { "KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL, 0, 0 },
- { "KMP_STACKOFFSET", __kmp_stg_parse_stackoffset, __kmp_stg_print_stackoffset, NULL, 0, 0 },
- { "KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize, NULL, 0, 0 },
- { "KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL, 0, 0 },
- { "KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0, 0 },
- { "KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL, 0, 0 },
-
- { "OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0 },
- { "OMP_NUM_THREADS", __kmp_stg_parse_num_threads, __kmp_stg_print_num_threads, NULL, 0, 0 },
- { "OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize, NULL, 0, 0 },
-
- { "KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0, 0 },
- { "KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing, __kmp_stg_print_task_stealing, NULL, 0, 0 },
- { "OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels, __kmp_stg_print_max_active_levels, NULL, 0, 0 },
+ {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
+ 0, 0},
+ {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
+ __kmp_stg_print_stackoffset, NULL, 0, 0},
+ {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
+ NULL, 0, 0},
+ {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
+ 0, 0},
+ {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
+ 0},
+ {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
+ 0, 0},
+
+ {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
+ {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
+ __kmp_stg_print_num_threads, NULL, 0, 0},
+ {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
+ NULL, 0, 0},
+
+ {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
+ 0},
+ {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
+ __kmp_stg_print_task_stealing, NULL, 0, 0},
+ {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
+ __kmp_stg_print_max_active_levels, NULL, 0, 0},
#if OMP_40_ENABLED
- { "OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device, __kmp_stg_print_default_device, NULL, 0, 0 },
+ {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
+ __kmp_stg_print_default_device, NULL, 0, 0},
#endif
#if OMP_45_ENABLED
- { "OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority, __kmp_stg_print_max_task_priority, NULL, 0, 0 },
+ {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
+ __kmp_stg_print_max_task_priority, NULL, 0, 0},
#endif
- { "OMP_THREAD_LIMIT", __kmp_stg_parse_all_threads, __kmp_stg_print_all_threads, NULL, 0, 0 },
- { "OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy, NULL, 0, 0 },
- { "KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers, __kmp_stg_print_disp_buffers, NULL, 0, 0 },
+ {"OMP_THREAD_LIMIT", __kmp_stg_parse_all_threads,
+ __kmp_stg_print_all_threads, NULL, 0, 0},
+ {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
+ __kmp_stg_print_wait_policy, NULL, 0, 0},
+ {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
+ __kmp_stg_print_disp_buffers, NULL, 0, 0},
#if KMP_NESTED_HOT_TEAMS
- { "KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level, __kmp_stg_print_hot_teams_level, NULL, 0, 0 },
- { "KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode, __kmp_stg_print_hot_teams_mode, NULL, 0, 0 },
+ {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
+ __kmp_stg_print_hot_teams_level, NULL, 0, 0},
+ {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
+ __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
#endif // KMP_NESTED_HOT_TEAMS
#if KMP_HANDLE_SIGNALS
- { "KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals, __kmp_stg_print_handle_signals, NULL, 0, 0 },
+ {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
+ __kmp_stg_print_handle_signals, NULL, 0, 0},
#endif
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
- { "KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control, __kmp_stg_print_inherit_fp_control, NULL, 0, 0 },
+ {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
+ __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
#ifdef KMP_GOMP_COMPAT
- { "GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0 },
+ {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
#endif
#ifdef KMP_DEBUG
- { "KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0, 0 },
- { "KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0, 0 },
- { "KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0, 0 },
- { "KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0, 0 },
- { "KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0, 0 },
- { "KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0, 0 },
- { "KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0 },
- { "KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf, NULL, 0, 0 },
- { "KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic, __kmp_stg_print_debug_buf_atomic, NULL, 0, 0 },
- { "KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars, __kmp_stg_print_debug_buf_chars, NULL, 0, 0 },
- { "KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines, __kmp_stg_print_debug_buf_lines, NULL, 0, 0 },
- { "KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0 },
-
- { "KMP_PAR_RANGE", __kmp_stg_parse_par_range_env, __kmp_stg_print_par_range_env, NULL, 0, 0 },
- { "KMP_YIELD_CYCLE", __kmp_stg_parse_yield_cycle, __kmp_stg_print_yield_cycle, NULL, 0, 0 },
- { "KMP_YIELD_ON", __kmp_stg_parse_yield_on, __kmp_stg_print_yield_on, NULL, 0, 0 },
- { "KMP_YIELD_OFF", __kmp_stg_parse_yield_off, __kmp_stg_print_yield_off, NULL, 0, 0 },
+ {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
+ 0},
+ {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
+ 0},
+ {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
+ 0},
+ {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
+ 0},
+ {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
+ 0},
+ {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
+ 0},
+ {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
+ {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
+ NULL, 0, 0},
+ {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
+ __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
+ {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
+ __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
+ {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
+ __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
+ {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},
+
+ {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
+ __kmp_stg_print_par_range_env, NULL, 0, 0},
+ {"KMP_YIELD_CYCLE", __kmp_stg_parse_yield_cycle,
+ __kmp_stg_print_yield_cycle, NULL, 0, 0},
+ {"KMP_YIELD_ON", __kmp_stg_parse_yield_on, __kmp_stg_print_yield_on, NULL,
+ 0, 0},
+ {"KMP_YIELD_OFF", __kmp_stg_parse_yield_off, __kmp_stg_print_yield_off,
+ NULL, 0, 0},
#endif // KMP_DEBUG
- { "KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc, __kmp_stg_print_align_alloc, NULL, 0, 0 },
+ {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
+ __kmp_stg_print_align_alloc, NULL, 0, 0},
- { "KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit, __kmp_stg_print_barrier_branch_bit, NULL, 0, 0 },
- { "KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern, __kmp_stg_print_barrier_pattern, NULL, 0, 0 },
- { "KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit, __kmp_stg_print_barrier_branch_bit, NULL, 0, 0 },
- { "KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern, __kmp_stg_print_barrier_pattern, NULL, 0, 0 },
+ {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
+ __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
+ {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
+ __kmp_stg_print_barrier_pattern, NULL, 0, 0},
+ {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
+ __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
+ {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
+ __kmp_stg_print_barrier_pattern, NULL, 0, 0},
#if KMP_FAST_REDUCTION_BARRIER
- { "KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit, __kmp_stg_print_barrier_branch_bit, NULL, 0, 0 },
- { "KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern, __kmp_stg_print_barrier_pattern, NULL, 0, 0 },
+ {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
+ __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
+ {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
+ __kmp_stg_print_barrier_pattern, NULL, 0, 0},
#endif
- { "KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay, __kmp_stg_print_abort_delay, NULL, 0, 0 },
- { "KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file, __kmp_stg_print_cpuinfo_file, NULL, 0, 0 },
- { "KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction, __kmp_stg_print_force_reduction, NULL, 0, 0 },
- { "KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction, __kmp_stg_print_force_reduction, NULL, 0, 0 },
- { "KMP_STORAGE_MAP", __kmp_stg_parse_storage_map, __kmp_stg_print_storage_map, NULL, 0, 0 },
- { "KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate, __kmp_stg_print_all_threadprivate, NULL, 0, 0 },
- { "KMP_FOREIGN_THREADS_THREADPRIVATE", __kmp_stg_parse_foreign_threads_threadprivate, __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0 },
+ {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
+ __kmp_stg_print_abort_delay, NULL, 0, 0},
+ {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
+ __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
+ {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
+ __kmp_stg_print_force_reduction, NULL, 0, 0},
+ {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
+ __kmp_stg_print_force_reduction, NULL, 0, 0},
+ {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
+ __kmp_stg_print_storage_map, NULL, 0, 0},
+ {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
+ __kmp_stg_print_all_threadprivate, NULL, 0, 0},
+ {"KMP_FOREIGN_THREADS_THREADPRIVATE",
+ __kmp_stg_parse_foreign_threads_threadprivate,
+ __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},
#if KMP_AFFINITY_SUPPORTED
- { "KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL, 0, 0 },
-# ifdef KMP_GOMP_COMPAT
- { "GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL, /* no print */ NULL, 0, 0 },
-# endif /* KMP_GOMP_COMPAT */
-# if OMP_40_ENABLED
- { "OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind, NULL, 0, 0 },
- { "OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0 },
-# else
- { "OMP_PROC_BIND", __kmp_stg_parse_proc_bind, NULL, /* no print */ NULL, 0, 0 },
-# endif /* OMP_40_ENABLED */
+ {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
+ 0, 0},
+#ifdef KMP_GOMP_COMPAT
+ {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
+ /* no print */ NULL, 0, 0},
+#endif /* KMP_GOMP_COMPAT */
+#if OMP_40_ENABLED
+ {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
+ NULL, 0, 0},
+ {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
+#else
+ {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, NULL, /* no print */ NULL, 0,
+ 0},
+#endif /* OMP_40_ENABLED */
- { "KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method, __kmp_stg_print_topology_method, NULL, 0, 0 },
+ {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
+ __kmp_stg_print_topology_method, NULL, 0, 0},
#else
- //
- // KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
- // OMP_PROC_BIND and proc-bind-var are supported, however.
- //
-# if OMP_40_ENABLED
- { "OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind, NULL, 0, 0 },
-# endif
+// KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
+// OMP_PROC_BIND and proc-bind-var are supported, however.
+#if OMP_40_ENABLED
+ {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
+ NULL, 0, 0},
+#endif
#endif // KMP_AFFINITY_SUPPORTED
- { "KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork, __kmp_stg_print_init_at_fork, NULL, 0, 0 },
- { "KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL, 0, 0 },
- { "OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule, NULL, 0, 0 },
- { "KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode, __kmp_stg_print_atomic_mode, NULL, 0, 0 },
- { "KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check, __kmp_stg_print_consistency_check, NULL, 0, 0 },
+ {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
+ __kmp_stg_print_init_at_fork, NULL, 0, 0},
+ {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
+ 0, 0},
+ {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
+ NULL, 0, 0},
+ {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
+ __kmp_stg_print_atomic_mode, NULL, 0, 0},
+ {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
+ __kmp_stg_print_consistency_check, NULL, 0, 0},
#if USE_ITT_BUILD && USE_ITT_NOTIFY
- { "KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay, __kmp_stg_print_itt_prepare_delay, NULL, 0, 0 },
+ {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
+ __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
- { "KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr, __kmp_stg_print_malloc_pool_incr, NULL, 0, 0 },
- { "KMP_INIT_WAIT", __kmp_stg_parse_init_wait, __kmp_stg_print_init_wait, NULL, 0, 0 },
- { "KMP_NEXT_WAIT", __kmp_stg_parse_next_wait, __kmp_stg_print_next_wait, NULL, 0, 0 },
- { "KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode, NULL, 0, 0 },
- { "OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic, NULL, 0, 0 },
- { "KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode, __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0 },
+ {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
+ __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
+ {"KMP_INIT_WAIT", __kmp_stg_parse_init_wait, __kmp_stg_print_init_wait,
+ NULL, 0, 0},
+ {"KMP_NEXT_WAIT", __kmp_stg_parse_next_wait, __kmp_stg_print_next_wait,
+ NULL, 0, 0},
+ {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
+ NULL, 0, 0},
+ {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
+ NULL, 0, 0},
+ {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
+ __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},
#ifdef USE_LOAD_BALANCE
- { "KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,__kmp_stg_print_ld_balance_interval,NULL, 0, 0 },
+ {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
+ __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
#endif
- { "KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block, __kmp_stg_print_lock_block, NULL, 0, 0 },
- { "KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind, NULL, 0, 0 },
- { "KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params, __kmp_stg_print_spin_backoff_params, NULL, 0, 0 },
+ {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
+ __kmp_stg_print_lock_block, NULL, 0, 0},
+ {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
+ NULL, 0, 0},
+ {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
+ __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
#if KMP_USE_ADAPTIVE_LOCKS
- { "KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,__kmp_stg_print_adaptive_lock_props, NULL, 0, 0 },
+ {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
+ __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
#if KMP_DEBUG_ADAPTIVE_LOCKS
- { "KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,__kmp_stg_print_speculative_statsfile, NULL, 0, 0 },
+ {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
+ __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
#endif
#endif // KMP_USE_ADAPTIVE_LOCKS
- { "KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset, NULL, 0, 0 },
- { "KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset, NULL, 0, 0 },
+ {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
+ NULL, 0, 0},
+ {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
+ NULL, 0, 0},
#if USE_ITT_BUILD
- { "KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames, __kmp_stg_print_forkjoin_frames, NULL, 0, 0 },
- { "KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,__kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0 },
+ {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
+ __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
+ {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
+ __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
#endif
-# if OMP_40_ENABLED
- { "OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env, __kmp_stg_print_omp_display_env, NULL, 0, 0 },
- { "OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation, __kmp_stg_print_omp_cancellation, NULL, 0, 0 },
+#if OMP_40_ENABLED
+ {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
+ __kmp_stg_print_omp_display_env, NULL, 0, 0},
+ {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
+ __kmp_stg_print_omp_cancellation, NULL, 0, 0},
#endif
- { "", NULL, NULL, NULL, 0, 0 }
-}; // settings
+ {"", NULL, NULL, NULL, 0, 0}}; // settings
-static int const __kmp_stg_count = sizeof( __kmp_stg_table ) / sizeof( kmp_setting_t );
+static int const __kmp_stg_count =
+ sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);
-static inline
-kmp_setting_t *
-__kmp_stg_find( char const * name ) {
+static inline kmp_setting_t *__kmp_stg_find(char const *name) {
- int i;
- if ( name != NULL ) {
- for ( i = 0; i < __kmp_stg_count; ++ i ) {
- if ( strcmp( __kmp_stg_table[ i ].name, name ) == 0 ) {
- return & __kmp_stg_table[ i ];
- }; // if
- }; // for
- }; // if
- return NULL;
+ int i;
+ if (name != NULL) {
+ for (i = 0; i < __kmp_stg_count; ++i) {
+ if (strcmp(__kmp_stg_table[i].name, name) == 0) {
+ return &__kmp_stg_table[i];
+ }; // if
+ }; // for
+ }; // if
+ return NULL;
} // __kmp_stg_find
-
-static int
-__kmp_stg_cmp( void const * _a, void const * _b ) {
- kmp_setting_t * a = (kmp_setting_t *) _a;
- kmp_setting_t * b = (kmp_setting_t *) _b;
-
- //
- // Process KMP_AFFINITY last.
- // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
- //
- if ( strcmp( a->name, "KMP_AFFINITY" ) == 0 ) {
- if ( strcmp( b->name, "KMP_AFFINITY" ) == 0 ) {
- return 0;
- }
- return 1;
- }
- else if ( strcmp( b->name, "KMP_AFFINITY" ) == 0 ) {
- return -1;
- }
- return strcmp( a->name, b->name );
+static int __kmp_stg_cmp(void const *_a, void const *_b) {
+ kmp_setting_t *a = (kmp_setting_t *)_a;
+ kmp_setting_t *b = (kmp_setting_t *)_b;
+
+ // Process KMP_AFFINITY last.
+ // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
+ if (strcmp(a->name, "KMP_AFFINITY") == 0) {
+ if (strcmp(b->name, "KMP_AFFINITY") == 0) {
+ return 0;
+ }
+ return 1;
+ } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
+ return -1;
+ }
+ return strcmp(a->name, b->name);
} // __kmp_stg_cmp
+static void __kmp_stg_init(void) {
-static void
-__kmp_stg_init( void
-) {
-
- static int initialized = 0;
+ static int initialized = 0;
- if ( ! initialized ) {
+ if (!initialized) {
- // Sort table.
- qsort( __kmp_stg_table, __kmp_stg_count - 1, sizeof( kmp_setting_t ), __kmp_stg_cmp );
+ // Sort table.
+ qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
+ __kmp_stg_cmp);
- { // Initialize *_STACKSIZE data.
-
- kmp_setting_t * kmp_stacksize = __kmp_stg_find( "KMP_STACKSIZE" ); // 1st priority.
+ { // Initialize *_STACKSIZE data.
+ kmp_setting_t *kmp_stacksize =
+ __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
#ifdef KMP_GOMP_COMPAT
- kmp_setting_t * gomp_stacksize = __kmp_stg_find( "GOMP_STACKSIZE" ); // 2nd priority.
+ kmp_setting_t *gomp_stacksize =
+ __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
#endif
- kmp_setting_t * omp_stacksize = __kmp_stg_find( "OMP_STACKSIZE" ); // 3rd priority.
+ kmp_setting_t *omp_stacksize =
+ __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.
- // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
- // !!! Compiler does not understand rivals is used and optimizes out assignments
- // !!! rivals[ i ++ ] = ...;
- static kmp_setting_t * volatile rivals[ 4 ];
- static kmp_stg_ss_data_t kmp_data = { 1, (kmp_setting_t **)rivals };
+ // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
+ // !!! Compiler does not understand rivals is used and optimizes out
+ // assignments
+ // !!! rivals[ i ++ ] = ...;
+ static kmp_setting_t *volatile rivals[4];
+ static kmp_stg_ss_data_t kmp_data = {1, (kmp_setting_t **)rivals};
#ifdef KMP_GOMP_COMPAT
- static kmp_stg_ss_data_t gomp_data = { 1024, (kmp_setting_t **)rivals };
+ static kmp_stg_ss_data_t gomp_data = {1024, (kmp_setting_t **)rivals};
#endif
- static kmp_stg_ss_data_t omp_data = { 1024, (kmp_setting_t **)rivals };
- int i = 0;
+ static kmp_stg_ss_data_t omp_data = {1024, (kmp_setting_t **)rivals};
+ int i = 0;
- rivals[ i ++ ] = kmp_stacksize;
+ rivals[i++] = kmp_stacksize;
#ifdef KMP_GOMP_COMPAT
- if ( gomp_stacksize != NULL ) {
- rivals[ i ++ ] = gomp_stacksize;
- }; // if
+ if (gomp_stacksize != NULL) {
+ rivals[i++] = gomp_stacksize;
+ }; // if
#endif
- rivals[ i ++ ] = omp_stacksize;
- rivals[ i ++ ] = NULL;
+ rivals[i++] = omp_stacksize;
+ rivals[i++] = NULL;
- kmp_stacksize->data = & kmp_data;
+ kmp_stacksize->data = &kmp_data;
#ifdef KMP_GOMP_COMPAT
- if ( gomp_stacksize != NULL ) {
- gomp_stacksize->data = & gomp_data;
- }; // if
+ if (gomp_stacksize != NULL) {
+ gomp_stacksize->data = &gomp_data;
+ }; // if
#endif
- omp_stacksize->data = & omp_data;
-
- }
-
- { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
-
- kmp_setting_t * kmp_library = __kmp_stg_find( "KMP_LIBRARY" ); // 1st priority.
- kmp_setting_t * omp_wait_policy = __kmp_stg_find( "OMP_WAIT_POLICY" ); // 2nd priority.
-
- // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
- static kmp_setting_t * volatile rivals[ 3 ];
- static kmp_stg_wp_data_t kmp_data = { 0, (kmp_setting_t **)rivals };
- static kmp_stg_wp_data_t omp_data = { 1, (kmp_setting_t **)rivals };
- int i = 0;
-
- rivals[ i ++ ] = kmp_library;
- if ( omp_wait_policy != NULL ) {
- rivals[ i ++ ] = omp_wait_policy;
- }; // if
- rivals[ i ++ ] = NULL;
-
- kmp_library->data = & kmp_data;
- if ( omp_wait_policy != NULL ) {
- omp_wait_policy->data = & omp_data;
- }; // if
+ omp_stacksize->data = &omp_data;
+ }
- }
+ { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
+ kmp_setting_t *kmp_library =
+ __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
+ kmp_setting_t *omp_wait_policy =
+ __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.
+
+ // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
+ static kmp_setting_t *volatile rivals[3];
+ static kmp_stg_wp_data_t kmp_data = {0, (kmp_setting_t **)rivals};
+ static kmp_stg_wp_data_t omp_data = {1, (kmp_setting_t **)rivals};
+ int i = 0;
+
+ rivals[i++] = kmp_library;
+ if (omp_wait_policy != NULL) {
+ rivals[i++] = omp_wait_policy;
+ }; // if
+ rivals[i++] = NULL;
+
+ kmp_library->data = &kmp_data;
+ if (omp_wait_policy != NULL) {
+ omp_wait_policy->data = &omp_data;
+ }; // if
+ }
+
+ { // Initialize KMP_ALL_THREADS, KMP_MAX_THREADS, and OMP_THREAD_LIMIT data.
+ kmp_setting_t *kmp_all_threads =
+ __kmp_stg_find("KMP_ALL_THREADS"); // 1st priority.
+ kmp_setting_t *kmp_max_threads =
+ __kmp_stg_find("KMP_MAX_THREADS"); // 2nd priority.
+ kmp_setting_t *omp_thread_limit =
+ __kmp_stg_find("OMP_THREAD_LIMIT"); // 3rd priority.
+
+ // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
+ static kmp_setting_t *volatile rivals[4];
+ int i = 0;
+
+ rivals[i++] = kmp_all_threads;
+ rivals[i++] = kmp_max_threads;
+ if (omp_thread_limit != NULL) {
+ rivals[i++] = omp_thread_limit;
+ }; // if
+ rivals[i++] = NULL;
+
+ kmp_all_threads->data = (void *)&rivals;
+ kmp_max_threads->data = (void *)&rivals;
+ if (omp_thread_limit != NULL) {
+ omp_thread_limit->data = (void *)&rivals;
+ }; // if
+ }
- { // Initialize KMP_ALL_THREADS, KMP_MAX_THREADS, and OMP_THREAD_LIMIT data.
+#if KMP_AFFINITY_SUPPORTED
+ { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
+ kmp_setting_t *kmp_affinity =
+ __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
+ KMP_DEBUG_ASSERT(kmp_affinity != NULL);
- kmp_setting_t * kmp_all_threads = __kmp_stg_find( "KMP_ALL_THREADS" ); // 1st priority.
- kmp_setting_t * kmp_max_threads = __kmp_stg_find( "KMP_MAX_THREADS" ); // 2nd priority.
- kmp_setting_t * omp_thread_limit = __kmp_stg_find( "OMP_THREAD_LIMIT" ); // 3rd priority.
-
- // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
- static kmp_setting_t * volatile rivals[ 4 ];
- int i = 0;
-
- rivals[ i ++ ] = kmp_all_threads;
- rivals[ i ++ ] = kmp_max_threads;
- if ( omp_thread_limit != NULL ) {
- rivals[ i ++ ] = omp_thread_limit;
- }; // if
- rivals[ i ++ ] = NULL;
-
- kmp_all_threads->data = (void*)& rivals;
- kmp_max_threads->data = (void*)& rivals;
- if ( omp_thread_limit != NULL ) {
- omp_thread_limit->data = (void*)& rivals;
- }; // if
+#ifdef KMP_GOMP_COMPAT
+ kmp_setting_t *gomp_cpu_affinity =
+ __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
+ KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
+#endif
- }
+ kmp_setting_t *omp_proc_bind =
+ __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
+ KMP_DEBUG_ASSERT(omp_proc_bind != NULL);
+
+ // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
+ static kmp_setting_t *volatile rivals[4];
+ int i = 0;
-#if KMP_AFFINITY_SUPPORTED
- { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
+ rivals[i++] = kmp_affinity;
- kmp_setting_t * kmp_affinity = __kmp_stg_find( "KMP_AFFINITY" ); // 1st priority.
- KMP_DEBUG_ASSERT( kmp_affinity != NULL );
+#ifdef KMP_GOMP_COMPAT
+ rivals[i++] = gomp_cpu_affinity;
+ gomp_cpu_affinity->data = (void *)&rivals;
+#endif
-# ifdef KMP_GOMP_COMPAT
- kmp_setting_t * gomp_cpu_affinity = __kmp_stg_find( "GOMP_CPU_AFFINITY" ); // 2nd priority.
- KMP_DEBUG_ASSERT( gomp_cpu_affinity != NULL );
-# endif
+ rivals[i++] = omp_proc_bind;
+ omp_proc_bind->data = (void *)&rivals;
+ rivals[i++] = NULL;
- kmp_setting_t * omp_proc_bind = __kmp_stg_find( "OMP_PROC_BIND" ); // 3rd priority.
- KMP_DEBUG_ASSERT( omp_proc_bind != NULL );
+#if OMP_40_ENABLED
+ static kmp_setting_t *volatile places_rivals[4];
+ i = 0;
- // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
- static kmp_setting_t * volatile rivals[ 4 ];
- int i = 0;
-
- rivals[ i ++ ] = kmp_affinity;
-
-# ifdef KMP_GOMP_COMPAT
- rivals[ i ++ ] = gomp_cpu_affinity;
- gomp_cpu_affinity->data = (void*)& rivals;
-# endif
+ kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
+ KMP_DEBUG_ASSERT(omp_places != NULL);
- rivals[ i ++ ] = omp_proc_bind;
- omp_proc_bind->data = (void*)& rivals;
- rivals[ i ++ ] = NULL;
-
-# if OMP_40_ENABLED
- static kmp_setting_t * volatile places_rivals[ 4 ];
- i = 0;
-
- kmp_setting_t * omp_places = __kmp_stg_find( "OMP_PLACES" ); // 3rd priority.
- KMP_DEBUG_ASSERT( omp_places != NULL );
-
- places_rivals[ i ++ ] = kmp_affinity;
-# ifdef KMP_GOMP_COMPAT
- places_rivals[ i ++ ] = gomp_cpu_affinity;
-# endif
- places_rivals[ i ++ ] = omp_places;
- omp_places->data = (void*)& places_rivals;
- places_rivals[ i ++ ] = NULL;
-# endif
- }
+ places_rivals[i++] = kmp_affinity;
+#ifdef KMP_GOMP_COMPAT
+ places_rivals[i++] = gomp_cpu_affinity;
+#endif
+ places_rivals[i++] = omp_places;
+ omp_places->data = (void *)&places_rivals;
+ places_rivals[i++] = NULL;
+#endif
+ }
#else
- // KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
- // OMP_PLACES not supported yet.
+// KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
+// OMP_PLACES not supported yet.
#endif // KMP_AFFINITY_SUPPORTED
- { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
-
- kmp_setting_t * kmp_force_red = __kmp_stg_find( "KMP_FORCE_REDUCTION" ); // 1st priority.
- kmp_setting_t * kmp_determ_red = __kmp_stg_find( "KMP_DETERMINISTIC_REDUCTION" ); // 2nd priority.
-
- // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
- static kmp_setting_t * volatile rivals[ 3 ];
- static kmp_stg_fr_data_t force_data = { 1, (kmp_setting_t **)rivals };
- static kmp_stg_fr_data_t determ_data = { 0, (kmp_setting_t **)rivals };
- int i = 0;
-
- rivals[ i ++ ] = kmp_force_red;
- if ( kmp_determ_red != NULL ) {
- rivals[ i ++ ] = kmp_determ_red;
- }; // if
- rivals[ i ++ ] = NULL;
-
- kmp_force_red->data = & force_data;
- if ( kmp_determ_red != NULL ) {
- kmp_determ_red->data = & determ_data;
- }; // if
- }
-
- initialized = 1;
-
- }; // if
-
- // Reset flags.
- int i;
- for ( i = 0; i < __kmp_stg_count; ++ i ) {
- __kmp_stg_table[ i ].set = 0;
- }; // for
+ { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
+ kmp_setting_t *kmp_force_red =
+ __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
+ kmp_setting_t *kmp_determ_red =
+ __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.
+
+ // !!! volatile keyword is Intel (R) C Compiler bug CQ49908 workaround.
+ static kmp_setting_t *volatile rivals[3];
+ static kmp_stg_fr_data_t force_data = {1, (kmp_setting_t **)rivals};
+ static kmp_stg_fr_data_t determ_data = {0, (kmp_setting_t **)rivals};
+ int i = 0;
+
+ rivals[i++] = kmp_force_red;
+ if (kmp_determ_red != NULL) {
+ rivals[i++] = kmp_determ_red;
+ }; // if
+ rivals[i++] = NULL;
+
+ kmp_force_red->data = &force_data;
+ if (kmp_determ_red != NULL) {
+ kmp_determ_red->data = &determ_data;
+ }; // if
+ }
+
+ initialized = 1;
+ }; // if
+
+ // Reset flags.
+ int i;
+ for (i = 0; i < __kmp_stg_count; ++i) {
+ __kmp_stg_table[i].set = 0;
+ }; // for
} // __kmp_stg_init
-
-static void
-__kmp_stg_parse(
- char const * name,
- char const * value
-) {
-
- // On Windows* OS there are some nameless variables like "C:=C:\" (yeah, really nameless, they are
- // presented in environment block as "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
- if ( name[ 0 ] == 0 ) {
- return;
- }; // if
-
- if ( value != NULL ) {
- kmp_setting_t * setting = __kmp_stg_find( name );
- if ( setting != NULL ) {
- setting->parse( name, value, setting->data );
- setting->defined = 1;
- }; // if
+static void __kmp_stg_parse(char const *name, char const *value) {
+ // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
+ // really nameless, they are presented in environment block as
+ // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
+ if (name[0] == 0) {
+ return;
+ }; // if
+
+ if (value != NULL) {
+ kmp_setting_t *setting = __kmp_stg_find(name);
+ if (setting != NULL) {
+ setting->parse(name, value, setting->data);
+ setting->defined = 1;
}; // if
+ }; // if
} // __kmp_stg_parse
+static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
+ char const *name, // Name of variable.
+ char const *value, // Value of the variable.
+ kmp_setting_t **rivals // List of rival settings (must include current one).
+ ) {
-static int
-__kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
- char const * name, // Name of variable.
- char const * value, // Value of the variable.
- kmp_setting_t * * rivals // List of rival settings (the list must include current one).
-) {
-
- if ( rivals == NULL ) {
- return 0;
- }
+ if (rivals == NULL) {
+ return 0;
+ }
- // Loop thru higher priority settings (listed before current).
- int i = 0;
- for ( ; strcmp( rivals[ i ]->name, name ) != 0; i++ ) {
- KMP_DEBUG_ASSERT( rivals[ i ] != NULL );
+ // Loop thru higher priority settings (listed before current).
+ int i = 0;
+ for (; strcmp(rivals[i]->name, name) != 0; i++) {
+ KMP_DEBUG_ASSERT(rivals[i] != NULL);
#if KMP_AFFINITY_SUPPORTED
- if ( rivals[ i ] == __kmp_affinity_notype ) {
- //
- // If KMP_AFFINITY is specified without a type name,
- // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
- //
- continue;
- }
+ if (rivals[i] == __kmp_affinity_notype) {
+ // If KMP_AFFINITY is specified without a type name,
+ // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
+ continue;
+ }
#endif
- if ( rivals[ i ]->set ) {
- KMP_WARNING( StgIgnored, name, rivals[ i ]->name );
- return 1;
- }; // if
- }; // while
+ if (rivals[i]->set) {
+ KMP_WARNING(StgIgnored, name, rivals[i]->name);
+ return 1;
+ }; // if
+ }; // while
- ++ i; // Skip current setting.
- return 0;
+ ++i; // Skip current setting.
+ return 0;
}; // __kmp_stg_check_rivals
-
-static int
-__kmp_env_toPrint( char const * name, int flag ) {
- int rc = 0;
- kmp_setting_t * setting = __kmp_stg_find( name );
- if ( setting != NULL ) {
- rc = setting->defined;
- if ( flag >= 0 ) {
- setting->defined = flag;
- }; // if
+static int __kmp_env_toPrint(char const *name, int flag) {
+ int rc = 0;
+ kmp_setting_t *setting = __kmp_stg_find(name);
+ if (setting != NULL) {
+ rc = setting->defined;
+ if (flag >= 0) {
+ setting->defined = flag;
}; // if
- return rc;
+ }; // if
+ return rc;
}
+static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {
-static void
-__kmp_aux_env_initialize( kmp_env_blk_t* block ) {
-
- char const * value;
+ char const *value;
- /* OMP_NUM_THREADS */
- value = __kmp_env_blk_var( block, "OMP_NUM_THREADS" );
- if ( value ) {
- ompc_set_num_threads( __kmp_dflt_team_nth );
- }
+ /* OMP_NUM_THREADS */
+ value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
+ if (value) {
+ ompc_set_num_threads(__kmp_dflt_team_nth);
+ }
- /* KMP_BLOCKTIME */
- value = __kmp_env_blk_var( block, "KMP_BLOCKTIME" );
- if ( value ) {
- kmpc_set_blocktime( __kmp_dflt_blocktime );
- }
+ /* KMP_BLOCKTIME */
+ value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
+ if (value) {
+ kmpc_set_blocktime(__kmp_dflt_blocktime);
+ }
- /* OMP_NESTED */
- value = __kmp_env_blk_var( block, "OMP_NESTED" );
- if ( value ) {
- ompc_set_nested( __kmp_dflt_nested );
- }
+ /* OMP_NESTED */
+ value = __kmp_env_blk_var(block, "OMP_NESTED");
+ if (value) {
+ ompc_set_nested(__kmp_dflt_nested);
+ }
- /* OMP_DYNAMIC */
- value = __kmp_env_blk_var( block, "OMP_DYNAMIC" );
- if ( value ) {
- ompc_set_dynamic( __kmp_global.g.g_dynamic );
- }
+ /* OMP_DYNAMIC */
+ value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
+ if (value) {
+ ompc_set_dynamic(__kmp_global.g.g_dynamic);
+ }
}
-void
-__kmp_env_initialize( char const * string ) {
-
- kmp_env_blk_t block;
- int i;
-
- __kmp_stg_init();
+void __kmp_env_initialize(char const *string) {
- // Hack!!!
- if ( string == NULL ) {
- // __kmp_max_nth = __kmp_sys_max_nth;
- __kmp_threads_capacity = __kmp_initial_threads_capacity( __kmp_dflt_team_nth_ub );
- }; // if
- __kmp_env_blk_init( & block, string );
-
- //
- // update the set flag on all entries that have an env var
- //
- for ( i = 0; i < block.count; ++ i ) {
- if (( block.vars[ i ].name == NULL )
- || ( *block.vars[ i ].name == '\0')) {
- continue;
- }
- if ( block.vars[ i ].value == NULL ) {
- continue;
- }
- kmp_setting_t * setting = __kmp_stg_find( block.vars[ i ].name );
- if ( setting != NULL ) {
- setting->set = 1;
- }
- }; // for i
+ kmp_env_blk_t block;
+ int i;
- // We need to know if blocktime was set when processing OMP_WAIT_POLICY
- blocktime_str = __kmp_env_blk_var( & block, "KMP_BLOCKTIME" );
+ __kmp_stg_init();
- // Special case. If we parse environment, not a string, process KMP_WARNINGS first.
- if ( string == NULL ) {
- char const * name = "KMP_WARNINGS";
- char const * value = __kmp_env_blk_var( & block, name );
- __kmp_stg_parse( name, value );
- }; // if
+ // Hack!!!
+ if (string == NULL) {
+ // __kmp_max_nth = __kmp_sys_max_nth;
+ __kmp_threads_capacity =
+ __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
+ }; // if
+ __kmp_env_blk_init(&block, string);
+
+ // update the set flag on all entries that have an env var
+ for (i = 0; i < block.count; ++i) {
+ if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
+ continue;
+ }
+ if (block.vars[i].value == NULL) {
+ continue;
+ }
+ kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
+ if (setting != NULL) {
+ setting->set = 1;
+ }
+ }; // for i
+
+ // We need to know if blocktime was set when processing OMP_WAIT_POLICY
+ blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");
+
+ // Special case. If we parse environment, not a string, process KMP_WARNINGS
+ // first.
+ if (string == NULL) {
+ char const *name = "KMP_WARNINGS";
+ char const *value = __kmp_env_blk_var(&block, name);
+ __kmp_stg_parse(name, value);
+ }; // if
#if KMP_AFFINITY_SUPPORTED
- //
- // Special case. KMP_AFFINITY is not a rival to other affinity env vars
- // if no affinity type is specified. We want to allow
- // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
- // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
- // affinity mechanism.
- //
- __kmp_affinity_notype = NULL;
- char const *aff_str = __kmp_env_blk_var( & block, "KMP_AFFINITY" );
- if ( aff_str != NULL ) {
- //
- // Check if the KMP_AFFINITY type is specified in the string.
- // We just search the string for "compact", "scatter", etc.
- // without really parsing the string. The syntax of the
- // KMP_AFFINITY env var is such that none of the affinity
- // type names can appear anywhere other that the type
- // specifier, even as substrings.
- //
- // I can't find a case-insensitive version of strstr on Windows* OS.
- // Use the case-sensitive version for now.
- //
-
-# if KMP_OS_WINDOWS
-# define FIND strstr
-# else
-# define FIND strcasestr
-# endif
+ // Special case. KMP_AFFINITY is not a rival to other affinity env vars
+ // if no affinity type is specified. We want to allow
+ // KMP_AFFINITY=[no],verbose/[no]warnings/etc. to be enabled when
+ // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
+ // affinity mechanism.
+ __kmp_affinity_notype = NULL;
+ char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
+ if (aff_str != NULL) {
+// Check if the KMP_AFFINITY type is specified in the string.
+// We just search the string for "compact", "scatter", etc.
+// without really parsing the string. The syntax of the
+// KMP_AFFINITY env var is such that none of the affinity
+// type names can appear anywhere other that the type
+// specifier, even as substrings.
+//
+// I can't find a case-insensitive version of strstr on Windows* OS.
+// Use the case-sensitive version for now.
- if ( ( FIND( aff_str, "none" ) == NULL )
- && ( FIND( aff_str, "physical" ) == NULL )
- && ( FIND( aff_str, "logical" ) == NULL )
- && ( FIND( aff_str, "compact" ) == NULL )
- && ( FIND( aff_str, "scatter" ) == NULL )
- && ( FIND( aff_str, "explicit" ) == NULL )
- && ( FIND( aff_str, "balanced" ) == NULL )
- && ( FIND( aff_str, "disabled" ) == NULL ) ) {
- __kmp_affinity_notype = __kmp_stg_find( "KMP_AFFINITY" );
- }
- else {
- //
- // A new affinity type is specified.
- // Reset the affinity flags to their default values,
- // in case this is called from kmp_set_defaults().
- //
- __kmp_affinity_type = affinity_default;
- __kmp_affinity_gran = affinity_gran_default;
- __kmp_affinity_top_method = affinity_top_method_default;
- __kmp_affinity_respect_mask = affinity_respect_mask_default;
- }
-# undef FIND
+#if KMP_OS_WINDOWS
+#define FIND strstr
+#else
+#define FIND strcasestr
+#endif
+
+ if ((FIND(aff_str, "none") == NULL) &&
+ (FIND(aff_str, "physical") == NULL) &&
+ (FIND(aff_str, "logical") == NULL) &&
+ (FIND(aff_str, "compact") == NULL) &&
+ (FIND(aff_str, "scatter") == NULL) &&
+ (FIND(aff_str, "explicit") == NULL) &&
+ (FIND(aff_str, "balanced") == NULL) &&
+ (FIND(aff_str, "disabled") == NULL)) {
+ __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
+ } else {
+ // A new affinity type is specified.
+ // Reset the affinity flags to their default values,
+ // in case this is called from kmp_set_defaults().
+ __kmp_affinity_type = affinity_default;
+ __kmp_affinity_gran = affinity_gran_default;
+ __kmp_affinity_top_method = affinity_top_method_default;
+ __kmp_affinity_respect_mask = affinity_respect_mask_default;
+ }
+#undef FIND
#if OMP_40_ENABLED
- //
- // Also reset the affinity flags if OMP_PROC_BIND is specified.
- //
- aff_str = __kmp_env_blk_var( & block, "OMP_PROC_BIND" );
- if ( aff_str != NULL ) {
- __kmp_affinity_type = affinity_default;
- __kmp_affinity_gran = affinity_gran_default;
- __kmp_affinity_top_method = affinity_top_method_default;
- __kmp_affinity_respect_mask = affinity_respect_mask_default;
- }
-#endif /* OMP_40_ENABLED */
+ // Also reset the affinity flags if OMP_PROC_BIND is specified.
+ aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
+ if (aff_str != NULL) {
+ __kmp_affinity_type = affinity_default;
+ __kmp_affinity_gran = affinity_gran_default;
+ __kmp_affinity_top_method = affinity_top_method_default;
+ __kmp_affinity_respect_mask = affinity_respect_mask_default;
}
+#endif /* OMP_40_ENABLED */
+ }
#endif /* KMP_AFFINITY_SUPPORTED */
#if OMP_40_ENABLED
- //
- // Set up the nested proc bind type vector.
- //
- if ( __kmp_nested_proc_bind.bind_types == NULL ) {
- __kmp_nested_proc_bind.bind_types = (kmp_proc_bind_t *)
- KMP_INTERNAL_MALLOC( sizeof(kmp_proc_bind_t) );
- if ( __kmp_nested_proc_bind.bind_types == NULL ) {
- KMP_FATAL( MemoryAllocFailed );
- }
- __kmp_nested_proc_bind.size = 1;
- __kmp_nested_proc_bind.used = 1;
-# if KMP_AFFINITY_SUPPORTED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
-# else
- // default proc bind is false if affinity not supported
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
-# endif
-
+ // Set up the nested proc bind type vector.
+ if (__kmp_nested_proc_bind.bind_types == NULL) {
+ __kmp_nested_proc_bind.bind_types =
+ (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
+ if (__kmp_nested_proc_bind.bind_types == NULL) {
+ KMP_FATAL(MemoryAllocFailed);
}
+ __kmp_nested_proc_bind.size = 1;
+ __kmp_nested_proc_bind.used = 1;
+#if KMP_AFFINITY_SUPPORTED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
+#else
+ // default proc bind is false if affinity not supported
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
+#endif
+ }
#endif /* OMP_40_ENABLED */
- //
- // Now process all of the settings.
- //
- for ( i = 0; i < block.count; ++ i ) {
- __kmp_stg_parse( block.vars[ i ].name, block.vars[ i ].value );
- }; // for i
-
- //
- // If user locks have been allocated yet, don't reset the lock vptr table.
- //
- if ( ! __kmp_init_user_locks ) {
- if ( __kmp_user_lock_kind == lk_default ) {
- __kmp_user_lock_kind = lk_queuing;
- }
+ // Now process all of the settings.
+ for (i = 0; i < block.count; ++i) {
+ __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
+ }; // for i
+
+ // If user locks have been allocated yet, don't reset the lock vptr table.
+ if (!__kmp_init_user_locks) {
+ if (__kmp_user_lock_kind == lk_default) {
+ __kmp_user_lock_kind = lk_queuing;
+ }
#if KMP_USE_DYNAMIC_LOCK
- __kmp_init_dynamic_user_locks();
+ __kmp_init_dynamic_user_locks();
#else
- __kmp_set_user_lock_vptrs( __kmp_user_lock_kind );
+ __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
#endif
- }
- else {
- KMP_DEBUG_ASSERT( string != NULL); // kmp_set_defaults() was called
- KMP_DEBUG_ASSERT( __kmp_user_lock_kind != lk_default );
- // Binds lock functions again to follow the transition between different
- // KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
- // as we do not allow lock kind changes after making a call to any
- // user lock functions (true).
+ } else {
+ KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
+ KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
+// Binds lock functions again to follow the transition between different
+// KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
+// as we do not allow lock kind changes after making a call to any
+// user lock functions (true).
#if KMP_USE_DYNAMIC_LOCK
- __kmp_init_dynamic_user_locks();
+ __kmp_init_dynamic_user_locks();
#else
- __kmp_set_user_lock_vptrs( __kmp_user_lock_kind );
+ __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
#endif
- }
+ }
#if KMP_AFFINITY_SUPPORTED
- if ( ! TCR_4(__kmp_init_middle) ) {
- //
- // Determine if the machine/OS is actually capable of supporting
- // affinity.
- //
- const char *var = "KMP_AFFINITY";
- KMPAffinity::pick_api();
- if ( __kmp_affinity_type == affinity_disabled ) {
- KMP_AFFINITY_DISABLE();
- }
- else if ( ! KMP_AFFINITY_CAPABLE() ) {
- __kmp_affinity_dispatch->determine_capable(var);
- if ( ! KMP_AFFINITY_CAPABLE() ) {
- if ( __kmp_affinity_verbose || ( __kmp_affinity_warnings
- && ( __kmp_affinity_type != affinity_default )
- && ( __kmp_affinity_type != affinity_none )
- && ( __kmp_affinity_type != affinity_disabled ) ) ) {
- KMP_WARNING( AffNotSupported, var );
- }
- __kmp_affinity_type = affinity_disabled;
- __kmp_affinity_respect_mask = 0;
- __kmp_affinity_gran = affinity_gran_fine;
- }
+ if (!TCR_4(__kmp_init_middle)) {
+ // Determine if the machine/OS is actually capable of supporting
+ // affinity.
+ const char *var = "KMP_AFFINITY";
+ KMPAffinity::pick_api();
+ if (__kmp_affinity_type == affinity_disabled) {
+ KMP_AFFINITY_DISABLE();
+ } else if (!KMP_AFFINITY_CAPABLE()) {
+ __kmp_affinity_dispatch->determine_capable(var);
+ if (!KMP_AFFINITY_CAPABLE()) {
+ if (__kmp_affinity_verbose ||
+ (__kmp_affinity_warnings &&
+ (__kmp_affinity_type != affinity_default) &&
+ (__kmp_affinity_type != affinity_none) &&
+ (__kmp_affinity_type != affinity_disabled))) {
+ KMP_WARNING(AffNotSupported, var);
}
+ __kmp_affinity_type = affinity_disabled;
+ __kmp_affinity_respect_mask = 0;
+ __kmp_affinity_gran = affinity_gran_fine;
+ }
+ }
-# if OMP_40_ENABLED
- if ( __kmp_affinity_type == affinity_disabled ) {
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
- }
- else if ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_true ) {
- //
- // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
- //
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
- }
-# endif /* OMP_40_ENABLED */
+#if OMP_40_ENABLED
+ if (__kmp_affinity_type == affinity_disabled) {
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
+ } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
+ // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
+ }
+#endif /* OMP_40_ENABLED */
- if ( KMP_AFFINITY_CAPABLE() ) {
+ if (KMP_AFFINITY_CAPABLE()) {
-# if KMP_GROUP_AFFINITY
+#if KMP_GROUP_AFFINITY
- //
- // Handle the Win 64 group affinity stuff if there are multiple
- // processor groups, or if the user requested it, and OMP 4.0
- // affinity is not in effect.
- //
- if ( ( ( __kmp_num_proc_groups > 1 )
- && ( __kmp_affinity_type == affinity_default )
-# if OMP_40_ENABLED
- && ( __kmp_nested_proc_bind.bind_types[0] == proc_bind_default ) )
-# endif
- || ( __kmp_affinity_top_method == affinity_top_method_group ) ) {
- if ( __kmp_affinity_respect_mask == affinity_respect_mask_default ) {
- __kmp_affinity_respect_mask = FALSE;
- }
- if ( __kmp_affinity_type == affinity_default ) {
- __kmp_affinity_type = affinity_compact;
-# if OMP_40_ENABLED
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
-# endif
- }
- if ( __kmp_affinity_top_method == affinity_top_method_default ) {
- if ( __kmp_affinity_gran == affinity_gran_default ) {
- __kmp_affinity_top_method = affinity_top_method_group;
- __kmp_affinity_gran = affinity_gran_group;
- }
- else if ( __kmp_affinity_gran == affinity_gran_group ) {
- __kmp_affinity_top_method = affinity_top_method_group;
- }
- else {
- __kmp_affinity_top_method = affinity_top_method_all;
- }
- }
- else if ( __kmp_affinity_top_method == affinity_top_method_group ) {
- if ( __kmp_affinity_gran == affinity_gran_default ) {
- __kmp_affinity_gran = affinity_gran_group;
- }
- else if ( ( __kmp_affinity_gran != affinity_gran_group )
- && ( __kmp_affinity_gran != affinity_gran_fine )
- && ( __kmp_affinity_gran != affinity_gran_thread ) ) {
- const char *str = NULL;
- switch ( __kmp_affinity_gran ) {
- case affinity_gran_core: str = "core"; break;
- case affinity_gran_package: str = "package"; break;
- case affinity_gran_node: str = "node"; break;
- default: KMP_DEBUG_ASSERT( 0 );
- }
- KMP_WARNING( AffGranTopGroup, var, str );
- __kmp_affinity_gran = affinity_gran_fine;
- }
- }
- else {
- if ( __kmp_affinity_gran == affinity_gran_default ) {
- __kmp_affinity_gran = affinity_gran_core;
- }
- else if ( __kmp_affinity_gran == affinity_gran_group ) {
- const char *str = NULL;
- switch ( __kmp_affinity_type ) {
- case affinity_physical: str = "physical"; break;
- case affinity_logical: str = "logical"; break;
- case affinity_compact: str = "compact"; break;
- case affinity_scatter: str = "scatter"; break;
- case affinity_explicit: str = "explicit"; break;
- // No MIC on windows, so no affinity_balanced case
- default: KMP_DEBUG_ASSERT( 0 );
- }
- KMP_WARNING( AffGranGroupType, var, str );
- __kmp_affinity_gran = affinity_gran_core;
- }
- }
+ // Handle the Win 64 group affinity stuff if there are multiple
+ // processor groups, or if the user requested it, and OMP 4.0
+ // affinity is not in effect.
+ if (((__kmp_num_proc_groups > 1) &&
+ (__kmp_affinity_type == affinity_default)
+#if OMP_40_ENABLED
+ && (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default))
+#endif
+ || (__kmp_affinity_top_method == affinity_top_method_group)) {
+ if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
+ __kmp_affinity_respect_mask = FALSE;
+ }
+ if (__kmp_affinity_type == affinity_default) {
+ __kmp_affinity_type = affinity_compact;
+#if OMP_40_ENABLED
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
+#endif
+ }
+ if (__kmp_affinity_top_method == affinity_top_method_default) {
+ if (__kmp_affinity_gran == affinity_gran_default) {
+ __kmp_affinity_top_method = affinity_top_method_group;
+ __kmp_affinity_gran = affinity_gran_group;
+ } else if (__kmp_affinity_gran == affinity_gran_group) {
+ __kmp_affinity_top_method = affinity_top_method_group;
+ } else {
+ __kmp_affinity_top_method = affinity_top_method_all;
+ }
+ } else if (__kmp_affinity_top_method == affinity_top_method_group) {
+ if (__kmp_affinity_gran == affinity_gran_default) {
+ __kmp_affinity_gran = affinity_gran_group;
+ } else if ((__kmp_affinity_gran != affinity_gran_group) &&
+ (__kmp_affinity_gran != affinity_gran_fine) &&
+ (__kmp_affinity_gran != affinity_gran_thread)) {
+ const char *str = NULL;
+ switch (__kmp_affinity_gran) {
+ case affinity_gran_core:
+ str = "core";
+ break;
+ case affinity_gran_package:
+ str = "package";
+ break;
+ case affinity_gran_node:
+ str = "node";
+ break;
+ default:
+ KMP_DEBUG_ASSERT(0);
}
- else
-
-# endif /* KMP_GROUP_AFFINITY */
-
- {
- if ( __kmp_affinity_respect_mask == affinity_respect_mask_default ) {
-# if KMP_GROUP_AFFINITY
- if ( __kmp_num_proc_groups > 1 ) {
- __kmp_affinity_respect_mask = FALSE;
- }
- else
-# endif /* KMP_GROUP_AFFINITY */
- {
- __kmp_affinity_respect_mask = TRUE;
- }
- }
-# if OMP_40_ENABLED
- if ( ( __kmp_nested_proc_bind.bind_types[0] != proc_bind_intel )
- && ( __kmp_nested_proc_bind.bind_types[0] != proc_bind_default ) ) {
- if ( __kmp_affinity_type == affinity_default ) {
- __kmp_affinity_type = affinity_compact;
- __kmp_affinity_dups = FALSE;
- }
- }
- else
-# endif /* OMP_40_ENABLED */
- if ( __kmp_affinity_type == affinity_default ) {
+ KMP_WARNING(AffGranTopGroup, var, str);
+ __kmp_affinity_gran = affinity_gran_fine;
+ }
+ } else {
+ if (__kmp_affinity_gran == affinity_gran_default) {
+ __kmp_affinity_gran = affinity_gran_core;
+ } else if (__kmp_affinity_gran == affinity_gran_group) {
+ const char *str = NULL;
+ switch (__kmp_affinity_type) {
+ case affinity_physical:
+ str = "physical";
+ break;
+ case affinity_logical:
+ str = "logical";
+ break;
+ case affinity_compact:
+ str = "compact";
+ break;
+ case affinity_scatter:
+ str = "scatter";
+ break;
+ case affinity_explicit:
+ str = "explicit";
+ break;
+ // No MIC on windows, so no affinity_balanced case
+ default:
+ KMP_DEBUG_ASSERT(0);
+ }
+ KMP_WARNING(AffGranGroupType, var, str);
+ __kmp_affinity_gran = affinity_gran_core;
+ }
+ }
+ } else
+
+#endif /* KMP_GROUP_AFFINITY */
+
+ {
+ if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
+#if KMP_GROUP_AFFINITY
+ if (__kmp_num_proc_groups > 1) {
+ __kmp_affinity_respect_mask = FALSE;
+ } else
+#endif /* KMP_GROUP_AFFINITY */
+ {
+ __kmp_affinity_respect_mask = TRUE;
+ }
+ }
+#if OMP_40_ENABLED
+ if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
+ (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
+ if (__kmp_affinity_type == affinity_default) {
+ __kmp_affinity_type = affinity_compact;
+ __kmp_affinity_dups = FALSE;
+ }
+ } else
+#endif /* OMP_40_ENABLED */
+ if (__kmp_affinity_type == affinity_default) {
#if OMP_40_ENABLED
#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
- if( __kmp_mic_type != non_mic ) {
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
- } else
-#endif
- {
- __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
- }
+ if (__kmp_mic_type != non_mic) {
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
+ } else
+#endif
+ {
+ __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
+ }
#endif /* OMP_40_ENABLED */
#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
- if( __kmp_mic_type != non_mic ) {
- __kmp_affinity_type = affinity_scatter;
- } else
-#endif
- {
- __kmp_affinity_type = affinity_none;
- }
-
- }
- if ( ( __kmp_affinity_gran == affinity_gran_default )
- && ( __kmp_affinity_gran_levels < 0 ) ) {
+ if (__kmp_mic_type != non_mic) {
+ __kmp_affinity_type = affinity_scatter;
+ } else
+#endif
+ {
+ __kmp_affinity_type = affinity_none;
+ }
+ }
+ if ((__kmp_affinity_gran == affinity_gran_default) &&
+ (__kmp_affinity_gran_levels < 0)) {
#if KMP_ARCH_X86_64 && (KMP_OS_LINUX || KMP_OS_WINDOWS)
- if( __kmp_mic_type != non_mic ) {
- __kmp_affinity_gran = affinity_gran_fine;
- } else
-#endif
- {
- __kmp_affinity_gran = affinity_gran_core;
- }
- }
- if ( __kmp_affinity_top_method == affinity_top_method_default ) {
- __kmp_affinity_top_method = affinity_top_method_all;
- }
- }
+ if (__kmp_mic_type != non_mic) {
+ __kmp_affinity_gran = affinity_gran_fine;
+ } else
+#endif
+ {
+ __kmp_affinity_gran = affinity_gran_core;
+ }
}
-
- K_DIAG( 1, ( "__kmp_affinity_type == %d\n", __kmp_affinity_type ) );
- K_DIAG( 1, ( "__kmp_affinity_compact == %d\n", __kmp_affinity_compact ) );
- K_DIAG( 1, ( "__kmp_affinity_offset == %d\n", __kmp_affinity_offset ) );
- K_DIAG( 1, ( "__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose ) );
- K_DIAG( 1, ( "__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings ) );
- K_DIAG( 1, ( "__kmp_affinity_respect_mask == %d\n", __kmp_affinity_respect_mask ) );
- K_DIAG( 1, ( "__kmp_affinity_gran == %d\n", __kmp_affinity_gran ) );
-
- KMP_DEBUG_ASSERT( __kmp_affinity_type != affinity_default);
-# if OMP_40_ENABLED
- KMP_DEBUG_ASSERT( __kmp_nested_proc_bind.bind_types[0] != proc_bind_default );
-# endif
+ if (__kmp_affinity_top_method == affinity_top_method_default) {
+ __kmp_affinity_top_method = affinity_top_method_all;
+ }
+ }
}
-#endif /* KMP_AFFINITY_SUPPORTED */
+ K_DIAG(1, ("__kmp_affinity_type == %d\n", __kmp_affinity_type));
+ K_DIAG(1, ("__kmp_affinity_compact == %d\n", __kmp_affinity_compact));
+ K_DIAG(1, ("__kmp_affinity_offset == %d\n", __kmp_affinity_offset));
+ K_DIAG(1, ("__kmp_affinity_verbose == %d\n", __kmp_affinity_verbose));
+ K_DIAG(1, ("__kmp_affinity_warnings == %d\n", __kmp_affinity_warnings));
+ K_DIAG(1, ("__kmp_affinity_respect_mask == %d\n",
+ __kmp_affinity_respect_mask));
+ K_DIAG(1, ("__kmp_affinity_gran == %d\n", __kmp_affinity_gran));
- if ( __kmp_version ) {
- __kmp_print_version_1();
- }; // if
+ KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
+#if OMP_40_ENABLED
+ KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
+#endif
+ }
- // Post-initialization step: some env. vars need their value's further processing
- if ( string != NULL) { // kmp_set_defaults() was called
- __kmp_aux_env_initialize( &block );
- }
+#endif /* KMP_AFFINITY_SUPPORTED */
+
+ if (__kmp_version) {
+ __kmp_print_version_1();
+ }; // if
+
+ // Post-initialization step: some env. vars need their value's further
+ // processing
+ if (string != NULL) { // kmp_set_defaults() was called
+ __kmp_aux_env_initialize(&block);
+ }
- __kmp_env_blk_free( & block );
+ __kmp_env_blk_free(&block);
- KMP_MB();
+ KMP_MB();
} // __kmp_env_initialize
+void __kmp_env_print() {
-void
-__kmp_env_print() {
-
- kmp_env_blk_t block;
- int i;
- kmp_str_buf_t buffer;
-
- __kmp_stg_init();
- __kmp_str_buf_init( & buffer );
-
- __kmp_env_blk_init( & block, NULL );
- __kmp_env_blk_sort( & block );
-
- // Print real environment values.
- __kmp_str_buf_print( & buffer, "\n%s\n\n", KMP_I18N_STR( UserSettings ) );
- for ( i = 0; i < block.count; ++ i ) {
- char const * name = block.vars[ i ].name;
- char const * value = block.vars[ i ].value;
- if (
- ( KMP_STRLEN( name ) > 4 && strncmp( name, "KMP_", 4 ) == 0 )
- || strncmp( name, "OMP_", 4 ) == 0
- #ifdef KMP_GOMP_COMPAT
- || strncmp( name, "GOMP_", 5 ) == 0
- #endif // KMP_GOMP_COMPAT
+ kmp_env_blk_t block;
+ int i;
+ kmp_str_buf_t buffer;
+
+ __kmp_stg_init();
+ __kmp_str_buf_init(&buffer);
+
+ __kmp_env_blk_init(&block, NULL);
+ __kmp_env_blk_sort(&block);
+
+ // Print real environment values.
+ __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
+ for (i = 0; i < block.count; ++i) {
+ char const *name = block.vars[i].name;
+ char const *value = block.vars[i].value;
+ if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
+ strncmp(name, "OMP_", 4) == 0
+#ifdef KMP_GOMP_COMPAT
+ || strncmp(name, "GOMP_", 5) == 0
+#endif // KMP_GOMP_COMPAT
) {
- __kmp_str_buf_print( & buffer, " %s=%s\n", name, value );
- }; // if
- }; // for
- __kmp_str_buf_print( & buffer, "\n" );
+ __kmp_str_buf_print(&buffer, " %s=%s\n", name, value);
+ }; // if
+ }; // for
+ __kmp_str_buf_print(&buffer, "\n");
- // Print internal (effective) settings.
- __kmp_str_buf_print( & buffer, "%s\n\n", KMP_I18N_STR( EffectiveSettings ) );
- for ( int i = 0; i < __kmp_stg_count; ++ i ) {
- if ( __kmp_stg_table[ i ].print != NULL ) {
- __kmp_stg_table[ i ].print( & buffer, __kmp_stg_table[ i ].name, __kmp_stg_table[ i ].data );
- }; // if
- }; // for
+ // Print internal (effective) settings.
+ __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
+ for (int i = 0; i < __kmp_stg_count; ++i) {
+ if (__kmp_stg_table[i].print != NULL) {
+ __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
+ __kmp_stg_table[i].data);
+ }; // if
+ }; // for
- __kmp_printf( "%s", buffer.str );
+ __kmp_printf("%s", buffer.str);
- __kmp_env_blk_free( & block );
- __kmp_str_buf_free( & buffer );
+ __kmp_env_blk_free(&block);
+ __kmp_str_buf_free(&buffer);
- __kmp_printf("\n");
+ __kmp_printf("\n");
} // __kmp_env_print
-
#if OMP_40_ENABLED
-void
-__kmp_env_print_2() {
+void __kmp_env_print_2() {
- kmp_env_blk_t block;
- kmp_str_buf_t buffer;
+ kmp_env_blk_t block;
+ kmp_str_buf_t buffer;
- __kmp_env_format = 1;
+ __kmp_env_format = 1;
- __kmp_stg_init();
- __kmp_str_buf_init( & buffer );
+ __kmp_stg_init();
+ __kmp_str_buf_init(&buffer);
- __kmp_env_blk_init( & block, NULL );
- __kmp_env_blk_sort( & block );
+ __kmp_env_blk_init(&block, NULL);
+ __kmp_env_blk_sort(&block);
- __kmp_str_buf_print( & buffer, "\n%s\n", KMP_I18N_STR( DisplayEnvBegin ) );
- __kmp_str_buf_print( & buffer, " _OPENMP='%d'\n", __kmp_openmp_version );
+ __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
+ __kmp_str_buf_print(&buffer, " _OPENMP='%d'\n", __kmp_openmp_version);
- for ( int i = 0; i < __kmp_stg_count; ++ i ) {
- if ( __kmp_stg_table[ i ].print != NULL &&
- ( ( __kmp_display_env && strncmp( __kmp_stg_table[ i ].name, "OMP_", 4 ) == 0 ) || __kmp_display_env_verbose ) ) {
- __kmp_stg_table[ i ].print( & buffer, __kmp_stg_table[ i ].name, __kmp_stg_table[ i ].data );
- }; // if
- }; // for
+ for (int i = 0; i < __kmp_stg_count; ++i) {
+ if (__kmp_stg_table[i].print != NULL &&
+ ((__kmp_display_env &&
+ strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
+ __kmp_display_env_verbose)) {
+ __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
+ __kmp_stg_table[i].data);
+ }; // if
+ }; // for
- __kmp_str_buf_print( & buffer, "%s\n", KMP_I18N_STR( DisplayEnvEnd ) );
- __kmp_str_buf_print( & buffer, "\n" );
+ __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
+ __kmp_str_buf_print(&buffer, "\n");
- __kmp_printf( "%s", buffer.str );
+ __kmp_printf("%s", buffer.str);
- __kmp_env_blk_free( & block );
- __kmp_str_buf_free( & buffer );
+ __kmp_env_blk_free(&block);
+ __kmp_str_buf_free(&buffer);
- __kmp_printf("\n");
+ __kmp_printf("\n");
} // __kmp_env_print_2
#endif // OMP_40_ENABLED
// end of file
-
Modified: openmp/trunk/runtime/src/kmp_settings.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_settings.h?rev=302929&r1=302928&r2=302929&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_settings.h (original)
+++ openmp/trunk/runtime/src/kmp_settings.h Fri May 12 13:01:32 2017
@@ -16,35 +16,52 @@
#ifndef KMP_SETTINGS_H
#define KMP_SETTINGS_H
-void __kmp_reset_global_vars( void );
-void __kmp_env_initialize( char const * );
+void __kmp_reset_global_vars(void);
+void __kmp_env_initialize(char const *);
void __kmp_env_print();
#if OMP_40_ENABLED
void __kmp_env_print_2();
#endif // OMP_40_ENABLED
-int __kmp_initial_threads_capacity( int req_nproc );
+int __kmp_initial_threads_capacity(int req_nproc);
void __kmp_init_dflt_team_nth();
-int __kmp_convert_to_milliseconds( char const * );
-int __kmp_default_tp_capacity( int, int, int);
+int __kmp_convert_to_milliseconds(char const *);
+int __kmp_default_tp_capacity(int, int, int);
#if KMP_MIC
-#define KMP_STR_BUF_PRINT_NAME __kmp_str_buf_print( buffer, " %s %s", KMP_I18N_STR(Device), name )
-#define KMP_STR_BUF_PRINT_NAME_EX(x) __kmp_str_buf_print( buffer, " %s %s='", KMP_I18N_STR(Device), x )
-#define KMP_STR_BUF_PRINT_BOOL __kmp_str_buf_print( buffer, " %s %s='%s'\n", KMP_I18N_STR(Device), name, value ? "TRUE" : "FALSE" );
-#define KMP_STR_BUF_PRINT_INT __kmp_str_buf_print( buffer, " %s %s='%d'\n", KMP_I18N_STR(Device), name, value )
-#define KMP_STR_BUF_PRINT_UINT64 __kmp_str_buf_print( buffer, " %s %s='%" KMP_UINT64_SPEC "'\n", KMP_I18N_STR(Device), name, value );
-#define KMP_STR_BUF_PRINT_STR __kmp_str_buf_print( buffer, " %s %s='%s'\n", KMP_I18N_STR(Device), name, value )
+#define KMP_STR_BUF_PRINT_NAME \
+ __kmp_str_buf_print(buffer, " %s %s", KMP_I18N_STR(Device), name)
+#define KMP_STR_BUF_PRINT_NAME_EX(x) \
+ __kmp_str_buf_print(buffer, " %s %s='", KMP_I18N_STR(Device), x)
+#define KMP_STR_BUF_PRINT_BOOL \
+ __kmp_str_buf_print(buffer, " %s %s='%s'\n", KMP_I18N_STR(Device), name, \
+ value ? "TRUE" : "FALSE");
+#define KMP_STR_BUF_PRINT_INT \
+ __kmp_str_buf_print(buffer, " %s %s='%d'\n", KMP_I18N_STR(Device), name, \
+ value)
+#define KMP_STR_BUF_PRINT_UINT64 \
+ __kmp_str_buf_print(buffer, " %s %s='%" KMP_UINT64_SPEC "'\n", \
+ KMP_I18N_STR(Device), name, value);
+#define KMP_STR_BUF_PRINT_STR \
+ __kmp_str_buf_print(buffer, " %s %s='%s'\n", KMP_I18N_STR(Device), name, \
+ value)
#else
-#define KMP_STR_BUF_PRINT_NAME __kmp_str_buf_print( buffer, " %s %s", KMP_I18N_STR(Host), name )
-#define KMP_STR_BUF_PRINT_NAME_EX(x) __kmp_str_buf_print( buffer, " %s %s='", KMP_I18N_STR(Host), x )
-#define KMP_STR_BUF_PRINT_BOOL __kmp_str_buf_print( buffer, " %s %s='%s'\n", KMP_I18N_STR(Host), name, value ? "TRUE" : "FALSE" );
-#define KMP_STR_BUF_PRINT_INT __kmp_str_buf_print( buffer, " %s %s='%d'\n", KMP_I18N_STR(Host), name, value )
-#define KMP_STR_BUF_PRINT_UINT64 __kmp_str_buf_print( buffer, " %s %s='%" KMP_UINT64_SPEC "'\n", KMP_I18N_STR(Host), name, value );
-#define KMP_STR_BUF_PRINT_STR __kmp_str_buf_print( buffer, " %s %s='%s'\n", KMP_I18N_STR(Host), name, value )
+#define KMP_STR_BUF_PRINT_NAME \
+ __kmp_str_buf_print(buffer, " %s %s", KMP_I18N_STR(Host), name)
+#define KMP_STR_BUF_PRINT_NAME_EX(x) \
+ __kmp_str_buf_print(buffer, " %s %s='", KMP_I18N_STR(Host), x)
+#define KMP_STR_BUF_PRINT_BOOL \
+ __kmp_str_buf_print(buffer, " %s %s='%s'\n", KMP_I18N_STR(Host), name, \
+ value ? "TRUE" : "FALSE");
+#define KMP_STR_BUF_PRINT_INT \
+ __kmp_str_buf_print(buffer, " %s %s='%d'\n", KMP_I18N_STR(Host), name, value)
+#define KMP_STR_BUF_PRINT_UINT64 \
+ __kmp_str_buf_print(buffer, " %s %s='%" KMP_UINT64_SPEC "'\n", \
+ KMP_I18N_STR(Host), name, value);
+#define KMP_STR_BUF_PRINT_STR \
+ __kmp_str_buf_print(buffer, " %s %s='%s'\n", KMP_I18N_STR(Host), name, value)
#endif
#endif // KMP_SETTINGS_H
// end of file //
-
More information about the Openmp-commits
mailing list