13#include "kmp_wait_release.h"
14#include "kmp_barrier.h"
18#include "ompt-specific.h"
20#include "kmp_affinity.h"
24#define USE_NGO_STORES 1
27#if KMP_MIC && USE_NGO_STORES
29#define ngo_load(src) __m512d Vt = _mm512_load_pd((void *)(src))
30#define ngo_store_icvs(dst, src) _mm512_storenrngo_pd((void *)(dst), Vt)
31#define ngo_store_go(dst, src) _mm512_storenrngo_pd((void *)(dst), Vt)
32#define ngo_sync() __asm__ volatile("lock; addl $0,0(%%rsp)" ::: "memory")
34#define ngo_load(src) ((void)0)
35#define ngo_store_icvs(dst, src) copy_icvs((dst), (src))
36#define ngo_store_go(dst, src) KMP_MEMCPY((dst), (src), CACHE_LINE)
37#define ngo_sync() ((void)0)
40void __kmp_print_structure(
void);
47void distributedBarrier::computeVarsForN(
size_t n) {
50 int socket_level = __kmp_topology->get_level(KMP_HW_SOCKET);
51 int core_level = __kmp_topology->get_level(KMP_HW_CORE);
52 int ncores_per_socket =
53 __kmp_topology->calculate_ratio(core_level, socket_level);
54 nsockets = __kmp_topology->get_count(socket_level);
58 if (ncores_per_socket <= 0)
59 ncores_per_socket = 1;
61 threads_per_go = ncores_per_socket >> 1;
62 if (!fix_threads_per_go) {
64 if (threads_per_go > 4) {
65 if (KMP_OPTIMIZE_FOR_REDUCTIONS) {
66 threads_per_go = threads_per_go >> 1;
68 if (threads_per_go > 4 && nsockets == 1)
69 threads_per_go = threads_per_go >> 1;
72 if (threads_per_go == 0)
74 fix_threads_per_go =
true;
75 num_gos = n / threads_per_go;
76 if (n % threads_per_go)
78 if (nsockets == 1 || num_gos == 1)
81 num_groups = num_gos / nsockets;
82 if (num_gos % nsockets)
87 gos_per_group = num_gos / num_groups;
88 if (num_gos % num_groups)
90 threads_per_group = threads_per_go * gos_per_group;
92 num_gos = n / threads_per_go;
93 if (n % threads_per_go)
98 num_groups = num_gos / 2;
102 gos_per_group = num_gos / num_groups;
103 if (num_gos % num_groups)
105 threads_per_group = threads_per_go * gos_per_group;
109void distributedBarrier::computeGo(
size_t n) {
111 for (num_gos = 1;; num_gos++)
112 if (IDEAL_CONTENTION * num_gos >= n)
114 threads_per_go = n / num_gos;
117 while (num_gos > MAX_GOS) {
119 num_gos = n / threads_per_go;
120 if (n % threads_per_go)
128void distributedBarrier::resize(
size_t nthr) {
129 KMP_DEBUG_ASSERT(nthr > max_threads);
132 max_threads = nthr * 2;
135 for (
int i = 0; i < MAX_ITERS; ++i) {
137 flags[i] = (flags_s *)KMP_INTERNAL_REALLOC(flags[i],
138 max_threads *
sizeof(flags_s));
140 flags[i] = (flags_s *)KMP_INTERNAL_MALLOC(max_threads *
sizeof(flags_s));
144 go = (go_s *)KMP_INTERNAL_REALLOC(go, max_threads *
sizeof(go_s));
146 go = (go_s *)KMP_INTERNAL_MALLOC(max_threads *
sizeof(go_s));
149 iter = (iter_s *)KMP_INTERNAL_REALLOC(iter, max_threads *
sizeof(iter_s));
151 iter = (iter_s *)KMP_INTERNAL_MALLOC(max_threads *
sizeof(iter_s));
155 (sleep_s *)KMP_INTERNAL_REALLOC(sleep, max_threads *
sizeof(sleep_s));
157 sleep = (sleep_s *)KMP_INTERNAL_MALLOC(max_threads *
sizeof(sleep_s));
163kmp_uint64 distributedBarrier::go_release() {
164 kmp_uint64 next_go = iter[0].iter + distributedBarrier::MAX_ITERS;
165 for (
size_t j = 0; j < num_gos; j++) {
166 go[j].go.store(next_go);
171void distributedBarrier::go_reset() {
172 for (
size_t j = 0; j < max_threads; ++j) {
173 for (
size_t i = 0; i < distributedBarrier::MAX_ITERS; ++i) {
174 flags[i][j].stillNeed.store(1, std::memory_order_relaxed);
183void distributedBarrier::init(
size_t nthr) {
184 size_t old_max = max_threads;
185 if (nthr > max_threads) {
189 for (
size_t i = 0; i < max_threads; i++) {
190 for (
size_t j = 0; j < distributedBarrier::MAX_ITERS; j++) {
191 flags[j][i].stillNeed.store(1, std::memory_order_relaxed);
196 sleep[i].sleep =
false;
200 computeVarsForN(nthr);
204 if (team_icvs == NULL)
205 team_icvs = __kmp_allocate(
sizeof(kmp_internal_control_t));
208void distributedBarrier::deallocate(distributedBarrier *db) {
209 for (
int i = 0; i < MAX_ITERS; ++i) {
211 KMP_INTERNAL_FREE(db->flags[i]);
215 KMP_INTERNAL_FREE(db->go);
219 KMP_INTERNAL_FREE(db->iter);
223 KMP_INTERNAL_FREE(db->sleep);
227 __kmp_free(db->team_icvs);
228 db->team_icvs = NULL;
230 KMP_ALIGNED_FREE(db);
235void __kmp_dist_barrier_wakeup(
enum barrier_type bt, kmp_team_t *team,
236 size_t start,
size_t stop,
size_t inc,
238 KMP_DEBUG_ASSERT(__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME);
239 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
242 kmp_info_t **other_threads = team->t.t_threads;
243 for (
size_t thr = start; thr < stop; thr += inc) {
244 KMP_DEBUG_ASSERT(other_threads[thr]);
245 int gtid = other_threads[thr]->th.th_info.ds.ds_gtid;
247 __kmp_atomic_resume_64(gtid, (kmp_atomic_flag_64<> *)NULL);
251static void __kmp_dist_barrier_gather(
252 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
253 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
254 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_dist_gather);
256 distributedBarrier *b;
257 kmp_info_t **other_threads;
258 kmp_uint64 my_current_iter, my_next_iter;
262 team = this_thr->th.th_team;
263 nproc = this_thr->th.th_team_nproc;
264 other_threads = team->t.t_threads;
266 my_current_iter = b->iter[tid].iter;
267 my_next_iter = (my_current_iter + 1) % distributedBarrier::MAX_ITERS;
268 group_leader = ((tid % b->threads_per_group) == 0);
271 (
"__kmp_dist_barrier_gather: T#%d(%d:%d) enter; barrier type %d\n",
272 gtid, team->t.t_id, tid, bt));
274#if USE_ITT_BUILD && USE_ITT_NOTIFY
276 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
277 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
278 __itt_get_timestamp();
284 size_t group_start = tid + 1;
285 size_t group_end = tid + b->threads_per_group;
286 size_t threads_pending = 0;
288 if (group_end > nproc)
293 for (
size_t thr = group_start; thr < group_end; thr++) {
297 threads_pending += b->flags[my_current_iter][thr].stillNeed.load(
298 std::memory_order_relaxed);
301 if (__kmp_tasking_mode != tskm_immediate_exec) {
302 kmp_task_team_t *task_team = this_thr->th.th_task_team;
303 if (task_team != NULL) {
304 if (TCR_SYNC_4(task_team->tt.tt_active)) {
305 if (KMP_TASKING_ENABLED(task_team)) {
306 int tasks_completed = FALSE;
307 __kmp_atomic_execute_tasks_64(
308 this_thr, gtid, (kmp_atomic_flag_64<> *)NULL, FALSE,
309 &tasks_completed USE_ITT_BUILD_ARG(itt_sync_obj), 0);
311 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
314 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
317 if (TCR_4(__kmp_global.g.g_done)) {
318 if (__kmp_global.g.g_abort)
319 __kmp_abort_thread();
321 }
else if (__kmp_tasking_mode != tskm_immediate_exec &&
322 this_thr->th.th_reap_state == KMP_SAFE_TO_REAP) {
323 this_thr->th.th_reap_state = KMP_NOT_SAFE_TO_REAP;
325 }
while (threads_pending > 0);
328 std::atomic_thread_fence(std::memory_order_acquire);
331 OMPT_REDUCTION_DECL(this_thr, gtid);
332 OMPT_REDUCTION_BEGIN;
334 for (
size_t thr = group_start; thr < group_end; thr++) {
335 (*reduce)(this_thr->th.th_local.reduce_data,
336 other_threads[thr]->th.th_local.reduce_data);
342 b->flags[my_next_iter][tid].stillNeed.store(1, std::memory_order_relaxed);
346 b->flags[my_current_iter][tid].stillNeed.store(0,
347 std::memory_order_release);
351 for (
size_t thr = 0; thr < nproc; thr += b->threads_per_group) {
352 threads_pending += b->flags[my_current_iter][thr].stillNeed.load(
353 std::memory_order_relaxed);
356 if (__kmp_tasking_mode != tskm_immediate_exec) {
357 kmp_task_team_t *task_team = this_thr->th.th_task_team;
358 if (task_team != NULL) {
359 if (TCR_SYNC_4(task_team->tt.tt_active)) {
360 if (KMP_TASKING_ENABLED(task_team)) {
361 int tasks_completed = FALSE;
362 __kmp_atomic_execute_tasks_64(
363 this_thr, gtid, (kmp_atomic_flag_64<> *)NULL, FALSE,
364 &tasks_completed USE_ITT_BUILD_ARG(itt_sync_obj), 0);
366 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
369 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
372 if (TCR_4(__kmp_global.g.g_done)) {
373 if (__kmp_global.g.g_abort)
374 __kmp_abort_thread();
376 }
else if (__kmp_tasking_mode != tskm_immediate_exec &&
377 this_thr->th.th_reap_state == KMP_SAFE_TO_REAP) {
378 this_thr->th.th_reap_state = KMP_NOT_SAFE_TO_REAP;
380 }
while (threads_pending > 0);
382 std::atomic_thread_fence(std::memory_order_acquire);
385 if (KMP_MASTER_TID(tid)) {
386 OMPT_REDUCTION_DECL(this_thr, gtid);
387 OMPT_REDUCTION_BEGIN;
388 for (
size_t thr = b->threads_per_group; thr < nproc;
389 thr += b->threads_per_group) {
390 (*reduce)(this_thr->th.th_local.reduce_data,
391 other_threads[thr]->th.th_local.reduce_data);
398 b->flags[my_next_iter][tid].stillNeed.store(1, std::memory_order_relaxed);
402 b->flags[my_current_iter][tid].stillNeed.store(0,
403 std::memory_order_release);
409 (
"__kmp_dist_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",
410 gtid, team->t.t_id, tid, bt));
413static void __kmp_dist_barrier_release(
414 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
415 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
416 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_dist_release);
418 distributedBarrier *b;
419 kmp_bstate_t *thr_bar;
420 kmp_uint64 my_current_iter, next_go;
424 KA_TRACE(20, (
"__kmp_dist_barrier_release: T#%d(%d) enter; barrier type %d\n",
427 thr_bar = &this_thr->th.th_bar[bt].bb;
429 if (!KMP_MASTER_TID(tid)) {
432 if (this_thr->th.th_used_in_team.load() != 1 &&
433 this_thr->th.th_used_in_team.load() != 3) {
438 kmp_flag_32<false, false> my_flag(&(this_thr->th.th_used_in_team), 3);
439 if (KMP_COMPARE_AND_STORE_ACQ32(&(this_thr->th.th_used_in_team), 2,
441 this_thr->th.th_used_in_team.load() == 0) {
442 my_flag.wait(this_thr,
true USE_ITT_BUILD_ARG(itt_sync_obj));
444#if USE_ITT_BUILD && USE_ITT_NOTIFY
445 if ((__itt_sync_create_ptr && itt_sync_obj == NULL) || KMP_ITT_DEBUG) {
448 __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
450 __kmp_itt_task_starting(itt_sync_obj);
452 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
455 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
456 if (itt_sync_obj != NULL)
458 __kmp_itt_task_finished(itt_sync_obj);
461 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
464 if (this_thr->th.th_used_in_team.load() != 1 &&
465 this_thr->th.th_used_in_team.load() != 3)
467 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
476 tid = __kmp_tid_from_gtid(gtid);
477 team = this_thr->th.th_team;
478 KMP_DEBUG_ASSERT(tid >= 0);
479 KMP_DEBUG_ASSERT(team);
481 my_current_iter = b->iter[tid].iter;
482 next_go = my_current_iter + distributedBarrier::MAX_ITERS;
483 my_go_index = tid / b->threads_per_go;
484 if (this_thr->th.th_used_in_team.load() == 3) {
485 (void)KMP_COMPARE_AND_STORE_ACQ32(&(this_thr->th.th_used_in_team), 3,
489 if (b->go[my_go_index].go.load() != next_go) {
491 kmp_atomic_flag_64<false, true> my_flag(
492 &(b->go[my_go_index].go), next_go, &(b->sleep[tid].sleep));
493 my_flag.wait(this_thr,
true USE_ITT_BUILD_ARG(itt_sync_obj));
494 KMP_DEBUG_ASSERT(my_current_iter == b->iter[tid].iter ||
495 b->iter[tid].iter == 0);
496 KMP_DEBUG_ASSERT(b->sleep[tid].sleep ==
false);
499 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
506 if (this_thr->th.th_used_in_team.load() == 1)
510 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
513 group_leader = ((tid % b->threads_per_group) == 0);
516 for (
size_t go_idx = my_go_index + 1;
517 go_idx < my_go_index + b->gos_per_group; go_idx++) {
518 b->go[go_idx].go.store(next_go);
524#if KMP_BARRIER_ICV_PUSH
525 if (propagate_icvs) {
526 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team,
528 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
529 (kmp_internal_control_t *)team->t.b->team_icvs);
530 copy_icvs(&thr_bar->th_fixed_icvs,
531 &team->t.t_implicit_task_taskdata[tid].td_icvs);
534 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME && group_leader) {
537 size_t nproc = this_thr->th.th_team_nproc;
538 size_t group_end = tid + b->threads_per_group;
539 if (nproc < group_end)
541 __kmp_dist_barrier_wakeup(bt, team, tid + 1, group_end, 1, tid);
544 team = this_thr->th.th_team;
546 my_current_iter = b->iter[tid].iter;
547 next_go = my_current_iter + distributedBarrier::MAX_ITERS;
548#if KMP_BARRIER_ICV_PUSH
549 if (propagate_icvs) {
551 copy_icvs(&thr_bar->th_fixed_icvs,
552 &team->t.t_implicit_task_taskdata[tid].td_icvs);
556 for (
size_t go_idx = 0; go_idx < b->num_gos; go_idx += b->gos_per_group) {
557 b->go[go_idx].go.store(next_go);
560 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
562 size_t nproc = this_thr->th.th_team_nproc;
563 __kmp_dist_barrier_wakeup(bt, team, tid + b->threads_per_group, nproc,
564 b->threads_per_group, tid);
568 for (
size_t go_idx = 1; go_idx < b->gos_per_group; go_idx++) {
569 b->go[go_idx].go.store(next_go);
575 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
577 size_t nproc = this_thr->th.th_team_nproc;
578 size_t group_end = tid + b->threads_per_group;
579 if (nproc < group_end)
581 __kmp_dist_barrier_wakeup(bt, team, tid + 1, group_end, 1, tid);
585 KMP_ASSERT(my_current_iter == b->iter[tid].iter);
586 b->iter[tid].iter = (b->iter[tid].iter + 1) % distributedBarrier::MAX_ITERS;
589 20, (
"__kmp_dist_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",
590 gtid, team->t.t_id, tid, bt));
594template <
bool cancellable = false>
595static bool __kmp_linear_barrier_gather_template(
596 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
597 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
598 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_linear_gather);
599 kmp_team_t *team = this_thr->th.th_team;
600 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
601 kmp_info_t **other_threads = team->t.t_threads;
605 (
"__kmp_linear_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",
606 gtid, team->t.t_id, tid, bt));
607 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
609#if USE_ITT_BUILD && USE_ITT_NOTIFY
611 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
612 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
613 __itt_get_timestamp();
618 if (!KMP_MASTER_TID(tid)) {
620 (
"__kmp_linear_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d)"
621 "arrived(%p): %llu => %llu\n",
622 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(0, team),
623 team->t.t_id, 0, &thr_bar->b_arrived, thr_bar->b_arrived,
624 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
629 kmp_flag_64<> flag(&thr_bar->b_arrived, other_threads[0]);
632 kmp_balign_team_t *team_bar = &team->t.t_bar[bt];
633 int nproc = this_thr->th.th_team_nproc;
636 kmp_uint64 new_state = team_bar->b_arrived + KMP_BARRIER_STATE_BUMP;
639 for (i = 1; i < nproc; ++i) {
643 KMP_CACHE_PREFETCH(&other_threads[i + 1]->th.th_bar[bt].bb.b_arrived);
645 KA_TRACE(20, (
"__kmp_linear_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%d) "
646 "arrived(%p) == %llu\n",
647 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(i, team),
649 &other_threads[i]->th.th_bar[bt].bb.b_arrived, new_state));
653 kmp_flag_64<true, false> flag(
654 &other_threads[i]->th.th_bar[bt].bb.b_arrived, new_state);
655 if (flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj)))
658 kmp_flag_64<> flag(&other_threads[i]->th.th_bar[bt].bb.b_arrived,
660 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
662#if USE_ITT_BUILD && USE_ITT_NOTIFY
665 if (__kmp_forkjoin_frames_mode == 2) {
666 this_thr->th.th_bar_min_time = KMP_MIN(
667 this_thr->th.th_bar_min_time, other_threads[i]->th.th_bar_min_time);
672 (
"__kmp_linear_barrier_gather: T#%d(%d:%d) += T#%d(%d:%d)\n",
673 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(i, team),
675 OMPT_REDUCTION_DECL(this_thr, gtid);
676 OMPT_REDUCTION_BEGIN;
677 (*reduce)(this_thr->th.th_local.reduce_data,
678 other_threads[i]->th.th_local.reduce_data);
683 team_bar->b_arrived = new_state;
684 KA_TRACE(20, (
"__kmp_linear_barrier_gather: T#%d(%d:%d) set team %d "
685 "arrived(%p) = %llu\n",
686 gtid, team->t.t_id, tid, team->t.t_id, &team_bar->b_arrived,
691 (
"__kmp_linear_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",
692 gtid, team->t.t_id, tid, bt));
696template <
bool cancellable = false>
697static bool __kmp_linear_barrier_release_template(
698 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
699 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
700 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_linear_release);
701 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
704 if (KMP_MASTER_TID(tid)) {
706 kmp_uint32 nproc = this_thr->th.th_team_nproc;
707 kmp_info_t **other_threads;
709 team = __kmp_threads[gtid]->th.th_team;
710 KMP_DEBUG_ASSERT(team != NULL);
711 other_threads = team->t.t_threads;
713 KA_TRACE(20, (
"__kmp_linear_barrier_release: T#%d(%d:%d) primary enter for "
715 gtid, team->t.t_id, tid, bt));
718#if KMP_BARRIER_ICV_PUSH
720 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy);
721 if (propagate_icvs) {
722 ngo_load(&team->t.t_implicit_task_taskdata[0].td_icvs);
723 for (i = 1; i < nproc; ++i) {
724 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[i],
726 ngo_store_icvs(&team->t.t_implicit_task_taskdata[i].td_icvs,
727 &team->t.t_implicit_task_taskdata[0].td_icvs);
735 for (i = 1; i < nproc; ++i) {
739 KMP_CACHE_PREFETCH(&other_threads[i + 1]->th.th_bar[bt].bb.b_go);
743 (
"__kmp_linear_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%d) "
744 "go(%p): %u => %u\n",
745 gtid, team->t.t_id, tid, other_threads[i]->th.th_info.ds.ds_gtid,
746 team->t.t_id, i, &other_threads[i]->th.th_bar[bt].bb.b_go,
747 other_threads[i]->th.th_bar[bt].bb.b_go,
748 other_threads[i]->th.th_bar[bt].bb.b_go + KMP_BARRIER_STATE_BUMP));
749 kmp_flag_64<> flag(&other_threads[i]->th.th_bar[bt].bb.b_go,
755 KA_TRACE(20, (
"__kmp_linear_barrier_release: T#%d wait go(%p) == %u\n",
756 gtid, &thr_bar->b_go, KMP_BARRIER_STATE_BUMP));
758 kmp_flag_64<true, false> flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
759 if (flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj)))
762 kmp_flag_64<> flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
763 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
765#if USE_ITT_BUILD && USE_ITT_NOTIFY
766 if ((__itt_sync_create_ptr && itt_sync_obj == NULL) || KMP_ITT_DEBUG) {
769 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
771 __kmp_itt_task_starting(itt_sync_obj);
773 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
776 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
777 if (itt_sync_obj != NULL)
779 __kmp_itt_task_finished(itt_sync_obj);
783 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
787 tid = __kmp_tid_from_gtid(gtid);
788 team = __kmp_threads[gtid]->th.th_team;
790 KMP_DEBUG_ASSERT(team != NULL);
791 TCW_4(thr_bar->b_go, KMP_INIT_BARRIER_STATE);
793 (
"__kmp_linear_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",
794 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
799 (
"__kmp_linear_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",
800 gtid, team->t.t_id, tid, bt));
804static void __kmp_linear_barrier_gather(
805 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
806 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
807 __kmp_linear_barrier_gather_template<false>(
808 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
811static bool __kmp_linear_barrier_gather_cancellable(
812 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
813 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
814 return __kmp_linear_barrier_gather_template<true>(
815 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
818static void __kmp_linear_barrier_release(
819 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
820 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
821 __kmp_linear_barrier_release_template<false>(
822 bt, this_thr, gtid, tid, propagate_icvs USE_ITT_BUILD_ARG(itt_sync_obj));
825static bool __kmp_linear_barrier_release_cancellable(
826 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
827 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
828 return __kmp_linear_barrier_release_template<true>(
829 bt, this_thr, gtid, tid, propagate_icvs USE_ITT_BUILD_ARG(itt_sync_obj));
833static void __kmp_tree_barrier_gather(
834 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
835 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
836 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_tree_gather);
837 kmp_team_t *team = this_thr->th.th_team;
838 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
839 kmp_info_t **other_threads = team->t.t_threads;
840 kmp_uint32 nproc = this_thr->th.th_team_nproc;
841 kmp_uint32 branch_bits = __kmp_barrier_gather_branch_bits[bt];
842 kmp_uint32 branch_factor = 1 << branch_bits;
844 kmp_uint32 child_tid;
845 kmp_uint64 new_state = 0;
848 20, (
"__kmp_tree_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",
849 gtid, team->t.t_id, tid, bt));
850 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
852#if USE_ITT_BUILD && USE_ITT_NOTIFY
854 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
855 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
856 __itt_get_timestamp();
861 child_tid = (tid << branch_bits) + 1;
862 if (child_tid < nproc) {
864 new_state = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
867 kmp_info_t *child_thr = other_threads[child_tid];
868 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
871 if (child + 1 <= branch_factor && child_tid + 1 < nproc)
873 &other_threads[child_tid + 1]->th.th_bar[bt].bb.b_arrived);
876 (
"__kmp_tree_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
877 "arrived(%p) == %llu\n",
878 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
879 team->t.t_id, child_tid, &child_bar->b_arrived, new_state));
881 kmp_flag_64<> flag(&child_bar->b_arrived, new_state);
882 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
883#if USE_ITT_BUILD && USE_ITT_NOTIFY
886 if (__kmp_forkjoin_frames_mode == 2) {
887 this_thr->th.th_bar_min_time = KMP_MIN(this_thr->th.th_bar_min_time,
888 child_thr->th.th_bar_min_time);
893 (
"__kmp_tree_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n",
894 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
895 team->t.t_id, child_tid));
896 OMPT_REDUCTION_DECL(this_thr, gtid);
897 OMPT_REDUCTION_BEGIN;
898 (*reduce)(this_thr->th.th_local.reduce_data,
899 child_thr->th.th_local.reduce_data);
904 }
while (child <= branch_factor && child_tid < nproc);
907 if (!KMP_MASTER_TID(tid)) {
908 kmp_int32 parent_tid = (tid - 1) >> branch_bits;
911 (
"__kmp_tree_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
912 "arrived(%p): %llu => %llu\n",
913 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(parent_tid, team),
914 team->t.t_id, parent_tid, &thr_bar->b_arrived, thr_bar->b_arrived,
915 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
921 kmp_flag_64<> flag(&thr_bar->b_arrived, other_threads[parent_tid]);
926 team->t.t_bar[bt].b_arrived = new_state;
928 team->t.t_bar[bt].b_arrived += KMP_BARRIER_STATE_BUMP;
929 KA_TRACE(20, (
"__kmp_tree_barrier_gather: T#%d(%d:%d) set team %d "
930 "arrived(%p) = %llu\n",
931 gtid, team->t.t_id, tid, team->t.t_id,
932 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived));
935 (
"__kmp_tree_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",
936 gtid, team->t.t_id, tid, bt));
939static void __kmp_tree_barrier_release(
940 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
941 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
942 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_tree_release);
944 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
946 kmp_uint32 branch_bits = __kmp_barrier_release_branch_bits[bt];
947 kmp_uint32 branch_factor = 1 << branch_bits;
949 kmp_uint32 child_tid;
954 KA_TRACE(20, (
"__kmp_tree_barrier_release: T#%d wait go(%p) == %u\n", gtid,
955 &thr_bar->b_go, KMP_BARRIER_STATE_BUMP));
957 kmp_flag_64<> flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
958 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
959#if USE_ITT_BUILD && USE_ITT_NOTIFY
960 if ((__itt_sync_create_ptr && itt_sync_obj == NULL) || KMP_ITT_DEBUG) {
963 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
965 __kmp_itt_task_starting(itt_sync_obj);
967 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
970 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
971 if (itt_sync_obj != NULL)
973 __kmp_itt_task_finished(itt_sync_obj);
977 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
981 team = __kmp_threads[gtid]->th.th_team;
982 KMP_DEBUG_ASSERT(team != NULL);
983 tid = __kmp_tid_from_gtid(gtid);
985 TCW_4(thr_bar->b_go, KMP_INIT_BARRIER_STATE);
987 (
"__kmp_tree_barrier_release: T#%d(%d:%d) set go(%p) = %u\n", gtid,
988 team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
991 team = __kmp_threads[gtid]->th.th_team;
992 KMP_DEBUG_ASSERT(team != NULL);
993 KA_TRACE(20, (
"__kmp_tree_barrier_release: T#%d(%d:%d) primary enter for "
995 gtid, team->t.t_id, tid, bt));
997 nproc = this_thr->th.th_team_nproc;
998 child_tid = (tid << branch_bits) + 1;
1000 if (child_tid < nproc) {
1001 kmp_info_t **other_threads = team->t.t_threads;
1005 kmp_info_t *child_thr = other_threads[child_tid];
1006 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1009 if (child + 1 <= branch_factor && child_tid + 1 < nproc)
1011 &other_threads[child_tid + 1]->th.th_bar[bt].bb.b_go);
1014#if KMP_BARRIER_ICV_PUSH
1016 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy);
1017 if (propagate_icvs) {
1018 __kmp_init_implicit_task(team->t.t_ident,
1019 team->t.t_threads[child_tid], team,
1021 copy_icvs(&team->t.t_implicit_task_taskdata[child_tid].td_icvs,
1022 &team->t.t_implicit_task_taskdata[0].td_icvs);
1027 (
"__kmp_tree_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
1028 "go(%p): %u => %u\n",
1029 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
1030 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,
1031 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1033 kmp_flag_64<> flag(&child_bar->b_go, child_thr);
1037 }
while (child <= branch_factor && child_tid < nproc);
1040 20, (
"__kmp_tree_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",
1041 gtid, team->t.t_id, tid, bt));
1045static void __kmp_hyper_barrier_gather(
1046 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
1047 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
1048 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hyper_gather);
1049 kmp_team_t *team = this_thr->th.th_team;
1050 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
1051 kmp_info_t **other_threads = team->t.t_threads;
1052 kmp_uint64 new_state = KMP_BARRIER_UNUSED_STATE;
1053 kmp_uint32 num_threads = this_thr->th.th_team_nproc;
1054 kmp_uint32 branch_bits = __kmp_barrier_gather_branch_bits[bt];
1055 kmp_uint32 branch_factor = 1 << branch_bits;
1061 (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",
1062 gtid, team->t.t_id, tid, bt));
1063 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
1065#if USE_ITT_BUILD && USE_ITT_NOTIFY
1067 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
1068 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
1069 __itt_get_timestamp();
1074 kmp_flag_64<> p_flag(&thr_bar->b_arrived);
1075 for (level = 0, offset = 1; offset < num_threads;
1076 level += branch_bits, offset <<= branch_bits) {
1078 kmp_uint32 child_tid;
1080 if (((tid >> level) & (branch_factor - 1)) != 0) {
1081 kmp_int32 parent_tid = tid & ~((1 << (level + branch_bits)) - 1);
1085 (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
1086 "arrived(%p): %llu => %llu\n",
1087 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(parent_tid, team),
1088 team->t.t_id, parent_tid, &thr_bar->b_arrived,
1090 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
1095 p_flag.set_waiter(other_threads[parent_tid]);
1101 if (new_state == KMP_BARRIER_UNUSED_STATE)
1102 new_state = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
1103 for (child = 1, child_tid = tid + (1 << level);
1104 child < branch_factor && child_tid < num_threads;
1105 child++, child_tid += (1 << level)) {
1106 kmp_info_t *child_thr = other_threads[child_tid];
1107 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1109 kmp_uint32 next_child_tid = child_tid + (1 << level);
1111 if (child + 1 < branch_factor && next_child_tid < num_threads)
1113 &other_threads[next_child_tid]->th.th_bar[bt].bb.b_arrived);
1116 (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
1117 "arrived(%p) == %llu\n",
1118 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
1119 team->t.t_id, child_tid, &child_bar->b_arrived, new_state));
1121 kmp_flag_64<> c_flag(&child_bar->b_arrived, new_state);
1122 c_flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1124#if USE_ITT_BUILD && USE_ITT_NOTIFY
1127 if (__kmp_forkjoin_frames_mode == 2) {
1128 this_thr->th.th_bar_min_time = KMP_MIN(this_thr->th.th_bar_min_time,
1129 child_thr->th.th_bar_min_time);
1134 (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n",
1135 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
1136 team->t.t_id, child_tid));
1137 OMPT_REDUCTION_DECL(this_thr, gtid);
1138 OMPT_REDUCTION_BEGIN;
1139 (*reduce)(this_thr->th.th_local.reduce_data,
1140 child_thr->th.th_local.reduce_data);
1146 if (KMP_MASTER_TID(tid)) {
1148 if (new_state == KMP_BARRIER_UNUSED_STATE)
1149 team->t.t_bar[bt].b_arrived += KMP_BARRIER_STATE_BUMP;
1151 team->t.t_bar[bt].b_arrived = new_state;
1152 KA_TRACE(20, (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) set team %d "
1153 "arrived(%p) = %llu\n",
1154 gtid, team->t.t_id, tid, team->t.t_id,
1155 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived));
1158 20, (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",
1159 gtid, team->t.t_id, tid, bt));
1163#define KMP_REVERSE_HYPER_BAR
1164static void __kmp_hyper_barrier_release(
1165 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
1166 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
1167 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hyper_release);
1169 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
1170 kmp_info_t **other_threads;
1171 kmp_uint32 num_threads;
1172 kmp_uint32 branch_bits = __kmp_barrier_release_branch_bits[bt];
1173 kmp_uint32 branch_factor = 1 << branch_bits;
1175 kmp_uint32 child_tid;
1183 if (KMP_MASTER_TID(tid)) {
1184 team = __kmp_threads[gtid]->th.th_team;
1185 KMP_DEBUG_ASSERT(team != NULL);
1186 KA_TRACE(20, (
"__kmp_hyper_barrier_release: T#%d(%d:%d) primary enter for "
1187 "barrier type %d\n",
1188 gtid, team->t.t_id, tid, bt));
1189#if KMP_BARRIER_ICV_PUSH
1190 if (propagate_icvs) {
1191 copy_icvs(&thr_bar->th_fixed_icvs,
1192 &team->t.t_implicit_task_taskdata[tid].td_icvs);
1196 KA_TRACE(20, (
"__kmp_hyper_barrier_release: T#%d wait go(%p) == %u\n", gtid,
1197 &thr_bar->b_go, KMP_BARRIER_STATE_BUMP));
1199 kmp_flag_64<> flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
1200 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
1201#if USE_ITT_BUILD && USE_ITT_NOTIFY
1202 if ((__itt_sync_create_ptr && itt_sync_obj == NULL) || KMP_ITT_DEBUG) {
1204 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
1206 __kmp_itt_task_starting(itt_sync_obj);
1208 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
1211 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
1212 if (itt_sync_obj != NULL)
1214 __kmp_itt_task_finished(itt_sync_obj);
1218 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
1222 team = __kmp_threads[gtid]->th.th_team;
1223 KMP_DEBUG_ASSERT(team != NULL);
1224 tid = __kmp_tid_from_gtid(gtid);
1226 TCW_4(thr_bar->b_go, KMP_INIT_BARRIER_STATE);
1228 (
"__kmp_hyper_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",
1229 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
1232 num_threads = this_thr->th.th_team_nproc;
1233 other_threads = team->t.t_threads;
1235#ifdef KMP_REVERSE_HYPER_BAR
1237 for (level = 0, offset = 1;
1238 offset < num_threads && (((tid >> level) & (branch_factor - 1)) == 0);
1239 level += branch_bits, offset <<= branch_bits)
1243 for (level -= branch_bits, offset >>= branch_bits; offset != 0;
1244 level -= branch_bits, offset >>= branch_bits)
1247 for (level = 0, offset = 1; offset < num_threads;
1248 level += branch_bits, offset <<= branch_bits)
1251#ifdef KMP_REVERSE_HYPER_BAR
1254 child = num_threads >> ((level == 0) ? level : level - 1);
1255 for (child = (child < branch_factor - 1) ? child : branch_factor - 1,
1256 child_tid = tid + (child << level);
1257 child >= 1; child--, child_tid -= (1 << level))
1259 if (((tid >> level) & (branch_factor - 1)) != 0)
1264 for (child = 1, child_tid = tid + (1 << level);
1265 child < branch_factor && child_tid < num_threads;
1266 child++, child_tid += (1 << level))
1269 if (child_tid >= num_threads)
1272 kmp_info_t *child_thr = other_threads[child_tid];
1273 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1275 kmp_uint32 next_child_tid = child_tid - (1 << level);
1277#ifdef KMP_REVERSE_HYPER_BAR
1278 if (child - 1 >= 1 && next_child_tid < num_threads)
1280 if (child + 1 < branch_factor && next_child_tid < num_threads)
1283 &other_threads[next_child_tid]->th.th_bar[bt].bb.b_go);
1286#if KMP_BARRIER_ICV_PUSH
1288 copy_icvs(&child_bar->th_fixed_icvs, &thr_bar->th_fixed_icvs);
1293 (
"__kmp_hyper_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
1294 "go(%p): %u => %u\n",
1295 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
1296 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,
1297 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1299 kmp_flag_64<> flag(&child_bar->b_go, child_thr);
1304#if KMP_BARRIER_ICV_PUSH
1305 if (propagate_icvs &&
1306 !KMP_MASTER_TID(tid)) {
1307 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team, tid,
1309 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1310 &thr_bar->th_fixed_icvs);
1315 (
"__kmp_hyper_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",
1316 gtid, team->t.t_id, tid, bt));
1329static bool __kmp_init_hierarchical_barrier_thread(
enum barrier_type bt,
1330 kmp_bstate_t *thr_bar,
1331 kmp_uint32 nproc,
int gtid,
1332 int tid, kmp_team_t *team) {
1336#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
1337#define __kmp_msb_byteoffset(offset) (offset)
1339#define __kmp_msb_byteoffset(offset) (7 - (offset))
1343 bool uninitialized = thr_bar->team == NULL;
1344 bool team_changed = team != thr_bar->team;
1345 bool team_sz_changed = nproc != thr_bar->nproc;
1346 bool tid_changed = tid != thr_bar->old_tid;
1347 bool retval =
false;
1349 if (uninitialized || team_sz_changed) {
1350 __kmp_get_hierarchy(nproc, thr_bar);
1353 if (uninitialized || team_sz_changed || tid_changed) {
1354 thr_bar->my_level = thr_bar->depth - 1;
1355 thr_bar->parent_tid = -1;
1356 thr_bar->offset = -1;
1357 if (!KMP_MASTER_TID(tid)) {
1360 while (d < thr_bar->depth) {
1363 if (d == thr_bar->depth - 2) {
1364 thr_bar->parent_tid = 0;
1365 thr_bar->my_level = d;
1367 }
else if ((rem = tid % thr_bar->skip_per_level[d + 1]) != 0) {
1370 thr_bar->parent_tid = tid - rem;
1371 thr_bar->my_level = d;
1377 kmp_uint32 offset = ((kmp_uint32)tid - thr_bar->parent_tid) /
1378 thr_bar->skip_per_level[thr_bar->my_level];
1379 offset = offset - 1;
1380 KMP_ASSERT(offset < 7);
1381 __kmp_type_convert(__kmp_msb_byteoffset(offset), &(thr_bar->offset));
1384 thr_bar->old_tid = tid;
1385 thr_bar->wait_flag = KMP_BARRIER_NOT_WAITING;
1386 thr_bar->team = team;
1387 thr_bar->parent_bar =
1388 &team->t.t_threads[thr_bar->parent_tid]->th.th_bar[bt].bb;
1390 if (uninitialized || team_changed || tid_changed) {
1391 thr_bar->team = team;
1392 thr_bar->parent_bar =
1393 &team->t.t_threads[thr_bar->parent_tid]->th.th_bar[bt].bb;
1396 if (uninitialized || team_sz_changed || tid_changed) {
1397 thr_bar->nproc = nproc;
1398 thr_bar->leaf_kids = thr_bar->base_leaf_kids;
1399 if (thr_bar->my_level == 0)
1400 thr_bar->leaf_kids = 0;
1401 if (thr_bar->leaf_kids && (kmp_uint32)tid + thr_bar->leaf_kids + 1 > nproc)
1402 __kmp_type_convert(nproc - tid - 1, &(thr_bar->leaf_kids));
1403 thr_bar->leaf_state = 0;
1404 for (
int i = 0; i < thr_bar->leaf_kids; ++i)
1405 ((
char *)&(thr_bar->leaf_state))[__kmp_msb_byteoffset(i)] = 1;
1409#undef __kmp_msb_byteoffset
1412static void __kmp_hierarchical_barrier_gather(
1413 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
1414 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
1415 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hier_gather);
1416 kmp_team_t *team = this_thr->th.th_team;
1417 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
1418 kmp_uint32 nproc = this_thr->th.th_team_nproc;
1419 kmp_info_t **other_threads = team->t.t_threads;
1420 kmp_uint64 new_state = 0;
1422 int level = team->t.t_level;
1423 if (other_threads[0]
1424 ->th.th_teams_microtask)
1425 if (this_thr->th.th_teams_size.nteams > 1)
1428 thr_bar->use_oncore_barrier = 1;
1430 thr_bar->use_oncore_barrier = 0;
1432 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) enter for "
1433 "barrier type %d\n",
1434 gtid, team->t.t_id, tid, bt));
1435 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
1437#if USE_ITT_BUILD && USE_ITT_NOTIFY
1439 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
1440 this_thr->th.th_bar_arrive_time = __itt_get_timestamp();
1444 (void)__kmp_init_hierarchical_barrier_thread(bt, thr_bar, nproc, gtid, tid,
1447 if (thr_bar->my_level) {
1448 kmp_int32 child_tid;
1450 (kmp_uint64)team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
1451 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
1452 thr_bar->use_oncore_barrier) {
1453 if (thr_bar->leaf_kids) {
1455 kmp_uint64 leaf_state =
1457 ? thr_bar->b_arrived | thr_bar->leaf_state
1458 : team->t.t_bar[bt].b_arrived | thr_bar->leaf_state;
1459 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) waiting "
1461 gtid, team->t.t_id, tid));
1462 kmp_flag_64<> flag(&thr_bar->b_arrived, leaf_state);
1463 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1465 OMPT_REDUCTION_DECL(this_thr, gtid);
1466 OMPT_REDUCTION_BEGIN;
1467 for (child_tid = tid + 1; child_tid <= tid + thr_bar->leaf_kids;
1469 KA_TRACE(100, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
1471 gtid, team->t.t_id, tid,
1472 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1474 (*reduce)(this_thr->th.th_local.reduce_data,
1475 other_threads[child_tid]->th.th_local.reduce_data);
1480 KMP_TEST_THEN_AND64(&thr_bar->b_arrived, ~(thr_bar->leaf_state));
1483 for (kmp_uint32 d = 1; d < thr_bar->my_level;
1485 kmp_uint32 last = tid + thr_bar->skip_per_level[d + 1],
1486 skip = thr_bar->skip_per_level[d];
1489 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
1490 kmp_info_t *child_thr = other_threads[child_tid];
1491 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1492 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
1494 "arrived(%p) == %llu\n",
1495 gtid, team->t.t_id, tid,
1496 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1497 child_tid, &child_bar->b_arrived, new_state));
1498 kmp_flag_64<> flag(&child_bar->b_arrived, new_state);
1499 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1501 KA_TRACE(100, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
1503 gtid, team->t.t_id, tid,
1504 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1506 (*reduce)(this_thr->th.th_local.reduce_data,
1507 child_thr->th.th_local.reduce_data);
1512 for (kmp_uint32 d = 0; d < thr_bar->my_level;
1514 kmp_uint32 last = tid + thr_bar->skip_per_level[d + 1],
1515 skip = thr_bar->skip_per_level[d];
1518 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
1519 kmp_info_t *child_thr = other_threads[child_tid];
1520 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1521 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
1523 "arrived(%p) == %llu\n",
1524 gtid, team->t.t_id, tid,
1525 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1526 child_tid, &child_bar->b_arrived, new_state));
1527 kmp_flag_64<> flag(&child_bar->b_arrived, new_state);
1528 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1530 KA_TRACE(100, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
1532 gtid, team->t.t_id, tid,
1533 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1535 (*reduce)(this_thr->th.th_local.reduce_data,
1536 child_thr->th.th_local.reduce_data);
1544 if (!KMP_MASTER_TID(tid)) {
1545 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) releasing"
1546 " T#%d(%d:%d) arrived(%p): %llu => %llu\n",
1547 gtid, team->t.t_id, tid,
1548 __kmp_gtid_from_tid(thr_bar->parent_tid, team), team->t.t_id,
1549 thr_bar->parent_tid, &thr_bar->b_arrived, thr_bar->b_arrived,
1550 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
1554 if (thr_bar->my_level || __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME ||
1555 !thr_bar->use_oncore_barrier) {
1557 kmp_flag_64<> flag(&thr_bar->b_arrived,
1558 other_threads[thr_bar->parent_tid]);
1562 thr_bar->b_arrived = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
1563 kmp_flag_oncore flag(&thr_bar->parent_bar->b_arrived, thr_bar->offset);
1564 flag.set_waiter(other_threads[thr_bar->parent_tid]);
1568 team->t.t_bar[bt].b_arrived = new_state;
1569 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) set team %d "
1570 "arrived(%p) = %llu\n",
1571 gtid, team->t.t_id, tid, team->t.t_id,
1572 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived));
1575 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) exit for "
1576 "barrier type %d\n",
1577 gtid, team->t.t_id, tid, bt));
1580static void __kmp_hierarchical_barrier_release(
1581 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
1582 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
1583 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hier_release);
1585 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
1587 bool team_change =
false;
1589 if (KMP_MASTER_TID(tid)) {
1590 team = __kmp_threads[gtid]->th.th_team;
1591 KMP_DEBUG_ASSERT(team != NULL);
1592 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) primary "
1593 "entered barrier type %d\n",
1594 gtid, team->t.t_id, tid, bt));
1597 if (!thr_bar->use_oncore_barrier ||
1598 __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME || thr_bar->my_level != 0 ||
1599 thr_bar->team == NULL) {
1601 thr_bar->wait_flag = KMP_BARRIER_OWN_FLAG;
1602 kmp_flag_64<> flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
1603 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
1604 TCW_8(thr_bar->b_go,
1605 KMP_INIT_BARRIER_STATE);
1609 thr_bar->wait_flag = KMP_BARRIER_PARENT_FLAG;
1610 kmp_flag_oncore flag(&thr_bar->parent_bar->b_go, KMP_BARRIER_STATE_BUMP,
1611 thr_bar->offset, bt,
1612 this_thr USE_ITT_BUILD_ARG(itt_sync_obj));
1613 flag.wait(this_thr, TRUE);
1614 if (thr_bar->wait_flag ==
1615 KMP_BARRIER_SWITCHING) {
1616 TCW_8(thr_bar->b_go,
1617 KMP_INIT_BARRIER_STATE);
1619 (RCAST(
volatile char *,
1620 &(thr_bar->parent_bar->b_go)))[thr_bar->offset] = 0;
1623 thr_bar->wait_flag = KMP_BARRIER_NOT_WAITING;
1625 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
1628 team = __kmp_threads[gtid]->th.th_team;
1629 KMP_DEBUG_ASSERT(team != NULL);
1630 tid = __kmp_tid_from_gtid(gtid);
1634 (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",
1635 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
1639 nproc = this_thr->th.th_team_nproc;
1640 int level = team->t.t_level;
1641 if (team->t.t_threads[0]
1642 ->th.th_teams_microtask) {
1643 if (team->t.t_pkfn != (microtask_t)__kmp_teams_master &&
1644 this_thr->th.th_teams_level == level)
1646 if (this_thr->th.th_teams_size.nteams > 1)
1650 thr_bar->use_oncore_barrier = 1;
1652 thr_bar->use_oncore_barrier = 0;
1656 unsigned short int old_leaf_kids = thr_bar->leaf_kids;
1657 kmp_uint64 old_leaf_state = thr_bar->leaf_state;
1658 team_change = __kmp_init_hierarchical_barrier_thread(bt, thr_bar, nproc, gtid,
1664#if KMP_BARRIER_ICV_PUSH
1665 if (propagate_icvs) {
1666 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team, tid,
1670 copy_icvs(&thr_bar->th_fixed_icvs,
1671 &team->t.t_implicit_task_taskdata[tid].td_icvs);
1672 }
else if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
1673 thr_bar->use_oncore_barrier) {
1674 if (!thr_bar->my_level)
1677 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1678 &thr_bar->parent_bar->th_fixed_icvs);
1681 if (thr_bar->my_level)
1683 copy_icvs(&thr_bar->th_fixed_icvs, &thr_bar->parent_bar->th_fixed_icvs);
1685 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1686 &thr_bar->parent_bar->th_fixed_icvs);
1692 if (thr_bar->my_level) {
1693 kmp_int32 child_tid;
1695 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
1696 thr_bar->use_oncore_barrier) {
1697 if (KMP_MASTER_TID(tid)) {
1700 thr_bar->b_go = KMP_BARRIER_STATE_BUMP;
1703 ngo_load(&thr_bar->th_fixed_icvs);
1706 for (child_tid = thr_bar->skip_per_level[1]; child_tid < (int)nproc;
1707 child_tid += thr_bar->skip_per_level[1]) {
1708 kmp_bstate_t *child_bar =
1709 &team->t.t_threads[child_tid]->th.th_bar[bt].bb;
1710 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
1711 "releasing T#%d(%d:%d)"
1712 " go(%p): %u => %u\n",
1713 gtid, team->t.t_id, tid,
1714 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1715 child_tid, &child_bar->b_go, child_bar->b_go,
1716 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1719 ngo_store_go(&child_bar->th_fixed_icvs, &thr_bar->th_fixed_icvs);
1723 TCW_8(thr_bar->b_go,
1724 KMP_INIT_BARRIER_STATE);
1726 if (thr_bar->leaf_kids) {
1729 old_leaf_kids < thr_bar->leaf_kids) {
1730 if (old_leaf_kids) {
1731 thr_bar->b_go |= old_leaf_state;
1734 last = tid + thr_bar->skip_per_level[1];
1737 for (child_tid = tid + 1 + old_leaf_kids; child_tid < (int)last;
1739 kmp_info_t *child_thr = team->t.t_threads[child_tid];
1740 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1743 (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) releasing"
1744 " T#%d(%d:%d) go(%p): %u => %u\n",
1745 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
1746 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,
1747 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1749 kmp_flag_64<> flag(&child_bar->b_go, child_thr);
1754 thr_bar->b_go |= thr_bar->leaf_state;
1758 for (
int d = thr_bar->my_level - 1; d >= 0;
1760 last = tid + thr_bar->skip_per_level[d + 1];
1761 kmp_uint32 skip = thr_bar->skip_per_level[d];
1764 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
1765 kmp_info_t *child_thr = team->t.t_threads[child_tid];
1766 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1767 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
1768 "releasing T#%d(%d:%d) go(%p): %u => %u\n",
1769 gtid, team->t.t_id, tid,
1770 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1771 child_tid, &child_bar->b_go, child_bar->b_go,
1772 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1774 kmp_flag_64<> flag(&child_bar->b_go, child_thr);
1779#if KMP_BARRIER_ICV_PUSH
1780 if (propagate_icvs && !KMP_MASTER_TID(tid))
1782 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1783 &thr_bar->th_fixed_icvs);
1786 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) exit for "
1787 "barrier type %d\n",
1788 gtid, team->t.t_id, tid, bt));
1796template <
bool cancellable>
struct is_cancellable {};
1797template <>
struct is_cancellable<true> {
1799 is_cancellable() : value(false) {}
1800 is_cancellable(
bool b) : value(b) {}
1801 is_cancellable &operator=(
bool b) {
1805 operator bool()
const {
return value; }
1807template <>
struct is_cancellable<false> {
1808 is_cancellable &operator=(
bool b) {
return *
this; }
1809 constexpr operator bool()
const {
return false; }
1820template <
bool cancellable = false>
1821static int __kmp_barrier_template(
enum barrier_type bt,
int gtid,
int is_split,
1822 size_t reduce_size,
void *reduce_data,
1823 void (*reduce)(
void *,
void *)) {
1824 KMP_TIME_PARTITIONED_BLOCK(OMP_plain_barrier);
1825 KMP_SET_THREAD_STATE_BLOCK(PLAIN_BARRIER);
1826 int tid = __kmp_tid_from_gtid(gtid);
1827 kmp_info_t *this_thr = __kmp_threads[gtid];
1828 kmp_team_t *team = this_thr->th.th_team;
1830 is_cancellable<cancellable> cancelled;
1831#if OMPT_SUPPORT && OMPT_OPTIONAL
1832 ompt_data_t *my_task_data;
1833 ompt_data_t *my_parallel_data;
1834 void *return_address;
1835 ompt_sync_region_t barrier_kind;
1838 KA_TRACE(15, (
"__kmp_barrier: T#%d(%d:%d) has arrived\n", gtid,
1839 __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid(gtid)));
1842 if (ompt_enabled.enabled) {
1844 my_task_data = OMPT_CUR_TASK_DATA(this_thr);
1845 my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
1846 return_address = OMPT_LOAD_RETURN_ADDRESS(gtid);
1847 barrier_kind = __ompt_get_barrier_kind(bt, this_thr);
1848 if (ompt_enabled.ompt_callback_sync_region) {
1849 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
1850 barrier_kind, ompt_scope_begin, my_parallel_data, my_task_data,
1853 if (ompt_enabled.ompt_callback_sync_region_wait) {
1854 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
1855 barrier_kind, ompt_scope_begin, my_parallel_data, my_task_data,
1862 auto *ompt_thr_info = &this_thr->th.ompt_thread_info;
1863 switch (barrier_kind) {
1864 case ompt_sync_region_barrier_explicit:
1865 ompt_thr_info->state = ompt_state_wait_barrier_explicit;
1867 case ompt_sync_region_barrier_implicit_workshare:
1868 ompt_thr_info->state = ompt_state_wait_barrier_implicit_workshare;
1870 case ompt_sync_region_barrier_implicit_parallel:
1871 ompt_thr_info->state = ompt_state_wait_barrier_implicit_parallel;
1873 case ompt_sync_region_barrier_teams:
1874 ompt_thr_info->state = ompt_state_wait_barrier_teams;
1876 case ompt_sync_region_barrier_implementation:
1879 ompt_thr_info->state = ompt_state_wait_barrier_implementation;
1884#if ENABLE_LIBOMPTARGET
1887 if (UNLIKELY(kmp_target_sync_cb != NULL))
1888 (*kmp_target_sync_cb)(
1889 NULL, gtid, KMP_TASKDATA_TO_TASK(this_thr->th.th_current_task), NULL);
1892 if (!team->t.t_serialized) {
1895 void *itt_sync_obj = NULL;
1897 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1898 itt_sync_obj = __kmp_itt_barrier_object(gtid, bt, 1);
1901 if (__kmp_tasking_mode == tskm_extra_barrier) {
1902 __kmp_tasking_barrier(team, this_thr, gtid);
1904 (
"__kmp_barrier: T#%d(%d:%d) past tasking barrier\n", gtid,
1905 __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid(gtid)));
1912 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
1914 this_thr->th.th_team_bt_intervals =
1915 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
1916 this_thr->th.th_team_bt_set =
1917 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
1919 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid);
1924 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1925 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
1929 if (KMP_MASTER_TID(tid)) {
1930 team->t.t_bar[bt].b_master_arrived += 1;
1932 this_thr->th.th_bar[bt].bb.b_worker_arrived += 1;
1935 if (reduce != NULL) {
1937 this_thr->th.th_local.reduce_data = reduce_data;
1940 if (KMP_MASTER_TID(tid) && __kmp_tasking_mode != tskm_immediate_exec)
1941 __kmp_task_team_setup(this_thr, team);
1944 cancelled = __kmp_linear_barrier_gather_cancellable(
1945 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1947 switch (__kmp_barrier_gather_pattern[bt]) {
1949 __kmp_dist_barrier_gather(bt, this_thr, gtid, tid,
1950 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1953 case bp_hyper_bar: {
1954 __kmp_hyper_barrier_gather(bt, this_thr, gtid, tid,
1955 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1958 case bp_hierarchical_bar: {
1959 __kmp_hierarchical_barrier_gather(
1960 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1964 __kmp_tree_barrier_gather(bt, this_thr, gtid, tid,
1965 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1969 __kmp_linear_barrier_gather(bt, this_thr, gtid, tid,
1970 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1977 if (KMP_MASTER_TID(tid)) {
1979 if (__kmp_tasking_mode != tskm_immediate_exec && !cancelled) {
1980 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
1985 team->t.t_bar[bt].b_team_arrived += 1;
1988 if (__kmp_omp_cancellation) {
1989 kmp_int32 cancel_request = KMP_ATOMIC_LD_RLX(&team->t.t_cancel_request);
1991 if (cancel_request == cancel_loop ||
1992 cancel_request == cancel_sections) {
1993 KMP_ATOMIC_ST_RLX(&team->t.t_cancel_request, cancel_noreq);
2001 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2002 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2004#if USE_ITT_BUILD && USE_ITT_NOTIFY
2006 if ((__itt_frame_submit_v3_ptr || KMP_ITT_DEBUG) &&
2007 __kmp_forkjoin_frames_mode &&
2008 (this_thr->th.th_teams_microtask == NULL ||
2009 this_thr->th.th_teams_size.nteams == 1) &&
2010 team->t.t_active_level == 1) {
2011 ident_t *loc = __kmp_threads[gtid]->th.th_ident;
2012 kmp_uint64 cur_time = __itt_get_timestamp();
2013 kmp_info_t **other_threads = team->t.t_threads;
2014 int nproc = this_thr->th.th_team_nproc;
2016 switch (__kmp_forkjoin_frames_mode) {
2018 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
2020 this_thr->th.th_frame_time = cur_time;
2024 __kmp_itt_frame_submit(gtid, this_thr->th.th_bar_min_time, cur_time,
2028 if (__itt_metadata_add_ptr) {
2030 kmp_uint64 delta = cur_time - this_thr->th.th_bar_arrive_time;
2033 this_thr->th.th_bar_arrive_time = 0;
2034 for (i = 1; i < nproc; ++i) {
2035 delta += (cur_time - other_threads[i]->th.th_bar_arrive_time);
2036 other_threads[i]->th.th_bar_arrive_time = 0;
2038 __kmp_itt_metadata_imbalance(gtid, this_thr->th.th_frame_time,
2040 (kmp_uint64)(reduce != NULL));
2042 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
2044 this_thr->th.th_frame_time = cur_time;
2052 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2053 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2056 if ((status == 1 || !is_split) && !cancelled) {
2058 cancelled = __kmp_linear_barrier_release_cancellable(
2059 bt, this_thr, gtid, tid, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2061 switch (__kmp_barrier_release_pattern[bt]) {
2063 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2064 __kmp_dist_barrier_release(bt, this_thr, gtid, tid,
2065 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2068 case bp_hyper_bar: {
2069 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2070 __kmp_hyper_barrier_release(bt, this_thr, gtid, tid,
2071 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2074 case bp_hierarchical_bar: {
2075 __kmp_hierarchical_barrier_release(
2076 bt, this_thr, gtid, tid, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2080 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2081 __kmp_tree_barrier_release(bt, this_thr, gtid, tid,
2082 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2086 __kmp_linear_barrier_release(bt, this_thr, gtid, tid,
2087 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2091 if (__kmp_tasking_mode != tskm_immediate_exec && !cancelled) {
2092 __kmp_task_team_sync(this_thr, team);
2100 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2101 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2105 if (__kmp_tasking_mode != tskm_immediate_exec) {
2106 if (this_thr->th.th_task_team != NULL) {
2108 void *itt_sync_obj = NULL;
2109 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2110 itt_sync_obj = __kmp_itt_barrier_object(gtid, bt, 1);
2111 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
2116 this_thr->th.th_task_team->tt.tt_found_proxy_tasks == TRUE ||
2117 this_thr->th.th_task_team->tt.tt_hidden_helper_task_encountered ==
2119 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
2120 __kmp_task_team_setup(this_thr, team);
2123 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2124 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2129 KA_TRACE(15, (
"__kmp_barrier: T#%d(%d:%d) is leaving with return value %d\n",
2130 gtid, __kmp_team_from_gtid(gtid)->t.t_id,
2131 __kmp_tid_from_gtid(gtid), status));
2134 if (ompt_enabled.enabled) {
2136 if (ompt_enabled.ompt_callback_sync_region_wait) {
2137 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2138 barrier_kind, ompt_scope_end, my_parallel_data, my_task_data,
2141 if (ompt_enabled.ompt_callback_sync_region) {
2142 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2143 barrier_kind, ompt_scope_end, my_parallel_data, my_task_data,
2147 this_thr->th.ompt_thread_info.state = ompt_state_work_parallel;
2152 return (
int)cancelled;
2157int __kmp_barrier(
enum barrier_type bt,
int gtid,
int is_split,
2158 size_t reduce_size,
void *reduce_data,
2159 void (*reduce)(
void *,
void *)) {
2160 return __kmp_barrier_template<>(bt, gtid, is_split, reduce_size, reduce_data,
2164#if defined(KMP_GOMP_COMPAT)
2166int __kmp_barrier_gomp_cancel(
int gtid) {
2167 if (__kmp_omp_cancellation) {
2168 int cancelled = __kmp_barrier_template<true>(bs_plain_barrier, gtid, FALSE,
2171 int tid = __kmp_tid_from_gtid(gtid);
2172 kmp_info_t *this_thr = __kmp_threads[gtid];
2173 if (KMP_MASTER_TID(tid)) {
2177 this_thr->th.th_bar[bs_plain_barrier].bb.b_arrived -=
2178 KMP_BARRIER_STATE_BUMP;
2183 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
2188void __kmp_end_split_barrier(
enum barrier_type bt,
int gtid) {
2189 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_end_split_barrier);
2190 KMP_SET_THREAD_STATE_BLOCK(PLAIN_BARRIER);
2191 KMP_DEBUG_ASSERT(bt < bs_last_barrier);
2192 int tid = __kmp_tid_from_gtid(gtid);
2193 kmp_info_t *this_thr = __kmp_threads[gtid];
2194 kmp_team_t *team = this_thr->th.th_team;
2196 if (!team->t.t_serialized) {
2197 if (KMP_MASTER_GTID(gtid)) {
2198 switch (__kmp_barrier_release_pattern[bt]) {
2200 __kmp_dist_barrier_release(bt, this_thr, gtid, tid,
2201 FALSE USE_ITT_BUILD_ARG(NULL));
2204 case bp_hyper_bar: {
2205 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2206 __kmp_hyper_barrier_release(bt, this_thr, gtid, tid,
2207 FALSE USE_ITT_BUILD_ARG(NULL));
2210 case bp_hierarchical_bar: {
2211 __kmp_hierarchical_barrier_release(bt, this_thr, gtid, tid,
2212 FALSE USE_ITT_BUILD_ARG(NULL));
2216 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2217 __kmp_tree_barrier_release(bt, this_thr, gtid, tid,
2218 FALSE USE_ITT_BUILD_ARG(NULL));
2222 __kmp_linear_barrier_release(bt, this_thr, gtid, tid,
2223 FALSE USE_ITT_BUILD_ARG(NULL));
2226 if (__kmp_tasking_mode != tskm_immediate_exec) {
2227 __kmp_task_team_sync(this_thr, team);
2233void __kmp_join_barrier(
int gtid) {
2234 KMP_TIME_PARTITIONED_BLOCK(OMP_join_barrier);
2235 KMP_SET_THREAD_STATE_BLOCK(FORK_JOIN_BARRIER);
2237 KMP_DEBUG_ASSERT(__kmp_threads && __kmp_threads[gtid]);
2239 kmp_info_t *this_thr = __kmp_threads[gtid];
2246 void *itt_sync_obj = NULL;
2248 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2250 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
2253#if ((USE_ITT_BUILD && USE_ITT_NOTIFY) || defined KMP_DEBUG)
2254 int nproc = this_thr->th.th_team_nproc;
2259 team = this_thr->th.th_team;
2260 KMP_DEBUG_ASSERT(nproc == team->t.t_nproc);
2261 tid = __kmp_tid_from_gtid(gtid);
2263 team_id = team->t.t_id;
2264 kmp_info_t *master_thread = this_thr->th.th_team_master;
2265 if (master_thread != team->t.t_threads[0]) {
2266 __kmp_print_structure();
2269 KMP_DEBUG_ASSERT(master_thread == team->t.t_threads[0]);
2273 KMP_DEBUG_ASSERT(TCR_PTR(this_thr->th.th_team));
2274 KMP_DEBUG_ASSERT(TCR_PTR(this_thr->th.th_root));
2275 KMP_DEBUG_ASSERT(this_thr == team->t.t_threads[tid]);
2276 KA_TRACE(10, (
"__kmp_join_barrier: T#%d(%d:%d) arrived at join barrier\n",
2277 gtid, team_id, tid));
2280 if (ompt_enabled.enabled) {
2282 ompt_data_t *my_task_data;
2283 ompt_data_t *my_parallel_data;
2284 void *codeptr = NULL;
2285 int ds_tid = this_thr->th.th_info.ds.ds_tid;
2286 if (KMP_MASTER_TID(ds_tid) &&
2287 (ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait) ||
2288 ompt_callbacks.ompt_callback(ompt_callback_sync_region)))
2289 codeptr = team->t.ompt_team_info.master_return_address;
2290 my_task_data = OMPT_CUR_TASK_DATA(this_thr);
2291 my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
2292 ompt_sync_region_t sync_kind = ompt_sync_region_barrier_implicit_parallel;
2293 ompt_state_t ompt_state = ompt_state_wait_barrier_implicit_parallel;
2294 if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league) {
2295 sync_kind = ompt_sync_region_barrier_teams;
2296 ompt_state = ompt_state_wait_barrier_teams;
2298 if (ompt_enabled.ompt_callback_sync_region) {
2299 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2300 sync_kind, ompt_scope_begin, my_parallel_data, my_task_data, codeptr);
2302 if (ompt_enabled.ompt_callback_sync_region_wait) {
2303 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2304 sync_kind, ompt_scope_begin, my_parallel_data, my_task_data, codeptr);
2306 if (!KMP_MASTER_TID(ds_tid))
2307 this_thr->th.ompt_thread_info.task_data = *OMPT_CUR_TASK_DATA(this_thr);
2309 this_thr->th.ompt_thread_info.state = ompt_state;
2313 if (__kmp_tasking_mode == tskm_extra_barrier) {
2314 __kmp_tasking_barrier(team, this_thr, gtid);
2315 KA_TRACE(10, (
"__kmp_join_barrier: T#%d(%d:%d) past tasking barrier\n",
2316 gtid, team_id, tid));
2319 if (__kmp_tasking_mode != tskm_immediate_exec) {
2320 KA_TRACE(20, (
"__kmp_join_barrier: T#%d, old team = %d, old task_team = "
2321 "%p, th_task_team = %p\n",
2322 __kmp_gtid_from_thread(this_thr), team_id,
2323 team->t.t_task_team[this_thr->th.th_task_state],
2324 this_thr->th.th_task_team));
2325 KMP_DEBUG_ASSERT_TASKTEAM_INVARIANT(team, this_thr);
2334 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
2336 this_thr->th.th_team_bt_intervals =
2337 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
2338 this_thr->th.th_team_bt_set =
2339 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
2341 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid);
2346 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2347 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
2350 switch (__kmp_barrier_gather_pattern[bs_forkjoin_barrier]) {
2352 __kmp_dist_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2353 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2356 case bp_hyper_bar: {
2357 __kmp_hyper_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2358 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2361 case bp_hierarchical_bar: {
2362 __kmp_hierarchical_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2363 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2367 __kmp_tree_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2368 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2372 __kmp_linear_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2373 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2381 if (KMP_MASTER_TID(tid)) {
2382 if (__kmp_tasking_mode != tskm_immediate_exec) {
2383 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
2385 if (__kmp_display_affinity) {
2386 KMP_CHECK_UPDATE(team->t.t_display_affinity, 0);
2388#if KMP_STATS_ENABLED
2392 for (
int i = 0; i < team->t.t_nproc; ++i) {
2393 kmp_info_t *team_thread = team->t.t_threads[i];
2394 if (team_thread == this_thr)
2396 team_thread->th.th_stats->setIdleFlag();
2397 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME &&
2398 team_thread->th.th_sleep_loc != NULL)
2399 __kmp_null_resume_wrapper(team_thread);
2403 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2404 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2407#if USE_ITT_BUILD && USE_ITT_NOTIFY
2409 if ((__itt_frame_submit_v3_ptr || KMP_ITT_DEBUG) &&
2410 __kmp_forkjoin_frames_mode &&
2411 (this_thr->th.th_teams_microtask == NULL ||
2412 this_thr->th.th_teams_size.nteams == 1) &&
2413 team->t.t_active_level == 1) {
2414 kmp_uint64 cur_time = __itt_get_timestamp();
2415 ident_t *loc = team->t.t_ident;
2416 kmp_info_t **other_threads = team->t.t_threads;
2417 switch (__kmp_forkjoin_frames_mode) {
2419 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
2423 __kmp_itt_frame_submit(gtid, this_thr->th.th_bar_min_time, cur_time, 1,
2427 if (__itt_metadata_add_ptr) {
2429 kmp_uint64 delta = cur_time - this_thr->th.th_bar_arrive_time;
2432 this_thr->th.th_bar_arrive_time = 0;
2433 for (
int i = 1; i < nproc; ++i) {
2434 delta += (cur_time - other_threads[i]->th.th_bar_arrive_time);
2435 other_threads[i]->th.th_bar_arrive_time = 0;
2437 __kmp_itt_metadata_imbalance(gtid, this_thr->th.th_frame_time,
2438 cur_time, delta, 0);
2440 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
2442 this_thr->th.th_frame_time = cur_time;
2450 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2451 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2456 if (KMP_MASTER_TID(tid)) {
2459 (
"__kmp_join_barrier: T#%d(%d:%d) says all %d team threads arrived\n",
2460 gtid, team_id, tid, nproc));
2467 (
"__kmp_join_barrier: T#%d(%d:%d) leaving\n", gtid, team_id, tid));
2473void __kmp_fork_barrier(
int gtid,
int tid) {
2474 KMP_TIME_PARTITIONED_BLOCK(OMP_fork_barrier);
2475 KMP_SET_THREAD_STATE_BLOCK(FORK_JOIN_BARRIER);
2476 kmp_info_t *this_thr = __kmp_threads[gtid];
2477 kmp_team_t *team = (tid == 0) ? this_thr->th.th_team : NULL;
2479 void *itt_sync_obj = NULL;
2483 KA_TRACE(10, (
"__kmp_fork_barrier: T#%d(%d:%d) has arrived\n", gtid,
2484 (team != NULL) ? team->t.t_id : -1, tid));
2487 if (KMP_MASTER_TID(tid)) {
2488#if USE_ITT_BUILD && USE_ITT_NOTIFY
2489 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2491 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 1);
2492 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2497 KMP_DEBUG_ASSERT(team);
2498 kmp_info_t **other_threads = team->t.t_threads;
2504 for (i = 1; i < team->t.t_nproc; ++i) {
2506 (
"__kmp_fork_barrier: T#%d(%d:0) checking T#%d(%d:%d) fork go "
2508 gtid, team->t.t_id, other_threads[i]->th.th_info.ds.ds_gtid,
2509 team->t.t_id, other_threads[i]->th.th_info.ds.ds_tid,
2510 other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go));
2512 (TCR_4(other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go) &
2513 ~(KMP_BARRIER_SLEEP_STATE)) == KMP_INIT_BARRIER_STATE);
2514 KMP_DEBUG_ASSERT(other_threads[i]->th.th_team == team);
2518 if (__kmp_tasking_mode != tskm_immediate_exec)
2519 __kmp_task_team_setup(this_thr, team);
2527 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
2529 this_thr->th.th_team_bt_intervals =
2530 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
2531 this_thr->th.th_team_bt_set =
2532 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
2534 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid);
2539 switch (__kmp_barrier_release_pattern[bs_forkjoin_barrier]) {
2541 __kmp_dist_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2542 TRUE USE_ITT_BUILD_ARG(NULL));
2545 case bp_hyper_bar: {
2546 KMP_ASSERT(__kmp_barrier_release_branch_bits[bs_forkjoin_barrier]);
2547 __kmp_hyper_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2548 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
2551 case bp_hierarchical_bar: {
2552 __kmp_hierarchical_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2553 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
2557 KMP_ASSERT(__kmp_barrier_release_branch_bits[bs_forkjoin_barrier]);
2558 __kmp_tree_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2559 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
2563 __kmp_linear_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2564 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
2569 ompt_state_t ompt_state = this_thr->th.ompt_thread_info.state;
2570 if (ompt_enabled.enabled &&
2571 (ompt_state == ompt_state_wait_barrier_teams ||
2572 ompt_state == ompt_state_wait_barrier_implicit_parallel)) {
2573 int ds_tid = this_thr->th.th_info.ds.ds_tid;
2574 ompt_data_t *task_data = (team)
2575 ? OMPT_CUR_TASK_DATA(this_thr)
2576 : &(this_thr->th.ompt_thread_info.task_data);
2577 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
2579 void *codeptr = NULL;
2580 if (KMP_MASTER_TID(ds_tid) &&
2581 (ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait) ||
2582 ompt_callbacks.ompt_callback(ompt_callback_sync_region)))
2583 codeptr = team ? team->t.ompt_team_info.master_return_address : NULL;
2584 ompt_sync_region_t sync_kind = ompt_sync_region_barrier_implicit_parallel;
2585 if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league)
2586 sync_kind = ompt_sync_region_barrier_teams;
2587 if (ompt_enabled.ompt_callback_sync_region_wait) {
2588 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2589 sync_kind, ompt_scope_end, NULL, task_data, codeptr);
2591 if (ompt_enabled.ompt_callback_sync_region) {
2592 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2593 sync_kind, ompt_scope_end, NULL, task_data, codeptr);
2596 if (!KMP_MASTER_TID(ds_tid) && ompt_enabled.ompt_callback_implicit_task) {
2597 ompt_callbacks.ompt_callback(ompt_callback_implicit_task)(
2598 ompt_scope_end, NULL, task_data, 0, ds_tid,
2599 ompt_task_implicit);
2605 if (TCR_4(__kmp_global.g.g_done)) {
2606 this_thr->th.th_task_team = NULL;
2608#if USE_ITT_BUILD && USE_ITT_NOTIFY
2609 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2610 if (!KMP_MASTER_TID(tid)) {
2611 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
2613 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2617 KA_TRACE(10, (
"__kmp_fork_barrier: T#%d is leaving early\n", gtid));
2625 team = (kmp_team_t *)TCR_PTR(this_thr->th.th_team);
2626 KMP_DEBUG_ASSERT(team != NULL);
2627 tid = __kmp_tid_from_gtid(gtid);
2629#if KMP_BARRIER_ICV_PULL
2637 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy);
2638 if (!KMP_MASTER_TID(tid)) {
2642 (
"__kmp_fork_barrier: T#%d(%d) is PULLing ICVs\n", gtid, tid));
2643 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team,
2645 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
2646 &team->t.t_threads[0]
2647 ->th.th_bar[bs_forkjoin_barrier]
2653 if (__kmp_tasking_mode != tskm_immediate_exec) {
2654 __kmp_task_team_sync(this_thr, team);
2657#if KMP_AFFINITY_SUPPORTED
2658 kmp_proc_bind_t proc_bind = team->t.t_proc_bind;
2659 if (proc_bind == proc_bind_intel) {
2661 if (__kmp_affinity.type == affinity_balanced && team->t.t_size_changed) {
2662 __kmp_balanced_affinity(this_thr, team->t.t_nproc);
2664 }
else if (proc_bind != proc_bind_false) {
2665 if (this_thr->th.th_new_place == this_thr->th.th_current_place) {
2666 KA_TRACE(100, (
"__kmp_fork_barrier: T#%d already in correct place %d\n",
2667 __kmp_gtid_from_thread(this_thr),
2668 this_thr->th.th_current_place));
2670 __kmp_affinity_bind_place(gtid);
2675 if (__kmp_display_affinity) {
2676 if (team->t.t_display_affinity
2677#
if KMP_AFFINITY_SUPPORTED
2678 || (__kmp_affinity.type == affinity_balanced && team->t.t_size_changed)
2682 __kmp_aux_display_affinity(gtid, NULL);
2683 this_thr->th.th_prev_num_threads = team->t.t_nproc;
2684 this_thr->th.th_prev_level = team->t.t_level;
2687 if (!KMP_MASTER_TID(tid))
2688 KMP_CHECK_UPDATE(this_thr->th.th_def_allocator, team->t.t_def_allocator);
2690#if USE_ITT_BUILD && USE_ITT_NOTIFY
2691 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2692 if (!KMP_MASTER_TID(tid)) {
2694 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
2695 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2699 KA_TRACE(10, (
"__kmp_fork_barrier: T#%d(%d:%d) is leaving\n", gtid,
2700 team->t.t_id, tid));
2703void __kmp_setup_icv_copy(kmp_team_t *team,
int new_nproc,
2704 kmp_internal_control_t *new_icvs,
ident_t *loc) {
2705 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_setup_icv_copy);
2707 KMP_DEBUG_ASSERT(team && new_nproc && new_icvs);
2708 KMP_DEBUG_ASSERT((!TCR_4(__kmp_init_parallel)) || new_icvs->nproc);
2713#if KMP_BARRIER_ICV_PULL
2717 KMP_DEBUG_ASSERT(team->t.t_threads[0]);
2720 &team->t.t_threads[0]->th.th_bar[bs_forkjoin_barrier].bb.th_fixed_icvs,
2722 KF_TRACE(10, (
"__kmp_setup_icv_copy: PULL: T#%d this_thread=%p team=%p\n", 0,
2723 team->t.t_threads[0], team));
2724#elif KMP_BARRIER_ICV_PUSH
2727 KF_TRACE(10, (
"__kmp_setup_icv_copy: PUSH: T#%d this_thread=%p team=%p\n", 0,
2728 team->t.t_threads[0], team));
2733 KMP_DEBUG_ASSERT(team->t.t_threads[0]);
2735 for (
int f = 1; f < new_nproc; ++f) {
2737 KF_TRACE(10, (
"__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n",
2738 f, team->t.t_threads[f], team));
2739 __kmp_init_implicit_task(loc, team->t.t_threads[f], team, f, FALSE);
2740 ngo_store_icvs(&team->t.t_implicit_task_taskdata[f].td_icvs, new_icvs);
2741 KF_TRACE(10, (
"__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n",
2742 f, team->t.t_threads[f], team));