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 = 1;
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 = 1;
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++) {
295 threads_pending += b->flags[my_current_iter][thr].stillNeed;
298 if (__kmp_tasking_mode != tskm_immediate_exec) {
299 kmp_task_team_t *task_team = this_thr->th.th_task_team;
300 if (task_team != NULL) {
301 if (TCR_SYNC_4(task_team->tt.tt_active)) {
302 if (KMP_TASKING_ENABLED(task_team)) {
303 int tasks_completed = FALSE;
304 __kmp_atomic_execute_tasks_64(
305 this_thr, gtid, (kmp_atomic_flag_64<> *)NULL, FALSE,
306 &tasks_completed USE_ITT_BUILD_ARG(itt_sync_obj), 0);
308 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
311 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
314 if (TCR_4(__kmp_global.g.g_done)) {
315 if (__kmp_global.g.g_abort)
316 __kmp_abort_thread();
318 }
else if (__kmp_tasking_mode != tskm_immediate_exec &&
319 this_thr->th.th_reap_state == KMP_SAFE_TO_REAP) {
320 this_thr->th.th_reap_state = KMP_NOT_SAFE_TO_REAP;
322 }
while (threads_pending > 0);
325 OMPT_REDUCTION_DECL(this_thr, gtid);
326 OMPT_REDUCTION_BEGIN;
328 for (
size_t thr = group_start; thr < group_end; thr++) {
329 (*reduce)(this_thr->th.th_local.reduce_data,
330 other_threads[thr]->th.th_local.reduce_data);
336 b->flags[my_next_iter][tid].stillNeed = 1;
339 b->flags[my_current_iter][tid].stillNeed = 0;
343 for (
size_t thr = 0; thr < nproc; thr += b->threads_per_group) {
344 threads_pending += b->flags[my_current_iter][thr].stillNeed;
347 if (__kmp_tasking_mode != tskm_immediate_exec) {
348 kmp_task_team_t *task_team = this_thr->th.th_task_team;
349 if (task_team != NULL) {
350 if (TCR_SYNC_4(task_team->tt.tt_active)) {
351 if (KMP_TASKING_ENABLED(task_team)) {
352 int tasks_completed = FALSE;
353 __kmp_atomic_execute_tasks_64(
354 this_thr, gtid, (kmp_atomic_flag_64<> *)NULL, FALSE,
355 &tasks_completed USE_ITT_BUILD_ARG(itt_sync_obj), 0);
357 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
360 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
363 if (TCR_4(__kmp_global.g.g_done)) {
364 if (__kmp_global.g.g_abort)
365 __kmp_abort_thread();
367 }
else if (__kmp_tasking_mode != tskm_immediate_exec &&
368 this_thr->th.th_reap_state == KMP_SAFE_TO_REAP) {
369 this_thr->th.th_reap_state = KMP_NOT_SAFE_TO_REAP;
371 }
while (threads_pending > 0);
374 if (KMP_MASTER_TID(tid)) {
375 OMPT_REDUCTION_DECL(this_thr, gtid);
376 OMPT_REDUCTION_BEGIN;
377 for (
size_t thr = b->threads_per_group; thr < nproc;
378 thr += b->threads_per_group) {
379 (*reduce)(this_thr->th.th_local.reduce_data,
380 other_threads[thr]->th.th_local.reduce_data);
387 b->flags[my_next_iter][tid].stillNeed = 1;
390 b->flags[my_current_iter][tid].stillNeed = 0;
396 (
"__kmp_dist_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",
397 gtid, team->t.t_id, tid, bt));
400static void __kmp_dist_barrier_release(
401 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
402 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
403 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_dist_release);
405 distributedBarrier *b;
406 kmp_bstate_t *thr_bar;
407 kmp_uint64 my_current_iter, next_go;
411 KA_TRACE(20, (
"__kmp_dist_barrier_release: T#%d(%d) enter; barrier type %d\n",
414 thr_bar = &this_thr->th.th_bar[bt].bb;
416 if (!KMP_MASTER_TID(tid)) {
419 if (this_thr->th.th_used_in_team.load() != 1 &&
420 this_thr->th.th_used_in_team.load() != 3) {
425 kmp_flag_32<false, false> my_flag(&(this_thr->th.th_used_in_team), 3);
426 if (KMP_COMPARE_AND_STORE_ACQ32(&(this_thr->th.th_used_in_team), 2,
428 this_thr->th.th_used_in_team.load() == 0) {
429 my_flag.wait(this_thr,
true USE_ITT_BUILD_ARG(itt_sync_obj));
431#if USE_ITT_BUILD && USE_ITT_NOTIFY
432 if ((__itt_sync_create_ptr && itt_sync_obj == NULL) || KMP_ITT_DEBUG) {
435 __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
437 __kmp_itt_task_starting(itt_sync_obj);
439 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
442 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
443 if (itt_sync_obj != NULL)
445 __kmp_itt_task_finished(itt_sync_obj);
448 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
451 if (this_thr->th.th_used_in_team.load() != 1 &&
452 this_thr->th.th_used_in_team.load() != 3)
454 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
463 tid = __kmp_tid_from_gtid(gtid);
464 team = this_thr->th.th_team;
465 KMP_DEBUG_ASSERT(tid >= 0);
466 KMP_DEBUG_ASSERT(team);
468 my_current_iter = b->iter[tid].iter;
469 next_go = my_current_iter + distributedBarrier::MAX_ITERS;
470 my_go_index = tid / b->threads_per_go;
471 if (this_thr->th.th_used_in_team.load() == 3) {
472 (void)KMP_COMPARE_AND_STORE_ACQ32(&(this_thr->th.th_used_in_team), 3,
476 if (b->go[my_go_index].go.load() != next_go) {
478 kmp_atomic_flag_64<false, true> my_flag(
479 &(b->go[my_go_index].go), next_go, &(b->sleep[tid].sleep));
480 my_flag.wait(this_thr,
true USE_ITT_BUILD_ARG(itt_sync_obj));
481 KMP_DEBUG_ASSERT(my_current_iter == b->iter[tid].iter ||
482 b->iter[tid].iter == 0);
483 KMP_DEBUG_ASSERT(b->sleep[tid].sleep ==
false);
486 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
493 if (this_thr->th.th_used_in_team.load() == 1)
497 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
500 group_leader = ((tid % b->threads_per_group) == 0);
503 for (
size_t go_idx = my_go_index + 1;
504 go_idx < my_go_index + b->gos_per_group; go_idx++) {
505 b->go[go_idx].go.store(next_go);
511#if KMP_BARRIER_ICV_PUSH
512 if (propagate_icvs) {
513 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team,
515 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
516 (kmp_internal_control_t *)team->t.b->team_icvs);
517 copy_icvs(&thr_bar->th_fixed_icvs,
518 &team->t.t_implicit_task_taskdata[tid].td_icvs);
521 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME && group_leader) {
524 size_t nproc = this_thr->th.th_team_nproc;
525 size_t group_end = tid + b->threads_per_group;
526 if (nproc < group_end)
528 __kmp_dist_barrier_wakeup(bt, team, tid + 1, group_end, 1, tid);
531 team = this_thr->th.th_team;
533 my_current_iter = b->iter[tid].iter;
534 next_go = my_current_iter + distributedBarrier::MAX_ITERS;
535#if KMP_BARRIER_ICV_PUSH
536 if (propagate_icvs) {
538 copy_icvs(&thr_bar->th_fixed_icvs,
539 &team->t.t_implicit_task_taskdata[tid].td_icvs);
543 for (
size_t go_idx = 0; go_idx < b->num_gos; go_idx += b->gos_per_group) {
544 b->go[go_idx].go.store(next_go);
547 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
549 size_t nproc = this_thr->th.th_team_nproc;
550 __kmp_dist_barrier_wakeup(bt, team, tid + b->threads_per_group, nproc,
551 b->threads_per_group, tid);
555 for (
size_t go_idx = 1; go_idx < b->gos_per_group; go_idx++) {
556 b->go[go_idx].go.store(next_go);
562 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
564 size_t nproc = this_thr->th.th_team_nproc;
565 size_t group_end = tid + b->threads_per_group;
566 if (nproc < group_end)
568 __kmp_dist_barrier_wakeup(bt, team, tid + 1, group_end, 1, tid);
572 KMP_ASSERT(my_current_iter == b->iter[tid].iter);
573 b->iter[tid].iter = (b->iter[tid].iter + 1) % distributedBarrier::MAX_ITERS;
576 20, (
"__kmp_dist_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",
577 gtid, team->t.t_id, tid, bt));
581template <
bool cancellable = false>
582static bool __kmp_linear_barrier_gather_template(
583 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
584 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
585 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_linear_gather);
586 kmp_team_t *team = this_thr->th.th_team;
587 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
588 kmp_info_t **other_threads = team->t.t_threads;
592 (
"__kmp_linear_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",
593 gtid, team->t.t_id, tid, bt));
594 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
596#if USE_ITT_BUILD && USE_ITT_NOTIFY
598 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
599 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
600 __itt_get_timestamp();
605 if (!KMP_MASTER_TID(tid)) {
607 (
"__kmp_linear_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d)"
608 "arrived(%p): %llu => %llu\n",
609 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(0, team),
610 team->t.t_id, 0, &thr_bar->b_arrived, thr_bar->b_arrived,
611 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
616 kmp_flag_64<> flag(&thr_bar->b_arrived, other_threads[0]);
619 kmp_balign_team_t *team_bar = &team->t.t_bar[bt];
620 int nproc = this_thr->th.th_team_nproc;
623 kmp_uint64 new_state = team_bar->b_arrived + KMP_BARRIER_STATE_BUMP;
626 for (i = 1; i < nproc; ++i) {
630 KMP_CACHE_PREFETCH(&other_threads[i + 1]->th.th_bar[bt].bb.b_arrived);
632 KA_TRACE(20, (
"__kmp_linear_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%d) "
633 "arrived(%p) == %llu\n",
634 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(i, team),
636 &other_threads[i]->th.th_bar[bt].bb.b_arrived, new_state));
640 kmp_flag_64<true, false> flag(
641 &other_threads[i]->th.th_bar[bt].bb.b_arrived, new_state);
642 if (flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj)))
645 kmp_flag_64<> flag(&other_threads[i]->th.th_bar[bt].bb.b_arrived,
647 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
649#if USE_ITT_BUILD && USE_ITT_NOTIFY
652 if (__kmp_forkjoin_frames_mode == 2) {
653 this_thr->th.th_bar_min_time = KMP_MIN(
654 this_thr->th.th_bar_min_time, other_threads[i]->th.th_bar_min_time);
659 (
"__kmp_linear_barrier_gather: T#%d(%d:%d) += T#%d(%d:%d)\n",
660 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(i, team),
662 OMPT_REDUCTION_DECL(this_thr, gtid);
663 OMPT_REDUCTION_BEGIN;
664 (*reduce)(this_thr->th.th_local.reduce_data,
665 other_threads[i]->th.th_local.reduce_data);
670 team_bar->b_arrived = new_state;
671 KA_TRACE(20, (
"__kmp_linear_barrier_gather: T#%d(%d:%d) set team %d "
672 "arrived(%p) = %llu\n",
673 gtid, team->t.t_id, tid, team->t.t_id, &team_bar->b_arrived,
678 (
"__kmp_linear_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",
679 gtid, team->t.t_id, tid, bt));
683template <
bool cancellable = false>
684static bool __kmp_linear_barrier_release_template(
685 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
686 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
687 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_linear_release);
688 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
691 if (KMP_MASTER_TID(tid)) {
693 kmp_uint32 nproc = this_thr->th.th_team_nproc;
694 kmp_info_t **other_threads;
696 team = __kmp_threads[gtid]->th.th_team;
697 KMP_DEBUG_ASSERT(team != NULL);
698 other_threads = team->t.t_threads;
700 KA_TRACE(20, (
"__kmp_linear_barrier_release: T#%d(%d:%d) primary enter for "
702 gtid, team->t.t_id, tid, bt));
705#if KMP_BARRIER_ICV_PUSH
707 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy);
708 if (propagate_icvs) {
709 ngo_load(&team->t.t_implicit_task_taskdata[0].td_icvs);
710 for (i = 1; i < nproc; ++i) {
711 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[i],
713 ngo_store_icvs(&team->t.t_implicit_task_taskdata[i].td_icvs,
714 &team->t.t_implicit_task_taskdata[0].td_icvs);
722 for (i = 1; i < nproc; ++i) {
726 KMP_CACHE_PREFETCH(&other_threads[i + 1]->th.th_bar[bt].bb.b_go);
730 (
"__kmp_linear_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%d) "
731 "go(%p): %u => %u\n",
732 gtid, team->t.t_id, tid, other_threads[i]->th.th_info.ds.ds_gtid,
733 team->t.t_id, i, &other_threads[i]->th.th_bar[bt].bb.b_go,
734 other_threads[i]->th.th_bar[bt].bb.b_go,
735 other_threads[i]->th.th_bar[bt].bb.b_go + KMP_BARRIER_STATE_BUMP));
736 kmp_flag_64<> flag(&other_threads[i]->th.th_bar[bt].bb.b_go,
742 KA_TRACE(20, (
"__kmp_linear_barrier_release: T#%d wait go(%p) == %u\n",
743 gtid, &thr_bar->b_go, KMP_BARRIER_STATE_BUMP));
745 kmp_flag_64<true, false> flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
746 if (flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj)))
749 kmp_flag_64<> flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
750 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
752#if USE_ITT_BUILD && USE_ITT_NOTIFY
753 if ((__itt_sync_create_ptr && itt_sync_obj == NULL) || KMP_ITT_DEBUG) {
756 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
758 __kmp_itt_task_starting(itt_sync_obj);
760 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
763 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
764 if (itt_sync_obj != NULL)
766 __kmp_itt_task_finished(itt_sync_obj);
770 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
774 tid = __kmp_tid_from_gtid(gtid);
775 team = __kmp_threads[gtid]->th.th_team;
777 KMP_DEBUG_ASSERT(team != NULL);
778 TCW_4(thr_bar->b_go, KMP_INIT_BARRIER_STATE);
780 (
"__kmp_linear_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",
781 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
786 (
"__kmp_linear_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",
787 gtid, team->t.t_id, tid, bt));
791static void __kmp_linear_barrier_gather(
792 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
793 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
794 __kmp_linear_barrier_gather_template<false>(
795 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
798static bool __kmp_linear_barrier_gather_cancellable(
799 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
800 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
801 return __kmp_linear_barrier_gather_template<true>(
802 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
805static void __kmp_linear_barrier_release(
806 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
807 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
808 __kmp_linear_barrier_release_template<false>(
809 bt, this_thr, gtid, tid, propagate_icvs USE_ITT_BUILD_ARG(itt_sync_obj));
812static bool __kmp_linear_barrier_release_cancellable(
813 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
814 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
815 return __kmp_linear_barrier_release_template<true>(
816 bt, this_thr, gtid, tid, propagate_icvs USE_ITT_BUILD_ARG(itt_sync_obj));
820static void __kmp_tree_barrier_gather(
821 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
822 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
823 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_tree_gather);
824 kmp_team_t *team = this_thr->th.th_team;
825 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
826 kmp_info_t **other_threads = team->t.t_threads;
827 kmp_uint32 nproc = this_thr->th.th_team_nproc;
828 kmp_uint32 branch_bits = __kmp_barrier_gather_branch_bits[bt];
829 kmp_uint32 branch_factor = 1 << branch_bits;
831 kmp_uint32 child_tid;
832 kmp_uint64 new_state = 0;
835 20, (
"__kmp_tree_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",
836 gtid, team->t.t_id, tid, bt));
837 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
839#if USE_ITT_BUILD && USE_ITT_NOTIFY
841 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
842 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
843 __itt_get_timestamp();
848 child_tid = (tid << branch_bits) + 1;
849 if (child_tid < nproc) {
851 new_state = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
854 kmp_info_t *child_thr = other_threads[child_tid];
855 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
858 if (child + 1 <= branch_factor && child_tid + 1 < nproc)
860 &other_threads[child_tid + 1]->th.th_bar[bt].bb.b_arrived);
863 (
"__kmp_tree_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
864 "arrived(%p) == %llu\n",
865 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
866 team->t.t_id, child_tid, &child_bar->b_arrived, new_state));
868 kmp_flag_64<> flag(&child_bar->b_arrived, new_state);
869 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
870#if USE_ITT_BUILD && USE_ITT_NOTIFY
873 if (__kmp_forkjoin_frames_mode == 2) {
874 this_thr->th.th_bar_min_time = KMP_MIN(this_thr->th.th_bar_min_time,
875 child_thr->th.th_bar_min_time);
880 (
"__kmp_tree_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n",
881 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
882 team->t.t_id, child_tid));
883 OMPT_REDUCTION_DECL(this_thr, gtid);
884 OMPT_REDUCTION_BEGIN;
885 (*reduce)(this_thr->th.th_local.reduce_data,
886 child_thr->th.th_local.reduce_data);
891 }
while (child <= branch_factor && child_tid < nproc);
894 if (!KMP_MASTER_TID(tid)) {
895 kmp_int32 parent_tid = (tid - 1) >> branch_bits;
898 (
"__kmp_tree_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
899 "arrived(%p): %llu => %llu\n",
900 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(parent_tid, team),
901 team->t.t_id, parent_tid, &thr_bar->b_arrived, thr_bar->b_arrived,
902 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
908 kmp_flag_64<> flag(&thr_bar->b_arrived, other_threads[parent_tid]);
913 team->t.t_bar[bt].b_arrived = new_state;
915 team->t.t_bar[bt].b_arrived += KMP_BARRIER_STATE_BUMP;
916 KA_TRACE(20, (
"__kmp_tree_barrier_gather: T#%d(%d:%d) set team %d "
917 "arrived(%p) = %llu\n",
918 gtid, team->t.t_id, tid, team->t.t_id,
919 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived));
922 (
"__kmp_tree_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",
923 gtid, team->t.t_id, tid, bt));
926static void __kmp_tree_barrier_release(
927 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
928 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
929 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_tree_release);
931 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
933 kmp_uint32 branch_bits = __kmp_barrier_release_branch_bits[bt];
934 kmp_uint32 branch_factor = 1 << branch_bits;
936 kmp_uint32 child_tid;
941 KA_TRACE(20, (
"__kmp_tree_barrier_release: T#%d wait go(%p) == %u\n", gtid,
942 &thr_bar->b_go, KMP_BARRIER_STATE_BUMP));
944 kmp_flag_64<> flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
945 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
946#if USE_ITT_BUILD && USE_ITT_NOTIFY
947 if ((__itt_sync_create_ptr && itt_sync_obj == NULL) || KMP_ITT_DEBUG) {
950 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
952 __kmp_itt_task_starting(itt_sync_obj);
954 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
957 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
958 if (itt_sync_obj != NULL)
960 __kmp_itt_task_finished(itt_sync_obj);
964 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
968 team = __kmp_threads[gtid]->th.th_team;
969 KMP_DEBUG_ASSERT(team != NULL);
970 tid = __kmp_tid_from_gtid(gtid);
972 TCW_4(thr_bar->b_go, KMP_INIT_BARRIER_STATE);
974 (
"__kmp_tree_barrier_release: T#%d(%d:%d) set go(%p) = %u\n", gtid,
975 team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
978 team = __kmp_threads[gtid]->th.th_team;
979 KMP_DEBUG_ASSERT(team != NULL);
980 KA_TRACE(20, (
"__kmp_tree_barrier_release: T#%d(%d:%d) primary enter for "
982 gtid, team->t.t_id, tid, bt));
984 nproc = this_thr->th.th_team_nproc;
985 child_tid = (tid << branch_bits) + 1;
987 if (child_tid < nproc) {
988 kmp_info_t **other_threads = team->t.t_threads;
992 kmp_info_t *child_thr = other_threads[child_tid];
993 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
996 if (child + 1 <= branch_factor && child_tid + 1 < nproc)
998 &other_threads[child_tid + 1]->th.th_bar[bt].bb.b_go);
1001#if KMP_BARRIER_ICV_PUSH
1003 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy);
1004 if (propagate_icvs) {
1005 __kmp_init_implicit_task(team->t.t_ident,
1006 team->t.t_threads[child_tid], team,
1008 copy_icvs(&team->t.t_implicit_task_taskdata[child_tid].td_icvs,
1009 &team->t.t_implicit_task_taskdata[0].td_icvs);
1014 (
"__kmp_tree_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
1015 "go(%p): %u => %u\n",
1016 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
1017 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,
1018 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1020 kmp_flag_64<> flag(&child_bar->b_go, child_thr);
1024 }
while (child <= branch_factor && child_tid < nproc);
1027 20, (
"__kmp_tree_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",
1028 gtid, team->t.t_id, tid, bt));
1032static void __kmp_hyper_barrier_gather(
1033 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
1034 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
1035 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hyper_gather);
1036 kmp_team_t *team = this_thr->th.th_team;
1037 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
1038 kmp_info_t **other_threads = team->t.t_threads;
1039 kmp_uint64 new_state = KMP_BARRIER_UNUSED_STATE;
1040 kmp_uint32 num_threads = this_thr->th.th_team_nproc;
1041 kmp_uint32 branch_bits = __kmp_barrier_gather_branch_bits[bt];
1042 kmp_uint32 branch_factor = 1 << branch_bits;
1048 (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",
1049 gtid, team->t.t_id, tid, bt));
1050 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
1052#if USE_ITT_BUILD && USE_ITT_NOTIFY
1054 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
1055 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
1056 __itt_get_timestamp();
1061 kmp_flag_64<> p_flag(&thr_bar->b_arrived);
1062 for (level = 0, offset = 1; offset < num_threads;
1063 level += branch_bits, offset <<= branch_bits) {
1065 kmp_uint32 child_tid;
1067 if (((tid >> level) & (branch_factor - 1)) != 0) {
1068 kmp_int32 parent_tid = tid & ~((1 << (level + branch_bits)) - 1);
1072 (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
1073 "arrived(%p): %llu => %llu\n",
1074 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(parent_tid, team),
1075 team->t.t_id, parent_tid, &thr_bar->b_arrived,
1077 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
1082 p_flag.set_waiter(other_threads[parent_tid]);
1088 if (new_state == KMP_BARRIER_UNUSED_STATE)
1089 new_state = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
1090 for (child = 1, child_tid = tid + (1 << level);
1091 child < branch_factor && child_tid < num_threads;
1092 child++, child_tid += (1 << level)) {
1093 kmp_info_t *child_thr = other_threads[child_tid];
1094 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1096 kmp_uint32 next_child_tid = child_tid + (1 << level);
1098 if (child + 1 < branch_factor && next_child_tid < num_threads)
1100 &other_threads[next_child_tid]->th.th_bar[bt].bb.b_arrived);
1103 (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
1104 "arrived(%p) == %llu\n",
1105 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
1106 team->t.t_id, child_tid, &child_bar->b_arrived, new_state));
1108 kmp_flag_64<> c_flag(&child_bar->b_arrived, new_state);
1109 c_flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1111#if USE_ITT_BUILD && USE_ITT_NOTIFY
1114 if (__kmp_forkjoin_frames_mode == 2) {
1115 this_thr->th.th_bar_min_time = KMP_MIN(this_thr->th.th_bar_min_time,
1116 child_thr->th.th_bar_min_time);
1121 (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n",
1122 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
1123 team->t.t_id, child_tid));
1124 OMPT_REDUCTION_DECL(this_thr, gtid);
1125 OMPT_REDUCTION_BEGIN;
1126 (*reduce)(this_thr->th.th_local.reduce_data,
1127 child_thr->th.th_local.reduce_data);
1133 if (KMP_MASTER_TID(tid)) {
1135 if (new_state == KMP_BARRIER_UNUSED_STATE)
1136 team->t.t_bar[bt].b_arrived += KMP_BARRIER_STATE_BUMP;
1138 team->t.t_bar[bt].b_arrived = new_state;
1139 KA_TRACE(20, (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) set team %d "
1140 "arrived(%p) = %llu\n",
1141 gtid, team->t.t_id, tid, team->t.t_id,
1142 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived));
1145 20, (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",
1146 gtid, team->t.t_id, tid, bt));
1150#define KMP_REVERSE_HYPER_BAR
1151static void __kmp_hyper_barrier_release(
1152 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
1153 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
1154 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hyper_release);
1156 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
1157 kmp_info_t **other_threads;
1158 kmp_uint32 num_threads;
1159 kmp_uint32 branch_bits = __kmp_barrier_release_branch_bits[bt];
1160 kmp_uint32 branch_factor = 1 << branch_bits;
1162 kmp_uint32 child_tid;
1170 if (KMP_MASTER_TID(tid)) {
1171 team = __kmp_threads[gtid]->th.th_team;
1172 KMP_DEBUG_ASSERT(team != NULL);
1173 KA_TRACE(20, (
"__kmp_hyper_barrier_release: T#%d(%d:%d) primary enter for "
1174 "barrier type %d\n",
1175 gtid, team->t.t_id, tid, bt));
1176#if KMP_BARRIER_ICV_PUSH
1177 if (propagate_icvs) {
1178 copy_icvs(&thr_bar->th_fixed_icvs,
1179 &team->t.t_implicit_task_taskdata[tid].td_icvs);
1183 KA_TRACE(20, (
"__kmp_hyper_barrier_release: T#%d wait go(%p) == %u\n", gtid,
1184 &thr_bar->b_go, KMP_BARRIER_STATE_BUMP));
1186 kmp_flag_64<> flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
1187 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
1188#if USE_ITT_BUILD && USE_ITT_NOTIFY
1189 if ((__itt_sync_create_ptr && itt_sync_obj == NULL) || KMP_ITT_DEBUG) {
1191 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
1193 __kmp_itt_task_starting(itt_sync_obj);
1195 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
1198 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
1199 if (itt_sync_obj != NULL)
1201 __kmp_itt_task_finished(itt_sync_obj);
1205 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
1209 team = __kmp_threads[gtid]->th.th_team;
1210 KMP_DEBUG_ASSERT(team != NULL);
1211 tid = __kmp_tid_from_gtid(gtid);
1213 TCW_4(thr_bar->b_go, KMP_INIT_BARRIER_STATE);
1215 (
"__kmp_hyper_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",
1216 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
1219 num_threads = this_thr->th.th_team_nproc;
1220 other_threads = team->t.t_threads;
1222#ifdef KMP_REVERSE_HYPER_BAR
1224 for (level = 0, offset = 1;
1225 offset < num_threads && (((tid >> level) & (branch_factor - 1)) == 0);
1226 level += branch_bits, offset <<= branch_bits)
1230 for (level -= branch_bits, offset >>= branch_bits; offset != 0;
1231 level -= branch_bits, offset >>= branch_bits)
1234 for (level = 0, offset = 1; offset < num_threads;
1235 level += branch_bits, offset <<= branch_bits)
1238#ifdef KMP_REVERSE_HYPER_BAR
1241 child = num_threads >> ((level == 0) ? level : level - 1);
1242 for (child = (child < branch_factor - 1) ? child : branch_factor - 1,
1243 child_tid = tid + (child << level);
1244 child >= 1; child--, child_tid -= (1 << level))
1246 if (((tid >> level) & (branch_factor - 1)) != 0)
1251 for (child = 1, child_tid = tid + (1 << level);
1252 child < branch_factor && child_tid < num_threads;
1253 child++, child_tid += (1 << level))
1256 if (child_tid >= num_threads)
1259 kmp_info_t *child_thr = other_threads[child_tid];
1260 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1262 kmp_uint32 next_child_tid = child_tid - (1 << level);
1264#ifdef KMP_REVERSE_HYPER_BAR
1265 if (child - 1 >= 1 && next_child_tid < num_threads)
1267 if (child + 1 < branch_factor && next_child_tid < num_threads)
1270 &other_threads[next_child_tid]->th.th_bar[bt].bb.b_go);
1273#if KMP_BARRIER_ICV_PUSH
1275 copy_icvs(&child_bar->th_fixed_icvs, &thr_bar->th_fixed_icvs);
1280 (
"__kmp_hyper_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
1281 "go(%p): %u => %u\n",
1282 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
1283 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,
1284 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1286 kmp_flag_64<> flag(&child_bar->b_go, child_thr);
1291#if KMP_BARRIER_ICV_PUSH
1292 if (propagate_icvs &&
1293 !KMP_MASTER_TID(tid)) {
1294 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team, tid,
1296 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1297 &thr_bar->th_fixed_icvs);
1302 (
"__kmp_hyper_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",
1303 gtid, team->t.t_id, tid, bt));
1316static bool __kmp_init_hierarchical_barrier_thread(
enum barrier_type bt,
1317 kmp_bstate_t *thr_bar,
1318 kmp_uint32 nproc,
int gtid,
1319 int tid, kmp_team_t *team) {
1323#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
1324#define __kmp_msb_byteoffset(offset) (offset)
1326#define __kmp_msb_byteoffset(offset) (7 - (offset))
1330 bool uninitialized = thr_bar->team == NULL;
1331 bool team_changed = team != thr_bar->team;
1332 bool team_sz_changed = nproc != thr_bar->nproc;
1333 bool tid_changed = tid != thr_bar->old_tid;
1334 bool retval =
false;
1336 if (uninitialized || team_sz_changed) {
1337 __kmp_get_hierarchy(nproc, thr_bar);
1340 if (uninitialized || team_sz_changed || tid_changed) {
1341 thr_bar->my_level = thr_bar->depth - 1;
1342 thr_bar->parent_tid = -1;
1343 thr_bar->offset = -1;
1344 if (!KMP_MASTER_TID(tid)) {
1347 while (d < thr_bar->depth) {
1350 if (d == thr_bar->depth - 2) {
1351 thr_bar->parent_tid = 0;
1352 thr_bar->my_level = d;
1354 }
else if ((rem = tid % thr_bar->skip_per_level[d + 1]) != 0) {
1357 thr_bar->parent_tid = tid - rem;
1358 thr_bar->my_level = d;
1364 kmp_uint32 offset = ((kmp_uint32)tid - thr_bar->parent_tid) /
1365 thr_bar->skip_per_level[thr_bar->my_level];
1366 offset = offset - 1;
1367 KMP_ASSERT(offset < 7);
1368 __kmp_type_convert(__kmp_msb_byteoffset(offset), &(thr_bar->offset));
1371 thr_bar->old_tid = tid;
1372 thr_bar->wait_flag = KMP_BARRIER_NOT_WAITING;
1373 thr_bar->team = team;
1374 thr_bar->parent_bar =
1375 &team->t.t_threads[thr_bar->parent_tid]->th.th_bar[bt].bb;
1377 if (uninitialized || team_changed || tid_changed) {
1378 thr_bar->team = team;
1379 thr_bar->parent_bar =
1380 &team->t.t_threads[thr_bar->parent_tid]->th.th_bar[bt].bb;
1383 if (uninitialized || team_sz_changed || tid_changed) {
1384 thr_bar->nproc = nproc;
1385 thr_bar->leaf_kids = thr_bar->base_leaf_kids;
1386 if (thr_bar->my_level == 0)
1387 thr_bar->leaf_kids = 0;
1388 if (thr_bar->leaf_kids && (kmp_uint32)tid + thr_bar->leaf_kids + 1 > nproc)
1389 __kmp_type_convert(nproc - tid - 1, &(thr_bar->leaf_kids));
1390 thr_bar->leaf_state = 0;
1391 for (
int i = 0; i < thr_bar->leaf_kids; ++i)
1392 ((
char *)&(thr_bar->leaf_state))[__kmp_msb_byteoffset(i)] = 1;
1396#undef __kmp_msb_byteoffset
1399static void __kmp_hierarchical_barrier_gather(
1400 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
1401 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
1402 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hier_gather);
1403 kmp_team_t *team = this_thr->th.th_team;
1404 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
1405 kmp_uint32 nproc = this_thr->th.th_team_nproc;
1406 kmp_info_t **other_threads = team->t.t_threads;
1407 kmp_uint64 new_state = 0;
1409 int level = team->t.t_level;
1410 if (other_threads[0]
1411 ->th.th_teams_microtask)
1412 if (this_thr->th.th_teams_size.nteams > 1)
1415 thr_bar->use_oncore_barrier = 1;
1417 thr_bar->use_oncore_barrier = 0;
1419 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) enter for "
1420 "barrier type %d\n",
1421 gtid, team->t.t_id, tid, bt));
1422 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
1424#if USE_ITT_BUILD && USE_ITT_NOTIFY
1426 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
1427 this_thr->th.th_bar_arrive_time = __itt_get_timestamp();
1431 (void)__kmp_init_hierarchical_barrier_thread(bt, thr_bar, nproc, gtid, tid,
1434 if (thr_bar->my_level) {
1435 kmp_int32 child_tid;
1437 (kmp_uint64)team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
1438 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
1439 thr_bar->use_oncore_barrier) {
1440 if (thr_bar->leaf_kids) {
1442 kmp_uint64 leaf_state =
1444 ? thr_bar->b_arrived | thr_bar->leaf_state
1445 : team->t.t_bar[bt].b_arrived | thr_bar->leaf_state;
1446 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) waiting "
1448 gtid, team->t.t_id, tid));
1449 kmp_flag_64<> flag(&thr_bar->b_arrived, leaf_state);
1450 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1452 OMPT_REDUCTION_DECL(this_thr, gtid);
1453 OMPT_REDUCTION_BEGIN;
1454 for (child_tid = tid + 1; child_tid <= tid + thr_bar->leaf_kids;
1456 KA_TRACE(100, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
1458 gtid, team->t.t_id, tid,
1459 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1461 (*reduce)(this_thr->th.th_local.reduce_data,
1462 other_threads[child_tid]->th.th_local.reduce_data);
1467 KMP_TEST_THEN_AND64(&thr_bar->b_arrived, ~(thr_bar->leaf_state));
1470 for (kmp_uint32 d = 1; d < thr_bar->my_level;
1472 kmp_uint32 last = tid + thr_bar->skip_per_level[d + 1],
1473 skip = thr_bar->skip_per_level[d];
1476 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
1477 kmp_info_t *child_thr = other_threads[child_tid];
1478 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1479 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
1481 "arrived(%p) == %llu\n",
1482 gtid, team->t.t_id, tid,
1483 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1484 child_tid, &child_bar->b_arrived, new_state));
1485 kmp_flag_64<> flag(&child_bar->b_arrived, new_state);
1486 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1488 KA_TRACE(100, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
1490 gtid, team->t.t_id, tid,
1491 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1493 (*reduce)(this_thr->th.th_local.reduce_data,
1494 child_thr->th.th_local.reduce_data);
1499 for (kmp_uint32 d = 0; d < thr_bar->my_level;
1501 kmp_uint32 last = tid + thr_bar->skip_per_level[d + 1],
1502 skip = thr_bar->skip_per_level[d];
1505 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
1506 kmp_info_t *child_thr = other_threads[child_tid];
1507 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1508 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
1510 "arrived(%p) == %llu\n",
1511 gtid, team->t.t_id, tid,
1512 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1513 child_tid, &child_bar->b_arrived, new_state));
1514 kmp_flag_64<> flag(&child_bar->b_arrived, new_state);
1515 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1517 KA_TRACE(100, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
1519 gtid, team->t.t_id, tid,
1520 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1522 (*reduce)(this_thr->th.th_local.reduce_data,
1523 child_thr->th.th_local.reduce_data);
1531 if (!KMP_MASTER_TID(tid)) {
1532 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) releasing"
1533 " T#%d(%d:%d) arrived(%p): %llu => %llu\n",
1534 gtid, team->t.t_id, tid,
1535 __kmp_gtid_from_tid(thr_bar->parent_tid, team), team->t.t_id,
1536 thr_bar->parent_tid, &thr_bar->b_arrived, thr_bar->b_arrived,
1537 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
1541 if (thr_bar->my_level || __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME ||
1542 !thr_bar->use_oncore_barrier) {
1544 kmp_flag_64<> flag(&thr_bar->b_arrived,
1545 other_threads[thr_bar->parent_tid]);
1549 thr_bar->b_arrived = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
1550 kmp_flag_oncore flag(&thr_bar->parent_bar->b_arrived, thr_bar->offset);
1551 flag.set_waiter(other_threads[thr_bar->parent_tid]);
1555 team->t.t_bar[bt].b_arrived = new_state;
1556 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) set team %d "
1557 "arrived(%p) = %llu\n",
1558 gtid, team->t.t_id, tid, team->t.t_id,
1559 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived));
1562 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) exit for "
1563 "barrier type %d\n",
1564 gtid, team->t.t_id, tid, bt));
1567static void __kmp_hierarchical_barrier_release(
1568 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
1569 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
1570 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hier_release);
1572 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
1574 bool team_change =
false;
1576 if (KMP_MASTER_TID(tid)) {
1577 team = __kmp_threads[gtid]->th.th_team;
1578 KMP_DEBUG_ASSERT(team != NULL);
1579 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) primary "
1580 "entered barrier type %d\n",
1581 gtid, team->t.t_id, tid, bt));
1584 if (!thr_bar->use_oncore_barrier ||
1585 __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME || thr_bar->my_level != 0 ||
1586 thr_bar->team == NULL) {
1588 thr_bar->wait_flag = KMP_BARRIER_OWN_FLAG;
1589 kmp_flag_64<> flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
1590 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
1591 TCW_8(thr_bar->b_go,
1592 KMP_INIT_BARRIER_STATE);
1596 thr_bar->wait_flag = KMP_BARRIER_PARENT_FLAG;
1597 kmp_flag_oncore flag(&thr_bar->parent_bar->b_go, KMP_BARRIER_STATE_BUMP,
1598 thr_bar->offset, bt,
1599 this_thr USE_ITT_BUILD_ARG(itt_sync_obj));
1600 flag.wait(this_thr, TRUE);
1601 if (thr_bar->wait_flag ==
1602 KMP_BARRIER_SWITCHING) {
1603 TCW_8(thr_bar->b_go,
1604 KMP_INIT_BARRIER_STATE);
1606 (RCAST(
volatile char *,
1607 &(thr_bar->parent_bar->b_go)))[thr_bar->offset] = 0;
1610 thr_bar->wait_flag = KMP_BARRIER_NOT_WAITING;
1612 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
1615 team = __kmp_threads[gtid]->th.th_team;
1616 KMP_DEBUG_ASSERT(team != NULL);
1617 tid = __kmp_tid_from_gtid(gtid);
1621 (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",
1622 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
1626 nproc = this_thr->th.th_team_nproc;
1627 int level = team->t.t_level;
1628 if (team->t.t_threads[0]
1629 ->th.th_teams_microtask) {
1630 if (team->t.t_pkfn != (microtask_t)__kmp_teams_master &&
1631 this_thr->th.th_teams_level == level)
1633 if (this_thr->th.th_teams_size.nteams > 1)
1637 thr_bar->use_oncore_barrier = 1;
1639 thr_bar->use_oncore_barrier = 0;
1643 unsigned short int old_leaf_kids = thr_bar->leaf_kids;
1644 kmp_uint64 old_leaf_state = thr_bar->leaf_state;
1645 team_change = __kmp_init_hierarchical_barrier_thread(bt, thr_bar, nproc, gtid,
1651#if KMP_BARRIER_ICV_PUSH
1652 if (propagate_icvs) {
1653 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team, tid,
1657 copy_icvs(&thr_bar->th_fixed_icvs,
1658 &team->t.t_implicit_task_taskdata[tid].td_icvs);
1659 }
else if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
1660 thr_bar->use_oncore_barrier) {
1661 if (!thr_bar->my_level)
1664 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1665 &thr_bar->parent_bar->th_fixed_icvs);
1668 if (thr_bar->my_level)
1670 copy_icvs(&thr_bar->th_fixed_icvs, &thr_bar->parent_bar->th_fixed_icvs);
1672 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1673 &thr_bar->parent_bar->th_fixed_icvs);
1679 if (thr_bar->my_level) {
1680 kmp_int32 child_tid;
1682 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
1683 thr_bar->use_oncore_barrier) {
1684 if (KMP_MASTER_TID(tid)) {
1687 thr_bar->b_go = KMP_BARRIER_STATE_BUMP;
1690 ngo_load(&thr_bar->th_fixed_icvs);
1693 for (child_tid = thr_bar->skip_per_level[1]; child_tid < (
int)nproc;
1694 child_tid += thr_bar->skip_per_level[1]) {
1695 kmp_bstate_t *child_bar =
1696 &team->t.t_threads[child_tid]->th.th_bar[bt].bb;
1697 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
1698 "releasing T#%d(%d:%d)"
1699 " go(%p): %u => %u\n",
1700 gtid, team->t.t_id, tid,
1701 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1702 child_tid, &child_bar->b_go, child_bar->b_go,
1703 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1706 ngo_store_go(&child_bar->th_fixed_icvs, &thr_bar->th_fixed_icvs);
1710 TCW_8(thr_bar->b_go,
1711 KMP_INIT_BARRIER_STATE);
1713 if (thr_bar->leaf_kids) {
1716 old_leaf_kids < thr_bar->leaf_kids) {
1717 if (old_leaf_kids) {
1718 thr_bar->b_go |= old_leaf_state;
1721 last = tid + thr_bar->skip_per_level[1];
1724 for (child_tid = tid + 1 + old_leaf_kids; child_tid < (int)last;
1726 kmp_info_t *child_thr = team->t.t_threads[child_tid];
1727 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1730 (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) releasing"
1731 " T#%d(%d:%d) go(%p): %u => %u\n",
1732 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
1733 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,
1734 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1736 kmp_flag_64<> flag(&child_bar->b_go, child_thr);
1741 thr_bar->b_go |= thr_bar->leaf_state;
1745 for (
int d = thr_bar->my_level - 1; d >= 0;
1747 last = tid + thr_bar->skip_per_level[d + 1];
1748 kmp_uint32 skip = thr_bar->skip_per_level[d];
1751 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
1752 kmp_info_t *child_thr = team->t.t_threads[child_tid];
1753 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1754 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
1755 "releasing T#%d(%d:%d) go(%p): %u => %u\n",
1756 gtid, team->t.t_id, tid,
1757 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1758 child_tid, &child_bar->b_go, child_bar->b_go,
1759 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1761 kmp_flag_64<> flag(&child_bar->b_go, child_thr);
1766#if KMP_BARRIER_ICV_PUSH
1767 if (propagate_icvs && !KMP_MASTER_TID(tid))
1769 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1770 &thr_bar->th_fixed_icvs);
1773 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) exit for "
1774 "barrier type %d\n",
1775 gtid, team->t.t_id, tid, bt));
1783template <
bool cancellable>
struct is_cancellable {};
1784template <>
struct is_cancellable<true> {
1786 is_cancellable() : value(false) {}
1787 is_cancellable(
bool b) : value(b) {}
1788 is_cancellable &operator=(
bool b) {
1792 operator bool()
const {
return value; }
1794template <>
struct is_cancellable<false> {
1795 is_cancellable &operator=(
bool b) {
return *
this; }
1796 constexpr operator bool()
const {
return false; }
1807template <
bool cancellable = false>
1808static int __kmp_barrier_template(
enum barrier_type bt,
int gtid,
int is_split,
1809 size_t reduce_size,
void *reduce_data,
1810 void (*reduce)(
void *,
void *)) {
1811 KMP_TIME_PARTITIONED_BLOCK(OMP_plain_barrier);
1812 KMP_SET_THREAD_STATE_BLOCK(PLAIN_BARRIER);
1813 int tid = __kmp_tid_from_gtid(gtid);
1814 kmp_info_t *this_thr = __kmp_threads[gtid];
1815 kmp_team_t *team = this_thr->th.th_team;
1817 is_cancellable<cancellable> cancelled;
1818#if OMPT_SUPPORT && OMPT_OPTIONAL
1819 ompt_data_t *my_task_data;
1820 ompt_data_t *my_parallel_data;
1821 void *return_address;
1822 ompt_sync_region_t barrier_kind;
1825 KA_TRACE(15, (
"__kmp_barrier: T#%d(%d:%d) has arrived\n", gtid,
1826 __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid(gtid)));
1829 if (ompt_enabled.enabled) {
1831 my_task_data = OMPT_CUR_TASK_DATA(this_thr);
1832 my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
1833 return_address = OMPT_LOAD_RETURN_ADDRESS(gtid);
1834 barrier_kind = __ompt_get_barrier_kind(bt, this_thr);
1835 if (ompt_enabled.ompt_callback_sync_region) {
1836 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
1837 barrier_kind, ompt_scope_begin, my_parallel_data, my_task_data,
1840 if (ompt_enabled.ompt_callback_sync_region_wait) {
1841 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
1842 barrier_kind, ompt_scope_begin, my_parallel_data, my_task_data,
1849 auto *ompt_thr_info = &this_thr->th.ompt_thread_info;
1850 switch (barrier_kind) {
1851 case ompt_sync_region_barrier_explicit:
1852 ompt_thr_info->state = ompt_state_wait_barrier_explicit;
1854 case ompt_sync_region_barrier_implicit_workshare:
1855 ompt_thr_info->state = ompt_state_wait_barrier_implicit_workshare;
1857 case ompt_sync_region_barrier_implicit_parallel:
1858 ompt_thr_info->state = ompt_state_wait_barrier_implicit_parallel;
1860 case ompt_sync_region_barrier_teams:
1861 ompt_thr_info->state = ompt_state_wait_barrier_teams;
1863 case ompt_sync_region_barrier_implementation:
1866 ompt_thr_info->state = ompt_state_wait_barrier_implementation;
1871#if ENABLE_LIBOMPTARGET
1874 if (UNLIKELY(kmp_target_sync_cb != NULL))
1875 (*kmp_target_sync_cb)(
1876 NULL, gtid, KMP_TASKDATA_TO_TASK(this_thr->th.th_current_task), NULL);
1879 if (!team->t.t_serialized) {
1882 void *itt_sync_obj = NULL;
1884 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1885 itt_sync_obj = __kmp_itt_barrier_object(gtid, bt, 1);
1888 if (__kmp_tasking_mode == tskm_extra_barrier) {
1889 __kmp_tasking_barrier(team, this_thr, gtid);
1891 (
"__kmp_barrier: T#%d(%d:%d) past tasking barrier\n", gtid,
1892 __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid(gtid)));
1899 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
1901 this_thr->th.th_team_bt_intervals =
1902 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
1903 this_thr->th.th_team_bt_set =
1904 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
1906 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid);
1911 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1912 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
1916 if (KMP_MASTER_TID(tid)) {
1917 team->t.t_bar[bt].b_master_arrived += 1;
1919 this_thr->th.th_bar[bt].bb.b_worker_arrived += 1;
1922 if (reduce != NULL) {
1924 this_thr->th.th_local.reduce_data = reduce_data;
1927 if (KMP_MASTER_TID(tid) && __kmp_tasking_mode != tskm_immediate_exec)
1928 __kmp_task_team_setup(this_thr, team);
1931 cancelled = __kmp_linear_barrier_gather_cancellable(
1932 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1934 switch (__kmp_barrier_gather_pattern[bt]) {
1936 __kmp_dist_barrier_gather(bt, this_thr, gtid, tid,
1937 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1940 case bp_hyper_bar: {
1941 __kmp_hyper_barrier_gather(bt, this_thr, gtid, tid,
1942 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1945 case bp_hierarchical_bar: {
1946 __kmp_hierarchical_barrier_gather(
1947 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1951 __kmp_tree_barrier_gather(bt, this_thr, gtid, tid,
1952 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1956 __kmp_linear_barrier_gather(bt, this_thr, gtid, tid,
1957 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1964 if (KMP_MASTER_TID(tid)) {
1966 if (__kmp_tasking_mode != tskm_immediate_exec && !cancelled) {
1967 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
1972 team->t.t_bar[bt].b_team_arrived += 1;
1975 if (__kmp_omp_cancellation) {
1976 kmp_int32 cancel_request = KMP_ATOMIC_LD_RLX(&team->t.t_cancel_request);
1978 if (cancel_request == cancel_loop ||
1979 cancel_request == cancel_sections) {
1980 KMP_ATOMIC_ST_RLX(&team->t.t_cancel_request, cancel_noreq);
1988 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1989 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
1991#if USE_ITT_BUILD && USE_ITT_NOTIFY
1993 if ((__itt_frame_submit_v3_ptr || KMP_ITT_DEBUG) &&
1994 __kmp_forkjoin_frames_mode &&
1995 (this_thr->th.th_teams_microtask == NULL ||
1996 this_thr->th.th_teams_size.nteams == 1) &&
1997 team->t.t_active_level == 1) {
1998 ident_t *loc = __kmp_threads[gtid]->th.th_ident;
1999 kmp_uint64 cur_time = __itt_get_timestamp();
2000 kmp_info_t **other_threads = team->t.t_threads;
2001 int nproc = this_thr->th.th_team_nproc;
2003 switch (__kmp_forkjoin_frames_mode) {
2005 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
2007 this_thr->th.th_frame_time = cur_time;
2011 __kmp_itt_frame_submit(gtid, this_thr->th.th_bar_min_time, cur_time,
2015 if (__itt_metadata_add_ptr) {
2017 kmp_uint64 delta = cur_time - this_thr->th.th_bar_arrive_time;
2020 this_thr->th.th_bar_arrive_time = 0;
2021 for (i = 1; i < nproc; ++i) {
2022 delta += (cur_time - other_threads[i]->th.th_bar_arrive_time);
2023 other_threads[i]->th.th_bar_arrive_time = 0;
2025 __kmp_itt_metadata_imbalance(gtid, this_thr->th.th_frame_time,
2027 (kmp_uint64)(reduce != NULL));
2029 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
2031 this_thr->th.th_frame_time = cur_time;
2039 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2040 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2043 if ((status == 1 || !is_split) && !cancelled) {
2045 cancelled = __kmp_linear_barrier_release_cancellable(
2046 bt, this_thr, gtid, tid, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2048 switch (__kmp_barrier_release_pattern[bt]) {
2050 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2051 __kmp_dist_barrier_release(bt, this_thr, gtid, tid,
2052 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2055 case bp_hyper_bar: {
2056 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2057 __kmp_hyper_barrier_release(bt, this_thr, gtid, tid,
2058 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2061 case bp_hierarchical_bar: {
2062 __kmp_hierarchical_barrier_release(
2063 bt, this_thr, gtid, tid, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2067 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2068 __kmp_tree_barrier_release(bt, this_thr, gtid, tid,
2069 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2073 __kmp_linear_barrier_release(bt, this_thr, gtid, tid,
2074 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
2078 if (__kmp_tasking_mode != tskm_immediate_exec && !cancelled) {
2079 __kmp_task_team_sync(this_thr, team);
2087 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2088 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2092 if (__kmp_tasking_mode != tskm_immediate_exec) {
2093 if (this_thr->th.th_task_team != NULL) {
2095 void *itt_sync_obj = NULL;
2096 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2097 itt_sync_obj = __kmp_itt_barrier_object(gtid, bt, 1);
2098 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
2103 this_thr->th.th_task_team->tt.tt_found_proxy_tasks == TRUE ||
2104 this_thr->th.th_task_team->tt.tt_hidden_helper_task_encountered ==
2106 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
2107 __kmp_task_team_setup(this_thr, team);
2110 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2111 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2116 KA_TRACE(15, (
"__kmp_barrier: T#%d(%d:%d) is leaving with return value %d\n",
2117 gtid, __kmp_team_from_gtid(gtid)->t.t_id,
2118 __kmp_tid_from_gtid(gtid), status));
2121 if (ompt_enabled.enabled) {
2123 if (ompt_enabled.ompt_callback_sync_region_wait) {
2124 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2125 barrier_kind, ompt_scope_end, my_parallel_data, my_task_data,
2128 if (ompt_enabled.ompt_callback_sync_region) {
2129 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2130 barrier_kind, ompt_scope_end, my_parallel_data, my_task_data,
2134 this_thr->th.ompt_thread_info.state = ompt_state_work_parallel;
2139 return (
int)cancelled;
2144int __kmp_barrier(
enum barrier_type bt,
int gtid,
int is_split,
2145 size_t reduce_size,
void *reduce_data,
2146 void (*reduce)(
void *,
void *)) {
2147 return __kmp_barrier_template<>(bt, gtid, is_split, reduce_size, reduce_data,
2151#if defined(KMP_GOMP_COMPAT)
2153int __kmp_barrier_gomp_cancel(
int gtid) {
2154 if (__kmp_omp_cancellation) {
2155 int cancelled = __kmp_barrier_template<true>(bs_plain_barrier, gtid, FALSE,
2158 int tid = __kmp_tid_from_gtid(gtid);
2159 kmp_info_t *this_thr = __kmp_threads[gtid];
2160 if (KMP_MASTER_TID(tid)) {
2164 this_thr->th.th_bar[bs_plain_barrier].bb.b_arrived -=
2165 KMP_BARRIER_STATE_BUMP;
2170 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
2175void __kmp_end_split_barrier(
enum barrier_type bt,
int gtid) {
2176 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_end_split_barrier);
2177 KMP_SET_THREAD_STATE_BLOCK(PLAIN_BARRIER);
2178 KMP_DEBUG_ASSERT(bt < bs_last_barrier);
2179 int tid = __kmp_tid_from_gtid(gtid);
2180 kmp_info_t *this_thr = __kmp_threads[gtid];
2181 kmp_team_t *team = this_thr->th.th_team;
2183 if (!team->t.t_serialized) {
2184 if (KMP_MASTER_GTID(gtid)) {
2185 switch (__kmp_barrier_release_pattern[bt]) {
2187 __kmp_dist_barrier_release(bt, this_thr, gtid, tid,
2188 FALSE USE_ITT_BUILD_ARG(NULL));
2191 case bp_hyper_bar: {
2192 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2193 __kmp_hyper_barrier_release(bt, this_thr, gtid, tid,
2194 FALSE USE_ITT_BUILD_ARG(NULL));
2197 case bp_hierarchical_bar: {
2198 __kmp_hierarchical_barrier_release(bt, this_thr, gtid, tid,
2199 FALSE USE_ITT_BUILD_ARG(NULL));
2203 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
2204 __kmp_tree_barrier_release(bt, this_thr, gtid, tid,
2205 FALSE USE_ITT_BUILD_ARG(NULL));
2209 __kmp_linear_barrier_release(bt, this_thr, gtid, tid,
2210 FALSE USE_ITT_BUILD_ARG(NULL));
2213 if (__kmp_tasking_mode != tskm_immediate_exec) {
2214 __kmp_task_team_sync(this_thr, team);
2220void __kmp_join_barrier(
int gtid) {
2221 KMP_TIME_PARTITIONED_BLOCK(OMP_join_barrier);
2222 KMP_SET_THREAD_STATE_BLOCK(FORK_JOIN_BARRIER);
2224 KMP_DEBUG_ASSERT(__kmp_threads && __kmp_threads[gtid]);
2226 kmp_info_t *this_thr = __kmp_threads[gtid];
2233 void *itt_sync_obj = NULL;
2235 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2237 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
2240#if ((USE_ITT_BUILD && USE_ITT_NOTIFY) || defined KMP_DEBUG)
2241 int nproc = this_thr->th.th_team_nproc;
2246 team = this_thr->th.th_team;
2247 KMP_DEBUG_ASSERT(nproc == team->t.t_nproc);
2248 tid = __kmp_tid_from_gtid(gtid);
2250 team_id = team->t.t_id;
2251 kmp_info_t *master_thread = this_thr->th.th_team_master;
2252 if (master_thread != team->t.t_threads[0]) {
2253 __kmp_print_structure();
2256 KMP_DEBUG_ASSERT(master_thread == team->t.t_threads[0]);
2260 KMP_DEBUG_ASSERT(TCR_PTR(this_thr->th.th_team));
2261 KMP_DEBUG_ASSERT(TCR_PTR(this_thr->th.th_root));
2262 KMP_DEBUG_ASSERT(this_thr == team->t.t_threads[tid]);
2263 KA_TRACE(10, (
"__kmp_join_barrier: T#%d(%d:%d) arrived at join barrier\n",
2264 gtid, team_id, tid));
2267 if (ompt_enabled.enabled) {
2269 ompt_data_t *my_task_data;
2270 ompt_data_t *my_parallel_data;
2271 void *codeptr = NULL;
2272 int ds_tid = this_thr->th.th_info.ds.ds_tid;
2273 if (KMP_MASTER_TID(ds_tid) &&
2274 (ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait) ||
2275 ompt_callbacks.ompt_callback(ompt_callback_sync_region)))
2276 codeptr = team->t.ompt_team_info.master_return_address;
2277 my_task_data = OMPT_CUR_TASK_DATA(this_thr);
2278 my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
2279 ompt_sync_region_t sync_kind = ompt_sync_region_barrier_implicit_parallel;
2280 ompt_state_t ompt_state = ompt_state_wait_barrier_implicit_parallel;
2281 if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league) {
2282 sync_kind = ompt_sync_region_barrier_teams;
2283 ompt_state = ompt_state_wait_barrier_teams;
2285 if (ompt_enabled.ompt_callback_sync_region) {
2286 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2287 sync_kind, ompt_scope_begin, my_parallel_data, my_task_data, codeptr);
2289 if (ompt_enabled.ompt_callback_sync_region_wait) {
2290 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2291 sync_kind, ompt_scope_begin, my_parallel_data, my_task_data, codeptr);
2293 if (!KMP_MASTER_TID(ds_tid))
2294 this_thr->th.ompt_thread_info.task_data = *OMPT_CUR_TASK_DATA(this_thr);
2296 this_thr->th.ompt_thread_info.state = ompt_state;
2300 if (__kmp_tasking_mode == tskm_extra_barrier) {
2301 __kmp_tasking_barrier(team, this_thr, gtid);
2302 KA_TRACE(10, (
"__kmp_join_barrier: T#%d(%d:%d) past tasking barrier\n",
2303 gtid, team_id, tid));
2306 if (__kmp_tasking_mode != tskm_immediate_exec) {
2307 KA_TRACE(20, (
"__kmp_join_barrier: T#%d, old team = %d, old task_team = "
2308 "%p, th_task_team = %p\n",
2309 __kmp_gtid_from_thread(this_thr), team_id,
2310 team->t.t_task_team[this_thr->th.th_task_state],
2311 this_thr->th.th_task_team));
2312 KMP_DEBUG_ASSERT_TASKTEAM_INVARIANT(team, this_thr);
2321 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
2323 this_thr->th.th_team_bt_intervals =
2324 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
2325 this_thr->th.th_team_bt_set =
2326 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
2328 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid);
2333 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2334 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
2337 switch (__kmp_barrier_gather_pattern[bs_forkjoin_barrier]) {
2339 __kmp_dist_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2340 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2343 case bp_hyper_bar: {
2344 __kmp_hyper_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2345 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2348 case bp_hierarchical_bar: {
2349 __kmp_hierarchical_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2350 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2354 __kmp_tree_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2355 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2359 __kmp_linear_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
2360 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
2368 if (KMP_MASTER_TID(tid)) {
2369 if (__kmp_tasking_mode != tskm_immediate_exec) {
2370 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
2372 if (__kmp_display_affinity) {
2373 KMP_CHECK_UPDATE(team->t.t_display_affinity, 0);
2375#if KMP_STATS_ENABLED
2379 for (
int i = 0; i < team->t.t_nproc; ++i) {
2380 kmp_info_t *team_thread = team->t.t_threads[i];
2381 if (team_thread == this_thr)
2383 team_thread->th.th_stats->setIdleFlag();
2384 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME &&
2385 team_thread->th.th_sleep_loc != NULL)
2386 __kmp_null_resume_wrapper(team_thread);
2390 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2391 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2394#if USE_ITT_BUILD && USE_ITT_NOTIFY
2396 if ((__itt_frame_submit_v3_ptr || KMP_ITT_DEBUG) &&
2397 __kmp_forkjoin_frames_mode &&
2398 (this_thr->th.th_teams_microtask == NULL ||
2399 this_thr->th.th_teams_size.nteams == 1) &&
2400 team->t.t_active_level == 1) {
2401 kmp_uint64 cur_time = __itt_get_timestamp();
2402 ident_t *loc = team->t.t_ident;
2403 kmp_info_t **other_threads = team->t.t_threads;
2404 switch (__kmp_forkjoin_frames_mode) {
2406 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
2410 __kmp_itt_frame_submit(gtid, this_thr->th.th_bar_min_time, cur_time, 1,
2414 if (__itt_metadata_add_ptr) {
2416 kmp_uint64 delta = cur_time - this_thr->th.th_bar_arrive_time;
2419 this_thr->th.th_bar_arrive_time = 0;
2420 for (
int i = 1; i < nproc; ++i) {
2421 delta += (cur_time - other_threads[i]->th.th_bar_arrive_time);
2422 other_threads[i]->th.th_bar_arrive_time = 0;
2424 __kmp_itt_metadata_imbalance(gtid, this_thr->th.th_frame_time,
2425 cur_time, delta, 0);
2427 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
2429 this_thr->th.th_frame_time = cur_time;
2437 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
2438 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2443 if (KMP_MASTER_TID(tid)) {
2446 (
"__kmp_join_barrier: T#%d(%d:%d) says all %d team threads arrived\n",
2447 gtid, team_id, tid, nproc));
2454 (
"__kmp_join_barrier: T#%d(%d:%d) leaving\n", gtid, team_id, tid));
2460void __kmp_fork_barrier(
int gtid,
int tid) {
2461 KMP_TIME_PARTITIONED_BLOCK(OMP_fork_barrier);
2462 KMP_SET_THREAD_STATE_BLOCK(FORK_JOIN_BARRIER);
2463 kmp_info_t *this_thr = __kmp_threads[gtid];
2464 kmp_team_t *team = (tid == 0) ? this_thr->th.th_team : NULL;
2466 void *itt_sync_obj = NULL;
2470 KA_TRACE(10, (
"__kmp_fork_barrier: T#%d(%d:%d) has arrived\n", gtid,
2471 (team != NULL) ? team->t.t_id : -1, tid));
2474 if (KMP_MASTER_TID(tid)) {
2475#if USE_ITT_BUILD && USE_ITT_NOTIFY
2476 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2478 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 1);
2479 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
2484 KMP_DEBUG_ASSERT(team);
2485 kmp_info_t **other_threads = team->t.t_threads;
2491 for (i = 1; i < team->t.t_nproc; ++i) {
2493 (
"__kmp_fork_barrier: T#%d(%d:0) checking T#%d(%d:%d) fork go "
2495 gtid, team->t.t_id, other_threads[i]->th.th_info.ds.ds_gtid,
2496 team->t.t_id, other_threads[i]->th.th_info.ds.ds_tid,
2497 other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go));
2499 (TCR_4(other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go) &
2500 ~(KMP_BARRIER_SLEEP_STATE)) == KMP_INIT_BARRIER_STATE);
2501 KMP_DEBUG_ASSERT(other_threads[i]->th.th_team == team);
2505 if (__kmp_tasking_mode != tskm_immediate_exec)
2506 __kmp_task_team_setup(this_thr, team);
2514 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
2516 this_thr->th.th_team_bt_intervals =
2517 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
2518 this_thr->th.th_team_bt_set =
2519 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
2521 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid);
2526 switch (__kmp_barrier_release_pattern[bs_forkjoin_barrier]) {
2528 __kmp_dist_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2529 TRUE USE_ITT_BUILD_ARG(NULL));
2532 case bp_hyper_bar: {
2533 KMP_ASSERT(__kmp_barrier_release_branch_bits[bs_forkjoin_barrier]);
2534 __kmp_hyper_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2535 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
2538 case bp_hierarchical_bar: {
2539 __kmp_hierarchical_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2540 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
2544 KMP_ASSERT(__kmp_barrier_release_branch_bits[bs_forkjoin_barrier]);
2545 __kmp_tree_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2546 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
2550 __kmp_linear_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
2551 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
2556 ompt_state_t ompt_state = this_thr->th.ompt_thread_info.state;
2557 if (ompt_enabled.enabled &&
2558 (ompt_state == ompt_state_wait_barrier_teams ||
2559 ompt_state == ompt_state_wait_barrier_implicit_parallel)) {
2560 int ds_tid = this_thr->th.th_info.ds.ds_tid;
2561 ompt_data_t *task_data = (team)
2562 ? OMPT_CUR_TASK_DATA(this_thr)
2563 : &(this_thr->th.ompt_thread_info.task_data);
2564 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
2566 void *codeptr = NULL;
2567 if (KMP_MASTER_TID(ds_tid) &&
2568 (ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait) ||
2569 ompt_callbacks.ompt_callback(ompt_callback_sync_region)))
2570 codeptr = team ? team->t.ompt_team_info.master_return_address : NULL;
2571 ompt_sync_region_t sync_kind = ompt_sync_region_barrier_implicit_parallel;
2572 if (this_thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league)
2573 sync_kind = ompt_sync_region_barrier_teams;
2574 if (ompt_enabled.ompt_callback_sync_region_wait) {
2575 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2576 sync_kind, ompt_scope_end, NULL, task_data, codeptr);
2578 if (ompt_enabled.ompt_callback_sync_region) {
2579 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2580 sync_kind, ompt_scope_end, NULL, task_data, codeptr);
2583 if (!KMP_MASTER_TID(ds_tid) && ompt_enabled.ompt_callback_implicit_task) {
2584 ompt_callbacks.ompt_callback(ompt_callback_implicit_task)(
2585 ompt_scope_end, NULL, task_data, 0, ds_tid,
2586 ompt_task_implicit);
2592 if (TCR_4(__kmp_global.g.g_done)) {
2593 this_thr->th.th_task_team = NULL;
2595#if USE_ITT_BUILD && USE_ITT_NOTIFY
2596 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2597 if (!KMP_MASTER_TID(tid)) {
2598 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
2600 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2604 KA_TRACE(10, (
"__kmp_fork_barrier: T#%d is leaving early\n", gtid));
2612 team = (kmp_team_t *)TCR_PTR(this_thr->th.th_team);
2613 KMP_DEBUG_ASSERT(team != NULL);
2614 tid = __kmp_tid_from_gtid(gtid);
2616#if KMP_BARRIER_ICV_PULL
2624 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy);
2625 if (!KMP_MASTER_TID(tid)) {
2629 (
"__kmp_fork_barrier: T#%d(%d) is PULLing ICVs\n", gtid, tid));
2630 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team,
2632 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
2633 &team->t.t_threads[0]
2634 ->th.th_bar[bs_forkjoin_barrier]
2640 if (__kmp_tasking_mode != tskm_immediate_exec) {
2641 __kmp_task_team_sync(this_thr, team);
2644#if KMP_AFFINITY_SUPPORTED
2645 kmp_proc_bind_t proc_bind = team->t.t_proc_bind;
2646 if (proc_bind == proc_bind_intel) {
2648 if (__kmp_affinity.type == affinity_balanced && team->t.t_size_changed) {
2649 __kmp_balanced_affinity(this_thr, team->t.t_nproc);
2651 }
else if (proc_bind != proc_bind_false) {
2652 if (this_thr->th.th_new_place == this_thr->th.th_current_place) {
2653 KA_TRACE(100, (
"__kmp_fork_barrier: T#%d already in correct place %d\n",
2654 __kmp_gtid_from_thread(this_thr),
2655 this_thr->th.th_current_place));
2657 __kmp_affinity_bind_place(gtid);
2662 if (__kmp_display_affinity) {
2663 if (team->t.t_display_affinity
2664#
if KMP_AFFINITY_SUPPORTED
2665 || (__kmp_affinity.type == affinity_balanced && team->t.t_size_changed)
2669 __kmp_aux_display_affinity(gtid, NULL);
2670 this_thr->th.th_prev_num_threads = team->t.t_nproc;
2671 this_thr->th.th_prev_level = team->t.t_level;
2674 if (!KMP_MASTER_TID(tid))
2675 KMP_CHECK_UPDATE(this_thr->th.th_def_allocator, team->t.t_def_allocator);
2677#if USE_ITT_BUILD && USE_ITT_NOTIFY
2678 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2679 if (!KMP_MASTER_TID(tid)) {
2681 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
2682 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2686 KA_TRACE(10, (
"__kmp_fork_barrier: T#%d(%d:%d) is leaving\n", gtid,
2687 team->t.t_id, tid));
2690void __kmp_setup_icv_copy(kmp_team_t *team,
int new_nproc,
2691 kmp_internal_control_t *new_icvs,
ident_t *loc) {
2692 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_setup_icv_copy);
2694 KMP_DEBUG_ASSERT(team && new_nproc && new_icvs);
2695 KMP_DEBUG_ASSERT((!TCR_4(__kmp_init_parallel)) || new_icvs->nproc);
2700#if KMP_BARRIER_ICV_PULL
2704 KMP_DEBUG_ASSERT(team->t.t_threads[0]);
2707 &team->t.t_threads[0]->th.th_bar[bs_forkjoin_barrier].bb.th_fixed_icvs,
2709 KF_TRACE(10, (
"__kmp_setup_icv_copy: PULL: T#%d this_thread=%p team=%p\n", 0,
2710 team->t.t_threads[0], team));
2711#elif KMP_BARRIER_ICV_PUSH
2714 KF_TRACE(10, (
"__kmp_setup_icv_copy: PUSH: T#%d this_thread=%p team=%p\n", 0,
2715 team->t.t_threads[0], team));
2720 KMP_DEBUG_ASSERT(team->t.t_threads[0]);
2722 for (
int f = 1; f < new_nproc; ++f) {
2724 KF_TRACE(10, (
"__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n",
2725 f, team->t.t_threads[f], team));
2726 __kmp_init_implicit_task(loc, team->t.t_threads[f], team, f, FALSE);
2727 ngo_store_icvs(&team->t.t_implicit_task_taskdata[f].td_icvs, new_icvs);
2728 KF_TRACE(10, (
"__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n",
2729 f, team->t.t_threads[f], team));