summaryrefslogtreecommitdiffstats
path: root/openmp/runtime/src/kmp_sched.cpp
diff options
context:
space:
mode:
authorJim Cownie <james.h.cownie@intel.com>2014-10-07 16:25:50 +0000
committerJim Cownie <james.h.cownie@intel.com>2014-10-07 16:25:50 +0000
commit4cc4bb4c60c786a253176106065e59d639bbc1a9 (patch)
treedfe5a4f9e4591505dd8a7d333b5b9201c50b52e3 /openmp/runtime/src/kmp_sched.cpp
parentf72fa67fc35622a8cd18a2fffd979fb225d82400 (diff)
downloadbcm5719-llvm-4cc4bb4c60c786a253176106065e59d639bbc1a9.tar.gz
bcm5719-llvm-4cc4bb4c60c786a253176106065e59d639bbc1a9.zip
I apologise in advance for the size of this check-in. At Intel we do
understand that this is not friendly, and are working to change our internal code-development to make it easier to make development features available more frequently and in finer (more functional) chunks. Unfortunately we haven't got that in place yet, and unpicking this into multiple separate check-ins would be non-trivial, so please bear with me on this one. We should be better in the future. Apologies over, what do we have here? GGC 4.9 compatibility -------------------- * We have implemented the new entrypoints used by code compiled by GCC 4.9 to implement the same functionality in gcc 4.8. Therefore code compiled with gcc 4.9 that used to work will continue to do so. However, there are some other new entrypoints (associated with task cancellation) which are not implemented. Therefore user code compiled by gcc 4.9 that uses these new features will not link against the LLVM runtime. (It remains unclear how to handle those entrypoints, since the GCC interface has potentially unpleasant performance implications for join barriers even when cancellation is not used) --- new parallel entry points --- new entry points that aren't OpenMP 4.0 related These are implemented fully :- GOMP_parallel_loop_dynamic() GOMP_parallel_loop_guided() GOMP_parallel_loop_runtime() GOMP_parallel_loop_static() GOMP_parallel_sections() GOMP_parallel() --- cancellation entry points --- Currently, these only give a runtime error if OMP_CANCELLATION is true because our plain barriers don't check for cancellation while waiting GOMP_barrier_cancel() GOMP_cancel() GOMP_cancellation_point() GOMP_loop_end_cancel() GOMP_sections_end_cancel() --- taskgroup entry points --- These are implemented fully. GOMP_taskgroup_start() GOMP_taskgroup_end() --- target entry points --- These are empty (as they are in libgomp) GOMP_target() GOMP_target_data() GOMP_target_end_data() GOMP_target_update() GOMP_teams() Improvements in Barriers and Fork/Join -------------------------------------- * Barrier and fork/join code is now in its own file (which makes it easier to understand and modify). * Wait/release code is now templated and in its own file; suspend/resume code is also templated * There's a new, hierarchical, barrier, which exploits the cache-hierarchy of the Intel(r) Xeon Phi(tm) coprocessor to improve fork/join and barrier performance. ***BEWARE*** the new source files have *not* been added to the legacy Cmake build system. If you want to use that fixes wil be required. Statistics Collection Code -------------------------- * New code has been added to collect application statistics (if this is enabled at library compile time; by default it is not). The statistics code itself is generally useful, the lightweight timing code uses the X86 rdtsc instruction, so will require changes for other architectures. The intent of this code is not for users to tune their codes but rather 1) For timing code-paths inside the runtime 2) For gathering general properties of OpenMP codes to focus attention on which OpenMP features are most used. Nested Hot Teams ---------------- * The runtime now maintains more state to reduce the overhead of creating and destroying inner parallel teams. This improves the performance of code that repeatedly uses nested parallelism with the same resource allocation. Set the new KMP_HOT_TEAMS_MAX_LEVEL envirable to a depth to enable this (and, of course, OMP_NESTED=true to enable nested parallelism at all). Improved Intel(r) VTune(Tm) Amplifier support --------------------------------------------- * The runtime provides additional information to Vtune via the itt_notify interface to allow it to display better OpenMP specific analyses of load-imbalance. Support for OpenMP Composite Statements --------------------------------------- * Implement new entrypoints required by some of the OpenMP 4.1 composite statements. Improved ifdefs --------------- * More separation of concepts ("Does this platform do X?") from platforms ("Are we compiling for platform Y?"), which should simplify future porting. ScaleMP* contribution --------------------- Stack padding to improve the performance in their environment where cross-node coherency is managed at the page level. Redesign of wait and release code --------------------------------- The code is simplified and performance improved. Bug Fixes --------- *Fixes for Windows multiple processor groups. *Fix Fortran module build on Linux: offload attribute added. *Fix entry names for distribute-parallel-loop construct to be consistent with the compiler codegen. *Fix an inconsistent error message for KMP_PLACE_THREADS environment variable. llvm-svn: 219214
Diffstat (limited to 'openmp/runtime/src/kmp_sched.cpp')
-rw-r--r--openmp/runtime/src/kmp_sched.cpp563
1 files changed, 540 insertions, 23 deletions
diff --git a/openmp/runtime/src/kmp_sched.cpp b/openmp/runtime/src/kmp_sched.cpp
index 18e5a38dc40..14fa62ee85d 100644
--- a/openmp/runtime/src/kmp_sched.cpp
+++ b/openmp/runtime/src/kmp_sched.cpp
@@ -1,7 +1,7 @@
/*
* kmp_sched.c -- static scheduling -- iteration initialization
- * $Revision: 42358 $
- * $Date: 2013-05-07 13:43:26 -0500 (Tue, 07 May 2013) $
+ * $Revision: 43457 $
+ * $Date: 2014-09-17 03:57:22 -0500 (Wed, 17 Sep 2014) $
*/
@@ -28,6 +28,8 @@
#include "kmp_i18n.h"
#include "kmp_str.h"
#include "kmp_error.h"
+#include "kmp_stats.h"
+#include "kmp_itt.h"
// template for type limits
template< typename T >
@@ -79,6 +81,7 @@ __kmp_for_static_init(
typename traits_t< T >::signed_t incr,
typename traits_t< T >::signed_t chunk
) {
+ KMP_COUNT_BLOCK(OMP_FOR_static);
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.. */
@@ -88,6 +91,7 @@ __kmp_for_static_init(
register UT trip_count;
register kmp_team_t *team;
+ KMP_DEBUG_ASSERT( plastiter && plower && pupper && pstride );
KE_TRACE( 10, ("__kmpc_for_static_init called (%d)\n", global_tid));
#ifdef KMP_DEBUG
{
@@ -108,12 +112,12 @@ __kmp_for_static_init(
__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) ) {
- *plastiter = FALSE;
+ 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,\
@@ -149,7 +153,8 @@ __kmp_for_static_init(
/* determine if "for" loop is an active worksharing construct */
if ( team -> t.t_serialized ) {
/* serialized parallel, each thread executes whole iteration space */
- *plastiter = TRUE;
+ if( plastiter != NULL )
+ *plastiter = TRUE;
/* leave pupper and plower set to entire iteration space */
*pstride = (incr > 0) ? (*pupper - *plower + 1) : (-(*plower - *pupper + 1));
@@ -169,8 +174,9 @@ __kmp_for_static_init(
}
nth = team->t.t_nproc;
if ( nth == 1 ) {
- *plastiter = TRUE;
-
+ if( plastiter != NULL )
+ *plastiter = TRUE;
+ *pstride = (incr > 0) ? (*pupper - *plower + 1) : (-(*plower - *pupper + 1));
#ifdef KMP_DEBUG
{
const char * buff;
@@ -192,12 +198,13 @@ __kmp_for_static_init(
} else if (incr == -1) {
trip_count = *plower - *pupper + 1;
} else {
- if ( incr > 1 ) {
+ if ( incr > 1 ) { // the check is needed for unsigned division when incr < 0
trip_count = (*pupper - *plower) / incr + 1;
} else {
trip_count = (*plower - *pupper) / ( -incr ) + 1;
}
}
+
if ( __kmp_env_consistency_check ) {
/* tripcount overflow? */
if ( trip_count == 0 && *pupper != *plower ) {
@@ -219,14 +226,16 @@ __kmp_for_static_init(
} else {
*plower = *pupper + incr;
}
- *plastiter = ( tid == trip_count - 1 );
+ 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 );
- *plastiter = ( tid == nth - 1 );
+ if( plastiter != NULL )
+ *plastiter = ( tid == nth - 1 );
} else {
register T big_chunk_inc_count = ( trip_count/nth +
( ( trip_count % nth ) ? 1 : 0) ) * incr;
@@ -238,16 +247,16 @@ __kmp_for_static_init(
*plower += tid * big_chunk_inc_count;
*pupper = *plower + big_chunk_inc_count - incr;
if ( incr > 0 ) {
- if ( *pupper < *plower ) {
+ if( *pupper < *plower )
*pupper = i_maxmin< T >::mx;
- }
- *plastiter = *plower <= old_upper && *pupper > old_upper - incr;
+ if( plastiter != NULL )
+ *plastiter = *plower <= old_upper && *pupper > old_upper - incr;
if ( *pupper > old_upper ) *pupper = old_upper; // tracker C73258
} else {
- if ( *pupper > *plower ) {
+ if( *pupper > *plower )
*pupper = i_maxmin< T >::mn;
- }
- *plastiter = *plower >= old_upper && *pupper < old_upper - incr;
+ if( plastiter != NULL )
+ *plastiter = *plower >= old_upper && *pupper < old_upper - incr;
if ( *pupper < old_upper ) *pupper = old_upper; // tracker C73258
}
}
@@ -256,7 +265,7 @@ __kmp_for_static_init(
}
case kmp_sch_static_chunked:
{
- register T span;
+ register ST span;
if ( chunk < 1 ) {
chunk = 1;
}
@@ -264,11 +273,8 @@ __kmp_for_static_init(
*pstride = span * nth;
*plower = *plower + (span * tid);
*pupper = *plower + span - incr;
- /* TODO: is the following line a bug? Shouldn't it be plastiter instead of *plastiter ? */
- if (*plastiter) { /* only calculate this if it was requested */
- kmp_int32 lasttid = ((trip_count - 1) / ( UT )chunk) % nth;
- *plastiter = (tid == lasttid);
- }
+ if( plastiter != NULL )
+ *plastiter = (tid == ((trip_count - 1)/( UT )chunk) % nth);
break;
}
default:
@@ -276,6 +282,18 @@ __kmp_for_static_init(
break;
}
+#if USE_ITT_BUILD
+ // Report loop metadata
+ if ( KMP_MASTER_TID(tid) && __itt_metadata_add_ptr && __kmp_forkjoin_frames_mode == 3 ) {
+ 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;
@@ -291,6 +309,355 @@ __kmp_for_static_init(
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_DISTR_FOR_static);
+ 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];
+ KMP_DEBUG_ASSERT(th->th.th_teams_microtask); // we are in the teams construct
+ nth = th->th.th_team_nproc;
+ team = th->th.th_team;
+ #if OMP_40_ENABLED
+ 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 {
+ trip_count = (ST)(*pupper - *plower) / incr + 1; // cast to signed to cover incr<0 case
+ }
+ *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
+ }
+ 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 = i_maxmin< T >::mx;
+ 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 = i_maxmin< T >::mn;
+ 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 {
+ trip_count = (ST)(*pupperDist - *plower) / 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 = i_maxmin< T >::mx;
+ 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 = i_maxmin< T >::mn;
+ 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;
+ }
+ }
+ 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];
+ KMP_DEBUG_ASSERT(th->th.th_teams_microtask); // we are in the teams construct
+ team = th->th.th_team;
+ #if OMP_40_ENABLED
+ 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 {
+ trip_count = (ST)(upper - lower) / incr + 1; // cast to signed to cover incr<0 case
+ }
+ 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 = i_maxmin< T >::mx;
+ if( *p_ub > upper )
+ *p_ub = upper; // tracker C73258
+ } else { // incr < 0
+ if( *p_ub > *p_lb )
+ *p_ub = i_maxmin< T >::mn;
+ 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" {
@@ -310,7 +677,7 @@ 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 bround, stride, increment and chunk size.
+initial values of the bounds, stride, increment and chunk size.
@{
*/
@@ -362,5 +729,155 @@ __kmpc_for_static_init_8u( ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype, km
@}
*/
+/*!
+@ingroup WORK_SHARING
+@param loc Source code location
+@param gtid Global thread id of this thread
+@param scheduleD Scheduling type for the distribute
+@param scheduleL Scheduling type for the parallel loop
+@param plastiter Pointer to the "last iteration" flag
+@param plower Pointer to the lower bound
+@param pupper Pointer to the upper bound of loop chunk
+@param pupperD Pointer to the upper bound of dist_chunk
+@param pstrideD Pointer to the stride for distribute
+@param pstrideL Pointer to the stride for parallel loop
+@param incr Loop increment
+@param chunkD The chunk size for the distribute
+@param chunkL The chunk size for the parallel loop
+
+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.
+
+@{
+*/
+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 );
+}
+
+/*!
+ 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 );
+}
+
+/*!
+ 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 );
+}
+/*!
+@}
+*/
+
+//-----------------------------------------------------------------------------------------
+// Auxiliary routines for Distribute Parallel Loop construct implementation
+// Transfer call to template< type T >
+// __kmp_team_static_init( ident_t *loc, int gtid,
+// int *p_last, T *lb, T *ub, ST *st, ST incr, ST chunk )
+
+/*!
+@ingroup WORK_SHARING
+@{
+@param loc Source location
+@param gtid Global thread id
+@param p_last pointer to last iteration flag
+@param p_lb pointer to Lower bound
+@param p_ub pointer to Upper bound
+@param p_st Step (or increment if you prefer)
+@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.
+*/
+
+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 );
+}
+
+/*!
+ 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 );
+}
+
+/*!
+ 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 );
+}
+/*!
+@}
+*/
+
} // extern "C"
OpenPOWER on IntegriCloud