diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h --- a/openmp/runtime/src/kmp.h +++ b/openmp/runtime/src/kmp.h @@ -218,6 +218,7 @@ KMP_IDENT_ATOMIC_HINT_CONTENDED = 0x020000, KMP_IDENT_ATOMIC_HINT_NONSPECULATIVE = 0x040000, KMP_IDENT_ATOMIC_HINT_SPECULATIVE = 0x080000, + KMP_IDENT_OPENMP_SPEC_VERSION_MASK = 0xFF000000 }; /*! @@ -237,6 +238,10 @@ The string is composed of semi-colon separated fields which describe the source file, the function and a pair of line numbers that delimit the construct. */ + // Returns the OpenMP version in form major*10+minor (e.g., 50 for 5.0) + kmp_int32 get_openmp_version() { + return (((flags & KMP_IDENT_OPENMP_SPEC_VERSION_MASK) >> 24) & 0xFF); + } } ident_t; /*! @} diff --git a/openmp/runtime/src/kmp_dispatch.cpp b/openmp/runtime/src/kmp_dispatch.cpp --- a/openmp/runtime/src/kmp_dispatch.cpp +++ b/openmp/runtime/src/kmp_dispatch.cpp @@ -69,16 +69,24 @@ } // Returns either SCHEDULE_MONOTONIC or SCHEDULE_NONMONOTONIC -static inline int __kmp_get_monotonicity(enum sched_type schedule, +static inline int __kmp_get_monotonicity(ident_t *loc, enum sched_type schedule, bool use_hier = false) { // Pick up the nonmonotonic/monotonic bits from the scheduling type - int monotonicity; - // default to monotonic - monotonicity = SCHEDULE_MONOTONIC; - if (SCHEDULE_HAS_NONMONOTONIC(schedule)) + // TODO: make nonmonotonic when static_steal is fixed + int monotonicity = SCHEDULE_MONOTONIC; + + // Let default be monotonic for executables + // compiled with OpenMP* 4.5 or less compilers + if (loc->get_openmp_version() < 50) + monotonicity = SCHEDULE_MONOTONIC; + + if (use_hier) + monotonicity = SCHEDULE_MONOTONIC; + else if (SCHEDULE_HAS_NONMONOTONIC(schedule)) monotonicity = SCHEDULE_NONMONOTONIC; else if (SCHEDULE_HAS_MONOTONIC(schedule)) monotonicity = SCHEDULE_MONOTONIC; + return monotonicity; } @@ -146,7 +154,7 @@ #endif /* Pick up the nonmonotonic/monotonic bits from the scheduling type */ - monotonicity = __kmp_get_monotonicity(schedule, use_hier); + monotonicity = __kmp_get_monotonicity(loc, schedule, use_hier); schedule = SCHEDULE_WITHOUT_MODIFIERS(schedule); /* Pick up the nomerge/ordered bits from the scheduling type */ @@ -177,7 +185,7 @@ // Use the scheduling specified by OMP_SCHEDULE (or __kmp_sch_default if // not specified) schedule = team->t.t_sched.r_sched_type; - monotonicity = __kmp_get_monotonicity(schedule, use_hier); + monotonicity = __kmp_get_monotonicity(loc, schedule, use_hier); schedule = SCHEDULE_WITHOUT_MODIFIERS(schedule); // Detail the schedule if needed (global controls are differentiated // appropriately) @@ -244,7 +252,7 @@ if (schedule == kmp_sch_runtime_simd) { // compiler provides simd_width in the chunk parameter schedule = team->t.t_sched.r_sched_type; - monotonicity = __kmp_get_monotonicity(schedule, use_hier); + monotonicity = __kmp_get_monotonicity(loc, schedule, use_hier); schedule = SCHEDULE_WITHOUT_MODIFIERS(schedule); // Detail the schedule if needed (global controls are differentiated // appropriately)