21 #include "kmp_error.h"
24 #include "kmp_stats.h"
26 #if KMP_USE_X87CONTROL
30 #include "kmp_dispatch.h"
31 #if KMP_USE_HIER_SCHED
32 #include "kmp_dispatch_hier.h"
36 #include "ompt-specific.h"
42 void __kmp_dispatch_deo_error(
int *gtid_ref,
int *cid_ref,
ident_t *loc_ref) {
45 KMP_DEBUG_ASSERT(gtid_ref);
47 if (__kmp_env_consistency_check) {
48 th = __kmp_threads[*gtid_ref];
49 if (th->th.th_root->r.r_active &&
50 (th->th.th_dispatch->th_dispatch_pr_current->pushed_ws != ct_none)) {
51 #if KMP_USE_DYNAMIC_LOCK
52 __kmp_push_sync(*gtid_ref, ct_ordered_in_pdo, loc_ref, NULL, 0);
54 __kmp_push_sync(*gtid_ref, ct_ordered_in_pdo, loc_ref, NULL);
60 void __kmp_dispatch_dxo_error(
int *gtid_ref,
int *cid_ref,
ident_t *loc_ref) {
63 if (__kmp_env_consistency_check) {
64 th = __kmp_threads[*gtid_ref];
65 if (th->th.th_dispatch->th_dispatch_pr_current->pushed_ws != ct_none) {
66 __kmp_pop_sync(*gtid_ref, ct_ordered_in_pdo, loc_ref);
72 static inline int __kmp_get_monotonicity(
enum sched_type schedule,
73 bool use_hier =
false) {
77 monotonicity = SCHEDULE_MONOTONIC;
78 if (SCHEDULE_HAS_NONMONOTONIC(schedule))
79 monotonicity = SCHEDULE_NONMONOTONIC;
80 else if (SCHEDULE_HAS_MONOTONIC(schedule))
81 monotonicity = SCHEDULE_MONOTONIC;
96 void __kmp_dispatch_init_algorithm(
ident_t *loc,
int gtid,
97 dispatch_private_info_template<T> *pr,
99 typename traits_t<T>::signed_t st,
101 kmp_uint64 *cur_chunk,
103 typename traits_t<T>::signed_t chunk,
105 typedef typename traits_t<T>::unsigned_t UT;
106 typedef typename traits_t<T>::floating_t DBL;
116 typedef typename traits_t<T>::signed_t ST;
120 buff = __kmp_str_format(
"__kmp_dispatch_init_algorithm: T#%%d called "
121 "pr:%%p lb:%%%s ub:%%%s st:%%%s "
122 "schedule:%%d chunk:%%%s nproc:%%%s tid:%%%s\n",
123 traits_t<T>::spec, traits_t<T>::spec,
124 traits_t<ST>::spec, traits_t<ST>::spec,
125 traits_t<T>::spec, traits_t<T>::spec);
126 KD_TRACE(10, (buff, gtid, pr, lb, ub, st, schedule, chunk, nproc, tid));
127 __kmp_str_free(&buff);
131 th = __kmp_threads[gtid];
132 team = th->th.th_team;
133 active = !team->t.t_serialized;
136 int itt_need_metadata_reporting =
137 __itt_metadata_add_ptr && __kmp_forkjoin_frames_mode == 3 &&
138 KMP_MASTER_GTID(gtid) && th->th.th_teams_microtask == NULL &&
139 team->t.t_active_level == 1;
142 #if KMP_USE_HIER_SCHED
143 use_hier = pr->flags.use_hier;
149 monotonicity = __kmp_get_monotonicity(schedule, use_hier);
150 schedule = SCHEDULE_WITHOUT_MODIFIERS(schedule);
154 pr->flags.nomerge = TRUE;
158 pr->flags.nomerge = FALSE;
160 pr->type_size = traits_t<T>::type_size;
162 pr->flags.ordered = TRUE;
166 pr->flags.ordered = FALSE;
169 if (pr->flags.ordered) {
170 monotonicity = SCHEDULE_MONOTONIC;
174 schedule = __kmp_static;
176 if (schedule == kmp_sch_runtime) {
179 schedule = team->t.t_sched.r_sched_type;
180 monotonicity = __kmp_get_monotonicity(schedule, use_hier);
181 schedule = SCHEDULE_WITHOUT_MODIFIERS(schedule);
185 schedule = __kmp_guided;
187 schedule = __kmp_static;
191 chunk = team->t.t_sched.chunk;
200 buff = __kmp_str_format(
"__kmp_dispatch_init_algorithm: T#%%d new: "
201 "schedule:%%d chunk:%%%s\n",
203 KD_TRACE(10, (buff, gtid, schedule, chunk));
204 __kmp_str_free(&buff);
209 schedule = __kmp_guided;
212 chunk = KMP_DEFAULT_CHUNK;
218 schedule = __kmp_auto;
223 buff = __kmp_str_format(
224 "__kmp_dispatch_init_algorithm: kmp_sch_auto: T#%%d new: "
225 "schedule:%%d chunk:%%%s\n",
227 KD_TRACE(10, (buff, gtid, schedule, chunk));
228 __kmp_str_free(&buff);
232 #if KMP_STATIC_STEAL_ENABLED
234 if (schedule == kmp_sch_dynamic_chunked) {
235 if (monotonicity == SCHEDULE_NONMONOTONIC)
236 schedule = kmp_sch_static_steal;
240 if (schedule == kmp_sch_guided_analytical_chunked && nproc > 1 << 20) {
241 schedule = kmp_sch_guided_iterative_chunked;
242 KMP_WARNING(DispatchManyThreads);
246 schedule = team->t.t_sched.r_sched_type;
247 monotonicity = __kmp_get_monotonicity(schedule, use_hier);
248 schedule = SCHEDULE_WITHOUT_MODIFIERS(schedule);
252 schedule == __kmp_static) {
253 schedule = kmp_sch_static_balanced_chunked;
258 chunk = team->t.t_sched.chunk * chunk;
268 buff = __kmp_str_format(
269 "__kmp_dispatch_init_algorithm: T#%%d new: schedule:%%d"
272 KD_TRACE(10, (buff, gtid, schedule, chunk));
273 __kmp_str_free(&buff);
277 pr->u.p.parm1 = chunk;
280 "unknown scheduling type");
284 if (__kmp_env_consistency_check) {
286 __kmp_error_construct(kmp_i18n_msg_CnsLoopIncrZeroProhibited,
287 (pr->flags.ordered ? ct_pdo_ordered : ct_pdo), loc);
301 tc = (UT)(lb - ub) / (-st) + 1;
309 tc = (UT)(ub - lb) / st + 1;
315 #if KMP_STATS_ENABLED
316 if (KMP_MASTER_GTID(gtid)) {
327 pr->u.p.last_upper = ub + st;
333 if (pr->flags.ordered) {
334 pr->ordered_bumped = 0;
335 pr->u.p.ordered_lower = 1;
336 pr->u.p.ordered_upper = 0;
341 #if (KMP_STATIC_STEAL_ENABLED)
342 case kmp_sch_static_steal: {
346 (
"__kmp_dispatch_init_algorithm: T#%d kmp_sch_static_steal case\n",
349 ntc = (tc % chunk ? 1 : 0) + tc / chunk;
350 if (nproc > 1 && ntc >= nproc) {
353 T small_chunk, extras;
355 small_chunk = ntc / nproc;
356 extras = ntc % nproc;
358 init =
id * small_chunk + (
id < extras ? id : extras);
359 pr->u.p.count = init;
360 pr->u.p.ub = init + small_chunk + (
id < extras ? 1 : 0);
366 pr->u.p.parm3 = KMP_MIN(small_chunk + extras, nproc);
367 pr->u.p.parm4 = (
id + 1) % nproc;
369 if (traits_t<T>::type_size > 4) {
375 KMP_DEBUG_ASSERT(th->th.th_dispatch->th_steal_lock == NULL);
376 th->th.th_dispatch->th_steal_lock =
377 (kmp_lock_t *)__kmp_allocate(
sizeof(kmp_lock_t));
378 __kmp_init_lock(th->th.th_dispatch->th_steal_lock);
382 KD_TRACE(100, (
"__kmp_dispatch_init_algorithm: T#%d falling-through to "
383 "kmp_sch_static_balanced\n",
385 schedule = kmp_sch_static_balanced;
392 case kmp_sch_static_balanced: {
397 (
"__kmp_dispatch_init_algorithm: T#%d kmp_sch_static_balanced case\n",
407 pr->u.p.parm1 = (
id == tc - 1);
410 pr->u.p.parm1 = FALSE;
414 T small_chunk = tc / nproc;
415 T extras = tc % nproc;
416 init =
id * small_chunk + (
id < extras ? id : extras);
417 limit = init + small_chunk - (
id < extras ? 0 : 1);
418 pr->u.p.parm1 = (
id == nproc - 1);
424 pr->u.p.parm1 = TRUE;
428 pr->u.p.parm1 = FALSE;
434 if (itt_need_metadata_reporting)
436 *cur_chunk = limit - init + 1;
439 pr->u.p.lb = lb + init;
440 pr->u.p.ub = lb + limit;
443 T ub_tmp = lb + limit * st;
444 pr->u.p.lb = lb + init * st;
448 pr->u.p.ub = (ub_tmp + st > ub ? ub : ub_tmp);
450 pr->u.p.ub = (ub_tmp + st < ub ? ub : ub_tmp);
453 if (pr->flags.ordered) {
454 pr->u.p.ordered_lower = init;
455 pr->u.p.ordered_upper = limit;
459 case kmp_sch_static_balanced_chunked: {
462 KD_TRACE(100, (
"__kmp_dispatch_init_algorithm: T#%d runtime(simd:static)"
463 " -> falling-through to static_greedy\n",
465 schedule = kmp_sch_static_greedy;
467 pr->u.p.parm1 = ((tc + nth - 1) / nth + chunk - 1) & ~(chunk - 1);
473 case kmp_sch_guided_iterative_chunked: {
476 (
"__kmp_dispatch_init_algorithm: T#%d kmp_sch_guided_iterative_chunked"
481 if ((2L * chunk + 1) * nproc >= tc) {
483 schedule = kmp_sch_dynamic_chunked;
486 pr->u.p.parm2 = guided_int_param * nproc * (chunk + 1);
487 *(
double *)&pr->u.p.parm3 =
488 guided_flt_param / nproc;
491 KD_TRACE(100, (
"__kmp_dispatch_init_algorithm: T#%d falling-through to "
492 "kmp_sch_static_greedy\n",
494 schedule = kmp_sch_static_greedy;
498 (
"__kmp_dispatch_init_algorithm: T#%d kmp_sch_static_greedy case\n",
504 case kmp_sch_guided_analytical_chunked: {
505 KD_TRACE(100, (
"__kmp_dispatch_init_algorithm: T#%d "
506 "kmp_sch_guided_analytical_chunked case\n",
510 if ((2L * chunk + 1) * nproc >= tc) {
512 schedule = kmp_sch_dynamic_chunked;
517 #if KMP_USE_X87CONTROL
527 unsigned int oldFpcw = _control87(0, 0);
528 _control87(_PC_64, _MCW_PC);
531 long double target = ((
long double)chunk * 2 + 1) * nproc / tc;
538 x = (
long double)1.0 - (
long double)0.5 / nproc;
549 ptrdiff_t natural_alignment =
550 (ptrdiff_t)&t.b - (ptrdiff_t)&t - (ptrdiff_t)1;
554 (((ptrdiff_t)&pr->u.p.parm3) & (natural_alignment)) == 0);
559 *(DBL *)&pr->u.p.parm3 = x;
572 p = __kmp_pow<UT>(x, right);
577 }
while (p > target && right < (1 << 27));
585 while (left + 1 < right) {
586 mid = (left + right) / 2;
587 if (__kmp_pow<UT>(x, mid) > target) {
596 KMP_ASSERT(cross && __kmp_pow<UT>(x, cross - 1) > target &&
597 __kmp_pow<UT>(x, cross) <= target);
600 pr->u.p.parm2 = cross;
603 #if ((KMP_OS_LINUX || KMP_OS_WINDOWS) && KMP_ARCH_X86) && (!defined(KMP_I8))
604 #define GUIDED_ANALYTICAL_WORKAROUND (*(DBL *)&pr->u.p.parm3)
606 #define GUIDED_ANALYTICAL_WORKAROUND (x)
609 pr->u.p.count = tc - __kmp_dispatch_guided_remaining(
610 tc, GUIDED_ANALYTICAL_WORKAROUND, cross) -
612 #if KMP_USE_X87CONTROL
614 _control87(oldFpcw, _MCW_PC);
618 KD_TRACE(100, (
"__kmp_dispatch_init_algorithm: T#%d falling-through to "
619 "kmp_sch_static_greedy\n",
621 schedule = kmp_sch_static_greedy;
627 case kmp_sch_static_greedy:
630 (
"__kmp_dispatch_init_algorithm: T#%d kmp_sch_static_greedy case\n",
632 pr->u.p.parm1 = (nproc > 1) ? (tc + nproc - 1) / nproc : tc;
634 case kmp_sch_static_chunked:
635 case kmp_sch_dynamic_chunked:
636 if (pr->u.p.parm1 <= 0) {
637 pr->u.p.parm1 = KMP_DEFAULT_CHUNK;
639 KD_TRACE(100, (
"__kmp_dispatch_init_algorithm: T#%d "
640 "kmp_sch_static_chunked/kmp_sch_dynamic_chunked cases\n",
643 case kmp_sch_trapezoidal: {
646 T parm1, parm2, parm3, parm4;
648 (
"__kmp_dispatch_init_algorithm: T#%d kmp_sch_trapezoidal case\n",
654 parm2 = (tc / (2 * nproc));
664 }
else if (parm1 > parm2) {
669 parm3 = (parm2 + parm1);
670 parm3 = (2 * tc + parm3 - 1) / parm3;
678 parm4 = (parm2 - parm1) / parm4;
685 pr->u.p.parm1 = parm1;
686 pr->u.p.parm2 = parm2;
687 pr->u.p.parm3 = parm3;
688 pr->u.p.parm4 = parm4;
693 __kmp_fatal(KMP_MSG(UnknownSchedTypeDetected),
694 KMP_HNT(GetNewerLibrary),
699 pr->schedule = schedule;
702 #if KMP_USE_HIER_SCHED
703 template <
typename T>
704 inline void __kmp_dispatch_init_hier_runtime(
ident_t *loc, T lb, T ub,
705 typename traits_t<T>::signed_t st);
708 __kmp_dispatch_init_hier_runtime<kmp_int32>(
ident_t *loc, kmp_int32 lb,
709 kmp_int32 ub, kmp_int32 st) {
710 __kmp_dispatch_init_hierarchy<kmp_int32>(
711 loc, __kmp_hier_scheds.size, __kmp_hier_scheds.layers,
712 __kmp_hier_scheds.scheds, __kmp_hier_scheds.small_chunks, lb, ub, st);
716 __kmp_dispatch_init_hier_runtime<kmp_uint32>(
ident_t *loc, kmp_uint32 lb,
717 kmp_uint32 ub, kmp_int32 st) {
718 __kmp_dispatch_init_hierarchy<kmp_uint32>(
719 loc, __kmp_hier_scheds.size, __kmp_hier_scheds.layers,
720 __kmp_hier_scheds.scheds, __kmp_hier_scheds.small_chunks, lb, ub, st);
724 __kmp_dispatch_init_hier_runtime<kmp_int64>(
ident_t *loc, kmp_int64 lb,
725 kmp_int64 ub, kmp_int64 st) {
726 __kmp_dispatch_init_hierarchy<kmp_int64>(
727 loc, __kmp_hier_scheds.size, __kmp_hier_scheds.layers,
728 __kmp_hier_scheds.scheds, __kmp_hier_scheds.large_chunks, lb, ub, st);
732 __kmp_dispatch_init_hier_runtime<kmp_uint64>(
ident_t *loc, kmp_uint64 lb,
733 kmp_uint64 ub, kmp_int64 st) {
734 __kmp_dispatch_init_hierarchy<kmp_uint64>(
735 loc, __kmp_hier_scheds.size, __kmp_hier_scheds.layers,
736 __kmp_hier_scheds.scheds, __kmp_hier_scheds.large_chunks, lb, ub, st);
740 void __kmp_dispatch_free_hierarchies(kmp_team_t *team) {
741 int num_disp_buff = team->t.t_max_nproc > 1 ? __kmp_dispatch_num_buffers : 2;
742 for (
int i = 0; i < num_disp_buff; ++i) {
745 reinterpret_cast<dispatch_shared_info_template<kmp_int32>
volatile *
>(
746 &team->t.t_disp_buffer[i]);
748 sh->hier->deallocate();
749 __kmp_free(sh->hier);
757 template <
typename T>
760 T ub,
typename traits_t<T>::signed_t st,
761 typename traits_t<T>::signed_t chunk,
int push_ws) {
762 typedef typename traits_t<T>::unsigned_t UT;
767 kmp_uint32 my_buffer_index;
768 dispatch_private_info_template<T> *pr;
769 dispatch_shared_info_template<T>
volatile *sh;
771 KMP_BUILD_ASSERT(
sizeof(dispatch_private_info_template<T>) ==
772 sizeof(dispatch_private_info));
773 KMP_BUILD_ASSERT(
sizeof(dispatch_shared_info_template<UT>) ==
774 sizeof(dispatch_shared_info));
776 if (!TCR_4(__kmp_init_parallel))
777 __kmp_parallel_initialize();
779 __kmp_resume_if_soft_paused();
781 #if INCLUDE_SSC_MARKS
782 SSC_MARK_DISPATCH_INIT();
785 typedef typename traits_t<T>::signed_t ST;
789 buff = __kmp_str_format(
"__kmp_dispatch_init: T#%%d called: schedule:%%d "
790 "chunk:%%%s lb:%%%s ub:%%%s st:%%%s\n",
791 traits_t<ST>::spec, traits_t<T>::spec,
792 traits_t<T>::spec, traits_t<ST>::spec);
793 KD_TRACE(10, (buff, gtid, schedule, chunk, lb, ub, st));
794 __kmp_str_free(&buff);
798 th = __kmp_threads[gtid];
799 team = th->th.th_team;
800 active = !team->t.t_serialized;
801 th->th.th_ident = loc;
806 if (schedule == __kmp_static) {
812 #if KMP_USE_HIER_SCHED
818 my_buffer_index = th->th.th_dispatch->th_disp_index;
819 pr =
reinterpret_cast<dispatch_private_info_template<T> *
>(
821 ->th_disp_buffer[my_buffer_index % __kmp_dispatch_num_buffers]);
822 my_sched = SCHEDULE_WITHOUT_MODIFIERS(my_sched);
827 if (pr->flags.use_hier) {
829 KD_TRACE(100, (
"__kmp_dispatch_init: T#%d ordered loop detected. "
830 "Disabling hierarchical scheduling.\n",
832 pr->flags.use_hier = FALSE;
835 if (schedule == kmp_sch_runtime && __kmp_hier_scheds.size > 0) {
838 if (!ordered && !pr->flags.use_hier)
839 __kmp_dispatch_init_hier_runtime<T>(loc, lb, ub, st);
844 kmp_uint64 cur_chunk = chunk;
845 int itt_need_metadata_reporting =
846 __itt_metadata_add_ptr && __kmp_forkjoin_frames_mode == 3 &&
847 KMP_MASTER_GTID(gtid) && th->th.th_teams_microtask == NULL &&
848 team->t.t_active_level == 1;
851 pr =
reinterpret_cast<dispatch_private_info_template<T> *
>(
852 th->th.th_dispatch->th_disp_buffer);
854 KMP_DEBUG_ASSERT(th->th.th_dispatch ==
855 &th->th.th_team->t.t_dispatch[th->th.th_info.ds.ds_tid]);
857 my_buffer_index = th->th.th_dispatch->th_disp_index++;
860 pr =
reinterpret_cast<dispatch_private_info_template<T> *
>(
862 ->th_disp_buffer[my_buffer_index % __kmp_dispatch_num_buffers]);
863 sh =
reinterpret_cast<dispatch_shared_info_template<T>
volatile *
>(
864 &team->t.t_disp_buffer[my_buffer_index % __kmp_dispatch_num_buffers]);
865 KD_TRACE(10, (
"__kmp_dispatch_init: T#%d my_buffer_index:%d\n", gtid,
869 __kmp_dispatch_init_algorithm(loc, gtid, pr, schedule, lb, ub, st,
873 chunk, (T)th->th.th_team_nproc,
874 (T)th->th.th_info.ds.ds_tid);
876 if (pr->flags.ordered == 0) {
877 th->th.th_dispatch->th_deo_fcn = __kmp_dispatch_deo_error;
878 th->th.th_dispatch->th_dxo_fcn = __kmp_dispatch_dxo_error;
880 th->th.th_dispatch->th_deo_fcn = __kmp_dispatch_deo<UT>;
881 th->th.th_dispatch->th_dxo_fcn = __kmp_dispatch_dxo<UT>;
889 KD_TRACE(100, (
"__kmp_dispatch_init: T#%d before wait: my_buffer_index:%d "
890 "sh->buffer_index:%d\n",
891 gtid, my_buffer_index, sh->buffer_index));
892 __kmp_wait<kmp_uint32>(&sh->buffer_index, my_buffer_index,
893 __kmp_eq<kmp_uint32> USE_ITT_BUILD_ARG(NULL));
897 KD_TRACE(100, (
"__kmp_dispatch_init: T#%d after wait: my_buffer_index:%d "
898 "sh->buffer_index:%d\n",
899 gtid, my_buffer_index, sh->buffer_index));
901 th->th.th_dispatch->th_dispatch_pr_current = (dispatch_private_info_t *)pr;
902 th->th.th_dispatch->th_dispatch_sh_current =
903 CCAST(dispatch_shared_info_t *, (
volatile dispatch_shared_info_t *)sh);
905 if (pr->flags.ordered) {
906 __kmp_itt_ordered_init(gtid);
909 if (itt_need_metadata_reporting) {
911 kmp_uint64 schedtype = 0;
913 case kmp_sch_static_chunked:
914 case kmp_sch_static_balanced:
916 case kmp_sch_static_greedy:
917 cur_chunk = pr->u.p.parm1;
919 case kmp_sch_dynamic_chunked:
922 case kmp_sch_guided_iterative_chunked:
923 case kmp_sch_guided_analytical_chunked:
933 __kmp_itt_metadata_loop(loc, schedtype, pr->u.p.tc, cur_chunk);
935 #if KMP_USE_HIER_SCHED
936 if (pr->flags.use_hier) {
938 pr->u.p.ub = pr->u.p.lb = pr->u.p.st = pr->u.p.tc = 0;
948 buff = __kmp_str_format(
949 "__kmp_dispatch_init: T#%%d returning: schedule:%%d ordered:%%%s "
951 " st:%%%s tc:%%%s count:%%%s\n\tordered_lower:%%%s ordered_upper:%%%s"
952 " parm1:%%%s parm2:%%%s parm3:%%%s parm4:%%%s\n",
953 traits_t<UT>::spec, traits_t<T>::spec, traits_t<T>::spec,
954 traits_t<ST>::spec, traits_t<UT>::spec, traits_t<UT>::spec,
955 traits_t<UT>::spec, traits_t<UT>::spec, traits_t<T>::spec,
956 traits_t<T>::spec, traits_t<T>::spec, traits_t<T>::spec);
957 KD_TRACE(10, (buff, gtid, pr->schedule, pr->flags.ordered, pr->u.p.lb,
958 pr->u.p.ub, pr->u.p.st, pr->u.p.tc, pr->u.p.count,
959 pr->u.p.ordered_lower, pr->u.p.ordered_upper, pr->u.p.parm1,
960 pr->u.p.parm2, pr->u.p.parm3, pr->u.p.parm4));
961 __kmp_str_free(&buff);
964 #if (KMP_STATIC_STEAL_ENABLED)
970 if (schedule == kmp_sch_static_steal) {
974 volatile T *p = &pr->u.p.static_steal_counter;
979 #if OMPT_SUPPORT && OMPT_OPTIONAL
980 if (ompt_enabled.ompt_callback_work) {
981 ompt_team_info_t *team_info = __ompt_get_teaminfo(0, NULL);
982 ompt_task_info_t *task_info = __ompt_get_task_info_object(0);
983 ompt_callbacks.ompt_callback(ompt_callback_work)(
984 ompt_work_loop, ompt_scope_begin, &(team_info->parallel_data),
985 &(task_info->task_data), pr->u.p.tc, OMPT_LOAD_RETURN_ADDRESS(gtid));
988 KMP_PUSH_PARTITIONED_TIMER(OMP_loop_dynamic);
996 template <
typename UT>
997 static void __kmp_dispatch_finish(
int gtid,
ident_t *loc) {
998 typedef typename traits_t<UT>::signed_t ST;
999 kmp_info_t *th = __kmp_threads[gtid];
1001 KD_TRACE(100, (
"__kmp_dispatch_finish: T#%d called\n", gtid));
1002 if (!th->th.th_team->t.t_serialized) {
1004 dispatch_private_info_template<UT> *pr =
1005 reinterpret_cast<dispatch_private_info_template<UT> *
>(
1006 th->th.th_dispatch->th_dispatch_pr_current);
1007 dispatch_shared_info_template<UT>
volatile *sh =
1008 reinterpret_cast<dispatch_shared_info_template<UT>
volatile *
>(
1009 th->th.th_dispatch->th_dispatch_sh_current);
1010 KMP_DEBUG_ASSERT(pr);
1011 KMP_DEBUG_ASSERT(sh);
1012 KMP_DEBUG_ASSERT(th->th.th_dispatch ==
1013 &th->th.th_team->t.t_dispatch[th->th.th_info.ds.ds_tid]);
1015 if (pr->ordered_bumped) {
1018 (
"__kmp_dispatch_finish: T#%d resetting ordered_bumped to zero\n",
1020 pr->ordered_bumped = 0;
1022 UT lower = pr->u.p.ordered_lower;
1028 buff = __kmp_str_format(
"__kmp_dispatch_finish: T#%%d before wait: "
1029 "ordered_iteration:%%%s lower:%%%s\n",
1030 traits_t<UT>::spec, traits_t<UT>::spec);
1031 KD_TRACE(1000, (buff, gtid, sh->u.s.ordered_iteration, lower));
1032 __kmp_str_free(&buff);
1036 __kmp_wait<UT>(&sh->u.s.ordered_iteration, lower,
1037 __kmp_ge<UT> USE_ITT_BUILD_ARG(NULL));
1043 buff = __kmp_str_format(
"__kmp_dispatch_finish: T#%%d after wait: "
1044 "ordered_iteration:%%%s lower:%%%s\n",
1045 traits_t<UT>::spec, traits_t<UT>::spec);
1046 KD_TRACE(1000, (buff, gtid, sh->u.s.ordered_iteration, lower));
1047 __kmp_str_free(&buff);
1051 test_then_inc<ST>((
volatile ST *)&sh->u.s.ordered_iteration);
1054 KD_TRACE(100, (
"__kmp_dispatch_finish: T#%d returned\n", gtid));
1057 #ifdef KMP_GOMP_COMPAT
1059 template <
typename UT>
1060 static void __kmp_dispatch_finish_chunk(
int gtid,
ident_t *loc) {
1061 typedef typename traits_t<UT>::signed_t ST;
1062 kmp_info_t *th = __kmp_threads[gtid];
1064 KD_TRACE(100, (
"__kmp_dispatch_finish_chunk: T#%d called\n", gtid));
1065 if (!th->th.th_team->t.t_serialized) {
1067 dispatch_private_info_template<UT> *pr =
1068 reinterpret_cast<dispatch_private_info_template<UT> *
>(
1069 th->th.th_dispatch->th_dispatch_pr_current);
1070 dispatch_shared_info_template<UT>
volatile *sh =
1071 reinterpret_cast<dispatch_shared_info_template<UT>
volatile *
>(
1072 th->th.th_dispatch->th_dispatch_sh_current);
1073 KMP_DEBUG_ASSERT(pr);
1074 KMP_DEBUG_ASSERT(sh);
1075 KMP_DEBUG_ASSERT(th->th.th_dispatch ==
1076 &th->th.th_team->t.t_dispatch[th->th.th_info.ds.ds_tid]);
1079 UT lower = pr->u.p.ordered_lower;
1080 UT upper = pr->u.p.ordered_upper;
1081 UT inc = upper - lower + 1;
1083 if (pr->ordered_bumped == inc) {
1086 (
"__kmp_dispatch_finish: T#%d resetting ordered_bumped to zero\n",
1088 pr->ordered_bumped = 0;
1090 inc -= pr->ordered_bumped;
1096 buff = __kmp_str_format(
1097 "__kmp_dispatch_finish_chunk: T#%%d before wait: "
1098 "ordered_iteration:%%%s lower:%%%s upper:%%%s\n",
1099 traits_t<UT>::spec, traits_t<UT>::spec, traits_t<UT>::spec);
1100 KD_TRACE(1000, (buff, gtid, sh->u.s.ordered_iteration, lower, upper));
1101 __kmp_str_free(&buff);
1105 __kmp_wait<UT>(&sh->u.s.ordered_iteration, lower,
1106 __kmp_ge<UT> USE_ITT_BUILD_ARG(NULL));
1109 KD_TRACE(1000, (
"__kmp_dispatch_finish_chunk: T#%d resetting "
1110 "ordered_bumped to zero\n",
1112 pr->ordered_bumped = 0;
1118 buff = __kmp_str_format(
1119 "__kmp_dispatch_finish_chunk: T#%%d after wait: "
1120 "ordered_iteration:%%%s inc:%%%s lower:%%%s upper:%%%s\n",
1121 traits_t<UT>::spec, traits_t<UT>::spec, traits_t<UT>::spec,
1122 traits_t<UT>::spec);
1124 (buff, gtid, sh->u.s.ordered_iteration, inc, lower, upper));
1125 __kmp_str_free(&buff);
1129 test_then_add<ST>((
volatile ST *)&sh->u.s.ordered_iteration,