14 #include "kmp_wait_release.h" 17 #include "kmp_stats.h" 18 #include "ompt-specific.h" 21 #include <immintrin.h> 22 #define USE_NGO_STORES 1 25 #include "tsan_annotations.h" 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) 40 void __kmp_print_structure(
void);
45 template <
bool cancellable = false>
46 static bool __kmp_linear_barrier_gather_template(
47 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
48 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
49 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_linear_gather);
50 kmp_team_t *team = this_thr->th.th_team;
51 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
52 kmp_info_t **other_threads = team->t.t_threads;
56 (
"__kmp_linear_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",
57 gtid, team->t.t_id, tid, bt));
58 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
60 #if USE_ITT_BUILD && USE_ITT_NOTIFY 62 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
63 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
64 __itt_get_timestamp();
69 if (!KMP_MASTER_TID(tid)) {
71 (
"__kmp_linear_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d)" 72 "arrived(%p): %llu => %llu\n",
73 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(0, team),
74 team->t.t_id, 0, &thr_bar->b_arrived, thr_bar->b_arrived,
75 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
80 ANNOTATE_BARRIER_BEGIN(this_thr);
81 kmp_flag_64 flag(&thr_bar->b_arrived, other_threads[0]);
84 kmp_balign_team_t *team_bar = &team->t.t_bar[bt];
85 int nproc = this_thr->th.th_team_nproc;
88 kmp_uint64 new_state = team_bar->b_arrived + KMP_BARRIER_STATE_BUMP;
91 for (i = 1; i < nproc; ++i) {
95 KMP_CACHE_PREFETCH(&other_threads[i + 1]->th.th_bar[bt].bb.b_arrived);
97 KA_TRACE(20, (
"__kmp_linear_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%d) " 98 "arrived(%p) == %llu\n",
99 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(i, team),
101 &other_threads[i]->th.th_bar[bt].bb.b_arrived, new_state));
104 kmp_flag_64 flag(&other_threads[i]->th.th_bar[bt].bb.b_arrived,
107 bool cancelled = flag.wait_cancellable_nosleep(
108 this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
112 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
114 ANNOTATE_BARRIER_END(other_threads[i]);
115 #if USE_ITT_BUILD && USE_ITT_NOTIFY 118 if (__kmp_forkjoin_frames_mode == 2) {
119 this_thr->th.th_bar_min_time = KMP_MIN(
120 this_thr->th.th_bar_min_time, other_threads[i]->th.th_bar_min_time);
125 (
"__kmp_linear_barrier_gather: T#%d(%d:%d) += T#%d(%d:%d)\n",
126 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(i, team),
128 ANNOTATE_REDUCE_AFTER(reduce);
129 OMPT_REDUCTION_DECL(this_thr, gtid);
130 OMPT_REDUCTION_BEGIN;
131 (*reduce)(this_thr->th.th_local.reduce_data,
132 other_threads[i]->th.th_local.reduce_data);
134 ANNOTATE_REDUCE_BEFORE(reduce);
135 ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
139 team_bar->b_arrived = new_state;
140 KA_TRACE(20, (
"__kmp_linear_barrier_gather: T#%d(%d:%d) set team %d " 141 "arrived(%p) = %llu\n",
142 gtid, team->t.t_id, tid, team->t.t_id, &team_bar->b_arrived,
147 (
"__kmp_linear_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",
148 gtid, team->t.t_id, tid, bt));
152 template <
bool cancellable = false>
153 static bool __kmp_linear_barrier_release_template(
154 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
155 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
156 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_linear_release);
157 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
160 if (KMP_MASTER_TID(tid)) {
162 kmp_uint32 nproc = this_thr->th.th_team_nproc;
163 kmp_info_t **other_threads;
165 team = __kmp_threads[gtid]->th.th_team;
166 KMP_DEBUG_ASSERT(team != NULL);
167 other_threads = team->t.t_threads;
169 KA_TRACE(20, (
"__kmp_linear_barrier_release: T#%d(%d:%d) master enter for " 171 gtid, team->t.t_id, tid, bt));
174 #if KMP_BARRIER_ICV_PUSH 176 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy);
177 if (propagate_icvs) {
178 ngo_load(&team->t.t_implicit_task_taskdata[0].td_icvs);
179 for (i = 1; i < nproc; ++i) {
180 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[i],
182 ngo_store_icvs(&team->t.t_implicit_task_taskdata[i].td_icvs,
183 &team->t.t_implicit_task_taskdata[0].td_icvs);
188 #endif // KMP_BARRIER_ICV_PUSH 191 for (i = 1; i < nproc; ++i) {
195 KMP_CACHE_PREFETCH(&other_threads[i + 1]->th.th_bar[bt].bb.b_go);
199 (
"__kmp_linear_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%d) " 200 "go(%p): %u => %u\n",
201 gtid, team->t.t_id, tid, other_threads[i]->th.th_info.ds.ds_gtid,
202 team->t.t_id, i, &other_threads[i]->th.th_bar[bt].bb.b_go,
203 other_threads[i]->th.th_bar[bt].bb.b_go,
204 other_threads[i]->th.th_bar[bt].bb.b_go + KMP_BARRIER_STATE_BUMP));
205 ANNOTATE_BARRIER_BEGIN(other_threads[i]);
206 kmp_flag_64 flag(&other_threads[i]->th.th_bar[bt].bb.b_go,
212 KA_TRACE(20, (
"__kmp_linear_barrier_release: T#%d wait go(%p) == %u\n",
213 gtid, &thr_bar->b_go, KMP_BARRIER_STATE_BUMP));
214 kmp_flag_64 flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
216 bool cancelled = flag.wait_cancellable_nosleep(
217 this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
222 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
224 ANNOTATE_BARRIER_END(this_thr);
225 #if USE_ITT_BUILD && USE_ITT_NOTIFY 226 if ((__itt_sync_create_ptr && itt_sync_obj == NULL) || KMP_ITT_DEBUG) {
229 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
231 __kmp_itt_task_starting(itt_sync_obj);
233 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
236 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
237 if (itt_sync_obj != NULL)
239 __kmp_itt_task_finished(itt_sync_obj);
243 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
247 tid = __kmp_tid_from_gtid(gtid);
248 team = __kmp_threads[gtid]->th.th_team;
250 KMP_DEBUG_ASSERT(team != NULL);
251 TCW_4(thr_bar->b_go, KMP_INIT_BARRIER_STATE);
253 (
"__kmp_linear_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",
254 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
259 (
"__kmp_linear_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",
260 gtid, team->t.t_id, tid, bt));
264 static void __kmp_linear_barrier_gather(
265 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
266 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
267 __kmp_linear_barrier_gather_template<false>(
268 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
271 static bool __kmp_linear_barrier_gather_cancellable(
272 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
273 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
274 return __kmp_linear_barrier_gather_template<true>(
275 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
278 static void __kmp_linear_barrier_release(
279 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
280 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
281 __kmp_linear_barrier_release_template<false>(
282 bt, this_thr, gtid, tid, propagate_icvs USE_ITT_BUILD_ARG(itt_sync_obj));
285 static bool __kmp_linear_barrier_release_cancellable(
286 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
287 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
288 return __kmp_linear_barrier_release_template<true>(
289 bt, this_thr, gtid, tid, propagate_icvs USE_ITT_BUILD_ARG(itt_sync_obj));
294 __kmp_tree_barrier_gather(
enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
295 int tid,
void (*reduce)(
void *,
void *)
296 USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
297 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_tree_gather);
298 kmp_team_t *team = this_thr->th.th_team;
299 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
300 kmp_info_t **other_threads = team->t.t_threads;
301 kmp_uint32 nproc = this_thr->th.th_team_nproc;
302 kmp_uint32 branch_bits = __kmp_barrier_gather_branch_bits[bt];
303 kmp_uint32 branch_factor = 1 << branch_bits;
305 kmp_uint32 child_tid;
306 kmp_uint64 new_state;
309 20, (
"__kmp_tree_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",
310 gtid, team->t.t_id, tid, bt));
311 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
313 #if USE_ITT_BUILD && USE_ITT_NOTIFY 315 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
316 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
317 __itt_get_timestamp();
322 child_tid = (tid << branch_bits) + 1;
323 if (child_tid < nproc) {
325 new_state = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
328 kmp_info_t *child_thr = other_threads[child_tid];
329 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
332 if (child + 1 <= branch_factor && child_tid + 1 < nproc)
334 &other_threads[child_tid + 1]->th.th_bar[bt].bb.b_arrived);
337 (
"__kmp_tree_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) " 338 "arrived(%p) == %llu\n",
339 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
340 team->t.t_id, child_tid, &child_bar->b_arrived, new_state));
342 kmp_flag_64 flag(&child_bar->b_arrived, new_state);
343 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
344 ANNOTATE_BARRIER_END(child_thr);
345 #if USE_ITT_BUILD && USE_ITT_NOTIFY 348 if (__kmp_forkjoin_frames_mode == 2) {
349 this_thr->th.th_bar_min_time = KMP_MIN(this_thr->th.th_bar_min_time,
350 child_thr->th.th_bar_min_time);
355 (
"__kmp_tree_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n",
356 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
357 team->t.t_id, child_tid));
358 ANNOTATE_REDUCE_AFTER(reduce);
359 OMPT_REDUCTION_DECL(this_thr, gtid);
360 OMPT_REDUCTION_BEGIN;
361 (*reduce)(this_thr->th.th_local.reduce_data,
362 child_thr->th.th_local.reduce_data);
364 ANNOTATE_REDUCE_BEFORE(reduce);
365 ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
369 }
while (child <= branch_factor && child_tid < nproc);
372 if (!KMP_MASTER_TID(tid)) {
373 kmp_int32 parent_tid = (tid - 1) >> branch_bits;
376 (
"__kmp_tree_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) " 377 "arrived(%p): %llu => %llu\n",
378 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(parent_tid, team),
379 team->t.t_id, parent_tid, &thr_bar->b_arrived, thr_bar->b_arrived,
380 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
386 ANNOTATE_BARRIER_BEGIN(this_thr);
387 kmp_flag_64 flag(&thr_bar->b_arrived, other_threads[parent_tid]);
392 team->t.t_bar[bt].b_arrived = new_state;
394 team->t.t_bar[bt].b_arrived += KMP_BARRIER_STATE_BUMP;
395 KA_TRACE(20, (
"__kmp_tree_barrier_gather: T#%d(%d:%d) set team %d " 396 "arrived(%p) = %llu\n",
397 gtid, team->t.t_id, tid, team->t.t_id,
398 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived));
401 (
"__kmp_tree_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",
402 gtid, team->t.t_id, tid, bt));
405 static void __kmp_tree_barrier_release(
406 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
407 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
408 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_tree_release);
410 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
412 kmp_uint32 branch_bits = __kmp_barrier_release_branch_bits[bt];
413 kmp_uint32 branch_factor = 1 << branch_bits;
415 kmp_uint32 child_tid;
420 KA_TRACE(20, (
"__kmp_tree_barrier_release: T#%d wait go(%p) == %u\n", gtid,
421 &thr_bar->b_go, KMP_BARRIER_STATE_BUMP));
423 kmp_flag_64 flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
424 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
425 ANNOTATE_BARRIER_END(this_thr);
426 #if USE_ITT_BUILD && USE_ITT_NOTIFY 427 if ((__itt_sync_create_ptr && itt_sync_obj == NULL) || KMP_ITT_DEBUG) {
430 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
432 __kmp_itt_task_starting(itt_sync_obj);
434 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
437 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
438 if (itt_sync_obj != NULL)
440 __kmp_itt_task_finished(itt_sync_obj);
444 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
448 team = __kmp_threads[gtid]->th.th_team;
449 KMP_DEBUG_ASSERT(team != NULL);
450 tid = __kmp_tid_from_gtid(gtid);
452 TCW_4(thr_bar->b_go, KMP_INIT_BARRIER_STATE);
454 (
"__kmp_tree_barrier_release: T#%d(%d:%d) set go(%p) = %u\n", gtid,
455 team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
458 team = __kmp_threads[gtid]->th.th_team;
459 KMP_DEBUG_ASSERT(team != NULL);
460 KA_TRACE(20, (
"__kmp_tree_barrier_release: T#%d(%d:%d) master enter for " 462 gtid, team->t.t_id, tid, bt));
464 nproc = this_thr->th.th_team_nproc;
465 child_tid = (tid << branch_bits) + 1;
467 if (child_tid < nproc) {
468 kmp_info_t **other_threads = team->t.t_threads;
472 kmp_info_t *child_thr = other_threads[child_tid];
473 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
476 if (child + 1 <= branch_factor && child_tid + 1 < nproc)
478 &other_threads[child_tid + 1]->th.th_bar[bt].bb.b_go);
481 #if KMP_BARRIER_ICV_PUSH 483 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy);
484 if (propagate_icvs) {
485 __kmp_init_implicit_task(team->t.t_ident,
486 team->t.t_threads[child_tid], team,
488 copy_icvs(&team->t.t_implicit_task_taskdata[child_tid].td_icvs,
489 &team->t.t_implicit_task_taskdata[0].td_icvs);
492 #endif // KMP_BARRIER_ICV_PUSH 494 (
"__kmp_tree_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)" 495 "go(%p): %u => %u\n",
496 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
497 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,
498 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
500 ANNOTATE_BARRIER_BEGIN(child_thr);
501 kmp_flag_64 flag(&child_bar->b_go, child_thr);
505 }
while (child <= branch_factor && child_tid < nproc);
508 20, (
"__kmp_tree_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",
509 gtid, team->t.t_id, tid, bt));
514 __kmp_hyper_barrier_gather(
enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
515 int tid,
void (*reduce)(
void *,
void *)
516 USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
517 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hyper_gather);
518 kmp_team_t *team = this_thr->th.th_team;
519 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
520 kmp_info_t **other_threads = team->t.t_threads;
521 kmp_uint64 new_state = KMP_BARRIER_UNUSED_STATE;
522 kmp_uint32 num_threads = this_thr->th.th_team_nproc;
523 kmp_uint32 branch_bits = __kmp_barrier_gather_branch_bits[bt];
524 kmp_uint32 branch_factor = 1 << branch_bits;
530 (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",
531 gtid, team->t.t_id, tid, bt));
532 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
534 #if USE_ITT_BUILD && USE_ITT_NOTIFY 536 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
537 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
538 __itt_get_timestamp();
543 kmp_flag_64 p_flag(&thr_bar->b_arrived);
544 for (level = 0, offset = 1; offset < num_threads;
545 level += branch_bits, offset <<= branch_bits) {
547 kmp_uint32 child_tid;
549 if (((tid >> level) & (branch_factor - 1)) != 0) {
550 kmp_int32 parent_tid = tid & ~((1 << (level + branch_bits)) - 1);
554 (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) " 555 "arrived(%p): %llu => %llu\n",
556 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(parent_tid, team),
557 team->t.t_id, parent_tid, &thr_bar->b_arrived,
559 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
564 ANNOTATE_BARRIER_BEGIN(this_thr);
565 p_flag.set_waiter(other_threads[parent_tid]);
571 if (new_state == KMP_BARRIER_UNUSED_STATE)
572 new_state = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
573 for (child = 1, child_tid = tid + (1 << level);
574 child < branch_factor && child_tid < num_threads;
575 child++, child_tid += (1 << level)) {
576 kmp_info_t *child_thr = other_threads[child_tid];
577 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
579 kmp_uint32 next_child_tid = child_tid + (1 << level);
581 if (child + 1 < branch_factor && next_child_tid < num_threads)
583 &other_threads[next_child_tid]->th.th_bar[bt].bb.b_arrived);
586 (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) " 587 "arrived(%p) == %llu\n",
588 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
589 team->t.t_id, child_tid, &child_bar->b_arrived, new_state));
591 kmp_flag_64 c_flag(&child_bar->b_arrived, new_state);
592 c_flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
593 ANNOTATE_BARRIER_END(child_thr);
595 #if USE_ITT_BUILD && USE_ITT_NOTIFY 598 if (__kmp_forkjoin_frames_mode == 2) {
599 this_thr->th.th_bar_min_time = KMP_MIN(this_thr->th.th_bar_min_time,
600 child_thr->th.th_bar_min_time);
605 (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n",
606 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
607 team->t.t_id, child_tid));
608 ANNOTATE_REDUCE_AFTER(reduce);
609 OMPT_REDUCTION_DECL(this_thr, gtid);
610 OMPT_REDUCTION_BEGIN;
611 (*reduce)(this_thr->th.th_local.reduce_data,
612 child_thr->th.th_local.reduce_data);
614 ANNOTATE_REDUCE_BEFORE(reduce);
615 ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
620 if (KMP_MASTER_TID(tid)) {
622 if (new_state == KMP_BARRIER_UNUSED_STATE)
623 team->t.t_bar[bt].b_arrived += KMP_BARRIER_STATE_BUMP;
625 team->t.t_bar[bt].b_arrived = new_state;
626 KA_TRACE(20, (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) set team %d " 627 "arrived(%p) = %llu\n",
628 gtid, team->t.t_id, tid, team->t.t_id,
629 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived));
632 20, (
"__kmp_hyper_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",
633 gtid, team->t.t_id, tid, bt));
637 #define KMP_REVERSE_HYPER_BAR 638 static void __kmp_hyper_barrier_release(
639 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
640 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
641 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hyper_release);
643 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
644 kmp_info_t **other_threads;
645 kmp_uint32 num_threads;
646 kmp_uint32 branch_bits = __kmp_barrier_release_branch_bits[bt];
647 kmp_uint32 branch_factor = 1 << branch_bits;
649 kmp_uint32 child_tid;
657 if (KMP_MASTER_TID(tid)) {
658 team = __kmp_threads[gtid]->th.th_team;
659 KMP_DEBUG_ASSERT(team != NULL);
660 KA_TRACE(20, (
"__kmp_hyper_barrier_release: T#%d(%d:%d) master enter for " 662 gtid, team->t.t_id, tid, bt));
663 #if KMP_BARRIER_ICV_PUSH 664 if (propagate_icvs) {
665 copy_icvs(&thr_bar->th_fixed_icvs,
666 &team->t.t_implicit_task_taskdata[tid].td_icvs);
670 KA_TRACE(20, (
"__kmp_hyper_barrier_release: T#%d wait go(%p) == %u\n", gtid,
671 &thr_bar->b_go, KMP_BARRIER_STATE_BUMP));
673 kmp_flag_64 flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
674 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
675 ANNOTATE_BARRIER_END(this_thr);
676 #if USE_ITT_BUILD && USE_ITT_NOTIFY 677 if ((__itt_sync_create_ptr && itt_sync_obj == NULL) || KMP_ITT_DEBUG) {
679 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
681 __kmp_itt_task_starting(itt_sync_obj);
683 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
686 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
687 if (itt_sync_obj != NULL)
689 __kmp_itt_task_finished(itt_sync_obj);
693 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
697 team = __kmp_threads[gtid]->th.th_team;
698 KMP_DEBUG_ASSERT(team != NULL);
699 tid = __kmp_tid_from_gtid(gtid);
701 TCW_4(thr_bar->b_go, KMP_INIT_BARRIER_STATE);
703 (
"__kmp_hyper_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",
704 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
707 num_threads = this_thr->th.th_team_nproc;
708 other_threads = team->t.t_threads;
710 #ifdef KMP_REVERSE_HYPER_BAR 712 for (level = 0, offset = 1;
713 offset < num_threads && (((tid >> level) & (branch_factor - 1)) == 0);
714 level += branch_bits, offset <<= branch_bits)
718 for (level -= branch_bits, offset >>= branch_bits; offset != 0;
719 level -= branch_bits, offset >>= branch_bits)
722 for (level = 0, offset = 1; offset < num_threads;
723 level += branch_bits, offset <<= branch_bits)
726 #ifdef KMP_REVERSE_HYPER_BAR 729 child = num_threads >> ((level == 0) ? level : level - 1);
730 for (child = (child < branch_factor - 1) ? child : branch_factor - 1,
731 child_tid = tid + (child << level);
732 child >= 1; child--, child_tid -= (1 << level))
734 if (((tid >> level) & (branch_factor - 1)) != 0)
739 for (child = 1, child_tid = tid + (1 << level);
740 child < branch_factor && child_tid < num_threads;
741 child++, child_tid += (1 << level))
742 #endif // KMP_REVERSE_HYPER_BAR 744 if (child_tid >= num_threads)
747 kmp_info_t *child_thr = other_threads[child_tid];
748 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
750 kmp_uint32 next_child_tid = child_tid - (1 << level);
752 #ifdef KMP_REVERSE_HYPER_BAR 753 if (child - 1 >= 1 && next_child_tid < num_threads)
755 if (child + 1 < branch_factor && next_child_tid < num_threads)
756 #endif // KMP_REVERSE_HYPER_BAR 758 &other_threads[next_child_tid]->th.th_bar[bt].bb.b_go);
761 #if KMP_BARRIER_ICV_PUSH 763 copy_icvs(&child_bar->th_fixed_icvs, &thr_bar->th_fixed_icvs);
764 #endif // KMP_BARRIER_ICV_PUSH 768 (
"__kmp_hyper_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)" 769 "go(%p): %u => %u\n",
770 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
771 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,
772 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
774 ANNOTATE_BARRIER_BEGIN(child_thr);
775 kmp_flag_64 flag(&child_bar->b_go, child_thr);
780 #if KMP_BARRIER_ICV_PUSH 781 if (propagate_icvs &&
782 !KMP_MASTER_TID(tid)) {
783 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team, tid,
785 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
786 &thr_bar->th_fixed_icvs);
791 (
"__kmp_hyper_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",
792 gtid, team->t.t_id, tid, bt));
805 static bool __kmp_init_hierarchical_barrier_thread(
enum barrier_type bt,
806 kmp_bstate_t *thr_bar,
807 kmp_uint32 nproc,
int gtid,
808 int tid, kmp_team_t *team) {
810 bool uninitialized = thr_bar->team == NULL;
811 bool team_changed = team != thr_bar->team;
812 bool team_sz_changed = nproc != thr_bar->nproc;
813 bool tid_changed = tid != thr_bar->old_tid;
816 if (uninitialized || team_sz_changed) {
817 __kmp_get_hierarchy(nproc, thr_bar);
820 if (uninitialized || team_sz_changed || tid_changed) {
821 thr_bar->my_level = thr_bar->depth - 1;
822 thr_bar->parent_tid = -1;
826 while (d < thr_bar->depth) {
829 if (d == thr_bar->depth - 2) {
830 thr_bar->parent_tid = 0;
831 thr_bar->my_level = d;
833 }
else if ((rem = tid % thr_bar->skip_per_level[d + 1]) !=
836 thr_bar->parent_tid = tid - rem;
837 thr_bar->my_level = d;
843 thr_bar->offset = 7 - (tid - thr_bar->parent_tid - 1);
844 thr_bar->old_tid = tid;
845 thr_bar->wait_flag = KMP_BARRIER_NOT_WAITING;
846 thr_bar->team = team;
847 thr_bar->parent_bar =
848 &team->t.t_threads[thr_bar->parent_tid]->th.th_bar[bt].bb;
850 if (uninitialized || team_changed || tid_changed) {
851 thr_bar->team = team;
852 thr_bar->parent_bar =
853 &team->t.t_threads[thr_bar->parent_tid]->th.th_bar[bt].bb;
856 if (uninitialized || team_sz_changed || tid_changed) {
857 thr_bar->nproc = nproc;
858 thr_bar->leaf_kids = thr_bar->base_leaf_kids;
859 if (thr_bar->my_level == 0)
860 thr_bar->leaf_kids = 0;
861 if (thr_bar->leaf_kids && (kmp_uint32)tid + thr_bar->leaf_kids + 1 > nproc)
862 thr_bar->leaf_kids = nproc - tid - 1;
863 thr_bar->leaf_state = 0;
864 for (
int i = 0; i < thr_bar->leaf_kids; ++i)
865 ((
char *)&(thr_bar->leaf_state))[7 - i] = 1;
870 static void __kmp_hierarchical_barrier_gather(
871 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
872 void (*reduce)(
void *,
void *) USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
873 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hier_gather);
874 kmp_team_t *team = this_thr->th.th_team;
875 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
876 kmp_uint32 nproc = this_thr->th.th_team_nproc;
877 kmp_info_t **other_threads = team->t.t_threads;
878 kmp_uint64 new_state;
880 int level = team->t.t_level;
882 ->th.th_teams_microtask)
883 if (this_thr->th.th_teams_size.nteams > 1)
886 thr_bar->use_oncore_barrier = 1;
888 thr_bar->use_oncore_barrier = 0;
890 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) enter for " 892 gtid, team->t.t_id, tid, bt));
893 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]);
895 #if USE_ITT_BUILD && USE_ITT_NOTIFY 897 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
898 this_thr->th.th_bar_arrive_time = __itt_get_timestamp();
902 (void)__kmp_init_hierarchical_barrier_thread(bt, thr_bar, nproc, gtid, tid,
905 if (thr_bar->my_level) {
908 (kmp_uint64)team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
909 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
910 thr_bar->use_oncore_barrier) {
911 if (thr_bar->leaf_kids) {
913 kmp_uint64 leaf_state =
915 ? thr_bar->b_arrived | thr_bar->leaf_state
916 : team->t.t_bar[bt].b_arrived | thr_bar->leaf_state;
917 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) waiting " 919 gtid, team->t.t_id, tid));
920 kmp_flag_64 flag(&thr_bar->b_arrived, leaf_state);
921 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
923 ANNOTATE_REDUCE_AFTER(reduce);
924 OMPT_REDUCTION_DECL(this_thr, gtid);
925 OMPT_REDUCTION_BEGIN;
926 for (child_tid = tid + 1; child_tid <= tid + thr_bar->leaf_kids;
928 KA_TRACE(100, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += " 930 gtid, team->t.t_id, tid,
931 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
933 ANNOTATE_BARRIER_END(other_threads[child_tid]);
934 (*reduce)(this_thr->th.th_local.reduce_data,
935 other_threads[child_tid]->th.th_local.reduce_data);
938 ANNOTATE_REDUCE_BEFORE(reduce);
939 ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
942 KMP_TEST_THEN_AND64(&thr_bar->b_arrived, ~(thr_bar->leaf_state));
945 for (kmp_uint32 d = 1; d < thr_bar->my_level;
947 kmp_uint32 last = tid + thr_bar->skip_per_level[d + 1],
948 skip = thr_bar->skip_per_level[d];
951 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
952 kmp_info_t *child_thr = other_threads[child_tid];
953 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
954 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait " 956 "arrived(%p) == %llu\n",
957 gtid, team->t.t_id, tid,
958 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
959 child_tid, &child_bar->b_arrived, new_state));
960 kmp_flag_64 flag(&child_bar->b_arrived, new_state);
961 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
962 ANNOTATE_BARRIER_END(child_thr);
964 KA_TRACE(100, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += " 966 gtid, team->t.t_id, tid,
967 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
969 ANNOTATE_REDUCE_AFTER(reduce);
970 (*reduce)(this_thr->th.th_local.reduce_data,
971 child_thr->th.th_local.reduce_data);
972 ANNOTATE_REDUCE_BEFORE(reduce);
973 ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
978 for (kmp_uint32 d = 0; d < thr_bar->my_level;
980 kmp_uint32 last = tid + thr_bar->skip_per_level[d + 1],
981 skip = thr_bar->skip_per_level[d];
984 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
985 kmp_info_t *child_thr = other_threads[child_tid];
986 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
987 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait " 989 "arrived(%p) == %llu\n",
990 gtid, team->t.t_id, tid,
991 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
992 child_tid, &child_bar->b_arrived, new_state));
993 kmp_flag_64 flag(&child_bar->b_arrived, new_state);
994 flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
995 ANNOTATE_BARRIER_END(child_thr);
997 KA_TRACE(100, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += " 999 gtid, team->t.t_id, tid,
1000 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1002 ANNOTATE_REDUCE_AFTER(reduce);
1003 (*reduce)(this_thr->th.th_local.reduce_data,
1004 child_thr->th.th_local.reduce_data);
1005 ANNOTATE_REDUCE_BEFORE(reduce);
1006 ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
1014 if (!KMP_MASTER_TID(tid)) {
1015 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) releasing" 1016 " T#%d(%d:%d) arrived(%p): %llu => %llu\n",
1017 gtid, team->t.t_id, tid,
1018 __kmp_gtid_from_tid(thr_bar->parent_tid, team), team->t.t_id,
1019 thr_bar->parent_tid, &thr_bar->b_arrived, thr_bar->b_arrived,
1020 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP));
1024 if (thr_bar->my_level || __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME ||
1025 !thr_bar->use_oncore_barrier) {
1027 ANNOTATE_BARRIER_BEGIN(this_thr);
1028 kmp_flag_64 flag(&thr_bar->b_arrived, other_threads[thr_bar->parent_tid]);
1032 thr_bar->b_arrived = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP;
1033 kmp_flag_oncore flag(&thr_bar->parent_bar->b_arrived, thr_bar->offset);
1034 flag.set_waiter(other_threads[thr_bar->parent_tid]);
1038 team->t.t_bar[bt].b_arrived = new_state;
1039 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) set team %d " 1040 "arrived(%p) = %llu\n",
1041 gtid, team->t.t_id, tid, team->t.t_id,
1042 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived));
1045 KA_TRACE(20, (
"__kmp_hierarchical_barrier_gather: T#%d(%d:%d) exit for " 1046 "barrier type %d\n",
1047 gtid, team->t.t_id, tid, bt));
1050 static void __kmp_hierarchical_barrier_release(
1051 enum barrier_type bt, kmp_info_t *this_thr,
int gtid,
int tid,
1052 int propagate_icvs USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
1053 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hier_release);
1055 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
1057 bool team_change =
false;
1059 if (KMP_MASTER_TID(tid)) {
1060 team = __kmp_threads[gtid]->th.th_team;
1061 KMP_DEBUG_ASSERT(team != NULL);
1062 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) master " 1063 "entered barrier type %d\n",
1064 gtid, team->t.t_id, tid, bt));
1067 if (!thr_bar->use_oncore_barrier ||
1068 __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME || thr_bar->my_level != 0 ||
1069 thr_bar->team == NULL) {
1071 thr_bar->wait_flag = KMP_BARRIER_OWN_FLAG;
1072 kmp_flag_64 flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP);
1073 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
1074 ANNOTATE_BARRIER_END(this_thr);
1075 TCW_8(thr_bar->b_go,
1076 KMP_INIT_BARRIER_STATE);
1080 thr_bar->wait_flag = KMP_BARRIER_PARENT_FLAG;
1081 kmp_flag_oncore flag(&thr_bar->parent_bar->b_go, KMP_BARRIER_STATE_BUMP,
1082 thr_bar->offset, bt,
1083 this_thr USE_ITT_BUILD_ARG(itt_sync_obj));
1084 flag.wait(this_thr, TRUE);
1085 if (thr_bar->wait_flag ==
1086 KMP_BARRIER_SWITCHING) {
1087 TCW_8(thr_bar->b_go,
1088 KMP_INIT_BARRIER_STATE);
1090 (RCAST(
volatile char *,
1091 &(thr_bar->parent_bar->b_go)))[thr_bar->offset] = 0;
1094 thr_bar->wait_flag = KMP_BARRIER_NOT_WAITING;
1096 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done))
1099 team = __kmp_threads[gtid]->th.th_team;
1100 KMP_DEBUG_ASSERT(team != NULL);
1101 tid = __kmp_tid_from_gtid(gtid);
1105 (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",
1106 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE));
1110 nproc = this_thr->th.th_team_nproc;
1111 int level = team->t.t_level;
1112 if (team->t.t_threads[0]
1113 ->th.th_teams_microtask) {
1114 if (team->t.t_pkfn != (microtask_t)__kmp_teams_master &&
1115 this_thr->th.th_teams_level == level)
1117 if (this_thr->th.th_teams_size.nteams > 1)
1121 thr_bar->use_oncore_barrier = 1;
1123 thr_bar->use_oncore_barrier = 0;
1127 unsigned short int old_leaf_kids = thr_bar->leaf_kids;
1128 kmp_uint64 old_leaf_state = thr_bar->leaf_state;
1129 team_change = __kmp_init_hierarchical_barrier_thread(bt, thr_bar, nproc, gtid,
1135 #if KMP_BARRIER_ICV_PUSH 1136 if (propagate_icvs) {
1137 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team, tid,
1141 copy_icvs(&thr_bar->th_fixed_icvs,
1142 &team->t.t_implicit_task_taskdata[tid].td_icvs);
1143 }
else if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
1144 thr_bar->use_oncore_barrier) {
1145 if (!thr_bar->my_level)
1148 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1149 &thr_bar->parent_bar->th_fixed_icvs);
1152 if (thr_bar->my_level)
1154 copy_icvs(&thr_bar->th_fixed_icvs, &thr_bar->parent_bar->th_fixed_icvs);
1156 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1157 &thr_bar->parent_bar->th_fixed_icvs);
1160 #endif // KMP_BARRIER_ICV_PUSH 1163 if (thr_bar->my_level) {
1164 kmp_int32 child_tid;
1166 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
1167 thr_bar->use_oncore_barrier) {
1168 if (KMP_MASTER_TID(tid)) {
1171 thr_bar->b_go = KMP_BARRIER_STATE_BUMP;
1174 ngo_load(&thr_bar->th_fixed_icvs);
1177 for (child_tid = thr_bar->skip_per_level[1]; child_tid < (
int)nproc;
1178 child_tid += thr_bar->skip_per_level[1]) {
1179 kmp_bstate_t *child_bar =
1180 &team->t.t_threads[child_tid]->th.th_bar[bt].bb;
1181 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) " 1182 "releasing T#%d(%d:%d)" 1183 " go(%p): %u => %u\n",
1184 gtid, team->t.t_id, tid,
1185 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1186 child_tid, &child_bar->b_go, child_bar->b_go,
1187 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1190 ngo_store_go(&child_bar->th_fixed_icvs, &thr_bar->th_fixed_icvs);
1194 TCW_8(thr_bar->b_go,
1195 KMP_INIT_BARRIER_STATE);
1197 if (thr_bar->leaf_kids) {
1200 old_leaf_kids < thr_bar->leaf_kids) {
1201 if (old_leaf_kids) {
1202 thr_bar->b_go |= old_leaf_state;
1205 last = tid + thr_bar->skip_per_level[1];
1208 for (child_tid = tid + 1 + old_leaf_kids; child_tid < (int)last;
1210 kmp_info_t *child_thr = team->t.t_threads[child_tid];
1211 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1214 (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) releasing" 1215 " T#%d(%d:%d) go(%p): %u => %u\n",
1216 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),
1217 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,
1218 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1220 ANNOTATE_BARRIER_BEGIN(child_thr);
1221 kmp_flag_64 flag(&child_bar->b_go, child_thr);
1226 thr_bar->b_go |= thr_bar->leaf_state;
1230 for (
int d = thr_bar->my_level - 1; d >= 0;
1232 last = tid + thr_bar->skip_per_level[d + 1];
1233 kmp_uint32 skip = thr_bar->skip_per_level[d];
1236 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
1237 kmp_info_t *child_thr = team->t.t_threads[child_tid];
1238 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1239 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) " 1240 "releasing T#%d(%d:%d) go(%p): %u => %u\n",
1241 gtid, team->t.t_id, tid,
1242 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
1243 child_tid, &child_bar->b_go, child_bar->b_go,
1244 child_bar->b_go + KMP_BARRIER_STATE_BUMP));
1246 ANNOTATE_BARRIER_BEGIN(child_thr);
1247 kmp_flag_64 flag(&child_bar->b_go, child_thr);
1252 #if KMP_BARRIER_ICV_PUSH 1253 if (propagate_icvs && !KMP_MASTER_TID(tid))
1255 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1256 &thr_bar->th_fixed_icvs);
1257 #endif // KMP_BARRIER_ICV_PUSH 1259 KA_TRACE(20, (
"__kmp_hierarchical_barrier_release: T#%d(%d:%d) exit for " 1260 "barrier type %d\n",
1261 gtid, team->t.t_id, tid, bt));
1269 template <
bool cancellable>
struct is_cancellable {};
1270 template <>
struct is_cancellable<true> {
1272 is_cancellable() : value(false) {}
1273 is_cancellable(
bool b) : value(b) {}
1274 is_cancellable &operator=(
bool b) {
1278 operator bool()
const {
return value; }
1280 template <>
struct is_cancellable<false> {
1281 is_cancellable &operator=(
bool b) {
return *
this; }
1282 constexpr
operator bool()
const {
return false; }
1293 template <
bool cancellable = false>
1294 static int __kmp_barrier_template(
enum barrier_type bt,
int gtid,
int is_split,
1295 size_t reduce_size,
void *reduce_data,
1296 void (*reduce)(
void *,
void *)) {
1297 KMP_TIME_PARTITIONED_BLOCK(OMP_plain_barrier);
1298 KMP_SET_THREAD_STATE_BLOCK(PLAIN_BARRIER);
1299 int tid = __kmp_tid_from_gtid(gtid);
1300 kmp_info_t *this_thr = __kmp_threads[gtid];
1301 kmp_team_t *team = this_thr->th.th_team;
1303 is_cancellable<cancellable> cancelled;
1304 #if OMPT_SUPPORT && OMPT_OPTIONAL 1305 ompt_data_t *my_task_data;
1306 ompt_data_t *my_parallel_data;
1307 void *return_address;
1308 ompt_sync_region_t barrier_kind;
1311 KA_TRACE(15, (
"__kmp_barrier: T#%d(%d:%d) has arrived\n", gtid,
1312 __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid(gtid)));
1314 ANNOTATE_BARRIER_BEGIN(&team->t.t_bar);
1316 if (ompt_enabled.enabled) {
1318 my_task_data = OMPT_CUR_TASK_DATA(this_thr);
1319 my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
1320 return_address = OMPT_LOAD_RETURN_ADDRESS(gtid);
1321 barrier_kind = __ompt_get_barrier_kind(bt, this_thr);
1322 if (ompt_enabled.ompt_callback_sync_region) {
1323 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
1324 barrier_kind, ompt_scope_begin, my_parallel_data, my_task_data,
1327 if (ompt_enabled.ompt_callback_sync_region_wait) {
1328 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
1329 barrier_kind, ompt_scope_begin, my_parallel_data, my_task_data,
1336 this_thr->th.ompt_thread_info.state = ompt_state_wait_barrier;
1340 if (!team->t.t_serialized) {
1343 void *itt_sync_obj = NULL;
1345 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1346 itt_sync_obj = __kmp_itt_barrier_object(gtid, bt, 1);
1349 if (__kmp_tasking_mode == tskm_extra_barrier) {
1350 __kmp_tasking_barrier(team, this_thr, gtid);
1352 (
"__kmp_barrier: T#%d(%d:%d) past tasking barrier\n", gtid,
1353 __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid(gtid)));
1360 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
1362 this_thr->th.th_team_bt_intervals =
1363 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
1364 this_thr->th.th_team_bt_set =
1365 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
1367 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid);
1372 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1373 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
1377 if (KMP_MASTER_TID(tid)) {
1378 team->t.t_bar[bt].b_master_arrived += 1;
1380 this_thr->th.th_bar[bt].bb.b_worker_arrived += 1;
1383 if (reduce != NULL) {
1385 this_thr->th.th_local.reduce_data = reduce_data;
1388 if (KMP_MASTER_TID(tid) && __kmp_tasking_mode != tskm_immediate_exec)
1390 __kmp_task_team_setup(this_thr, team, 0);
1393 cancelled = __kmp_linear_barrier_gather_cancellable(
1394 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1396 switch (__kmp_barrier_gather_pattern[bt]) {
1397 case bp_hyper_bar: {
1399 KMP_ASSERT(__kmp_barrier_gather_branch_bits[bt]);
1400 __kmp_hyper_barrier_gather(bt, this_thr, gtid, tid,
1401 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1404 case bp_hierarchical_bar: {
1405 __kmp_hierarchical_barrier_gather(
1406 bt, this_thr, gtid, tid, reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1411 KMP_ASSERT(__kmp_barrier_gather_branch_bits[bt]);
1412 __kmp_tree_barrier_gather(bt, this_thr, gtid, tid,
1413 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1417 __kmp_linear_barrier_gather(bt, this_thr, gtid, tid,
1418 reduce USE_ITT_BUILD_ARG(itt_sync_obj));
1425 if (KMP_MASTER_TID(tid)) {
1427 if (__kmp_tasking_mode != tskm_immediate_exec && !cancelled) {
1428 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
1433 team->t.t_bar[bt].b_team_arrived += 1;
1436 if (__kmp_omp_cancellation) {
1437 kmp_int32 cancel_request = KMP_ATOMIC_LD_RLX(&team->t.t_cancel_request);
1439 if (cancel_request == cancel_loop ||
1440 cancel_request == cancel_sections) {
1441 KMP_ATOMIC_ST_RLX(&team->t.t_cancel_request, cancel_noreq);
1449 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1450 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
1452 #if USE_ITT_BUILD && USE_ITT_NOTIFY 1454 if ((__itt_frame_submit_v3_ptr || KMP_ITT_DEBUG) &&
1455 __kmp_forkjoin_frames_mode &&
1456 this_thr->th.th_teams_microtask == NULL &&
1457 team->t.t_active_level == 1) {
1458 ident_t *loc = __kmp_threads[gtid]->th.th_ident;
1459 kmp_uint64 cur_time = __itt_get_timestamp();
1460 kmp_info_t **other_threads = team->t.t_threads;
1461 int nproc = this_thr->th.th_team_nproc;
1463 switch (__kmp_forkjoin_frames_mode) {
1465 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
1467 this_thr->th.th_frame_time = cur_time;
1471 __kmp_itt_frame_submit(gtid, this_thr->th.th_bar_min_time, cur_time,
1475 if (__itt_metadata_add_ptr) {
1477 kmp_uint64 delta = cur_time - this_thr->th.th_bar_arrive_time;
1480 this_thr->th.th_bar_arrive_time = 0;
1481 for (i = 1; i < nproc; ++i) {
1482 delta += (cur_time - other_threads[i]->th.th_bar_arrive_time);
1483 other_threads[i]->th.th_bar_arrive_time = 0;
1485 __kmp_itt_metadata_imbalance(gtid, this_thr->th.th_frame_time,
1487 (kmp_uint64)(reduce != NULL));
1489 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
1491 this_thr->th.th_frame_time = cur_time;
1499 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1500 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
1503 if ((status == 1 || !is_split) && !cancelled) {
1505 cancelled = __kmp_linear_barrier_release_cancellable(
1506 bt, this_thr, gtid, tid, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1508 switch (__kmp_barrier_release_pattern[bt]) {
1509 case bp_hyper_bar: {
1510 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
1511 __kmp_hyper_barrier_release(bt, this_thr, gtid, tid,
1512 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1515 case bp_hierarchical_bar: {
1516 __kmp_hierarchical_barrier_release(
1517 bt, this_thr, gtid, tid, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1521 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
1522 __kmp_tree_barrier_release(bt, this_thr, gtid, tid,
1523 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1527 __kmp_linear_barrier_release(bt, this_thr, gtid, tid,
1528 FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
1532 if (__kmp_tasking_mode != tskm_immediate_exec && !cancelled) {
1533 __kmp_task_team_sync(this_thr, team);
1541 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1542 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
1546 if (__kmp_tasking_mode != tskm_immediate_exec) {
1547 if (this_thr->th.th_task_team != NULL) {
1549 void *itt_sync_obj = NULL;
1550 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
1551 itt_sync_obj = __kmp_itt_barrier_object(gtid, bt, 1);
1552 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
1556 KMP_DEBUG_ASSERT(this_thr->th.th_task_team->tt.tt_found_proxy_tasks ==
1558 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
1559 __kmp_task_team_setup(this_thr, team, 0);
1562 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1563 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
1568 KA_TRACE(15, (
"__kmp_barrier: T#%d(%d:%d) is leaving with return value %d\n",
1569 gtid, __kmp_team_from_gtid(gtid)->t.t_id,
1570 __kmp_tid_from_gtid(gtid), status));
1573 if (ompt_enabled.enabled) {
1575 if (ompt_enabled.ompt_callback_sync_region_wait) {
1576 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
1577 barrier_kind, ompt_scope_end, my_parallel_data, my_task_data,
1580 if (ompt_enabled.ompt_callback_sync_region) {
1581 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
1582 barrier_kind, ompt_scope_end, my_parallel_data, my_task_data,
1586 this_thr->th.ompt_thread_info.state = ompt_state_work_parallel;
1589 ANNOTATE_BARRIER_END(&team->t.t_bar);
1592 return (
int)cancelled;
1597 int __kmp_barrier(
enum barrier_type bt,
int gtid,
int is_split,
1598 size_t reduce_size,
void *reduce_data,
1599 void (*reduce)(
void *,
void *)) {
1600 return __kmp_barrier_template<>(bt, gtid, is_split, reduce_size, reduce_data,
1604 #if defined(KMP_GOMP_COMPAT) 1606 int __kmp_barrier_gomp_cancel(
int gtid) {
1607 if (__kmp_omp_cancellation) {
1608 int cancelled = __kmp_barrier_template<true>(bs_plain_barrier, gtid, FALSE,
1611 int tid = __kmp_tid_from_gtid(gtid);
1612 kmp_info_t *this_thr = __kmp_threads[gtid];
1613 if (KMP_MASTER_TID(tid)) {
1617 this_thr->th.th_bar[bs_plain_barrier].bb.b_arrived -=
1618 KMP_BARRIER_STATE_BUMP;
1623 __kmp_barrier(bs_plain_barrier, gtid, FALSE, 0, NULL, NULL);
1628 void __kmp_end_split_barrier(
enum barrier_type bt,
int gtid) {
1629 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_end_split_barrier);
1630 KMP_SET_THREAD_STATE_BLOCK(PLAIN_BARRIER);
1631 int tid = __kmp_tid_from_gtid(gtid);
1632 kmp_info_t *this_thr = __kmp_threads[gtid];
1633 kmp_team_t *team = this_thr->th.th_team;
1635 ANNOTATE_BARRIER_BEGIN(&team->t.t_bar);
1636 if (!team->t.t_serialized) {
1637 if (KMP_MASTER_GTID(gtid)) {
1638 switch (__kmp_barrier_release_pattern[bt]) {
1639 case bp_hyper_bar: {
1640 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
1641 __kmp_hyper_barrier_release(bt, this_thr, gtid, tid,
1642 FALSE USE_ITT_BUILD_ARG(NULL));
1645 case bp_hierarchical_bar: {
1646 __kmp_hierarchical_barrier_release(bt, this_thr, gtid, tid,
1647 FALSE USE_ITT_BUILD_ARG(NULL));
1651 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt]);
1652 __kmp_tree_barrier_release(bt, this_thr, gtid, tid,
1653 FALSE USE_ITT_BUILD_ARG(NULL));
1657 __kmp_linear_barrier_release(bt, this_thr, gtid, tid,
1658 FALSE USE_ITT_BUILD_ARG(NULL));
1661 if (__kmp_tasking_mode != tskm_immediate_exec) {
1662 __kmp_task_team_sync(this_thr, team);
1666 ANNOTATE_BARRIER_END(&team->t.t_bar);
1669 void __kmp_join_barrier(
int gtid) {
1670 KMP_TIME_PARTITIONED_BLOCK(OMP_join_barrier);
1671 KMP_SET_THREAD_STATE_BLOCK(FORK_JOIN_BARRIER);
1672 kmp_info_t *this_thr = __kmp_threads[gtid];
1675 kmp_info_t *master_thread;
1681 void *itt_sync_obj = NULL;
1683 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1685 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
1691 team = this_thr->th.th_team;
1692 nproc = this_thr->th.th_team_nproc;
1693 KMP_DEBUG_ASSERT((
int)nproc == team->t.t_nproc);
1694 tid = __kmp_tid_from_gtid(gtid);
1696 team_id = team->t.t_id;
1698 master_thread = this_thr->th.th_team_master;
1700 if (master_thread != team->t.t_threads[0]) {
1701 __kmp_print_structure();
1704 KMP_DEBUG_ASSERT(master_thread == team->t.t_threads[0]);
1708 KMP_DEBUG_ASSERT(__kmp_threads && __kmp_threads[gtid]);
1709 KMP_DEBUG_ASSERT(TCR_PTR(this_thr->th.th_team));
1710 KMP_DEBUG_ASSERT(TCR_PTR(this_thr->th.th_root));
1711 KMP_DEBUG_ASSERT(this_thr == team->t.t_threads[tid]);
1712 KA_TRACE(10, (
"__kmp_join_barrier: T#%d(%d:%d) arrived at join barrier\n",
1713 gtid, team_id, tid));
1715 ANNOTATE_BARRIER_BEGIN(&team->t.t_bar);
1717 if (ompt_enabled.enabled) {
1719 ompt_data_t *my_task_data;
1720 ompt_data_t *my_parallel_data;
1721 void *codeptr = NULL;
1722 int ds_tid = this_thr->th.th_info.ds.ds_tid;
1723 if (KMP_MASTER_TID(ds_tid) &&
1724 (ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait) ||
1725 ompt_callbacks.ompt_callback(ompt_callback_sync_region)))
1726 codeptr = team->t.ompt_team_info.master_return_address;
1727 my_task_data = OMPT_CUR_TASK_DATA(this_thr);
1728 my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr);
1729 if (ompt_enabled.ompt_callback_sync_region) {
1730 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
1731 ompt_sync_region_barrier_implicit, ompt_scope_begin, my_parallel_data,
1732 my_task_data, codeptr);
1734 if (ompt_enabled.ompt_callback_sync_region_wait) {
1735 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
1736 ompt_sync_region_barrier_implicit, ompt_scope_begin, my_parallel_data,
1737 my_task_data, codeptr);
1739 if (!KMP_MASTER_TID(ds_tid))
1740 this_thr->th.ompt_thread_info.task_data = *OMPT_CUR_TASK_DATA(this_thr);
1742 this_thr->th.ompt_thread_info.state = ompt_state_wait_barrier_implicit;
1746 if (__kmp_tasking_mode == tskm_extra_barrier) {
1747 __kmp_tasking_barrier(team, this_thr, gtid);
1748 KA_TRACE(10, (
"__kmp_join_barrier: T#%d(%d:%d) past taking barrier\n", gtid,
1752 if (__kmp_tasking_mode != tskm_immediate_exec) {
1753 KA_TRACE(20, (
"__kmp_join_barrier: T#%d, old team = %d, old task_team = " 1754 "%p, th_task_team = %p\n",
1755 __kmp_gtid_from_thread(this_thr), team_id,
1756 team->t.t_task_team[this_thr->th.th_task_state],
1757 this_thr->th.th_task_team));
1758 KMP_DEBUG_ASSERT(this_thr->th.th_task_team ==
1759 team->t.t_task_team[this_thr->th.th_task_state]);
1768 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
1770 this_thr->th.th_team_bt_intervals =
1771 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
1772 this_thr->th.th_team_bt_set =
1773 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
1775 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid);
1780 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1781 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
1784 switch (__kmp_barrier_gather_pattern[bs_forkjoin_barrier]) {
1785 case bp_hyper_bar: {
1786 KMP_ASSERT(__kmp_barrier_gather_branch_bits[bs_forkjoin_barrier]);
1787 __kmp_hyper_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
1788 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
1791 case bp_hierarchical_bar: {
1792 __kmp_hierarchical_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
1793 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
1797 KMP_ASSERT(__kmp_barrier_gather_branch_bits[bs_forkjoin_barrier]);
1798 __kmp_tree_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
1799 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
1803 __kmp_linear_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
1804 NULL USE_ITT_BUILD_ARG(itt_sync_obj));
1812 if (KMP_MASTER_TID(tid)) {
1813 if (__kmp_tasking_mode != tskm_immediate_exec) {
1814 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj));
1816 if (__kmp_display_affinity) {
1817 KMP_CHECK_UPDATE(team->t.t_display_affinity, 0);
1819 #if KMP_STATS_ENABLED 1823 for (
int i = 0; i < team->t.t_nproc; ++i) {
1824 kmp_info_t *team_thread = team->t.t_threads[i];
1825 if (team_thread == this_thr)
1827 team_thread->th.th_stats->setIdleFlag();
1828 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME &&
1829 team_thread->th.th_sleep_loc != NULL)
1830 __kmp_null_resume_wrapper(__kmp_gtid_from_thread(team_thread),
1831 team_thread->th.th_sleep_loc);
1835 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1836 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
1839 #if USE_ITT_BUILD && USE_ITT_NOTIFY 1841 if ((__itt_frame_submit_v3_ptr || KMP_ITT_DEBUG) &&
1842 __kmp_forkjoin_frames_mode && this_thr->th.th_teams_microtask == NULL &&
1843 team->t.t_active_level == 1) {
1844 kmp_uint64 cur_time = __itt_get_timestamp();
1845 ident_t *loc = team->t.t_ident;
1846 kmp_info_t **other_threads = team->t.t_threads;
1847 int nproc = this_thr->th.th_team_nproc;
1849 switch (__kmp_forkjoin_frames_mode) {
1851 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
1855 __kmp_itt_frame_submit(gtid, this_thr->th.th_bar_min_time, cur_time, 1,
1859 if (__itt_metadata_add_ptr) {
1861 kmp_uint64 delta = cur_time - this_thr->th.th_bar_arrive_time;
1864 this_thr->th.th_bar_arrive_time = 0;
1865 for (i = 1; i < nproc; ++i) {
1866 delta += (cur_time - other_threads[i]->th.th_bar_arrive_time);
1867 other_threads[i]->th.th_bar_arrive_time = 0;
1869 __kmp_itt_metadata_imbalance(gtid, this_thr->th.th_frame_time,
1870 cur_time, delta, 0);
1872 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
1874 this_thr->th.th_frame_time = cur_time;
1882 if (__itt_sync_create_ptr || KMP_ITT_DEBUG)
1883 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
1888 if (KMP_MASTER_TID(tid)) {
1891 (
"__kmp_join_barrier: T#%d(%d:%d) says all %d team threads arrived\n",
1892 gtid, team_id, tid, nproc));
1899 (
"__kmp_join_barrier: T#%d(%d:%d) leaving\n", gtid, team_id, tid));
1901 ANNOTATE_BARRIER_END(&team->t.t_bar);
1906 void __kmp_fork_barrier(
int gtid,
int tid) {
1907 KMP_TIME_PARTITIONED_BLOCK(OMP_fork_barrier);
1908 KMP_SET_THREAD_STATE_BLOCK(FORK_JOIN_BARRIER);
1909 kmp_info_t *this_thr = __kmp_threads[gtid];
1910 kmp_team_t *team = (tid == 0) ? this_thr->th.th_team : NULL;
1912 void *itt_sync_obj = NULL;
1915 ANNOTATE_BARRIER_END(&team->t.t_bar);
1917 KA_TRACE(10, (
"__kmp_fork_barrier: T#%d(%d:%d) has arrived\n", gtid,
1918 (team != NULL) ? team->t.t_id : -1, tid));
1921 if (KMP_MASTER_TID(tid)) {
1922 #if USE_ITT_BUILD && USE_ITT_NOTIFY 1923 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
1925 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 1);
1926 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
1931 kmp_info_t **other_threads = team->t.t_threads;
1937 for (i = 1; i < team->t.t_nproc; ++i) {
1939 (
"__kmp_fork_barrier: T#%d(%d:0) checking T#%d(%d:%d) fork go " 1941 gtid, team->t.t_id, other_threads[i]->th.th_info.ds.ds_gtid,
1942 team->t.t_id, other_threads[i]->th.th_info.ds.ds_tid,
1943 other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go));
1945 (TCR_4(other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go) &
1946 ~(KMP_BARRIER_SLEEP_STATE)) == KMP_INIT_BARRIER_STATE);
1947 KMP_DEBUG_ASSERT(other_threads[i]->th.th_team == team);
1951 if (__kmp_tasking_mode != tskm_immediate_exec) {
1953 __kmp_task_team_setup(this_thr, team, 0);
1962 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
1964 this_thr->th.th_team_bt_intervals =
1965 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
1966 this_thr->th.th_team_bt_set =
1967 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
1969 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid);
1974 switch (__kmp_barrier_release_pattern[bs_forkjoin_barrier]) {
1975 case bp_hyper_bar: {
1976 KMP_ASSERT(__kmp_barrier_release_branch_bits[bs_forkjoin_barrier]);
1977 __kmp_hyper_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
1978 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
1981 case bp_hierarchical_bar: {
1982 __kmp_hierarchical_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
1983 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
1987 KMP_ASSERT(__kmp_barrier_release_branch_bits[bs_forkjoin_barrier]);
1988 __kmp_tree_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
1989 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
1993 __kmp_linear_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
1994 TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
1999 if (ompt_enabled.enabled &&
2000 this_thr->th.ompt_thread_info.state == ompt_state_wait_barrier_implicit) {
2001 int ds_tid = this_thr->th.th_info.ds.ds_tid;
2002 ompt_data_t *task_data = (team)
2003 ? OMPT_CUR_TASK_DATA(this_thr)
2004 : &(this_thr->th.ompt_thread_info.task_data);
2005 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
2007 void *codeptr = NULL;
2008 if (KMP_MASTER_TID(ds_tid) &&
2009 (ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait) ||
2010 ompt_callbacks.ompt_callback(ompt_callback_sync_region)))
2011 codeptr = team->t.ompt_team_info.master_return_address;
2012 if (ompt_enabled.ompt_callback_sync_region_wait) {
2013 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2014 ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, task_data,
2017 if (ompt_enabled.ompt_callback_sync_region) {
2018 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2019 ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, task_data,
2023 if (!KMP_MASTER_TID(ds_tid) && ompt_enabled.ompt_callback_implicit_task) {
2024 ompt_callbacks.ompt_callback(ompt_callback_implicit_task)(
2025 ompt_scope_end, NULL, task_data, 0, ds_tid, ompt_task_implicit);
2031 if (TCR_4(__kmp_global.g.g_done)) {
2032 this_thr->th.th_task_team = NULL;
2034 #if USE_ITT_BUILD && USE_ITT_NOTIFY 2035 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2036 if (!KMP_MASTER_TID(tid)) {
2037 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
2039 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2043 KA_TRACE(10, (
"__kmp_fork_barrier: T#%d is leaving early\n", gtid));
2051 team = (kmp_team_t *)TCR_PTR(this_thr->th.th_team);
2052 KMP_DEBUG_ASSERT(team != NULL);
2053 tid = __kmp_tid_from_gtid(gtid);
2055 #if KMP_BARRIER_ICV_PULL 2063 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy);
2064 if (!KMP_MASTER_TID(tid)) {
2068 (
"__kmp_fork_barrier: T#%d(%d) is PULLing ICVs\n", gtid, tid));
2069 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team,
2071 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
2072 &team->t.t_threads[0]
2073 ->th.th_bar[bs_forkjoin_barrier]
2077 #endif // KMP_BARRIER_ICV_PULL 2079 if (__kmp_tasking_mode != tskm_immediate_exec) {
2080 __kmp_task_team_sync(this_thr, team);
2083 #if KMP_AFFINITY_SUPPORTED 2084 kmp_proc_bind_t proc_bind = team->t.t_proc_bind;
2085 if (proc_bind == proc_bind_intel) {
2087 if (__kmp_affinity_type == affinity_balanced && team->t.t_size_changed) {
2088 __kmp_balanced_affinity(this_thr, team->t.t_nproc);
2090 }
else if (proc_bind != proc_bind_false) {
2091 if (this_thr->th.th_new_place == this_thr->th.th_current_place) {
2092 KA_TRACE(100, (
"__kmp_fork_barrier: T#%d already in correct place %d\n",
2093 __kmp_gtid_from_thread(this_thr),
2094 this_thr->th.th_current_place));
2096 __kmp_affinity_set_place(gtid);
2099 #endif // KMP_AFFINITY_SUPPORTED 2101 if (__kmp_display_affinity) {
2102 if (team->t.t_display_affinity
2103 #
if KMP_AFFINITY_SUPPORTED
2104 || (__kmp_affinity_type == affinity_balanced && team->t.t_size_changed)
2108 __kmp_aux_display_affinity(gtid, NULL);
2109 this_thr->th.th_prev_num_threads = team->t.t_nproc;
2110 this_thr->th.th_prev_level = team->t.t_level;
2113 if (!KMP_MASTER_TID(tid))
2114 KMP_CHECK_UPDATE(this_thr->th.th_def_allocator, team->t.t_def_allocator);
2116 #if USE_ITT_BUILD && USE_ITT_NOTIFY 2117 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2118 if (!KMP_MASTER_TID(tid)) {
2120 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
2121 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
2125 ANNOTATE_BARRIER_END(&team->t.t_bar);
2126 KA_TRACE(10, (
"__kmp_fork_barrier: T#%d(%d:%d) is leaving\n", gtid,
2127 team->t.t_id, tid));
2130 void __kmp_setup_icv_copy(kmp_team_t *team,
int new_nproc,
2131 kmp_internal_control_t *new_icvs,
ident_t *loc) {
2132 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_setup_icv_copy);
2134 KMP_DEBUG_ASSERT(team && new_nproc && new_icvs);
2135 KMP_DEBUG_ASSERT((!TCR_4(__kmp_init_parallel)) || new_icvs->nproc);
2140 #if KMP_BARRIER_ICV_PULL 2144 KMP_DEBUG_ASSERT(team->t.t_threads[0]);
2147 &team->t.t_threads[0]->th.th_bar[bs_forkjoin_barrier].bb.th_fixed_icvs,
2149 KF_TRACE(10, (
"__kmp_setup_icv_copy: PULL: T#%d this_thread=%p team=%p\n", 0,
2150 team->t.t_threads[0], team));
2151 #elif KMP_BARRIER_ICV_PUSH 2154 KF_TRACE(10, (
"__kmp_setup_icv_copy: PUSH: T#%d this_thread=%p team=%p\n", 0,
2155 team->t.t_threads[0], team));
2160 KMP_DEBUG_ASSERT(team->t.t_threads[0]);
2162 for (
int f = 1; f < new_nproc; ++f) {
2164 KF_TRACE(10, (
"__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n",
2165 f, team->t.t_threads[f], team));
2166 __kmp_init_implicit_task(loc, team->t.t_threads[f], team, f, FALSE);
2167 ngo_store_icvs(&team->t.t_implicit_task_taskdata[f].td_icvs, new_icvs);
2168 KF_TRACE(10, (
"__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n",
2169 f, team->t.t_threads[f], team));
2172 #endif // KMP_BARRIER_ICV_PULL