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) {
1334 bool uninitialized = thr_bar->team == NULL;
1335 bool team_changed = team != thr_bar->team;
1336 bool team_sz_changed = nproc != thr_bar->nproc;
1337 bool tid_changed = tid != thr_bar->old_tid;
1338 bool retval =
false;
1340 if (uninitialized || team_sz_changed) {
1341 __kmp_get_hierarchy(nproc, thr_bar);
1344 if (uninitialized || team_sz_changed || tid_changed) {
1345 thr_bar->my_level = thr_bar->depth - 1;
1346 thr_bar->parent_tid = -1;
1347 if (!KMP_MASTER_TID(tid)) {
1350 while (d < thr_bar->depth) {
1353 if (d == thr_bar->depth - 2) {
1354 thr_bar->parent_tid = 0;
1355 thr_bar->my_level = d;
1357 }
else if ((rem = tid % thr_bar->skip_per_level[d + 1]) != 0) {
1360 thr_bar->parent_tid = tid - rem;
1361 thr_bar->my_level = d;
1367 __kmp_type_convert(7 - ((tid - thr_bar->parent_tid) /
1368 (thr_bar->skip_per_level[thr_bar->my_level])),
1369 &(thr_bar->offset));
1370 thr_bar->old_tid = tid;
1371 thr_bar->wait_flag = KMP_BARRIER_NOT_WAITING;
1372 thr_bar->team = team;
1373 thr_bar->parent_bar =
1374 &team->t.t_threads[thr_bar->parent_tid]->th.th_bar[bt].bb;
1376 if (uninitialized || team_changed || tid_changed) {
1377 thr_bar->team = team;
1378 thr_bar->parent_bar =
1379 &team->t.t_threads[thr_bar->parent_tid]->th.th_bar[bt].bb;
1382 if (uninitialized || team_sz_changed || tid_changed) {
1383 thr_bar->nproc = nproc;
1384 thr_bar->leaf_kids = thr_bar->base_leaf_kids;
1385 if (thr_bar->my_level == 0)
1386 thr_bar->leaf_kids = 0;
1387 if (thr_bar->leaf_kids && (kmp_uint32)tid + thr_bar->leaf_kids + 1 > nproc)
1388 __kmp_type_convert(nproc - tid - 1, &(thr_bar->leaf_kids));
1389 thr_bar->leaf_state = 0;
1390 for (
int i = 0; i < thr_bar->leaf_kids; ++i)
1391 ((
char *)&(thr_bar->leaf_state))[7 - i] = 1;
1396static void __kmp_hierarchical_barrier_gather(
1397 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
1398 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
1399 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hier_gather);
1400 kmp_team_t *team = this_thr->th.th_team;
1401 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
1402 kmp_uint32 nproc = this_thr->th.th_team_nproc;
1403 kmp_info_t **other_threads = team->t.t_threads;
1404 kmp_uint64 new_state = 0;
1406 int level = team->t.t_level;
1407 if (other_threads[0]
1408 ->th.th_teams_microtask)
1409 if (this_thr->th.th_teams_size.nteams > 1)
1412 thr_bar->use_oncore_barrier = 1;
1414 thr_bar->use_oncore_barrier = 0;
1416 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) enter for "
1417 "barrier type %d\n",
1418 gtid, team->t.t_id, tid, bt));
1419 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
1421#if USE_ITT_BUILD && USE_ITT_NOTIFY
1423 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
1424 this_thr->th.th_bar_arrive_time = __itt_get_timestamp();
1428 (void)__kmp_init_hierarchical_barrier_thread(bt, thr_bar, nproc, gtid, tid,
1431 if (thr_bar->my_level) {
1432 kmp_int32 child_tid;
1434 (kmp_uint64)team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
1435 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
1436 thr_bar->use_oncore_barrier) {
1437 if (thr_bar->leaf_kids) {
1439 kmp_uint64 leaf_state =
1441 ? thr_bar->b_arrived | thr_bar->leaf_state
1442 : team->t.t_bar[bt].b_arrived | thr_bar->leaf_state;
1443 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) waiting "
1445 gtid, team->t.t_id, tid));
1446 kmp_flag_64<> flag(&thr_bar->b_arrived, leaf_state);
1447 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1449 OMPT_REDUCTION_DECL(this_thr, gtid);
1450 OMPT_REDUCTION_BEGIN;
1451 for (child_tid = tid + 1; child_tid <= tid + thr_bar->leaf_kids;
1453 KA_TRACE(100, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
1455 gtid, team->t.t_id, tid,
1456 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1458 (*reduce)(this_thr->th.th_local.reduce_data,
1459 other_threads[child_tid]->th.th_local.reduce_data);
1464 KMP_TEST_THEN_AND64(&thr_bar->b_arrived, ~(thr_bar->leaf_state));
1467 for (kmp_uint32 d = 1; d < thr_bar->my_level;
1469 kmp_uint32 last = tid + thr_bar->skip_per_level[d + 1],
1470 skip = thr_bar->skip_per_level[d];
1473 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
1474 kmp_info_t *child_thr = other_threads[child_tid];
1475 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1476 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
1478 "arrived(%p) == %llu\n",
1479 gtid, team->t.t_id, tid,
1480 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1481 child_tid, &child_bar->b_arrived, new_state));
1482 kmp_flag_64<> flag(&child_bar->b_arrived, new_state);
1483 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1485 KA_TRACE(100, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
1487 gtid, team->t.t_id, tid,
1488 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1490 (*reduce)(this_thr->th.th_local.reduce_data,
1491 child_thr->th.th_local.reduce_data);
1496 for (kmp_uint32 d = 0; d < thr_bar->my_level;
1498 kmp_uint32 last = tid + thr_bar->skip_per_level[d + 1],
1499 skip = thr_bar->skip_per_level[d];
1502 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
1503 kmp_info_t *child_thr = other_threads[child_tid];
1504 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1505 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
1507 "arrived(%p) == %llu\n",
1508 gtid, team->t.t_id, tid,
1509 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1510 child_tid, &child_bar->b_arrived, new_state));
1511 kmp_flag_64<> flag(&child_bar->b_arrived, new_state);
1512 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1514 KA_TRACE(100, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
1516 gtid, team->t.t_id, tid,
1517 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1519 (*reduce)(this_thr->th.th_local.reduce_data,
1520 child_thr->th.th_local.reduce_data);
1528 if (!KMP_MASTER_TID(tid)) {
1529 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) releasing"
1530 " T#%d(%d:%d) arrived(%p): %llu => %llu\n",
1531 gtid, team->t.t_id, tid,
1532 __kmp_gtid_from_tid(thr_bar->parent_tid, team), team->t.t_id,
1533 thr_bar->parent_tid, &thr_bar->b_arrived, thr_bar->b_arrived,
1534 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
1538 if (thr_bar->my_level || __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME ||
1539 !thr_bar->use_oncore_barrier) {
1541 kmp_flag_64<> flag(&thr_bar->b_arrived,
1542 other_threads[thr_bar->parent_tid]);
1546 thr_bar->b_arrived = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
1547 kmp_flag_oncore flag(&thr_bar->parent_bar->b_arrived,
1548 thr_bar->offset + 1);
1549 flag.set_waiter(other_threads[thr_bar->parent_tid]);
1553 team->t.t_bar[bt].b_arrived = new_state;
1554 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) set team %d "
1555 "arrived(%p) = %llu\n",
1556 gtid, team->t.t_id, tid, team->t.t_id,
1557 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived));
1560 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) exit for "
1561 "barrier type %d\n",
1562 gtid, team->t.t_id, tid, bt));
1565static void __kmp_hierarchical_barrier_release(
1566 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
1567 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
1568 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hier_release);
1570 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
1572 bool team_change =
false;
1574 if (KMP_MASTER_TID(tid)) {
1575 team = __kmp_threads[gtid]->th.th_team;
1576 KMP_DEBUG_ASSERT(team != NULL);
1577 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) primary "
1578 "entered barrier type %d\n",
1579 gtid, team->t.t_id, tid, bt));
1582 if (!thr_bar->use_oncore_barrier ||
1583 __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME || thr_bar->my_level != 0 ||
1584 thr_bar->team == NULL) {
1586 thr_bar->wait_flag = KMP_BARRIER_OWN_FLAG;
1587 kmp_flag_64<> flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
1588 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
1589 TCW_8(thr_bar->b_go,
1590 KMP_INIT_BARRIER_STATE);
1594 thr_bar->wait_flag = KMP_BARRIER_PARENT_FLAG;
1595 kmp_flag_oncore flag(&thr_bar->parent_bar->b_go, KMP_BARRIER_STATE_BUMP,
1596 thr_bar->offset + 1, bt,
1597 this_thr USE_ITT_BUILD_ARG(itt_sync_obj));
1598 flag.wait(this_thr, TRUE);
1599 if (thr_bar->wait_flag ==
1600 KMP_BARRIER_SWITCHING) {
1601 TCW_8(thr_bar->b_go,
1602 KMP_INIT_BARRIER_STATE);
1604 (RCAST(
volatile char *,
1605 &(thr_bar->parent_bar->b_go)))[thr_bar->offset + 1] = 0;
1608 thr_bar->wait_flag = KMP_BARRIER_NOT_WAITING;
1610 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
1613 team = __kmp_threads[gtid]->th.th_team;
1614 KMP_DEBUG_ASSERT(team != NULL);
1615 tid = __kmp_tid_from_gtid(gtid);
1619 (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",
1620 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
1624 nproc = this_thr->th.th_team_nproc;
1625 int level = team->t.t_level;
1626 if (team->t.t_threads[0]
1627 ->th.th_teams_microtask) {
1628 if (team->t.t_pkfn != (microtask_t)__kmp_teams_master &&
1629 this_thr->th.th_teams_level == level)
1631 if (this_thr->th.th_teams_size.nteams > 1)
1635 thr_bar->use_oncore_barrier = 1;
1637 thr_bar->use_oncore_barrier = 0;
1641 unsigned short int old_leaf_kids = thr_bar->leaf_kids;
1642 kmp_uint64 old_leaf_state = thr_bar->leaf_state;
1643 team_change = __kmp_init_hierarchical_barrier_thread(bt, thr_bar, nproc, gtid,
1649#if KMP_BARRIER_ICV_PUSH
1650 if (propagate_icvs) {
1651 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team, tid,
1655 copy_icvs(&thr_bar->th_fixed_icvs,
1656 &team->t.t_implicit_task_taskdata[tid].td_icvs);
1657 }
else if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
1658 thr_bar->use_oncore_barrier) {
1659 if (!thr_bar->my_level)
1662 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1663 &thr_bar->parent_bar->th_fixed_icvs);
1666 if (thr_bar->my_level)
1668 copy_icvs(&thr_bar->th_fixed_icvs, &thr_bar->parent_bar->th_fixed_icvs);
1670 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1671 &thr_bar->parent_bar->th_fixed_icvs);
1677 if (thr_bar->my_level) {
1678 kmp_int32 child_tid;
1680 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
1681 thr_bar->use_oncore_barrier) {
1682 if (KMP_MASTER_TID(tid)) {
1685 thr_bar->b_go = KMP_BARRIER_STATE_BUMP;
1688 ngo_load(&thr_bar->th_fixed_icvs);
1691 for (child_tid = thr_bar->skip_per_level[1]; child_tid < (
int)nproc;
1692 child_tid += thr_bar->skip_per_level[1]) {
1693 kmp_bstate_t *child_bar =
1694 &team->t.t_threads[child_tid]->th.th_bar[bt].bb;
1695 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
1696 "releasing T#%d(%d:%d)"
1697 " go(%p): %u => %u\n",
1698 gtid, team->t.t_id, tid,
1699 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1700 child_tid, &child_bar->b_go, child_bar->b_go,
1701 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1704 ngo_store_go(&child_bar->th_fixed_icvs, &thr_bar->th_fixed_icvs);
1708 TCW_8(thr_bar->b_go,
1709 KMP_INIT_BARRIER_STATE);
1711 if (thr_bar->leaf_kids) {
1714 old_leaf_kids < thr_bar->leaf_kids) {
1715 if (old_leaf_kids) {
1716 thr_bar->b_go |= old_leaf_state;
1719 last = tid + thr_bar->skip_per_level[1];
1722 for (child_tid = tid + 1 + old_leaf_kids; child_tid < (int)last;
1724 kmp_info_t *child_thr = team->t.t_threads[child_tid];
1725 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1728 (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) releasing"
1729 " T#%d(%d:%d) go(%p): %u => %u\n",
1730 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
1731 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,
1732 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1734 kmp_flag_64<> flag(&child_bar->b_go, child_thr);
1739 thr_bar->b_go |= thr_bar->leaf_state;
1743 for (
int d = thr_bar->my_level - 1; d >= 0;
1745 last = tid + thr_bar->skip_per_level[d + 1];
1746 kmp_uint32 skip = thr_bar->skip_per_level[d];
1749 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
1750 kmp_info_t *child_thr = team->t.t_threads[child_tid];
1751 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1752 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
1753 "releasing T#%d(%d:%d) go(%p): %u => %u\n",
1754 gtid, team->t.t_id, tid,
1755 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1756 child_tid, &child_bar->b_go, child_bar->b_go,
1757 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1759 kmp_flag_64<> flag(&child_bar->b_go, child_thr);
1764#if KMP_BARRIER_ICV_PUSH
1765 if (propagate_icvs && !KMP_MASTER_TID(tid))
1767 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1768 &thr_bar->th_fixed_icvs);
1771 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) exit for "
1772 "barrier type %d\n",
1773 gtid, team->t.t_id, tid, bt));
1781template <
bool cancellable>
struct is_cancellable {};
1782template <>
struct is_cancellable<true> {
1784 is_cancellable() : value(false) {}
1785 is_cancellable(
bool b) : value(b) {}
1786 is_cancellable &operator=(
bool b) {
1790 operator bool()
const {
return value; }
1792template <>
struct is_cancellable<false> {
1793 is_cancellable &operator=(
bool b) {
return *
this; }
1794 constexpr operator bool()
const {
return false; }
1805template <
bool cancellable = false>
1806static int __kmp_barrier_template(
enum barrier_type bt,
int gtid,
int is_split,
1807 size_t reduce_size,
void *reduce_data,
1808 void (*reduce)(
void *,
void *)) {
1809 KMP_TIME_PARTITIONED_BLOCK(OMP_plain_barrier);
1810 KMP_SET_THREAD_STATE_BLOCK(PLAIN_BARRIER);
1811 int tid = __kmp_tid_from_gtid(gtid);
1812 kmp_info_t *this_thr = __kmp_threads[gtid];
1813 kmp_team_t *team = this_thr->th.th_team;
1815 is_cancellable<cancellable> cancelled;
1816#if OMPT_SUPPORT && OMPT_OPTIONAL
1817 ompt_data_t *my_task_data;
1818 ompt_data_t *my_parallel_data;
1819 void *return_address;
1820 ompt_sync_region_t barrier_kind;
1823 KA_TRACE(15, (
"__kmp_barrier: T#%d(%d:%d) has arrived\n", gtid,
1824 __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid(gtid)));
1827 if (ompt_enabled.enabled) {
1829 my_task_data = OMPT_CUR_TASK_DATA(this_thr);
1830 my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
1831 return_address = OMPT_LOAD_RETURN_ADDRESS(gtid);
1832 barrier_kind = __ompt_get_barrier_kind(bt, this_thr);
1833 if (ompt_enabled.ompt_callback_sync_region) {
1834 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
1835 barrier_kind, ompt_scope_begin, my_parallel_data, my_task_data,
1838 if (ompt_enabled.ompt_callback_sync_region_wait) {
1839 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
1840 barrier_kind, ompt_scope_begin, my_parallel_data, my_task_data,
1847 auto *ompt_thr_info = &this_thr->th.ompt_thread_info;
1848 switch (barrier_kind) {
1849 case ompt_sync_region_barrier_explicit:
1850 ompt_thr_info->state = ompt_state_wait_barrier_explicit;
1852 case ompt_sync_region_barrier_implicit_workshare:
1853 ompt_thr_info->state = ompt_state_wait_barrier_implicit_workshare;
1855 case ompt_sync_region_barrier_implicit_parallel:
1856 ompt_thr_info->state = ompt_state_wait_barrier_implicit_parallel;
1858 case ompt_sync_region_barrier_teams:
1859 ompt_thr_info->state = ompt_state_wait_barrier_teams;
1861 case ompt_sync_region_barrier_implementation:
1864 ompt_thr_info->state = ompt_state_wait_barrier_implementation;
1869#if ENABLE_LIBOMPTARGET
1872 if (UNLIKELY(kmp_target_sync_cb != NULL))
1873 (*kmp_target_sync_cb)(
1874 NULL, gtid, KMP_TASKDATA_TO_TASK(this_thr->th.th_current_task), NULL);
1877 if (!team->t.t_serialized) {
1880 void *itt_sync_obj = NULL;
1882 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1883 itt_sync_obj = __kmp_itt_barrier_object(gtid, bt, 1);
1886 if (__kmp_tasking_mode == tskm_extra_barrier) {
1887 __kmp_tasking_barrier(team, this_thr, gtid);
1889 (
"__kmp_barrier: T#%d(%d:%d) past tasking barrier\n", gtid,
1890 __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid(gtid)));
1897 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
1899 this_thr->th.th_team_bt_intervals =
1900 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
1901 this_thr->th.th_team_bt_set =
1902 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
1904 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid);
1909 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1910 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
1914 if (KMP_MASTER_TID(tid)) {
1915 team->t.t_bar[bt].b_master_arrived += 1;
1917 this_thr->th.th_bar[bt].bb.b_worker_arrived += 1;
1920 if (reduce != NULL) {
1922 this_thr->th.th_local.reduce_data = reduce_data;
1925 if (KMP_MASTER_TID(tid) && __kmp_tasking_mode != tskm_immediate_exec)
1926 __kmp_task_team_setup(this_thr, team);
1929 cancelled = __kmp_linear_barrier_gather_cancellable(
1930 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1932 switch (__kmp_barrier_gather_pattern[bt]) {
1934 __kmp_dist_barrier_gather(bt, this_thr, gtid, tid,
1935 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1938 case bp_hyper_bar: {
1939 __kmp_hyper_barrier_gather(bt, this_thr, gtid, tid,
1940 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1943 case bp_hierarchical_bar: {
1944 __kmp_hierarchical_barrier_gather(
1945 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1949 __kmp_tree_barrier_gather(bt, this_thr, gtid, tid,
1950 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1954 __kmp_linear_barrier_gather(bt, this_thr, gtid, tid,
1955 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1962 if (KMP_MASTER_TID(tid)) {
1964 if (__kmp_tasking_mode != tskm_immediate_exec && !cancelled) {
1965 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
1970 team->t.t_bar[bt].b_team_arrived += 1;
1973 if (__kmp_omp_cancellation) {
1974 kmp_int32 cancel_request = KMP_ATOMIC_LD_RLX(&team->t.t_cancel_request);
1976 if (cancel_request == cancel_loop ||
1977 cancel_request == cancel_sections) {
1978 KMP_ATOMIC_ST_RLX(&team->t.t_cancel_request, cancel_noreq);
1986 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1987 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
1989#if USE_ITT_BUILD && USE_ITT_NOTIFY
1991 if ((__itt_frame_submit_v3_ptr || KMP_ITT_DEBUG) &&
1992 __kmp_forkjoin_frames_mode &&
1993 (this_thr->th.th_teams_microtask == NULL ||
1994 this_thr->th.th_teams_size.nteams == 1) &&
1995 team->t.t_active_level == 1) {
1996 ident_t *loc = __kmp_threads[gtid]->th.th_ident;
1997 kmp_uint64 cur_time = __itt_get_timestamp();
1998 kmp_info_t **other_threads = team->t.t_threads;
1999 int nproc = this_thr->th.th_team_nproc;
2001 switch (__kmp_forkjoin_frames_mode) {
2003 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
2005 this_thr->th.th_frame_time = cur_time;
2009 __kmp_itt_frame_submit(gtid, this_thr->th.th_bar_min_time, cur_time,
2013 if (__itt_metadata_add_ptr) {
2015 kmp_uint64 delta = cur_time - this_thr->th.th_bar_arrive_time;
2018 this_thr->th.th_bar_arrive_time = 0;
2019 for (i = 1; i < nproc; ++i) {
2020 delta += (cur_time - other_threads[i]->th.th_bar_arrive_time);
2021 other_threads[i]->th.th_bar_arrive_time = 0;
2023 __kmp_itt_metadata_imbalance(gtid, this_thr->th.th_frame_time,
2025 (kmp_uint64)(reduce != NULL));
2027 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
2029 this_thr->th.th_frame_time = cur_time;
2037 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2038 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2041 if ((status == 1 || !is_split) && !cancelled) {
2043 cancelled = __kmp_linear_barrier_release_cancellable(
2044 bt, this_thr, gtid, tid, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2046 switch (__kmp_barrier_release_pattern[bt]) {
2048 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2049 __kmp_dist_barrier_release(bt, this_thr, gtid, tid,
2050 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2053 case bp_hyper_bar: {
2054 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2055 __kmp_hyper_barrier_release(bt, this_thr, gtid, tid,
2056 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2059 case bp_hierarchical_bar: {
2060 __kmp_hierarchical_barrier_release(
2061 bt, this_thr, gtid, tid, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2065 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2066 __kmp_tree_barrier_release(bt, this_thr, gtid, tid,
2067 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2071 __kmp_linear_barrier_release(bt, this_thr, gtid, tid,
2072 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2076 if (__kmp_tasking_mode != tskm_immediate_exec && !cancelled) {
2077 __kmp_task_team_sync(this_thr, team);
2085 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2086 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2090 if (__kmp_tasking_mode != tskm_immediate_exec) {
2091 if (this_thr->th.th_task_team != NULL) {
2093 void *itt_sync_obj = NULL;
2094 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2095 itt_sync_obj = __kmp_itt_barrier_object(gtid, bt, 1);
2096 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
2101 this_thr->th.th_task_team->tt.tt_found_proxy_tasks == TRUE ||
2102 this_thr->th.th_task_team->tt.tt_hidden_helper_task_encountered ==
2104 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
2105 __kmp_task_team_setup(this_thr, team);
2108 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2109 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2114 KA_TRACE(15, (
"__kmp_barrier: T#%d(%d:%d) is leaving with return value %d\n",
2115 gtid, __kmp_team_from_gtid(gtid)->t.t_id,
2116 __kmp_tid_from_gtid(gtid), status));
2119 if (ompt_enabled.enabled) {
2121 if (ompt_enabled.ompt_callback_sync_region_wait) {
2122 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2123 barrier_kind, ompt_scope_end, my_parallel_data, my_task_data,
2126 if (ompt_enabled.ompt_callback_sync_region) {
2127 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2128 barrier_kind, ompt_scope_end, my_parallel_data, my_task_data,
2132 this_thr->th.ompt_thread_info.state = ompt_state_work_parallel;
2137 return (
int)cancelled;
2142int __kmp_barrier(
enum barrier_type bt,
int gtid,
int is_split,
2143 size_t reduce_size,
void *reduce_data,
2144 void (*reduce)(
void *,
void *)) {
2145 return __kmp_barrier_template<>(bt, gtid, is_split, reduce_size, reduce_data,
2149#if defined(KMP_GOMP_COMPAT)
2151int __kmp_barrier_gomp_cancel(
int gtid) {
2152 if (__kmp_omp_cancellation) {
2153 int cancelled = __kmp_barrier_template<true>(bs_plain_barrier, gtid, FALSE,
2156 int tid = __kmp_tid_from_gtid(gtid);
2157 kmp_info_t *this_thr = __kmp_threads[gtid];
2158 if (KMP_MASTER_TID(tid)) {
2162 this_thr->th.th_bar[bs_plain_barrier].bb.b_arrived -=
2163 KMP_BARRIER_STATE_BUMP;
2168 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
2173void __kmp_end_split_barrier(
enum barrier_type bt,
int gtid) {
2174 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_end_split_barrier);
2175 KMP_SET_THREAD_STATE_BLOCK(PLAIN_BARRIER);
2176 KMP_DEBUG_ASSERT(bt < bs_last_barrier);
2177 int tid = __kmp_tid_from_gtid(gtid);
2178 kmp_info_t *this_thr = __kmp_threads[gtid];
2179 kmp_team_t *team = this_thr->th.th_team;
2181 if (!team->t.t_serialized) {
2182 if (KMP_MASTER_GTID(gtid)) {
2183 switch (__kmp_barrier_release_pattern[bt]) {
2185 __kmp_dist_barrier_release(bt, this_thr, gtid, tid,
2186 FALSE USE_ITT_BUILD_ARG(NULL));
2189 case bp_hyper_bar: {
2190 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2191 __kmp_hyper_barrier_release(bt, this_thr, gtid, tid,
2192 FALSE USE_ITT_BUILD_ARG(NULL));
2195 case bp_hierarchical_bar: {
2196 __kmp_hierarchical_barrier_release(bt, this_thr, gtid, tid,
2197 FALSE USE_ITT_BUILD_ARG(NULL));
2201 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2202 __kmp_tree_barrier_release(bt, this_thr, gtid, tid,
2203 FALSE USE_ITT_BUILD_ARG(NULL));
2207 __kmp_linear_barrier_release(bt, this_thr, gtid, tid,
2208 FALSE USE_ITT_BUILD_ARG(NULL));
2211 if (__kmp_tasking_mode != tskm_immediate_exec) {
2212 __kmp_task_team_sync(this_thr, team);
2218void __kmp_join_barrier(
int gtid) {
2219 KMP_TIME_PARTITIONED_BLOCK(OMP_join_barrier);
2220 KMP_SET_THREAD_STATE_BLOCK(FORK_JOIN_BARRIER);
2222 KMP_DEBUG_ASSERT(__kmp_threads && __kmp_threads[gtid]);
2224 kmp_info_t *this_thr = __kmp_threads[gtid];
2231 void *itt_sync_obj = NULL;
2233 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2235 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
2238#if ((USE_ITT_BUILD && USE_ITT_NOTIFY) || defined KMP_DEBUG)
2239 int nproc = this_thr->th.th_team_nproc;
2244 team = this_thr->th.th_team;
2245 KMP_DEBUG_ASSERT(nproc == team->t.t_nproc);
2246 tid = __kmp_tid_from_gtid(gtid);
2248 team_id = team->t.t_id;
2249 kmp_info_t *master_thread = this_thr->th.th_team_master;
2250 if (master_thread != team->t.t_threads[0]) {
2251 __kmp_print_structure();
2254 KMP_DEBUG_ASSERT(master_thread == team->t.t_threads[0]);
2258 KMP_DEBUG_ASSERT(TCR_PTR(this_thr->th.th_team));
2259 KMP_DEBUG_ASSERT(TCR_PTR(this_thr->th.th_root));
2260 KMP_DEBUG_ASSERT(this_thr == team->t.t_threads[tid]);
2261 KA_TRACE(10, (
"__kmp_join_barrier: T#%d(%d:%d) arrived at join barrier\n",
2262 gtid, team_id, tid));
2265 if (ompt_enabled.enabled) {
2267 ompt_data_t *my_task_data;
2268 ompt_data_t *my_parallel_data;
2269 void *codeptr = NULL;
2270 int ds_tid = this_thr->th.th_info.ds.ds_tid;
2271 if (KMP_MASTER_TID(ds_tid) &&
2272 (ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait) ||
2273 ompt_callbacks.ompt_callback(ompt_callback_sync_region)))
2274 codeptr = team->t.ompt_team_info.master_return_address;
2275 my_task_data = OMPT_CUR_TASK_DATA(this_thr);
2276 my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
2277 ompt_sync_region_t sync_kind = ompt_sync_region_barrier_implicit_parallel;
2278 ompt_state_t ompt_state = ompt_state_wait_barrier_implicit_parallel;
2279 if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league) {
2280 sync_kind = ompt_sync_region_barrier_teams;
2281 ompt_state = ompt_state_wait_barrier_teams;
2283 if (ompt_enabled.ompt_callback_sync_region) {
2284 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2285 sync_kind, ompt_scope_begin, my_parallel_data, my_task_data, codeptr);
2287 if (ompt_enabled.ompt_callback_sync_region_wait) {
2288 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2289 sync_kind, ompt_scope_begin, my_parallel_data, my_task_data, codeptr);
2291 if (!KMP_MASTER_TID(ds_tid))
2292 this_thr->th.ompt_thread_info.task_data = *OMPT_CUR_TASK_DATA(this_thr);
2294 this_thr->th.ompt_thread_info.state = ompt_state;
2298 if (__kmp_tasking_mode == tskm_extra_barrier) {
2299 __kmp_tasking_barrier(team, this_thr, gtid);
2300 KA_TRACE(10, (
"__kmp_join_barrier: T#%d(%d:%d) past tasking barrier\n",
2301 gtid, team_id, tid));
2304 if (__kmp_tasking_mode != tskm_immediate_exec) {
2305 KA_TRACE(20, (
"__kmp_join_barrier: T#%d, old team = %d, old task_team = "
2306 "%p, th_task_team = %p\n",
2307 __kmp_gtid_from_thread(this_thr), team_id,
2308 team->t.t_task_team[this_thr->th.th_task_state],
2309 this_thr->th.th_task_team));
2310 KMP_DEBUG_ASSERT_TASKTEAM_INVARIANT(team, this_thr);
2319 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
2321 this_thr->th.th_team_bt_intervals =
2322 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
2323 this_thr->th.th_team_bt_set =
2324 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
2326 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid);
2331 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2332 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
2335 switch (__kmp_barrier_gather_pattern[bs_forkjoin_barrier]) {
2337 __kmp_dist_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2338 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2341 case bp_hyper_bar: {
2342 __kmp_hyper_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2343 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2346 case bp_hierarchical_bar: {
2347 __kmp_hierarchical_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2348 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2352 __kmp_tree_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2353 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2357 __kmp_linear_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2358 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2366 if (KMP_MASTER_TID(tid)) {
2367 if (__kmp_tasking_mode != tskm_immediate_exec) {
2368 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
2370 if (__kmp_display_affinity) {
2371 KMP_CHECK_UPDATE(team->t.t_display_affinity, 0);
2373#if KMP_STATS_ENABLED
2377 for (
int i = 0; i < team->t.t_nproc; ++i) {
2378 kmp_info_t *team_thread = team->t.t_threads[i];
2379 if (team_thread == this_thr)
2381 team_thread->th.th_stats->setIdleFlag();
2382 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME &&
2383 team_thread->th.th_sleep_loc != NULL)
2384 __kmp_null_resume_wrapper(team_thread);
2388 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2389 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2392#if USE_ITT_BUILD && USE_ITT_NOTIFY
2394 if ((__itt_frame_submit_v3_ptr || KMP_ITT_DEBUG) &&
2395 __kmp_forkjoin_frames_mode &&
2396 (this_thr->th.th_teams_microtask == NULL ||
2397 this_thr->th.th_teams_size.nteams == 1) &&
2398 team->t.t_active_level == 1) {
2399 kmp_uint64 cur_time = __itt_get_timestamp();
2400 ident_t *loc = team->t.t_ident;
2401 kmp_info_t **other_threads = team->t.t_threads;
2402 switch (__kmp_forkjoin_frames_mode) {
2404 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
2408 __kmp_itt_frame_submit(gtid, this_thr->th.th_bar_min_time, cur_time, 1,
2412 if (__itt_metadata_add_ptr) {
2414 kmp_uint64 delta = cur_time - this_thr->th.th_bar_arrive_time;
2417 this_thr->th.th_bar_arrive_time = 0;
2418 for (
int i = 1; i < nproc; ++i) {
2419 delta += (cur_time - other_threads[i]->th.th_bar_arrive_time);
2420 other_threads[i]->th.th_bar_arrive_time = 0;
2422 __kmp_itt_metadata_imbalance(gtid, this_thr->th.th_frame_time,
2423 cur_time, delta, 0);
2425 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
2427 this_thr->th.th_frame_time = cur_time;
2435 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2436 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2441 if (KMP_MASTER_TID(tid)) {
2444 (
"__kmp_join_barrier: T#%d(%d:%d) says all %d team threads arrived\n",
2445 gtid, team_id, tid, nproc));
2452 (
"__kmp_join_barrier: T#%d(%d:%d) leaving\n", gtid, team_id, tid));
2458void __kmp_fork_barrier(
int gtid,
int tid) {
2459 KMP_TIME_PARTITIONED_BLOCK(OMP_fork_barrier);
2460 KMP_SET_THREAD_STATE_BLOCK(FORK_JOIN_BARRIER);
2461 kmp_info_t *this_thr = __kmp_threads[gtid];
2462 kmp_team_t *team = (tid == 0) ? this_thr->th.th_team : NULL;
2464 void *itt_sync_obj = NULL;
2468 KA_TRACE(10, (
"__kmp_fork_barrier: T#%d(%d:%d) has arrived\n", gtid,
2469 (team != NULL) ? team->t.t_id : -1, tid));
2472 if (KMP_MASTER_TID(tid)) {
2473#if USE_ITT_BUILD && USE_ITT_NOTIFY
2474 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2476 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 1);
2477 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2482 KMP_DEBUG_ASSERT(team);
2483 kmp_info_t **other_threads = team->t.t_threads;
2489 for (i = 1; i < team->t.t_nproc; ++i) {
2491 (
"__kmp_fork_barrier: T#%d(%d:0) checking T#%d(%d:%d) fork go "
2493 gtid, team->t.t_id, other_threads[i]->th.th_info.ds.ds_gtid,
2494 team->t.t_id, other_threads[i]->th.th_info.ds.ds_tid,
2495 other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go));
2497 (TCR_4(other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go) &
2498 ~(KMP_BARRIER_SLEEP_STATE)) == KMP_INIT_BARRIER_STATE);
2499 KMP_DEBUG_ASSERT(other_threads[i]->th.th_team == team);
2503 if (__kmp_tasking_mode != tskm_immediate_exec)
2504 __kmp_task_team_setup(this_thr, team);
2512 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
2514 this_thr->th.th_team_bt_intervals =
2515 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
2516 this_thr->th.th_team_bt_set =
2517 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
2519 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid);
2524 switch (__kmp_barrier_release_pattern[bs_forkjoin_barrier]) {
2526 __kmp_dist_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2527 TRUE USE_ITT_BUILD_ARG(NULL));
2530 case bp_hyper_bar: {
2531 KMP_ASSERT(__kmp_barrier_release_branch_bits[bs_forkjoin_barrier]);
2532 __kmp_hyper_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2533 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
2536 case bp_hierarchical_bar: {
2537 __kmp_hierarchical_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2538 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
2542 KMP_ASSERT(__kmp_barrier_release_branch_bits[bs_forkjoin_barrier]);
2543 __kmp_tree_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2544 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
2548 __kmp_linear_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2549 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
2554 ompt_state_t ompt_state = this_thr->th.ompt_thread_info.state;
2555 if (ompt_enabled.enabled &&
2556 (ompt_state == ompt_state_wait_barrier_teams ||
2557 ompt_state == ompt_state_wait_barrier_implicit_parallel)) {
2558 int ds_tid = this_thr->th.th_info.ds.ds_tid;
2559 ompt_data_t *task_data = (team)
2560 ? OMPT_CUR_TASK_DATA(this_thr)
2561 : &(this_thr->th.ompt_thread_info.task_data);
2562 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
2564 void *codeptr = NULL;
2565 if (KMP_MASTER_TID(ds_tid) &&
2566 (ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait) ||
2567 ompt_callbacks.ompt_callback(ompt_callback_sync_region)))
2568 codeptr = team ? team->t.ompt_team_info.master_return_address : NULL;
2569 ompt_sync_region_t sync_kind = ompt_sync_region_barrier_implicit_parallel;
2570 if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league)
2571 sync_kind = ompt_sync_region_barrier_teams;
2572 if (ompt_enabled.ompt_callback_sync_region_wait) {
2573 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2574 sync_kind, ompt_scope_end, NULL, task_data, codeptr);
2576 if (ompt_enabled.ompt_callback_sync_region) {
2577 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2578 sync_kind, ompt_scope_end, NULL, task_data, codeptr);
2581 if (!KMP_MASTER_TID(ds_tid) && ompt_enabled.ompt_callback_implicit_task) {
2582 ompt_callbacks.ompt_callback(ompt_callback_implicit_task)(
2583 ompt_scope_end, NULL, task_data, 0, ds_tid,
2584 ompt_task_implicit);
2590 if (TCR_4(__kmp_global.g.g_done)) {
2591 this_thr->th.th_task_team = NULL;
2593#if USE_ITT_BUILD && USE_ITT_NOTIFY
2594 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2595 if (!KMP_MASTER_TID(tid)) {
2596 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
2598 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2602 KA_TRACE(10, (
"__kmp_fork_barrier: T#%d is leaving early\n", gtid));
2610 team = (kmp_team_t *)TCR_PTR(this_thr->th.th_team);
2611 KMP_DEBUG_ASSERT(team != NULL);
2612 tid = __kmp_tid_from_gtid(gtid);
2614#if KMP_BARRIER_ICV_PULL
2622 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy);
2623 if (!KMP_MASTER_TID(tid)) {
2627 (
"__kmp_fork_barrier: T#%d(%d) is PULLing ICVs\n", gtid, tid));
2628 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team,
2630 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
2631 &team->t.t_threads[0]
2632 ->th.th_bar[bs_forkjoin_barrier]
2638 if (__kmp_tasking_mode != tskm_immediate_exec) {
2639 __kmp_task_team_sync(this_thr, team);
2642#if KMP_AFFINITY_SUPPORTED
2643 kmp_proc_bind_t proc_bind = team->t.t_proc_bind;
2644 if (proc_bind == proc_bind_intel) {
2646 if (__kmp_affinity.type == affinity_balanced && team->t.t_size_changed) {
2647 __kmp_balanced_affinity(this_thr, team->t.t_nproc);
2649 }
else if (proc_bind != proc_bind_false) {
2650 if (this_thr->th.th_new_place == this_thr->th.th_current_place) {
2651 KA_TRACE(100, (
"__kmp_fork_barrier: T#%d already in correct place %d\n",
2652 __kmp_gtid_from_thread(this_thr),
2653 this_thr->th.th_current_place));
2655 __kmp_affinity_bind_place(gtid);
2660 if (__kmp_display_affinity) {
2661 if (team->t.t_display_affinity
2662#
if KMP_AFFINITY_SUPPORTED
2663 || (__kmp_affinity.type == affinity_balanced && team->t.t_size_changed)
2667 __kmp_aux_display_affinity(gtid, NULL);
2668 this_thr->th.th_prev_num_threads = team->t.t_nproc;
2669 this_thr->th.th_prev_level = team->t.t_level;
2672 if (!KMP_MASTER_TID(tid))
2673 KMP_CHECK_UPDATE(this_thr->th.th_def_allocator, team->t.t_def_allocator);
2675#if USE_ITT_BUILD && USE_ITT_NOTIFY
2676 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2677 if (!KMP_MASTER_TID(tid)) {
2679 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
2680 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2684 KA_TRACE(10, (
"__kmp_fork_barrier: T#%d(%d:%d) is leaving\n", gtid,
2685 team->t.t_id, tid));
2688void __kmp_setup_icv_copy(kmp_team_t *team,
int new_nproc,
2689 kmp_internal_control_t *new_icvs,
ident_t *loc) {
2690 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_setup_icv_copy);
2692 KMP_DEBUG_ASSERT(team && new_nproc && new_icvs);
2693 KMP_DEBUG_ASSERT((!TCR_4(__kmp_init_parallel)) || new_icvs->nproc);
2698#if KMP_BARRIER_ICV_PULL
2702 KMP_DEBUG_ASSERT(team->t.t_threads[0]);
2705 &team->t.t_threads[0]->th.th_bar[bs_forkjoin_barrier].bb.th_fixed_icvs,
2707 KF_TRACE(10, (
"__kmp_setup_icv_copy: PULL: T#%d this_thread=%p team=%p\n", 0,
2708 team->t.t_threads[0], team));
2709#elif KMP_BARRIER_ICV_PUSH
2712 KF_TRACE(10, (
"__kmp_setup_icv_copy: PUSH: T#%d this_thread=%p team=%p\n", 0,
2713 team->t.t_threads[0], team));
2718 KMP_DEBUG_ASSERT(team->t.t_threads[0]);
2720 for (
int f = 1; f < new_nproc; ++f) {
2722 KF_TRACE(10, (
"__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n",
2723 f, team->t.t_threads[f], team));
2724 __kmp_init_implicit_task(loc, team->t.t_threads[f], team, f, FALSE);
2725 ngo_store_icvs(&team->t.t_implicit_task_taskdata[f].td_icvs, new_icvs);
2726 KF_TRACE(10, (
"__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n",
2727 f, team->t.t_threads[f], team));