aboutsummaryrefslogtreecommitdiff
path: root/openmp/runtime/src/kmp_sched.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'openmp/runtime/src/kmp_sched.cpp')
-rw-r--r--openmp/runtime/src/kmp_sched.cpp43
1 files changed, 29 insertions, 14 deletions
diff --git a/openmp/runtime/src/kmp_sched.cpp b/openmp/runtime/src/kmp_sched.cpp
index 2d8f644c88b2..09e497e02914 100644
--- a/openmp/runtime/src/kmp_sched.cpp
+++ b/openmp/runtime/src/kmp_sched.cpp
@@ -78,7 +78,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
,
void *codeptr
#endif
- ) {
+) {
KMP_COUNT_BLOCK(OMP_LOOP_STATIC);
KMP_PUSH_PARTITIONED_TIMER(OMP_loop_static);
KMP_PUSH_PARTITIONED_TIMER(OMP_loop_static_scheduling);
@@ -167,6 +167,7 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
"signed?<%s>, loc = %%s\n",
traits_t<T>::spec, traits_t<T>::spec,
traits_t<ST>::spec, traits_t<T>::spec);
+ check_loc(loc);
KD_TRACE(100,
(buff, *plastiter, *plower, *pupper, *pstride, loc->psource));
__kmp_str_free(&buff);
@@ -301,7 +302,8 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
if (tid < trip_count) {
*pupper = *plower = *plower + tid * incr;
} else {
- *plower = *pupper + incr;
+ // set bounds so non-active threads execute no iterations
+ *plower = *pupper + (incr > 0 ? 1 : -1);
}
if (plastiter != NULL)
*plastiter = (tid == trip_count - 1);
@@ -345,15 +347,28 @@ static void __kmp_for_static_init(ident_t *loc, kmp_int32 global_tid,
}
case kmp_sch_static_chunked: {
ST span;
- if (chunk < 1) {
+ UT nchunks;
+ if (chunk < 1)
chunk = 1;
- }
+ else if ((UT)chunk > trip_count)
+ chunk = trip_count;
+ nchunks = (trip_count) / (UT)chunk + (trip_count % (UT)chunk ? 1 : 0);
span = chunk * incr;
- *pstride = span * nth;
- *plower = *plower + (span * tid);
- *pupper = *plower + span - incr;
+ if (nchunks < nth) {
+ *pstride = span * nchunks;
+ if (tid < nchunks) {
+ *plower = *plower + (span * tid);
+ *pupper = *plower + span - incr;
+ } else {
+ *plower = *pupper + (incr > 0 ? 1 : -1);
+ }
+ } else {
+ *pstride = span * nth;
+ *plower = *plower + (span * tid);
+ *pupper = *plower + span - incr;
+ }
if (plastiter != NULL)
- *plastiter = (tid == ((trip_count - 1) / (UT)chunk) % nth);
+ *plastiter = (tid == (nchunks - 1) % nth);
break;
}
case kmp_sch_static_balanced_chunked: {
@@ -508,8 +523,8 @@ static void __kmp_dist_for_static_init(ident_t *loc, kmp_int32 gtid,
__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
+ // only primary threads 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 {
@@ -811,7 +826,7 @@ void __kmpc_for_static_init_4(ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype,
,
OMPT_GET_RETURN_ADDRESS(0)
#endif
- );
+ );
}
/*!
@@ -828,7 +843,7 @@ void __kmpc_for_static_init_4u(ident_t *loc, kmp_int32 gtid,
,
OMPT_GET_RETURN_ADDRESS(0)
#endif
- );
+ );
}
/*!
@@ -844,7 +859,7 @@ void __kmpc_for_static_init_8(ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype,
,
OMPT_GET_RETURN_ADDRESS(0)
#endif
- );
+ );
}
/*!
@@ -861,7 +876,7 @@ void __kmpc_for_static_init_8u(ident_t *loc, kmp_int32 gtid,
,
OMPT_GET_RETURN_ADDRESS(0)
#endif
- );
+ );
}
/*!
@}