Bug Summary

File:projects/openmp/runtime/src/kmp_barrier.cpp
Warning:line 1620, column 7
Called function pointer is null (null dereference)

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name kmp_barrier.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D omp_EXPORTS -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/projects/openmp/runtime/src -I /build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn345461/include -I /build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/i18n -I /build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/include/50 -I /build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/thirdparty/ittnotify -U NDEBUG -D _GNU_SOURCE -D _REENTRANT -D _FORTIFY_SOURCE=2 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -Wno-switch -Wno-missing-field-initializers -Wno-missing-braces -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/projects/openmp/runtime/src -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fno-rtti -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-10-27-211344-32123-1 -x c++ /build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp -faddrsig

/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp

1/*
2 * kmp_barrier.cpp
3 */
4
5//===----------------------------------------------------------------------===//
6//
7// The LLVM Compiler Infrastructure
8//
9// This file is dual licensed under the MIT and the University of Illinois Open
10// Source Licenses. See LICENSE.txt for details.
11//
12//===----------------------------------------------------------------------===//
13
14#include "kmp.h"
15#include "kmp_wait_release.h"
16#include "kmp_itt.h"
17#include "kmp_os.h"
18#include "kmp_stats.h"
19#if OMPT_SUPPORT1
20#include "ompt-specific.h"
21#endif
22
23#if KMP_MIC0
24#include <immintrin.h>
25#define USE_NGO_STORES 1
26#endif // KMP_MIC
27
28#include "tsan_annotations.h"
29
30#if KMP_MIC0 && USE_NGO_STORES
31// ICV copying
32#define ngo_load(src)((void)0) __m512d Vt = _mm512_load_pd((void *)(src))
33#define ngo_store_icvs(dst, src)copy_icvs((dst), (src)) _mm512_storenrngo_pd((void *)(dst), Vt)
34#define ngo_store_go(dst, src)memcpy((dst), (src), 64) _mm512_storenrngo_pd((void *)(dst), Vt)
35#define ngo_sync()((void)0) __asm__ volatile("lock; addl $0,0(%%rsp)" ::: "memory")
36#else
37#define ngo_load(src)((void)0) ((void)0)
38#define ngo_store_icvs(dst, src)copy_icvs((dst), (src)) copy_icvs((dst), (src))
39#define ngo_store_go(dst, src)memcpy((dst), (src), 64) KMP_MEMCPYmemcpy((dst), (src), CACHE_LINE64)
40#define ngo_sync()((void)0) ((void)0)
41#endif /* KMP_MIC && USE_NGO_STORES */
42
43void __kmp_print_structure(void); // Forward declaration
44
45// ---------------------------- Barrier Algorithms ----------------------------
46
47// Linear Barrier
48static void __kmp_linear_barrier_gather(
49 enum barrier_type bt, kmp_info_t *this_thr, int gtid, int tid,
50 void (*reduce)(void *, void *) USE_ITT_BUILD_ARG(void *itt_sync_obj), void *itt_sync_obj) {
51 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_linear_gather)((void)0);
52 kmp_team_t *team = this_thr->th.th_team;
53 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
54 kmp_info_t **other_threads = team->t.t_threads;
55
56 KA_TRACE(if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
57 20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
58 ("__kmp_linear_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
59 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
;
60 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid])if (!(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid
])) { __kmp_debug_assert("this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 60); }
;
61
62#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
63 // Barrier imbalance - save arrive time to the thread
64 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
65 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
66 __itt_get_timestamp(!__kmp_itt_get_timestamp_ptr__3_0) ? 0 : __kmp_itt_get_timestamp_ptr__3_0();
67 }
68#endif
69 // We now perform a linear reduction to signal that all of the threads have
70 // arrived.
71 if (!KMP_MASTER_TID(tid)((tid) == 0)) {
72 KA_TRACE(20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d)"
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(0, team), team->t.t_id, 0, &thr_bar
->b_arrived, thr_bar->b_arrived, thr_bar->b_arrived +
(1 << 2)); }
73 ("__kmp_linear_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d)"if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d)"
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(0, team), team->t.t_id, 0, &thr_bar
->b_arrived, thr_bar->b_arrived, thr_bar->b_arrived +
(1 << 2)); }
74 "arrived(%p): %llu => %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d)"
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(0, team), team->t.t_id, 0, &thr_bar
->b_arrived, thr_bar->b_arrived, thr_bar->b_arrived +
(1 << 2)); }
75 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(0, team),if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d)"
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(0, team), team->t.t_id, 0, &thr_bar
->b_arrived, thr_bar->b_arrived, thr_bar->b_arrived +
(1 << 2)); }
76 team->t.t_id, 0, &thr_bar->b_arrived, thr_bar->b_arrived,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d)"
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(0, team), team->t.t_id, 0, &thr_bar
->b_arrived, thr_bar->b_arrived, thr_bar->b_arrived +
(1 << 2)); }
77 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d)"
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(0, team), team->t.t_id, 0, &thr_bar
->b_arrived, thr_bar->b_arrived, thr_bar->b_arrived +
(1 << 2)); }
;
78 // Mark arrival to master thread
79 /* After performing this write, a worker thread may not assume that the team
80 is valid any more - it could be deallocated by the master thread at any
81 time. */
82 ANNOTATE_BARRIER_BEGIN(this_thr);
83 kmp_flag_64 flag(&thr_bar->b_arrived, other_threads[0]);
84 flag.release();
85 } else {
86 kmp_balign_team_t *team_bar = &team->t.t_bar[bt];
87 int nproc = this_thr->th.th_team_nproc;
88 int i;
89 // Don't have to worry about sleep bit here or atomic since team setting
90 kmp_uint64 new_state = team_bar->b_arrived + KMP_BARRIER_STATE_BUMP(1 << 2);
91
92 // Collect all the worker team member threads.
93 for (i = 1; i < nproc; ++i) {
94#if KMP_CACHE_MANAGE
95 // Prefetch next thread's arrived count
96 if (i + 1 < nproc)
97 KMP_CACHE_PREFETCH(&other_threads[i + 1]->th.th_bar[bt].bb.b_arrived);
98#endif /* KMP_CACHE_MANAGE */
99 KA_TRACE(20, ("__kmp_linear_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%d) "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%d) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(i, team), team->t.t_id, i, &other_threads[i]->th.th_bar
[bt].bb.b_arrived, new_state); }
100 "arrived(%p) == %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%d) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(i, team), team->t.t_id, i, &other_threads[i]->th.th_bar
[bt].bb.b_arrived, new_state); }
101 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(i, team),if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%d) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(i, team), team->t.t_id, i, &other_threads[i]->th.th_bar
[bt].bb.b_arrived, new_state); }
102 team->t.t_id, i,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%d) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(i, team), team->t.t_id, i, &other_threads[i]->th.th_bar
[bt].bb.b_arrived, new_state); }
103 &other_threads[i]->th.th_bar[bt].bb.b_arrived, new_state))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%d) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(i, team), team->t.t_id, i, &other_threads[i]->th.th_bar
[bt].bb.b_arrived, new_state); }
;
104
105 // Wait for worker thread to arrive
106 kmp_flag_64 flag(&other_threads[i]->th.th_bar[bt].bb.b_arrived,
107 new_state);
108 flag.wait(this_thr, FALSE0 USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
109 ANNOTATE_BARRIER_END(other_threads[i]);
110#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
111 // Barrier imbalance - write min of the thread time and the other thread
112 // time to the thread.
113 if (__kmp_forkjoin_frames_mode == 2) {
114 this_thr->th.th_bar_min_time = KMP_MIN(((this_thr->th.th_bar_min_time) < (other_threads[i]->
th.th_bar_min_time) ? (this_thr->th.th_bar_min_time) : (other_threads
[i]->th.th_bar_min_time))
115 this_thr->th.th_bar_min_time, other_threads[i]->th.th_bar_min_time)((this_thr->th.th_bar_min_time) < (other_threads[i]->
th.th_bar_min_time) ? (this_thr->th.th_bar_min_time) : (other_threads
[i]->th.th_bar_min_time))
;
116 }
117#endif
118 if (reduce) {
119 KA_TRACE(100,if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) += T#%d(%d:%d)\n"
, gtid, team->t.t_id, tid, __kmp_gtid_from_tid(i, team), team
->t.t_id, i); }
120 ("__kmp_linear_barrier_gather: T#%d(%d:%d) += T#%d(%d:%d)\n",if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) += T#%d(%d:%d)\n"
, gtid, team->t.t_id, tid, __kmp_gtid_from_tid(i, team), team
->t.t_id, i); }
121 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(i, team),if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) += T#%d(%d:%d)\n"
, gtid, team->t.t_id, tid, __kmp_gtid_from_tid(i, team), team
->t.t_id, i); }
122 team->t.t_id, i))if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) += T#%d(%d:%d)\n"
, gtid, team->t.t_id, tid, __kmp_gtid_from_tid(i, team), team
->t.t_id, i); }
;
123 ANNOTATE_REDUCE_AFTER(reduce);
124 (*reduce)(this_thr->th.th_local.reduce_data,
125 other_threads[i]->th.th_local.reduce_data);
126 ANNOTATE_REDUCE_BEFORE(reduce);
127 ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
128 }
129 }
130 // Don't have to worry about sleep bit here or atomic since team setting
131 team_bar->b_arrived = new_state;
132 KA_TRACE(20, ("__kmp_linear_barrier_gather: T#%d(%d:%d) set team %d "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team_bar->b_arrived, new_state); }
133 "arrived(%p) = %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team_bar->b_arrived, new_state); }
134 gtid, team->t.t_id, tid, team->t.t_id, &team_bar->b_arrived,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team_bar->b_arrived, new_state); }
135 new_state))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team_bar->b_arrived, new_state); }
;
136 }
137 KA_TRACE(if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
138 20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
139 ("__kmp_linear_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
140 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
;
141}
142
143static void __kmp_linear_barrier_release(
144 enum barrier_type bt, kmp_info_t *this_thr, int gtid, int tid,
145 int propagate_icvs USE_ITT_BUILD_ARG(void *itt_sync_obj), void *itt_sync_obj) {
146 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_linear_release)((void)0);
147 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
148 kmp_team_t *team;
149
150 if (KMP_MASTER_TID(tid)((tid) == 0)) {
151 unsigned int i;
152 kmp_uint32 nproc = this_thr->th.th_team_nproc;
153 kmp_info_t **other_threads;
154
155 team = __kmp_threads[gtid]->th.th_team;
156 KMP_DEBUG_ASSERT(team != NULL)if (!(team != __null)) { __kmp_debug_assert("team != __null",
"/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 156); }
;
157 other_threads = team->t.t_threads;
158
159 KA_TRACE(20, ("__kmp_linear_barrier_release: T#%d(%d:%d) master enter for "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) master enter for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
160 "barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) master enter for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
161 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) master enter for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
;
162
163 if (nproc > 1) {
164#if KMP_BARRIER_ICV_PUSH1
165 {
166 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy)((void)0);
167 if (propagate_icvs) {
168 ngo_load(&team->t.t_implicit_task_taskdata[0].td_icvs)((void)0);
169 for (i = 1; i < nproc; ++i) {
170 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[i],
171 team, i, FALSE0);
172 ngo_store_icvs(&team->t.t_implicit_task_taskdata[i].td_icvs,copy_icvs((&team->t.t_implicit_task_taskdata[i].td_icvs
), (&team->t.t_implicit_task_taskdata[0].td_icvs))
173 &team->t.t_implicit_task_taskdata[0].td_icvs)copy_icvs((&team->t.t_implicit_task_taskdata[i].td_icvs
), (&team->t.t_implicit_task_taskdata[0].td_icvs))
;
174 }
175 ngo_sync()((void)0);
176 }
177 }
178#endif // KMP_BARRIER_ICV_PUSH
179
180 // Now, release all of the worker threads
181 for (i = 1; i < nproc; ++i) {
182#if KMP_CACHE_MANAGE
183 // Prefetch next thread's go flag
184 if (i + 1 < nproc)
185 KMP_CACHE_PREFETCH(&other_threads[i + 1]->th.th_bar[bt].bb.b_go);
186#endif /* KMP_CACHE_MANAGE */
187 KA_TRACE(if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%d) "
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, other_threads
[i]->th.th_info.ds.ds_gtid, team->t.t_id, i, &other_threads
[i]->th.th_bar[bt].bb.b_go, other_threads[i]->th.th_bar
[bt].bb.b_go, other_threads[i]->th.th_bar[bt].bb.b_go + (1
<< 2)); }
188 20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%d) "
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, other_threads
[i]->th.th_info.ds.ds_gtid, team->t.t_id, i, &other_threads
[i]->th.th_bar[bt].bb.b_go, other_threads[i]->th.th_bar
[bt].bb.b_go, other_threads[i]->th.th_bar[bt].bb.b_go + (1
<< 2)); }
189 ("__kmp_linear_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%d) "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%d) "
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, other_threads
[i]->th.th_info.ds.ds_gtid, team->t.t_id, i, &other_threads
[i]->th.th_bar[bt].bb.b_go, other_threads[i]->th.th_bar
[bt].bb.b_go, other_threads[i]->th.th_bar[bt].bb.b_go + (1
<< 2)); }
190 "go(%p): %u => %u\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%d) "
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, other_threads
[i]->th.th_info.ds.ds_gtid, team->t.t_id, i, &other_threads
[i]->th.th_bar[bt].bb.b_go, other_threads[i]->th.th_bar
[bt].bb.b_go, other_threads[i]->th.th_bar[bt].bb.b_go + (1
<< 2)); }
191 gtid, team->t.t_id, tid, other_threads[i]->th.th_info.ds.ds_gtid,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%d) "
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, other_threads
[i]->th.th_info.ds.ds_gtid, team->t.t_id, i, &other_threads
[i]->th.th_bar[bt].bb.b_go, other_threads[i]->th.th_bar
[bt].bb.b_go, other_threads[i]->th.th_bar[bt].bb.b_go + (1
<< 2)); }
192 team->t.t_id, i, &other_threads[i]->th.th_bar[bt].bb.b_go,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%d) "
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, other_threads
[i]->th.th_info.ds.ds_gtid, team->t.t_id, i, &other_threads
[i]->th.th_bar[bt].bb.b_go, other_threads[i]->th.th_bar
[bt].bb.b_go, other_threads[i]->th.th_bar[bt].bb.b_go + (1
<< 2)); }
193 other_threads[i]->th.th_bar[bt].bb.b_go,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%d) "
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, other_threads
[i]->th.th_info.ds.ds_gtid, team->t.t_id, i, &other_threads
[i]->th.th_bar[bt].bb.b_go, other_threads[i]->th.th_bar
[bt].bb.b_go, other_threads[i]->th.th_bar[bt].bb.b_go + (1
<< 2)); }
194 other_threads[i]->th.th_bar[bt].bb.b_go + KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%d) "
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, other_threads
[i]->th.th_info.ds.ds_gtid, team->t.t_id, i, &other_threads
[i]->th.th_bar[bt].bb.b_go, other_threads[i]->th.th_bar
[bt].bb.b_go, other_threads[i]->th.th_bar[bt].bb.b_go + (1
<< 2)); }
;
195 ANNOTATE_BARRIER_BEGIN(other_threads[i]);
196 kmp_flag_64 flag(&other_threads[i]->th.th_bar[bt].bb.b_go,
197 other_threads[i]);
198 flag.release();
199 }
200 }
201 } else { // Wait for the MASTER thread to release us
202 KA_TRACE(20, ("__kmp_linear_barrier_release: T#%d wait go(%p) == %u\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d wait go(%p) == %u\n"
, gtid, &thr_bar->b_go, (1 << 2)); }
203 gtid, &thr_bar->b_go, KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d wait go(%p) == %u\n"
, gtid, &thr_bar->b_go, (1 << 2)); }
;
204 kmp_flag_64 flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP(1 << 2));
205 flag.wait(this_thr, TRUE(!0) USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
206 ANNOTATE_BARRIER_END(this_thr);
207#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
208 if ((__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 && itt_sync_obj == NULL__null) || KMP_ITT_DEBUG0) {
209 // In a fork barrier; cannot get the object reliably (or ITTNOTIFY is
210 // disabled)
211 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
212 // Cancel wait on previous parallel region...
213 __kmp_itt_task_starting(itt_sync_obj);
214
215 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done)(__kmp_global.g.g_done))
216 return;
217
218 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
219 if (itt_sync_obj != NULL__null)
220 // Call prepare as early as possible for "new" barrier
221 __kmp_itt_task_finished(itt_sync_obj);
222 } else
223#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
224 // Early exit for reaping threads releasing forkjoin barrier
225 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done)(__kmp_global.g.g_done))
226 return;
227// The worker thread may now assume that the team is valid.
228#ifdef KMP_DEBUG1
229 tid = __kmp_tid_from_gtid(gtid);
230 team = __kmp_threads[gtid]->th.th_team;
231#endif
232 KMP_DEBUG_ASSERT(team != NULL)if (!(team != __null)) { __kmp_debug_assert("team != __null",
"/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 232); }
;
233 TCW_4(thr_bar->b_go, KMP_INIT_BARRIER_STATE)(thr_bar->b_go) = (0);
234 KA_TRACE(20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
235 ("__kmp_linear_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
236 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
;
237 KMP_MB(); // Flush all pending memory write invalidates.
238 }
239 KA_TRACE(if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
240 20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
241 ("__kmp_linear_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
242 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_linear_barrier_release: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
;
243}
244
245// Tree barrier
246static void
247__kmp_tree_barrier_gather(enum barrier_type bt, kmp_info_t *this_thr, int gtid,
248 int tid, void (*reduce)(void *, void *)
249 USE_ITT_BUILD_ARG(void *itt_sync_obj), void *itt_sync_obj) {
250 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_tree_gather)((void)0);
251 kmp_team_t *team = this_thr->th.th_team;
252 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
253 kmp_info_t **other_threads = team->t.t_threads;
254 kmp_uint32 nproc = this_thr->th.th_team_nproc;
255 kmp_uint32 branch_bits = __kmp_barrier_gather_branch_bits[bt];
256 kmp_uint32 branch_factor = 1 << branch_bits;
257 kmp_uint32 child;
258 kmp_uint32 child_tid;
259 kmp_uint64 new_state;
260
261 KA_TRACE(if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
262 20, ("__kmp_tree_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
263 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
;
264 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid])if (!(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid
])) { __kmp_debug_assert("this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 264); }
;
265
266#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
267 // Barrier imbalance - save arrive time to the thread
268 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
269 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
270 __itt_get_timestamp(!__kmp_itt_get_timestamp_ptr__3_0) ? 0 : __kmp_itt_get_timestamp_ptr__3_0();
271 }
272#endif
273 // Perform tree gather to wait until all threads have arrived; reduce any
274 // required data as we go
275 child_tid = (tid << branch_bits) + 1;
276 if (child_tid < nproc) {
277 // Parent threads wait for all their children to arrive
278 new_state = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP(1 << 2);
279 child = 1;
280 do {
281 kmp_info_t *child_thr = other_threads[child_tid];
282 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
283#if KMP_CACHE_MANAGE
284 // Prefetch next thread's arrived count
285 if (child + 1 <= branch_factor && child_tid + 1 < nproc)
286 KMP_CACHE_PREFETCH(
287 &other_threads[child_tid + 1]->th.th_bar[bt].bb.b_arrived);
288#endif /* KMP_CACHE_MANAGE */
289 KA_TRACE(20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_arrived, new_state); }
290 ("__kmp_tree_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_arrived, new_state); }
291 "arrived(%p) == %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_arrived, new_state); }
292 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_arrived, new_state); }
293 team->t.t_id, child_tid, &child_bar->b_arrived, new_state))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_arrived, new_state); }
;
294 // Wait for child to arrive
295 kmp_flag_64 flag(&child_bar->b_arrived, new_state);
296 flag.wait(this_thr, FALSE0 USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
297 ANNOTATE_BARRIER_END(child_thr);
298#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
299 // Barrier imbalance - write min of the thread time and a child time to
300 // the thread.
301 if (__kmp_forkjoin_frames_mode == 2) {
302 this_thr->th.th_bar_min_time = KMP_MIN(this_thr->th.th_bar_min_time,((this_thr->th.th_bar_min_time) < (child_thr->th.th_bar_min_time
) ? (this_thr->th.th_bar_min_time) : (child_thr->th.th_bar_min_time
))
303 child_thr->th.th_bar_min_time)((this_thr->th.th_bar_min_time) < (child_thr->th.th_bar_min_time
) ? (this_thr->th.th_bar_min_time) : (child_thr->th.th_bar_min_time
))
;
304 }
305#endif
306 if (reduce) {
307 KA_TRACE(100,if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n"
, gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team
), team->t.t_id, child_tid); }
308 ("__kmp_tree_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n",if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n"
, gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team
), team->t.t_id, child_tid); }
309 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n"
, gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team
), team->t.t_id, child_tid); }
310 team->t.t_id, child_tid))if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n"
, gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team
), team->t.t_id, child_tid); }
;
311 ANNOTATE_REDUCE_AFTER(reduce);
312 (*reduce)(this_thr->th.th_local.reduce_data,
313 child_thr->th.th_local.reduce_data);
314 ANNOTATE_REDUCE_BEFORE(reduce);
315 ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
316 }
317 child++;
318 child_tid++;
319 } while (child <= branch_factor && child_tid < nproc);
320 }
321
322 if (!KMP_MASTER_TID(tid)((tid) == 0)) { // Worker threads
323 kmp_int32 parent_tid = (tid - 1) >> branch_bits;
324
325 KA_TRACE(20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
326 ("__kmp_tree_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
327 "arrived(%p): %llu => %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
328 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(parent_tid, team),if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
329 team->t.t_id, parent_tid, &thr_bar->b_arrived, thr_bar->b_arrived,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
330 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
;
331
332 // Mark arrival to parent thread
333 /* After performing this write, a worker thread may not assume that the team
334 is valid any more - it could be deallocated by the master thread at any
335 time. */
336 ANNOTATE_BARRIER_BEGIN(this_thr);
337 kmp_flag_64 flag(&thr_bar->b_arrived, other_threads[parent_tid]);
338 flag.release();
339 } else {
340 // Need to update the team arrived pointer if we are the master thread
341 if (nproc > 1) // New value was already computed above
342 team->t.t_bar[bt].b_arrived = new_state;
343 else
344 team->t.t_bar[bt].b_arrived += KMP_BARRIER_STATE_BUMP(1 << 2);
345 KA_TRACE(20, ("__kmp_tree_barrier_gather: T#%d(%d:%d) set team %d "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team->t.t_bar[bt].b_arrived, team->t.t_bar
[bt].b_arrived); }
346 "arrived(%p) = %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team->t.t_bar[bt].b_arrived, team->t.t_bar
[bt].b_arrived); }
347 gtid, team->t.t_id, tid, team->t.t_id,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team->t.t_bar[bt].b_arrived, team->t.t_bar
[bt].b_arrived); }
348 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team->t.t_bar[bt].b_arrived, team->t.t_bar
[bt].b_arrived); }
;
349 }
350 KA_TRACE(20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
351 ("__kmp_tree_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
352 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
;
353}
354
355static void __kmp_tree_barrier_release(
356 enum barrier_type bt, kmp_info_t *this_thr, int gtid, int tid,
357 int propagate_icvs USE_ITT_BUILD_ARG(void *itt_sync_obj), void *itt_sync_obj) {
358 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_tree_release)((void)0);
359 kmp_team_t *team;
360 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
361 kmp_uint32 nproc;
362 kmp_uint32 branch_bits = __kmp_barrier_release_branch_bits[bt];
363 kmp_uint32 branch_factor = 1 << branch_bits;
364 kmp_uint32 child;
365 kmp_uint32 child_tid;
366
367 // Perform a tree release for all of the threads that have been gathered
368 if (!KMP_MASTER_TID(((tid) == 0)
369 tid)((tid) == 0)) { // Handle fork barrier workers who aren't part of a team yet
370 KA_TRACE(20, ("__kmp_tree_barrier_release: T#%d wait go(%p) == %u\n", gtid,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d wait go(%p) == %u\n"
, gtid, &thr_bar->b_go, (1 << 2)); }
371 &thr_bar->b_go, KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d wait go(%p) == %u\n"
, gtid, &thr_bar->b_go, (1 << 2)); }
;
372 // Wait for parent thread to release us
373 kmp_flag_64 flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP(1 << 2));
374 flag.wait(this_thr, TRUE(!0) USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
375 ANNOTATE_BARRIER_END(this_thr);
376#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
377 if ((__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 && itt_sync_obj == NULL__null) || KMP_ITT_DEBUG0) {
378 // In fork barrier where we could not get the object reliably (or
379 // ITTNOTIFY is disabled)
380 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
381 // Cancel wait on previous parallel region...
382 __kmp_itt_task_starting(itt_sync_obj);
383
384 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done)(__kmp_global.g.g_done))
385 return;
386
387 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
388 if (itt_sync_obj != NULL__null)
389 // Call prepare as early as possible for "new" barrier
390 __kmp_itt_task_finished(itt_sync_obj);
391 } else
392#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
393 // Early exit for reaping threads releasing forkjoin barrier
394 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done)(__kmp_global.g.g_done))
395 return;
396
397 // The worker thread may now assume that the team is valid.
398 team = __kmp_threads[gtid]->th.th_team;
399 KMP_DEBUG_ASSERT(team != NULL)if (!(team != __null)) { __kmp_debug_assert("team != __null",
"/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 399); }
;
400 tid = __kmp_tid_from_gtid(gtid);
401
402 TCW_4(thr_bar->b_go, KMP_INIT_BARRIER_STATE)(thr_bar->b_go) = (0);
403 KA_TRACE(20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
404 ("__kmp_tree_barrier_release: T#%d(%d:%d) set go(%p) = %u\n", gtid,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
405 team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
;
406 KMP_MB(); // Flush all pending memory write invalidates.
407 } else {
408 team = __kmp_threads[gtid]->th.th_team;
409 KMP_DEBUG_ASSERT(team != NULL)if (!(team != __null)) { __kmp_debug_assert("team != __null",
"/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 409); }
;
410 KA_TRACE(20, ("__kmp_tree_barrier_release: T#%d(%d:%d) master enter for "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) master enter for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
411 "barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) master enter for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
412 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) master enter for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
;
413 }
414 nproc = this_thr->th.th_team_nproc;
415 child_tid = (tid << branch_bits) + 1;
416
417 if (child_tid < nproc) {
418 kmp_info_t **other_threads = team->t.t_threads;
419 child = 1;
420 // Parent threads release all their children
421 do {
422 kmp_info_t *child_thr = other_threads[child_tid];
423 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
424#if KMP_CACHE_MANAGE
425 // Prefetch next thread's go count
426 if (child + 1 <= branch_factor && child_tid + 1 < nproc)
427 KMP_CACHE_PREFETCH(
428 &other_threads[child_tid + 1]->th.th_bar[bt].bb.b_go);
429#endif /* KMP_CACHE_MANAGE */
430
431#if KMP_BARRIER_ICV_PUSH1
432 {
433 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy)((void)0);
434 if (propagate_icvs) {
435 __kmp_init_implicit_task(team->t.t_ident,
436 team->t.t_threads[child_tid], team,
437 child_tid, FALSE0);
438 copy_icvs(&team->t.t_implicit_task_taskdata[child_tid].td_icvs,
439 &team->t.t_implicit_task_taskdata[0].td_icvs);
440 }
441 }
442#endif // KMP_BARRIER_ICV_PUSH
443 KA_TRACE(20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
444 ("__kmp_tree_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
445 "go(%p): %u => %u\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
446 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
447 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
448 child_bar->b_go + KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
;
449 // Release child from barrier
450 ANNOTATE_BARRIER_BEGIN(child_thr);
451 kmp_flag_64 flag(&child_bar->b_go, child_thr);
452 flag.release();
453 child++;
454 child_tid++;
455 } while (child <= branch_factor && child_tid < nproc);
456 }
457 KA_TRACE(if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
458 20, ("__kmp_tree_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
459 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_tree_barrier_release: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
;
460}
461
462// Hyper Barrier
463static void
464__kmp_hyper_barrier_gather(enum barrier_type bt, kmp_info_t *this_thr, int gtid,
465 int tid, void (*reduce)(void *, void *)
466 USE_ITT_BUILD_ARG(void *itt_sync_obj), void *itt_sync_obj) {
467 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hyper_gather)((void)0);
468 kmp_team_t *team = this_thr->th.th_team;
469 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
470 kmp_info_t **other_threads = team->t.t_threads;
471 kmp_uint64 new_state = KMP_BARRIER_UNUSED_STATE(1 << 1);
472 kmp_uint32 num_threads = this_thr->th.th_team_nproc;
473 kmp_uint32 branch_bits = __kmp_barrier_gather_branch_bits[bt];
474 kmp_uint32 branch_factor = 1 << branch_bits;
475 kmp_uint32 offset;
476 kmp_uint32 level;
477
478 KA_TRACE(if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
479 20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
480 ("__kmp_hyper_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
481 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) enter for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
;
482 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid])if (!(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid
])) { __kmp_debug_assert("this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 482); }
;
483
484#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
485 // Barrier imbalance - save arrive time to the thread
486 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
487 this_thr->th.th_bar_arrive_time = this_thr->th.th_bar_min_time =
488 __itt_get_timestamp(!__kmp_itt_get_timestamp_ptr__3_0) ? 0 : __kmp_itt_get_timestamp_ptr__3_0();
489 }
490#endif
491 /* Perform a hypercube-embedded tree gather to wait until all of the threads
492 have arrived, and reduce any required data as we go. */
493 kmp_flag_64 p_flag(&thr_bar->b_arrived);
494 for (level = 0, offset = 1; offset < num_threads;
495 level += branch_bits, offset <<= branch_bits) {
496 kmp_uint32 child;
497 kmp_uint32 child_tid;
498
499 if (((tid >> level) & (branch_factor - 1)) != 0) {
500 kmp_int32 parent_tid = tid & ~((1 << (level + branch_bits)) - 1);
501
502 KA_TRACE(20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
503 ("__kmp_hyper_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
504 "arrived(%p): %llu => %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
505 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(parent_tid, team),if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
506 team->t.t_id, parent_tid, &thr_bar->b_arrived,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
507 thr_bar->b_arrived,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
508 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
"arrived(%p): %llu => %llu\n", gtid, team->t.t_id, tid
, __kmp_gtid_from_tid(parent_tid, team), team->t.t_id, parent_tid
, &thr_bar->b_arrived, thr_bar->b_arrived, thr_bar->
b_arrived + (1 << 2)); }
;
509 // Mark arrival to parent thread
510 /* After performing this write (in the last iteration of the enclosing for
511 loop), a worker thread may not assume that the team is valid any more
512 - it could be deallocated by the master thread at any time. */
513 ANNOTATE_BARRIER_BEGIN(this_thr);
514 p_flag.set_waiter(other_threads[parent_tid]);
515 p_flag.release();
516 break;
517 }
518
519 // Parent threads wait for children to arrive
520 if (new_state == KMP_BARRIER_UNUSED_STATE(1 << 1))
521 new_state = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP(1 << 2);
522 for (child = 1, child_tid = tid + (1 << level);
523 child < branch_factor && child_tid < num_threads;
524 child++, child_tid += (1 << level)) {
525 kmp_info_t *child_thr = other_threads[child_tid];
526 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
527#if KMP_CACHE_MANAGE
528 kmp_uint32 next_child_tid = child_tid + (1 << level);
529 // Prefetch next thread's arrived count
530 if (child + 1 < branch_factor && next_child_tid < num_threads)
531 KMP_CACHE_PREFETCH(
532 &other_threads[next_child_tid]->th.th_bar[bt].bb.b_arrived);
533#endif /* KMP_CACHE_MANAGE */
534 KA_TRACE(20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_arrived, new_state); }
535 ("__kmp_hyper_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_arrived, new_state); }
536 "arrived(%p) == %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_arrived, new_state); }
537 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_arrived, new_state); }
538 team->t.t_id, child_tid, &child_bar->b_arrived, new_state))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) wait T#%d(%d:%u) "
"arrived(%p) == %llu\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_arrived, new_state); }
;
539 // Wait for child to arrive
540 kmp_flag_64 c_flag(&child_bar->b_arrived, new_state);
541 c_flag.wait(this_thr, FALSE0 USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
542 ANNOTATE_BARRIER_END(child_thr);
543#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
544 // Barrier imbalance - write min of the thread time and a child time to
545 // the thread.
546 if (__kmp_forkjoin_frames_mode == 2) {
547 this_thr->th.th_bar_min_time = KMP_MIN(this_thr->th.th_bar_min_time,((this_thr->th.th_bar_min_time) < (child_thr->th.th_bar_min_time
) ? (this_thr->th.th_bar_min_time) : (child_thr->th.th_bar_min_time
))
548 child_thr->th.th_bar_min_time)((this_thr->th.th_bar_min_time) < (child_thr->th.th_bar_min_time
) ? (this_thr->th.th_bar_min_time) : (child_thr->th.th_bar_min_time
))
;
549 }
550#endif
551 if (reduce) {
552 KA_TRACE(100,if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n"
, gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team
), team->t.t_id, child_tid); }
553 ("__kmp_hyper_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n",if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n"
, gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team
), team->t.t_id, child_tid); }
554 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n"
, gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team
), team->t.t_id, child_tid); }
555 team->t.t_id, child_tid))if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) += T#%d(%d:%u)\n"
, gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team
), team->t.t_id, child_tid); }
;
556 ANNOTATE_REDUCE_AFTER(reduce);
557 (*reduce)(this_thr->th.th_local.reduce_data,
558 child_thr->th.th_local.reduce_data);
559 ANNOTATE_REDUCE_BEFORE(reduce);
560 ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
561 }
562 }
563 }
564
565 if (KMP_MASTER_TID(tid)((tid) == 0)) {
566 // Need to update the team arrived pointer if we are the master thread
567 if (new_state == KMP_BARRIER_UNUSED_STATE(1 << 1))
568 team->t.t_bar[bt].b_arrived += KMP_BARRIER_STATE_BUMP(1 << 2);
569 else
570 team->t.t_bar[bt].b_arrived = new_state;
571 KA_TRACE(20, ("__kmp_hyper_barrier_gather: T#%d(%d:%d) set team %d "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team->t.t_bar[bt].b_arrived, team->t.t_bar
[bt].b_arrived); }
572 "arrived(%p) = %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team->t.t_bar[bt].b_arrived, team->t.t_bar
[bt].b_arrived); }
573 gtid, team->t.t_id, tid, team->t.t_id,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team->t.t_bar[bt].b_arrived, team->t.t_bar
[bt].b_arrived); }
574 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team->t.t_bar[bt].b_arrived, team->t.t_bar
[bt].b_arrived); }
;
575 }
576 KA_TRACE(if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
577 20, ("__kmp_hyper_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
578 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_gather: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
;
579}
580
581// The reverse versions seem to beat the forward versions overall
582#define KMP_REVERSE_HYPER_BAR
583static void __kmp_hyper_barrier_release(
584 enum barrier_type bt, kmp_info_t *this_thr, int gtid, int tid,
585 int propagate_icvs USE_ITT_BUILD_ARG(void *itt_sync_obj), void *itt_sync_obj) {
586 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hyper_release)((void)0);
587 kmp_team_t *team;
588 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
589 kmp_info_t **other_threads;
590 kmp_uint32 num_threads;
591 kmp_uint32 branch_bits = __kmp_barrier_release_branch_bits[bt];
592 kmp_uint32 branch_factor = 1 << branch_bits;
593 kmp_uint32 child;
594 kmp_uint32 child_tid;
595 kmp_uint32 offset;
596 kmp_uint32 level;
597
598 /* Perform a hypercube-embedded tree release for all of the threads that have
599 been gathered. If KMP_REVERSE_HYPER_BAR is defined (default) the threads
600 are released in the reverse order of the corresponding gather, otherwise
601 threads are released in the same order. */
602 if (KMP_MASTER_TID(tid)((tid) == 0)) { // master
603 team = __kmp_threads[gtid]->th.th_team;
604 KMP_DEBUG_ASSERT(team != NULL)if (!(team != __null)) { __kmp_debug_assert("team != __null",
"/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 604); }
;
605 KA_TRACE(20, ("__kmp_hyper_barrier_release: T#%d(%d:%d) master enter for "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) master enter for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
606 "barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) master enter for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
607 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) master enter for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
;
608#if KMP_BARRIER_ICV_PUSH1
609 if (propagate_icvs) { // master already has ICVs in final destination; copy
610 copy_icvs(&thr_bar->th_fixed_icvs,
611 &team->t.t_implicit_task_taskdata[tid].td_icvs);
612 }
613#endif
614 } else { // Handle fork barrier workers who aren't part of a team yet
615 KA_TRACE(20, ("__kmp_hyper_barrier_release: T#%d wait go(%p) == %u\n", gtid,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d wait go(%p) == %u\n"
, gtid, &thr_bar->b_go, (1 << 2)); }
616 &thr_bar->b_go, KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d wait go(%p) == %u\n"
, gtid, &thr_bar->b_go, (1 << 2)); }
;
617 // Wait for parent thread to release us
618 kmp_flag_64 flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP(1 << 2));
619 flag.wait(this_thr, TRUE(!0) USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
620 ANNOTATE_BARRIER_END(this_thr);
621#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
622 if ((__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 && itt_sync_obj == NULL__null) || KMP_ITT_DEBUG0) {
623 // In fork barrier where we could not get the object reliably
624 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 0, -1);
625 // Cancel wait on previous parallel region...
626 __kmp_itt_task_starting(itt_sync_obj);
627
628 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done)(__kmp_global.g.g_done))
629 return;
630
631 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
632 if (itt_sync_obj != NULL__null)
633 // Call prepare as early as possible for "new" barrier
634 __kmp_itt_task_finished(itt_sync_obj);
635 } else
636#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
637 // Early exit for reaping threads releasing forkjoin barrier
638 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done)(__kmp_global.g.g_done))
639 return;
640
641 // The worker thread may now assume that the team is valid.
642 team = __kmp_threads[gtid]->th.th_team;
643 KMP_DEBUG_ASSERT(team != NULL)if (!(team != __null)) { __kmp_debug_assert("team != __null",
"/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 643); }
;
644 tid = __kmp_tid_from_gtid(gtid);
645
646 TCW_4(thr_bar->b_go, KMP_INIT_BARRIER_STATE)(thr_bar->b_go) = (0);
647 KA_TRACE(20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
648 ("__kmp_hyper_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
649 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
;
650 KMP_MB(); // Flush all pending memory write invalidates.
651 }
652 num_threads = this_thr->th.th_team_nproc;
653 other_threads = team->t.t_threads;
654
655#ifdef KMP_REVERSE_HYPER_BAR
656 // Count up to correct level for parent
657 for (level = 0, offset = 1;
658 offset < num_threads && (((tid >> level) & (branch_factor - 1)) == 0);
659 level += branch_bits, offset <<= branch_bits)
660 ;
661
662 // Now go down from there
663 for (level -= branch_bits, offset >>= branch_bits; offset != 0;
664 level -= branch_bits, offset >>= branch_bits)
665#else
666 // Go down the tree, level by level
667 for (level = 0, offset = 1; offset < num_threads;
668 level += branch_bits, offset <<= branch_bits)
669#endif // KMP_REVERSE_HYPER_BAR
670 {
671#ifdef KMP_REVERSE_HYPER_BAR
672 /* Now go in reverse order through the children, highest to lowest.
673 Initial setting of child is conservative here. */
674 child = num_threads >> ((level == 0) ? level : level - 1);
675 for (child = (child < branch_factor - 1) ? child : branch_factor - 1,
676 child_tid = tid + (child << level);
677 child >= 1; child--, child_tid -= (1 << level))
678#else
679 if (((tid >> level) & (branch_factor - 1)) != 0)
680 // No need to go lower than this, since this is the level parent would be
681 // notified
682 break;
683 // Iterate through children on this level of the tree
684 for (child = 1, child_tid = tid + (1 << level);
685 child < branch_factor && child_tid < num_threads;
686 child++, child_tid += (1 << level))
687#endif // KMP_REVERSE_HYPER_BAR
688 {
689 if (child_tid >= num_threads)
690 continue; // Child doesn't exist so keep going
691 else {
692 kmp_info_t *child_thr = other_threads[child_tid];
693 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
694#if KMP_CACHE_MANAGE
695 kmp_uint32 next_child_tid = child_tid - (1 << level);
696// Prefetch next thread's go count
697#ifdef KMP_REVERSE_HYPER_BAR
698 if (child - 1 >= 1 && next_child_tid < num_threads)
699#else
700 if (child + 1 < branch_factor && next_child_tid < num_threads)
701#endif // KMP_REVERSE_HYPER_BAR
702 KMP_CACHE_PREFETCH(
703 &other_threads[next_child_tid]->th.th_bar[bt].bb.b_go);
704#endif /* KMP_CACHE_MANAGE */
705
706#if KMP_BARRIER_ICV_PUSH1
707 if (propagate_icvs) // push my fixed ICVs to my child
708 copy_icvs(&child_bar->th_fixed_icvs, &thr_bar->th_fixed_icvs);
709#endif // KMP_BARRIER_ICV_PUSH
710
711 KA_TRACE(if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
712 20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
713 ("__kmp_hyper_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
714 "go(%p): %u => %u\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
715 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
716 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
717 child_bar->b_go + KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) releasing T#%d(%d:%u)"
"go(%p): %u => %u\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid, &child_bar
->b_go, child_bar->b_go, child_bar->b_go + (1 <<
2)); }
;
718 // Release child from barrier
719 ANNOTATE_BARRIER_BEGIN(child_thr);
720 kmp_flag_64 flag(&child_bar->b_go, child_thr);
721 flag.release();
722 }
723 }
724 }
725#if KMP_BARRIER_ICV_PUSH1
726 if (propagate_icvs &&
727 !KMP_MASTER_TID(tid)((tid) == 0)) { // copy ICVs locally to final dest
728 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team, tid,
729 FALSE0);
730 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
731 &thr_bar->th_fixed_icvs);
732 }
733#endif
734 KA_TRACE(if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
735 20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
736 ("__kmp_hyper_barrier_release: T#%d(%d:%d) exit for barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
737 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hyper_barrier_release: T#%d(%d:%d) exit for barrier type %d\n"
, gtid, team->t.t_id, tid, bt); }
;
738}
739
740// Hierarchical Barrier
741
742// Initialize thread barrier data
743/* Initializes/re-initializes the hierarchical barrier data stored on a thread.
744 Performs the minimum amount of initialization required based on how the team
745 has changed. Returns true if leaf children will require both on-core and
746 traditional wake-up mechanisms. For example, if the team size increases,
747 threads already in the team will respond to on-core wakeup on their parent
748 thread, but threads newly added to the team will only be listening on the
749 their local b_go. */
750static bool __kmp_init_hierarchical_barrier_thread(enum barrier_type bt,
751 kmp_bstate_t *thr_bar,
752 kmp_uint32 nproc, int gtid,
753 int tid, kmp_team_t *team) {
754 // Checks to determine if (re-)initialization is needed
755 bool uninitialized = thr_bar->team == NULL__null;
756 bool team_changed = team != thr_bar->team;
757 bool team_sz_changed = nproc != thr_bar->nproc;
758 bool tid_changed = tid != thr_bar->old_tid;
759 bool retval = false;
760
761 if (uninitialized || team_sz_changed) {
762 __kmp_get_hierarchy(nproc, thr_bar);
763 }
764
765 if (uninitialized || team_sz_changed || tid_changed) {
766 thr_bar->my_level = thr_bar->depth - 1; // default for master
767 thr_bar->parent_tid = -1; // default for master
768 if (!KMP_MASTER_TID(((tid) == 0)
769 tid)((tid) == 0)) { // if not master, find parent thread in hierarchy
770 kmp_uint32 d = 0;
771 while (d < thr_bar->depth) { // find parent based on level of thread in
772 // hierarchy, and note level
773 kmp_uint32 rem;
774 if (d == thr_bar->depth - 2) { // reached level right below the master
775 thr_bar->parent_tid = 0;
776 thr_bar->my_level = d;
777 break;
778 } else if ((rem = tid % thr_bar->skip_per_level[d + 1]) !=
779 0) { // TODO: can we make this op faster?
780 // thread is not a subtree root at next level, so this is max
781 thr_bar->parent_tid = tid - rem;
782 thr_bar->my_level = d;
783 break;
784 }
785 ++d;
786 }
787 }
788 thr_bar->offset = 7 - (tid - thr_bar->parent_tid - 1);
789 thr_bar->old_tid = tid;
790 thr_bar->wait_flag = KMP_BARRIER_NOT_WAITING0;
791 thr_bar->team = team;
792 thr_bar->parent_bar =
793 &team->t.t_threads[thr_bar->parent_tid]->th.th_bar[bt].bb;
794 }
795 if (uninitialized || team_changed || tid_changed) {
796 thr_bar->team = team;
797 thr_bar->parent_bar =
798 &team->t.t_threads[thr_bar->parent_tid]->th.th_bar[bt].bb;
799 retval = true;
800 }
801 if (uninitialized || team_sz_changed || tid_changed) {
802 thr_bar->nproc = nproc;
803 thr_bar->leaf_kids = thr_bar->base_leaf_kids;
804 if (thr_bar->my_level == 0)
805 thr_bar->leaf_kids = 0;
806 if (thr_bar->leaf_kids && (kmp_uint32)tid + thr_bar->leaf_kids + 1 > nproc)
807 thr_bar->leaf_kids = nproc - tid - 1;
808 thr_bar->leaf_state = 0;
809 for (int i = 0; i < thr_bar->leaf_kids; ++i)
810 ((char *)&(thr_bar->leaf_state))[7 - i] = 1;
811 }
812 return retval;
813}
814
815static void __kmp_hierarchical_barrier_gather(
816 enum barrier_type bt, kmp_info_t *this_thr, int gtid, int tid,
817 void (*reduce)(void *, void *) USE_ITT_BUILD_ARG(void *itt_sync_obj), void *itt_sync_obj) {
818 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hier_gather)((void)0);
819 kmp_team_t *team = this_thr->th.th_team;
820 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
821 kmp_uint32 nproc = this_thr->th.th_team_nproc;
822 kmp_info_t **other_threads = team->t.t_threads;
823 kmp_uint64 new_state;
824
825 int level = team->t.t_level;
826#if OMP_40_ENABLED(50 >= 40)
827 if (other_threads[0]
828 ->th.th_teams_microtask) // are we inside the teams construct?
829 if (this_thr->th.th_teams_size.nteams > 1)
830 ++level; // level was not increased in teams construct for team_of_masters
831#endif
832 if (level == 1)
833 thr_bar->use_oncore_barrier = 1;
834 else
835 thr_bar->use_oncore_barrier = 0; // Do not use oncore barrier when nested
836
837 KA_TRACE(20, ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) enter for "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) enter for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
838 "barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) enter for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
839 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) enter for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
;
840 KMP_DEBUG_ASSERT(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid])if (!(this_thr == other_threads[this_thr->th.th_info.ds.ds_tid
])) { __kmp_debug_assert("this_thr == other_threads[this_thr->th.th_info.ds.ds_tid]"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 840); }
;
841
842#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
843 // Barrier imbalance - save arrive time to the thread
844 if (__kmp_forkjoin_frames_mode == 3 || __kmp_forkjoin_frames_mode == 2) {
845 this_thr->th.th_bar_arrive_time = __itt_get_timestamp(!__kmp_itt_get_timestamp_ptr__3_0) ? 0 : __kmp_itt_get_timestamp_ptr__3_0();
846 }
847#endif
848
849 (void)__kmp_init_hierarchical_barrier_thread(bt, thr_bar, nproc, gtid, tid,
850 team);
851
852 if (thr_bar->my_level) { // not a leaf (my_level==0 means leaf)
853 kmp_int32 child_tid;
854 new_state =
855 (kmp_uint64)team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP(1 << 2);
856 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME(2147483647) &&
857 thr_bar->use_oncore_barrier) {
858 if (thr_bar->leaf_kids) {
859 // First, wait for leaf children to check-in on my b_arrived flag
860 kmp_uint64 leaf_state =
861 KMP_MASTER_TID(tid)((tid) == 0)
862 ? thr_bar->b_arrived | thr_bar->leaf_state
863 : team->t.t_bar[bt].b_arrived | thr_bar->leaf_state;
864 KA_TRACE(20, ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) waiting "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) waiting "
"for leaf kids\n", gtid, team->t.t_id, tid); }
865 "for leaf kids\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) waiting "
"for leaf kids\n", gtid, team->t.t_id, tid); }
866 gtid, team->t.t_id, tid))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) waiting "
"for leaf kids\n", gtid, team->t.t_id, tid); }
;
867 kmp_flag_64 flag(&thr_bar->b_arrived, leaf_state);
868 flag.wait(this_thr, FALSE0 USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
869 if (reduce) {
870 ANNOTATE_REDUCE_AFTER(reduce);
871 for (child_tid = tid + 1; child_tid <= tid + thr_bar->leaf_kids;
872 ++child_tid) {
873 KA_TRACE(100, ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
874 "T#%d(%d:%d)\n",if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
875 gtid, team->t.t_id, tid,if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
876 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
877 child_tid))if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
;
878 ANNOTATE_BARRIER_END(other_threads[child_tid]);
879 (*reduce)(this_thr->th.th_local.reduce_data,
880 other_threads[child_tid]->th.th_local.reduce_data);
881 }
882 ANNOTATE_REDUCE_BEFORE(reduce);
883 ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
884 }
885 // clear leaf_state bits
886 KMP_TEST_THEN_AND64(&thr_bar->b_arrived, ~(thr_bar->leaf_state))__sync_fetch_and_and((volatile kmp_uint64 *)(&thr_bar->
b_arrived), (kmp_uint64)(~(thr_bar->leaf_state)))
;
887 }
888 // Next, wait for higher level children on each child's b_arrived flag
889 for (kmp_uint32 d = 1; d < thr_bar->my_level;
890 ++d) { // gather lowest level threads first, but skip 0
891 kmp_uint32 last = tid + thr_bar->skip_per_level[d + 1],
892 skip = thr_bar->skip_per_level[d];
893 if (last > nproc)
894 last = nproc;
895 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
896 kmp_info_t *child_thr = other_threads[child_tid];
897 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
898 KA_TRACE(20, ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
"T#%d(%d:%d) " "arrived(%p) == %llu\n", gtid, team->t.t_id
, tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
child_tid, &child_bar->b_arrived, new_state); }
899 "T#%d(%d:%d) "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
"T#%d(%d:%d) " "arrived(%p) == %llu\n", gtid, team->t.t_id
, tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
child_tid, &child_bar->b_arrived, new_state); }
900 "arrived(%p) == %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
"T#%d(%d:%d) " "arrived(%p) == %llu\n", gtid, team->t.t_id
, tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
child_tid, &child_bar->b_arrived, new_state); }
901 gtid, team->t.t_id, tid,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
"T#%d(%d:%d) " "arrived(%p) == %llu\n", gtid, team->t.t_id
, tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
child_tid, &child_bar->b_arrived, new_state); }
902 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
"T#%d(%d:%d) " "arrived(%p) == %llu\n", gtid, team->t.t_id
, tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
child_tid, &child_bar->b_arrived, new_state); }
903 child_tid, &child_bar->b_arrived, new_state))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
"T#%d(%d:%d) " "arrived(%p) == %llu\n", gtid, team->t.t_id
, tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
child_tid, &child_bar->b_arrived, new_state); }
;
904 kmp_flag_64 flag(&child_bar->b_arrived, new_state);
905 flag.wait(this_thr, FALSE0 USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
906 ANNOTATE_BARRIER_END(child_thr);
907 if (reduce) {
908 KA_TRACE(100, ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
909 "T#%d(%d:%d)\n",if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
910 gtid, team->t.t_id, tid,if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
911 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
912 child_tid))if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
;
913 ANNOTATE_REDUCE_AFTER(reduce);
914 (*reduce)(this_thr->th.th_local.reduce_data,
915 child_thr->th.th_local.reduce_data);
916 ANNOTATE_REDUCE_BEFORE(reduce);
917 ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
918 }
919 }
920 }
921 } else { // Blocktime is not infinite
922 for (kmp_uint32 d = 0; d < thr_bar->my_level;
923 ++d) { // Gather lowest level threads first
924 kmp_uint32 last = tid + thr_bar->skip_per_level[d + 1],
925 skip = thr_bar->skip_per_level[d];
926 if (last > nproc)
927 last = nproc;
928 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
929 kmp_info_t *child_thr = other_threads[child_tid];
930 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
931 KA_TRACE(20, ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
"T#%d(%d:%d) " "arrived(%p) == %llu\n", gtid, team->t.t_id
, tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
child_tid, &child_bar->b_arrived, new_state); }
932 "T#%d(%d:%d) "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
"T#%d(%d:%d) " "arrived(%p) == %llu\n", gtid, team->t.t_id
, tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
child_tid, &child_bar->b_arrived, new_state); }
933 "arrived(%p) == %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
"T#%d(%d:%d) " "arrived(%p) == %llu\n", gtid, team->t.t_id
, tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
child_tid, &child_bar->b_arrived, new_state); }
934 gtid, team->t.t_id, tid,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
"T#%d(%d:%d) " "arrived(%p) == %llu\n", gtid, team->t.t_id
, tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
child_tid, &child_bar->b_arrived, new_state); }
935 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
"T#%d(%d:%d) " "arrived(%p) == %llu\n", gtid, team->t.t_id
, tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
child_tid, &child_bar->b_arrived, new_state); }
936 child_tid, &child_bar->b_arrived, new_state))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) wait "
"T#%d(%d:%d) " "arrived(%p) == %llu\n", gtid, team->t.t_id
, tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id,
child_tid, &child_bar->b_arrived, new_state); }
;
937 kmp_flag_64 flag(&child_bar->b_arrived, new_state);
938 flag.wait(this_thr, FALSE0 USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
939 ANNOTATE_BARRIER_END(child_thr);
940 if (reduce) {
941 KA_TRACE(100, ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
942 "T#%d(%d:%d)\n",if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
943 gtid, team->t.t_id, tid,if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
944 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
945 child_tid))if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) += "
"T#%d(%d:%d)\n", gtid, team->t.t_id, tid, __kmp_gtid_from_tid
(child_tid, team), team->t.t_id, child_tid); }
;
946 ANNOTATE_REDUCE_AFTER(reduce);
947 (*reduce)(this_thr->th.th_local.reduce_data,
948 child_thr->th.th_local.reduce_data);
949 ANNOTATE_REDUCE_BEFORE(reduce);
950 ANNOTATE_REDUCE_BEFORE(&team->t.t_bar);
951 }
952 }
953 }
954 }
955 }
956 // All subordinates are gathered; now release parent if not master thread
957
958 if (!KMP_MASTER_TID(tid)((tid) == 0)) { // worker threads release parent in hierarchy
959 KA_TRACE(20, ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) releasing"if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) releasing"
" T#%d(%d:%d) arrived(%p): %llu => %llu\n", gtid, team->
t.t_id, tid, __kmp_gtid_from_tid(thr_bar->parent_tid, team
), team->t.t_id, thr_bar->parent_tid, &thr_bar->
b_arrived, thr_bar->b_arrived, thr_bar->b_arrived + (1 <<
2)); }
960 " T#%d(%d:%d) arrived(%p): %llu => %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) releasing"
" T#%d(%d:%d) arrived(%p): %llu => %llu\n", gtid, team->
t.t_id, tid, __kmp_gtid_from_tid(thr_bar->parent_tid, team
), team->t.t_id, thr_bar->parent_tid, &thr_bar->
b_arrived, thr_bar->b_arrived, thr_bar->b_arrived + (1 <<
2)); }
961 gtid, team->t.t_id, tid,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) releasing"
" T#%d(%d:%d) arrived(%p): %llu => %llu\n", gtid, team->
t.t_id, tid, __kmp_gtid_from_tid(thr_bar->parent_tid, team
), team->t.t_id, thr_bar->parent_tid, &thr_bar->
b_arrived, thr_bar->b_arrived, thr_bar->b_arrived + (1 <<
2)); }
962 __kmp_gtid_from_tid(thr_bar->parent_tid, team), team->t.t_id,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) releasing"
" T#%d(%d:%d) arrived(%p): %llu => %llu\n", gtid, team->
t.t_id, tid, __kmp_gtid_from_tid(thr_bar->parent_tid, team
), team->t.t_id, thr_bar->parent_tid, &thr_bar->
b_arrived, thr_bar->b_arrived, thr_bar->b_arrived + (1 <<
2)); }
963 thr_bar->parent_tid, &thr_bar->b_arrived, thr_bar->b_arrived,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) releasing"
" T#%d(%d:%d) arrived(%p): %llu => %llu\n", gtid, team->
t.t_id, tid, __kmp_gtid_from_tid(thr_bar->parent_tid, team
), team->t.t_id, thr_bar->parent_tid, &thr_bar->
b_arrived, thr_bar->b_arrived, thr_bar->b_arrived + (1 <<
2)); }
964 thr_bar->b_arrived + KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) releasing"
" T#%d(%d:%d) arrived(%p): %llu => %llu\n", gtid, team->
t.t_id, tid, __kmp_gtid_from_tid(thr_bar->parent_tid, team
), team->t.t_id, thr_bar->parent_tid, &thr_bar->
b_arrived, thr_bar->b_arrived, thr_bar->b_arrived + (1 <<
2)); }
;
965 /* Mark arrival to parent: After performing this write, a worker thread may
966 not assume that the team is valid any more - it could be deallocated by
967 the master thread at any time. */
968 if (thr_bar->my_level || __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME(2147483647) ||
969 !thr_bar->use_oncore_barrier) { // Parent is waiting on my b_arrived
970 // flag; release it
971 ANNOTATE_BARRIER_BEGIN(this_thr);
972 kmp_flag_64 flag(&thr_bar->b_arrived, other_threads[thr_bar->parent_tid]);
973 flag.release();
974 } else {
975 // Leaf does special release on "offset" bits of parent's b_arrived flag
976 thr_bar->b_arrived = team->t.t_bar[bt].b_arrived + KMP_BARRIER_STATE_BUMP(1 << 2);
977 kmp_flag_oncore flag(&thr_bar->parent_bar->b_arrived, thr_bar->offset);
978 flag.set_waiter(other_threads[thr_bar->parent_tid]);
979 flag.release();
980 }
981 } else { // Master thread needs to update the team's b_arrived value
982 team->t.t_bar[bt].b_arrived = new_state;
983 KA_TRACE(20, ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) set team %d "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team->t.t_bar[bt].b_arrived, team->t.t_bar
[bt].b_arrived); }
984 "arrived(%p) = %llu\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team->t.t_bar[bt].b_arrived, team->t.t_bar
[bt].b_arrived); }
985 gtid, team->t.t_id, tid, team->t.t_id,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team->t.t_bar[bt].b_arrived, team->t.t_bar
[bt].b_arrived); }
986 &team->t.t_bar[bt].b_arrived, team->t.t_bar[bt].b_arrived))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) set team %d "
"arrived(%p) = %llu\n", gtid, team->t.t_id, tid, team->
t.t_id, &team->t.t_bar[bt].b_arrived, team->t.t_bar
[bt].b_arrived); }
;
987 }
988 // Is the team access below unsafe or just technically invalid?
989 KA_TRACE(20, ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) exit for "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) exit for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
990 "barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) exit for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
991 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_gather: T#%d(%d:%d) exit for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
;
992}
993
994static void __kmp_hierarchical_barrier_release(
995 enum barrier_type bt, kmp_info_t *this_thr, int gtid, int tid,
996 int propagate_icvs USE_ITT_BUILD_ARG(void *itt_sync_obj), void *itt_sync_obj) {
997 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_hier_release)((void)0);
998 kmp_team_t *team;
999 kmp_bstate_t *thr_bar = &this_thr->th.th_bar[bt].bb;
1000 kmp_uint32 nproc;
1001 bool team_change = false; // indicates on-core barrier shouldn't be used
1002
1003 if (KMP_MASTER_TID(tid)((tid) == 0)) {
1004 team = __kmp_threads[gtid]->th.th_team;
1005 KMP_DEBUG_ASSERT(team != NULL)if (!(team != __null)) { __kmp_debug_assert("team != __null",
"/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1005); }
;
1006 KA_TRACE(20, ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) master "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) master "
"entered barrier type %d\n", gtid, team->t.t_id, tid, bt)
; }
1007 "entered barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) master "
"entered barrier type %d\n", gtid, team->t.t_id, tid, bt)
; }
1008 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) master "
"entered barrier type %d\n", gtid, team->t.t_id, tid, bt)
; }
;
1009 } else { // Worker threads
1010 // Wait for parent thread to release me
1011 if (!thr_bar->use_oncore_barrier ||
1012 __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME(2147483647) || thr_bar->my_level != 0 ||
1013 thr_bar->team == NULL__null) {
1014 // Use traditional method of waiting on my own b_go flag
1015 thr_bar->wait_flag = KMP_BARRIER_OWN_FLAG1;
1016 kmp_flag_64 flag(&thr_bar->b_go, KMP_BARRIER_STATE_BUMP(1 << 2));
1017 flag.wait(this_thr, TRUE(!0) USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1018 ANNOTATE_BARRIER_END(this_thr);
1019 TCW_8(thr_bar->b_go,(thr_bar->b_go) = (0)
1020 KMP_INIT_BARRIER_STATE)(thr_bar->b_go) = (0); // Reset my b_go flag for next time
1021 } else { // Thread barrier data is initialized, this is a leaf, blocktime is
1022 // infinite, not nested
1023 // Wait on my "offset" bits on parent's b_go flag
1024 thr_bar->wait_flag = KMP_BARRIER_PARENT_FLAG2;
1025 kmp_flag_oncore flag(&thr_bar->parent_bar->b_go, KMP_BARRIER_STATE_BUMP(1 << 2),
1026 thr_bar->offset, bt,
1027 this_thr USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1028 flag.wait(this_thr, TRUE(!0));
1029 if (thr_bar->wait_flag ==
1030 KMP_BARRIER_SWITCHING4) { // Thread was switched to own b_go
1031 TCW_8(thr_bar->b_go,(thr_bar->b_go) = (0)
1032 KMP_INIT_BARRIER_STATE)(thr_bar->b_go) = (0); // Reset my b_go flag for next time
1033 } else { // Reset my bits on parent's b_go flag
1034 (RCAST(volatile char *,reinterpret_cast<volatile char *>(&(thr_bar->parent_bar
->b_go))
1035 &(thr_bar->parent_bar->b_go))reinterpret_cast<volatile char *>(&(thr_bar->parent_bar
->b_go))
)[thr_bar->offset] = 0;
1036 }
1037 }
1038 thr_bar->wait_flag = KMP_BARRIER_NOT_WAITING0;
1039 // Early exit for reaping threads releasing forkjoin barrier
1040 if (bt == bs_forkjoin_barrier && TCR_4(__kmp_global.g.g_done)(__kmp_global.g.g_done))
1041 return;
1042 // The worker thread may now assume that the team is valid.
1043 team = __kmp_threads[gtid]->th.th_team;
1044 KMP_DEBUG_ASSERT(team != NULL)if (!(team != __null)) { __kmp_debug_assert("team != __null",
"/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1044); }
;
1045 tid = __kmp_tid_from_gtid(gtid);
1046
1047 KA_TRACE(if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
1048 20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
1049 ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) set go(%p) = %u\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
1050 gtid, team->t.t_id, tid, &thr_bar->b_go, KMP_INIT_BARRIER_STATE))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) set go(%p) = %u\n"
, gtid, team->t.t_id, tid, &thr_bar->b_go, 0); }
;
1051 KMP_MB(); // Flush all pending memory write invalidates.
1052 }
1053
1054 nproc = this_thr->th.th_team_nproc;
1055 int level = team->t.t_level;
1056#if OMP_40_ENABLED(50 >= 40)
1057 if (team->t.t_threads[0]
1058 ->th.th_teams_microtask) { // are we inside the teams construct?
1059 if (team->t.t_pkfn != (microtask_t)__kmp_teams_master &&
1060 this_thr->th.th_teams_level == level)
1061 ++level; // level was not increased in teams construct for team_of_workers
1062 if (this_thr->th.th_teams_size.nteams > 1)
1063 ++level; // level was not increased in teams construct for team_of_masters
1064 }
1065#endif
1066 if (level == 1)
1067 thr_bar->use_oncore_barrier = 1;
1068 else
1069 thr_bar->use_oncore_barrier = 0; // Do not use oncore barrier when nested
1070
1071 // If the team size has increased, we still communicate with old leaves via
1072 // oncore barrier.
1073 unsigned short int old_leaf_kids = thr_bar->leaf_kids;
1074 kmp_uint64 old_leaf_state = thr_bar->leaf_state;
1075 team_change = __kmp_init_hierarchical_barrier_thread(bt, thr_bar, nproc, gtid,
1076 tid, team);
1077 // But if the entire team changes, we won't use oncore barrier at all
1078 if (team_change)
1079 old_leaf_kids = 0;
1080
1081#if KMP_BARRIER_ICV_PUSH1
1082 if (propagate_icvs) {
1083 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team, tid,
1084 FALSE0);
1085 if (KMP_MASTER_TID(((tid) == 0)
1086 tid)((tid) == 0)) { // master already has copy in final destination; copy
1087 copy_icvs(&thr_bar->th_fixed_icvs,
1088 &team->t.t_implicit_task_taskdata[tid].td_icvs);
1089 } else if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME(2147483647) &&
1090 thr_bar->use_oncore_barrier) { // optimization for inf blocktime
1091 if (!thr_bar->my_level) // I'm a leaf in the hierarchy (my_level==0)
1092 // leaves (on-core children) pull parent's fixed ICVs directly to local
1093 // ICV store
1094 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1095 &thr_bar->parent_bar->th_fixed_icvs);
1096 // non-leaves will get ICVs piggybacked with b_go via NGO store
1097 } else { // blocktime is not infinite; pull ICVs from parent's fixed ICVs
1098 if (thr_bar->my_level) // not a leaf; copy ICVs to my fixed ICVs child can
1099 // access
1100 copy_icvs(&thr_bar->th_fixed_icvs, &thr_bar->parent_bar->th_fixed_icvs);
1101 else // leaves copy parent's fixed ICVs directly to local ICV store
1102 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1103 &thr_bar->parent_bar->th_fixed_icvs);
1104 }
1105 }
1106#endif // KMP_BARRIER_ICV_PUSH
1107
1108 // Now, release my children
1109 if (thr_bar->my_level) { // not a leaf
1110 kmp_int32 child_tid;
1111 kmp_uint32 last;
1112 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME(2147483647) &&
1113 thr_bar->use_oncore_barrier) {
1114 if (KMP_MASTER_TID(tid)((tid) == 0)) { // do a flat release
1115 // Set local b_go to bump children via NGO store of the cache line
1116 // containing IVCs and b_go.
1117 thr_bar->b_go = KMP_BARRIER_STATE_BUMP(1 << 2);
1118 // Use ngo stores if available; b_go piggybacks in the last 8 bytes of
1119 // the cache line
1120 ngo_load(&thr_bar->th_fixed_icvs)((void)0);
1121 // This loops over all the threads skipping only the leaf nodes in the
1122 // hierarchy
1123 for (child_tid = thr_bar->skip_per_level[1]; child_tid < (int)nproc;
1124 child_tid += thr_bar->skip_per_level[1]) {
1125 kmp_bstate_t *child_bar =
1126 &team->t.t_threads[child_tid]->th.th_bar[bt].bb;
1127 KA_TRACE(20, ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d)" " go(%p): %u => %u\n", gtid, team
->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->
t.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
1128 "releasing T#%d(%d:%d)"if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d)" " go(%p): %u => %u\n", gtid, team
->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->
t.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
1129 " go(%p): %u => %u\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d)" " go(%p): %u => %u\n", gtid, team
->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->
t.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
1130 gtid, team->t.t_id, tid,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d)" " go(%p): %u => %u\n", gtid, team
->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->
t.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
1131 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d)" " go(%p): %u => %u\n", gtid, team
->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->
t.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
1132 child_tid, &child_bar->b_go, child_bar->b_go,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d)" " go(%p): %u => %u\n", gtid, team
->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->
t.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
1133 child_bar->b_go + KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d)" " go(%p): %u => %u\n", gtid, team
->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->
t.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
;
1134 // Use ngo store (if available) to both store ICVs and release child
1135 // via child's b_go
1136 ngo_store_go(&child_bar->th_fixed_icvs, &thr_bar->th_fixed_icvs)memcpy((&child_bar->th_fixed_icvs), (&thr_bar->
th_fixed_icvs), 64)
;
1137 }
1138 ngo_sync()((void)0);
1139 }
1140 TCW_8(thr_bar->b_go,(thr_bar->b_go) = (0)
1141 KMP_INIT_BARRIER_STATE)(thr_bar->b_go) = (0); // Reset my b_go flag for next time
1142 // Now, release leaf children
1143 if (thr_bar->leaf_kids) { // if there are any
1144 // We test team_change on the off-chance that the level 1 team changed.
1145 if (team_change ||
1146 old_leaf_kids < thr_bar->leaf_kids) { // some old, some new
1147 if (old_leaf_kids) { // release old leaf kids
1148 thr_bar->b_go |= old_leaf_state;
1149 }
1150 // Release new leaf kids
1151 last = tid + thr_bar->skip_per_level[1];
1152 if (last > nproc)
1153 last = nproc;
1154 for (child_tid = tid + 1 + old_leaf_kids; child_tid < (int)last;
1155 ++child_tid) { // skip_per_level[0]=1
1156 kmp_info_t *child_thr = team->t.t_threads[child_tid];
1157 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1158 KA_TRACE(if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) releasing"
" T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->t.t_id,
tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id, child_tid
, &child_bar->b_go, child_bar->b_go, child_bar->
b_go + (1 << 2)); }
1159 20,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) releasing"
" T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->t.t_id,
tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id, child_tid
, &child_bar->b_go, child_bar->b_go, child_bar->
b_go + (1 << 2)); }
1160 ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) releasing"if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) releasing"
" T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->t.t_id,
tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id, child_tid
, &child_bar->b_go, child_bar->b_go, child_bar->
b_go + (1 << 2)); }
1161 " T#%d(%d:%d) go(%p): %u => %u\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) releasing"
" T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->t.t_id,
tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id, child_tid
, &child_bar->b_go, child_bar->b_go, child_bar->
b_go + (1 << 2)); }
1162 gtid, team->t.t_id, tid, __kmp_gtid_from_tid(child_tid, team),if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) releasing"
" T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->t.t_id,
tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id, child_tid
, &child_bar->b_go, child_bar->b_go, child_bar->
b_go + (1 << 2)); }
1163 team->t.t_id, child_tid, &child_bar->b_go, child_bar->b_go,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) releasing"
" T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->t.t_id,
tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id, child_tid
, &child_bar->b_go, child_bar->b_go, child_bar->
b_go + (1 << 2)); }
1164 child_bar->b_go + KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) releasing"
" T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->t.t_id,
tid, __kmp_gtid_from_tid(child_tid, team), team->t.t_id, child_tid
, &child_bar->b_go, child_bar->b_go, child_bar->
b_go + (1 << 2)); }
;
1165 // Release child using child's b_go flag
1166 ANNOTATE_BARRIER_BEGIN(child_thr);
1167 kmp_flag_64 flag(&child_bar->b_go, child_thr);
1168 flag.release();
1169 }
1170 } else { // Release all children at once with leaf_state bits on my own
1171 // b_go flag
1172 thr_bar->b_go |= thr_bar->leaf_state;
1173 }
1174 }
1175 } else { // Blocktime is not infinite; do a simple hierarchical release
1176 for (int d = thr_bar->my_level - 1; d >= 0;
1177 --d) { // Release highest level threads first
1178 last = tid + thr_bar->skip_per_level[d + 1];
1179 kmp_uint32 skip = thr_bar->skip_per_level[d];
1180 if (last > nproc)
1181 last = nproc;
1182 for (child_tid = tid + skip; child_tid < (int)last; child_tid += skip) {
1183 kmp_info_t *child_thr = team->t.t_threads[child_tid];
1184 kmp_bstate_t *child_bar = &child_thr->th.th_bar[bt].bb;
1185 KA_TRACE(20, ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->
t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->t
.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
1186 "releasing T#%d(%d:%d) go(%p): %u => %u\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->
t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->t
.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
1187 gtid, team->t.t_id, tid,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->
t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->t
.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
1188 __kmp_gtid_from_tid(child_tid, team), team->t.t_id,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->
t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->t
.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
1189 child_tid, &child_bar->b_go, child_bar->b_go,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->
t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->t
.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
1190 child_bar->b_go + KMP_BARRIER_STATE_BUMP))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) "
"releasing T#%d(%d:%d) go(%p): %u => %u\n", gtid, team->
t.t_id, tid, __kmp_gtid_from_tid(child_tid, team), team->t
.t_id, child_tid, &child_bar->b_go, child_bar->b_go
, child_bar->b_go + (1 << 2)); }
;
1191 // Release child using child's b_go flag
1192 ANNOTATE_BARRIER_BEGIN(child_thr);
1193 kmp_flag_64 flag(&child_bar->b_go, child_thr);
1194 flag.release();
1195 }
1196 }
1197 }
1198#if KMP_BARRIER_ICV_PUSH1
1199 if (propagate_icvs && !KMP_MASTER_TID(tid)((tid) == 0))
1200 // non-leaves copy ICVs from fixed ICVs to local dest
1201 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1202 &thr_bar->th_fixed_icvs);
1203#endif // KMP_BARRIER_ICV_PUSH
1204 }
1205 KA_TRACE(20, ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) exit for "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) exit for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
1206 "barrier type %d\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) exit for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
1207 gtid, team->t.t_id, tid, bt))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_hierarchical_barrier_release: T#%d(%d:%d) exit for "
"barrier type %d\n", gtid, team->t.t_id, tid, bt); }
;
1208}
1209
1210// End of Barrier Algorithms
1211
1212// Internal function to do a barrier.
1213/* If is_split is true, do a split barrier, otherwise, do a plain barrier
1214 If reduce is non-NULL, do a split reduction barrier, otherwise, do a split
1215 barrier
1216 Returns 0 if master thread, 1 if worker thread. */
1217int __kmp_barrier(enum barrier_type bt, int gtid, int is_split,
1218 size_t reduce_size, void *reduce_data,
1219 void (*reduce)(void *, void *)) {
1220 KMP_TIME_PARTITIONED_BLOCK(OMP_plain_barrier)((void)0);
1221 KMP_SET_THREAD_STATE_BLOCK(PLAIN_BARRIER)((void)0);
1222 int tid = __kmp_tid_from_gtid(gtid);
1223 kmp_info_t *this_thr = __kmp_threads[gtid];
1224 kmp_team_t *team = this_thr->th.th_team;
1225 int status = 0;
1226#if OMPT_SUPPORT1 && OMPT_OPTIONAL1
1227 ompt_data_t *my_task_data;
1228 ompt_data_t *my_parallel_data;
1229 void *return_address;
1230#endif
1231
1232 KA_TRACE(15, ("__kmp_barrier: T#%d(%d:%d) has arrived\n", gtid,if (kmp_a_debug >= 15) { __kmp_debug_printf ("__kmp_barrier: T#%d(%d:%d) has arrived\n"
, gtid, __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid
(gtid)); }
1233 __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid(gtid)))if (kmp_a_debug >= 15) { __kmp_debug_printf ("__kmp_barrier: T#%d(%d:%d) has arrived\n"
, gtid, __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid
(gtid)); }
;
1234
1235 ANNOTATE_BARRIER_BEGIN(&team->t.t_bar);
1236#if OMPT_SUPPORT1
1237 if (ompt_enabled.enabled) {
1238#if OMPT_OPTIONAL1
1239 my_task_data = OMPT_CUR_TASK_DATA(this_thr)(&(this_thr->th.th_current_task->ompt_task_info.task_data
))
;
1240 my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr)(&(this_thr->th.th_team->t.ompt_team_info.parallel_data
))
;
1241 return_address = OMPT_LOAD_RETURN_ADDRESS(gtid)__ompt_load_return_address(gtid);
1242 if (ompt_enabled.ompt_callback_sync_region) {
1243 ompt_callbacks.ompt_callback(ompt_callback_sync_region)ompt_callback_sync_region_callback(
1244 ompt_sync_region_barrier, ompt_scope_begin, my_parallel_data,
1245 my_task_data, return_address);
1246 }
1247 if (ompt_enabled.ompt_callback_sync_region_wait) {
1248 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)ompt_callback_sync_region_wait_callback(
1249 ompt_sync_region_barrier, ompt_scope_begin, my_parallel_data,
1250 my_task_data, return_address);
1251 }
1252#endif
1253 // It is OK to report the barrier state after the barrier begin callback.
1254 // According to the OMPT specification, a compliant implementation may
1255 // even delay reporting this state until the barrier begins to wait.
1256 this_thr->th.ompt_thread_info.state = omp_state_wait_barrier;
1257 }
1258#endif
1259
1260 if (!team->t.t_serialized) {
1261#if USE_ITT_BUILD1
1262 // This value will be used in itt notify events below.
1263 void *itt_sync_obj = NULL__null;
1264#if USE_ITT_NOTIFY1
1265 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0)
1266 itt_sync_obj = __kmp_itt_barrier_object(gtid, bt, 1);
1267#endif
1268#endif /* USE_ITT_BUILD */
1269 if (__kmp_tasking_mode == tskm_extra_barrier) {
1270 __kmp_tasking_barrier(team, this_thr, gtid);
1271 KA_TRACE(15,if (kmp_a_debug >= 15) { __kmp_debug_printf ("__kmp_barrier: T#%d(%d:%d) past tasking barrier\n"
, gtid, __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid
(gtid)); }
1272 ("__kmp_barrier: T#%d(%d:%d) past tasking barrier\n", gtid,if (kmp_a_debug >= 15) { __kmp_debug_printf ("__kmp_barrier: T#%d(%d:%d) past tasking barrier\n"
, gtid, __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid
(gtid)); }
1273 __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid(gtid)))if (kmp_a_debug >= 15) { __kmp_debug_printf ("__kmp_barrier: T#%d(%d:%d) past tasking barrier\n"
, gtid, __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid
(gtid)); }
;
1274 }
1275
1276 /* Copy the blocktime info to the thread, where __kmp_wait_template() can
1277 access it when the team struct is not guaranteed to exist. */
1278 // See note about the corresponding code in __kmp_join_barrier() being
1279 // performance-critical.
1280 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME(2147483647)) {
1281#if KMP_USE_MONITOR
1282 this_thr->th.th_team_bt_intervals =
1283 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
1284 this_thr->th.th_team_bt_set =
1285 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
1286#else
1287 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid)((((team)->t.t_threads[(tid)]->th.th_current_task->td_icvs
.bt_set) ? ((team)->t.t_threads[(tid)]->th.th_current_task
->td_icvs.blocktime) : __kmp_dflt_blocktime) * __kmp_ticks_per_msec
)
;
1288#endif
1289 }
1290
1291#if USE_ITT_BUILD1
1292 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0)
1293 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
1294#endif /* USE_ITT_BUILD */
1295#if USE_DEBUGGER0
1296 // Let the debugger know: the thread arrived to the barrier and waiting.
1297 if (KMP_MASTER_TID(tid)((tid) == 0)) { // Master counter is stored in team structure.
1298 team->t.t_bar[bt].b_master_arrived += 1;
1299 } else {
1300 this_thr->th.th_bar[bt].bb.b_worker_arrived += 1;
1301 } // if
1302#endif /* USE_DEBUGGER */
1303 if (reduce != NULL__null) {
1304 // KMP_DEBUG_ASSERT( is_split == TRUE ); // #C69956
1305 this_thr->th.th_local.reduce_data = reduce_data;
1306 }
1307
1308 if (KMP_MASTER_TID(tid)((tid) == 0) && __kmp_tasking_mode != tskm_immediate_exec)
1309 __kmp_task_team_setup(
1310 this_thr, team,
1311 0); // use 0 to only setup the current team if nthreads > 1
1312
1313 switch (__kmp_barrier_gather_pattern[bt]) {
1314 case bp_hyper_bar: {
1315 KMP_ASSERT(__kmp_barrier_gather_branch_bits[bt])if (!(__kmp_barrier_gather_branch_bits[bt])) { __kmp_debug_assert
("__kmp_barrier_gather_branch_bits[bt]", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1315); }
; // don't set branch bits
1316 // to 0; use linear
1317 __kmp_hyper_barrier_gather(bt, this_thr, gtid, tid,
1318 reduce USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1319 break;
1320 }
1321 case bp_hierarchical_bar: {
1322 __kmp_hierarchical_barrier_gather(bt, this_thr, gtid, tid,
1323 reduce USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1324 break;
1325 }
1326 case bp_tree_bar: {
1327 KMP_ASSERT(__kmp_barrier_gather_branch_bits[bt])if (!(__kmp_barrier_gather_branch_bits[bt])) { __kmp_debug_assert
("__kmp_barrier_gather_branch_bits[bt]", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1327); }
; // don't set branch bits
1328 // to 0; use linear
1329 __kmp_tree_barrier_gather(bt, this_thr, gtid, tid,
1330 reduce USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1331 break;
1332 }
1333 default: {
1334 __kmp_linear_barrier_gather(bt, this_thr, gtid, tid,
1335 reduce USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1336 }
1337 }
1338
1339 KMP_MB();
1340
1341 if (KMP_MASTER_TID(tid)((tid) == 0)) {
1342 status = 0;
1343 if (__kmp_tasking_mode != tskm_immediate_exec) {
1344 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1345 }
1346#if USE_DEBUGGER0
1347 // Let the debugger know: All threads are arrived and starting leaving the
1348 // barrier.
1349 team->t.t_bar[bt].b_team_arrived += 1;
1350#endif
1351
1352#if OMP_40_ENABLED(50 >= 40)
1353 kmp_int32 cancel_request = KMP_ATOMIC_LD_RLX(&team->t.t_cancel_request)(&team->t.t_cancel_request)->load(std::memory_order_relaxed
)
;
1354 // Reset cancellation flag for worksharing constructs
1355 if (cancel_request == cancel_loop || cancel_request == cancel_sections) {
1356 KMP_ATOMIC_ST_RLX(&team->t.t_cancel_request, cancel_noreq)(&team->t.t_cancel_request)->store(cancel_noreq, std
::memory_order_relaxed)
;
1357 }
1358#endif
1359#if USE_ITT_BUILD1
1360 /* TODO: In case of split reduction barrier, master thread may send
1361 acquired event early, before the final summation into the shared
1362 variable is done (final summation can be a long operation for array
1363 reductions). */
1364 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0)
1365 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
1366#endif /* USE_ITT_BUILD */
1367#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
1368 // Barrier - report frame end (only if active_level == 1)
1369 if ((__itt_frame_submit_v3_ptr__kmp_itt_frame_submit_v3_ptr__3_0 || KMP_ITT_DEBUG0) &&
1370 __kmp_forkjoin_frames_mode &&
1371#if OMP_40_ENABLED(50 >= 40)
1372 this_thr->th.th_teams_microtask == NULL__null &&
1373#endif
1374 team->t.t_active_level == 1) {
1375 ident_t *loc = __kmp_threads[gtid]->th.th_ident;
1376 kmp_uint64 cur_time = __itt_get_timestamp(!__kmp_itt_get_timestamp_ptr__3_0) ? 0 : __kmp_itt_get_timestamp_ptr__3_0();
1377 kmp_info_t **other_threads = team->t.t_threads;
1378 int nproc = this_thr->th.th_team_nproc;
1379 int i;
1380 switch (__kmp_forkjoin_frames_mode) {
1381 case 1:
1382 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
1383 loc, nproc);
1384 this_thr->th.th_frame_time = cur_time;
1385 break;
1386 case 2: // AC 2015-01-19: currently does not work for hierarchical (to
1387 // be fixed)
1388 __kmp_itt_frame_submit(gtid, this_thr->th.th_bar_min_time, cur_time,
1389 1, loc, nproc);
1390 break;
1391 case 3:
1392 if (__itt_metadata_add_ptr__kmp_itt_metadata_add_ptr__3_0) {
1393 // Initialize with master's wait time
1394 kmp_uint64 delta = cur_time - this_thr->th.th_bar_arrive_time;
1395 // Set arrive time to zero to be able to check it in
1396 // __kmp_invoke_task(); the same is done inside the loop below
1397 this_thr->th.th_bar_arrive_time = 0;
1398 for (i = 1; i < nproc; ++i) {
1399 delta += (cur_time - other_threads[i]->th.th_bar_arrive_time);
1400 other_threads[i]->th.th_bar_arrive_time = 0;
1401 }
1402 __kmp_itt_metadata_imbalance(gtid, this_thr->th.th_frame_time,
1403 cur_time, delta,
1404 (kmp_uint64)(reduce != NULL__null));
1405 }
1406 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
1407 loc, nproc);
1408 this_thr->th.th_frame_time = cur_time;
1409 break;
1410 }
1411 }
1412#endif /* USE_ITT_BUILD */
1413 } else {
1414 status = 1;
1415#if USE_ITT_BUILD1
1416 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0)
1417 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
1418#endif /* USE_ITT_BUILD */
1419 }
1420 if (status == 1 || !is_split) {
1421 switch (__kmp_barrier_release_pattern[bt]) {
1422 case bp_hyper_bar: {
1423 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt])if (!(__kmp_barrier_release_branch_bits[bt])) { __kmp_debug_assert
("__kmp_barrier_release_branch_bits[bt]", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1423); }
;
1424 __kmp_hyper_barrier_release(bt, this_thr, gtid, tid,
1425 FALSE0 USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1426 break;
1427 }
1428 case bp_hierarchical_bar: {
1429 __kmp_hierarchical_barrier_release(
1430 bt, this_thr, gtid, tid, FALSE0 USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1431 break;
1432 }
1433 case bp_tree_bar: {
1434 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt])if (!(__kmp_barrier_release_branch_bits[bt])) { __kmp_debug_assert
("__kmp_barrier_release_branch_bits[bt]", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1434); }
;
1435 __kmp_tree_barrier_release(bt, this_thr, gtid, tid,
1436 FALSE0 USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1437 break;
1438 }
1439 default: {
1440 __kmp_linear_barrier_release(bt, this_thr, gtid, tid,
1441 FALSE0 USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1442 }
1443 }
1444 if (__kmp_tasking_mode != tskm_immediate_exec) {
1445 __kmp_task_team_sync(this_thr, team);
1446 }
1447 }
1448
1449#if USE_ITT_BUILD1
1450 /* GEH: TODO: Move this under if-condition above and also include in
1451 __kmp_end_split_barrier(). This will more accurately represent the actual
1452 release time of the threads for split barriers. */
1453 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0)
1454 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
1455#endif /* USE_ITT_BUILD */
1456 } else { // Team is serialized.
1457 status = 0;
1458 if (__kmp_tasking_mode != tskm_immediate_exec) {
1459#if OMP_45_ENABLED(50 >= 45)
1460 if (this_thr->th.th_task_team != NULL__null) {
1461#if USE_ITT_NOTIFY1
1462 void *itt_sync_obj = NULL__null;
1463 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0) {
1464 itt_sync_obj = __kmp_itt_barrier_object(gtid, bt, 1);
1465 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
1466 }
1467#endif
1468
1469 KMP_DEBUG_ASSERT(this_thr->th.th_task_team->tt.tt_found_proxy_tasks ==if (!(this_thr->th.th_task_team->tt.tt_found_proxy_tasks
== (!0))) { __kmp_debug_assert("this_thr->th.th_task_team->tt.tt_found_proxy_tasks == (!0)"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1470); }
1470 TRUE)if (!(this_thr->th.th_task_team->tt.tt_found_proxy_tasks
== (!0))) { __kmp_debug_assert("this_thr->th.th_task_team->tt.tt_found_proxy_tasks == (!0)"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1470); }
;
1471 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1472 __kmp_task_team_setup(this_thr, team, 0);
1473
1474#if USE_ITT_BUILD1
1475 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0)
1476 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
1477#endif /* USE_ITT_BUILD */
1478 }
1479#else
1480 // The task team should be NULL for serialized code (tasks will be
1481 // executed immediately)
1482 KMP_DEBUG_ASSERT(team->t.t_task_team[this_thr->th.th_task_state] == NULL)if (!(team->t.t_task_team[this_thr->th.th_task_state] ==
__null)) { __kmp_debug_assert("team->t.t_task_team[this_thr->th.th_task_state] == __null"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1482); }
;
1483 KMP_DEBUG_ASSERT(this_thr->th.th_task_team == NULL)if (!(this_thr->th.th_task_team == __null)) { __kmp_debug_assert
("this_thr->th.th_task_team == __null", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1483); }
;
1484#endif
1485 }
1486 }
1487 KA_TRACE(15, ("__kmp_barrier: T#%d(%d:%d) is leaving with return value %d\n",if (kmp_a_debug >= 15) { __kmp_debug_printf ("__kmp_barrier: T#%d(%d:%d) is leaving with return value %d\n"
, gtid, __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid
(gtid), status); }
1488 gtid, __kmp_team_from_gtid(gtid)->t.t_id,if (kmp_a_debug >= 15) { __kmp_debug_printf ("__kmp_barrier: T#%d(%d:%d) is leaving with return value %d\n"
, gtid, __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid
(gtid), status); }
1489 __kmp_tid_from_gtid(gtid), status))if (kmp_a_debug >= 15) { __kmp_debug_printf ("__kmp_barrier: T#%d(%d:%d) is leaving with return value %d\n"
, gtid, __kmp_team_from_gtid(gtid)->t.t_id, __kmp_tid_from_gtid
(gtid), status); }
;
1490
1491#if OMPT_SUPPORT1
1492 if (ompt_enabled.enabled) {
1493#if OMPT_OPTIONAL1
1494 if (ompt_enabled.ompt_callback_sync_region_wait) {
1495 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)ompt_callback_sync_region_wait_callback(
1496 ompt_sync_region_barrier, ompt_scope_end, my_parallel_data,
1497 my_task_data, return_address);
1498 }
1499 if (ompt_enabled.ompt_callback_sync_region) {
1500 ompt_callbacks.ompt_callback(ompt_callback_sync_region)ompt_callback_sync_region_callback(
1501 ompt_sync_region_barrier, ompt_scope_end, my_parallel_data,
1502 my_task_data, return_address);
1503 }
1504#endif
1505 this_thr->th.ompt_thread_info.state = omp_state_work_parallel;
1506 }
1507#endif
1508 ANNOTATE_BARRIER_END(&team->t.t_bar);
1509
1510 return status;
1511}
1512
1513void __kmp_end_split_barrier(enum barrier_type bt, int gtid) {
1514 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_end_split_barrier)((void)0);
1515 KMP_SET_THREAD_STATE_BLOCK(PLAIN_BARRIER)((void)0);
1516 int tid = __kmp_tid_from_gtid(gtid);
1517 kmp_info_t *this_thr = __kmp_threads[gtid];
1518 kmp_team_t *team = this_thr->th.th_team;
1519
1520 ANNOTATE_BARRIER_BEGIN(&team->t.t_bar);
1521 if (!team->t.t_serialized) {
1522 if (KMP_MASTER_GTID(gtid)(__kmp_tid_from_gtid((gtid)) == 0)) {
1523 switch (__kmp_barrier_release_pattern[bt]) {
1524 case bp_hyper_bar: {
1525 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt])if (!(__kmp_barrier_release_branch_bits[bt])) { __kmp_debug_assert
("__kmp_barrier_release_branch_bits[bt]", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1525); }
;
1526 __kmp_hyper_barrier_release(bt, this_thr, gtid, tid,
1527 FALSE0 USE_ITT_BUILD_ARG(NULL), __null);
1528 break;
1529 }
1530 case bp_hierarchical_bar: {
1531 __kmp_hierarchical_barrier_release(bt, this_thr, gtid, tid,
1532 FALSE0 USE_ITT_BUILD_ARG(NULL), __null);
1533 break;
1534 }
1535 case bp_tree_bar: {
1536 KMP_ASSERT(__kmp_barrier_release_branch_bits[bt])if (!(__kmp_barrier_release_branch_bits[bt])) { __kmp_debug_assert
("__kmp_barrier_release_branch_bits[bt]", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1536); }
;
1537 __kmp_tree_barrier_release(bt, this_thr, gtid, tid,
1538 FALSE0 USE_ITT_BUILD_ARG(NULL), __null);
1539 break;
1540 }
1541 default: {
1542 __kmp_linear_barrier_release(bt, this_thr, gtid, tid,
1543 FALSE0 USE_ITT_BUILD_ARG(NULL), __null);
1544 }
1545 }
1546 if (__kmp_tasking_mode != tskm_immediate_exec) {
1547 __kmp_task_team_sync(this_thr, team);
1548 } // if
1549 }
1550 }
1551 ANNOTATE_BARRIER_END(&team->t.t_bar);
1552}
1553
1554void __kmp_join_barrier(int gtid) {
1555 KMP_TIME_PARTITIONED_BLOCK(OMP_join_barrier)((void)0);
1556 KMP_SET_THREAD_STATE_BLOCK(FORK_JOIN_BARRIER)((void)0);
1557 kmp_info_t *this_thr = __kmp_threads[gtid];
1558 kmp_team_t *team;
1559 kmp_uint nproc;
1560 kmp_info_t *master_thread;
1561 int tid;
1562#ifdef KMP_DEBUG1
1563 int team_id;
1564#endif /* KMP_DEBUG */
1565#if USE_ITT_BUILD1
1566 void *itt_sync_obj = NULL__null;
1567#if USE_ITT_NOTIFY1
1568 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0) // Don't call routine without need
1
Taking false branch
1569 // Get object created at fork_barrier
1570 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
1571#endif
1572#endif /* USE_ITT_BUILD */
1573 KMP_MB();
1574
1575 // Get current info
1576 team = this_thr->th.th_team;
1577 nproc = this_thr->th.th_team_nproc;
1578 KMP_DEBUG_ASSERT((int)nproc == team->t.t_nproc)if (!((int)nproc == team->t.t_nproc)) { __kmp_debug_assert
("(int)nproc == team->t.t_nproc", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1578); }
;
1579 tid = __kmp_tid_from_gtid(gtid);
2
Calling '__kmp_tid_from_gtid'
4
Returning from '__kmp_tid_from_gtid'
1580#ifdef KMP_DEBUG1
1581 team_id = team->t.t_id;
1582#endif /* KMP_DEBUG */
1583 master_thread = this_thr->th.th_team_master;
1584#ifdef KMP_DEBUG1
1585 if (master_thread != team->t.t_threads[0]) {
5
Assuming the condition is false
6
Taking false branch
1586 __kmp_print_structure();
1587 }
1588#endif /* KMP_DEBUG */
1589 KMP_DEBUG_ASSERT(master_thread == team->t.t_threads[0])if (!(master_thread == team->t.t_threads[0])) { __kmp_debug_assert
("master_thread == team->t.t_threads[0]", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1589); }
;
1590 KMP_MB();
1591
1592 // Verify state
1593 KMP_DEBUG_ASSERT(__kmp_threads && __kmp_threads[gtid])if (!(__kmp_threads && __kmp_threads[gtid])) { __kmp_debug_assert
("__kmp_threads && __kmp_threads[gtid]", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1593); }
;
1594 KMP_DEBUG_ASSERT(TCR_PTR(this_thr->th.th_team))if (!(((void *)(this_thr->th.th_team)))) { __kmp_debug_assert
("((void *)(this_thr->th.th_team))", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1594); }
;
1595 KMP_DEBUG_ASSERT(TCR_PTR(this_thr->th.th_root))if (!(((void *)(this_thr->th.th_root)))) { __kmp_debug_assert
("((void *)(this_thr->th.th_root))", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1595); }
;
1596 KMP_DEBUG_ASSERT(this_thr == team->t.t_threads[tid])if (!(this_thr == team->t.t_threads[tid])) { __kmp_debug_assert
("this_thr == team->t.t_threads[tid]", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1596); }
;
1597 KA_TRACE(10, ("__kmp_join_barrier: T#%d(%d:%d) arrived at join barrier\n",if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_join_barrier: T#%d(%d:%d) arrived at join barrier\n"
, gtid, team_id, tid); }
1598 gtid, team_id, tid))if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_join_barrier: T#%d(%d:%d) arrived at join barrier\n"
, gtid, team_id, tid); }
;
1599
1600 ANNOTATE_BARRIER_BEGIN(&team->t.t_bar);
1601#if OMPT_SUPPORT1
1602 if (ompt_enabled.enabled) {
7
Assuming the condition is true
8
Taking true branch
1603#if OMPT_OPTIONAL1
1604 ompt_data_t *my_task_data;
1605 ompt_data_t *my_parallel_data;
1606 void *codeptr = NULL__null;
1607 int ds_tid = this_thr->th.th_info.ds.ds_tid;
1608 if (KMP_MASTER_TID(ds_tid)((ds_tid) == 0) &&
11
Taking false branch
1609 (ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)ompt_callback_sync_region_wait_callback ||
9
Assuming pointer value is null
1610 ompt_callbacks.ompt_callback(ompt_callback_sync_region)ompt_callback_sync_region_callback))
10
Assuming the condition is false
1611 codeptr = team->t.ompt_team_info.master_return_address;
1612 my_task_data = OMPT_CUR_TASK_DATA(this_thr)(&(this_thr->th.th_current_task->ompt_task_info.task_data
))
;
1613 my_parallel_data = OMPT_CUR_TEAM_DATA(this_thr)(&(this_thr->th.th_team->t.ompt_team_info.parallel_data
))
;
1614 if (ompt_enabled.ompt_callback_sync_region) {
12
Assuming the condition is false
13
Taking false branch
1615 ompt_callbacks.ompt_callback(ompt_callback_sync_region)ompt_callback_sync_region_callback(
1616 ompt_sync_region_barrier, ompt_scope_begin, my_parallel_data,
1617 my_task_data, codeptr);
1618 }
1619 if (ompt_enabled.ompt_callback_sync_region_wait) {
14
Assuming the condition is true
15
Taking true branch
1620 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)ompt_callback_sync_region_wait_callback(
16
Called function pointer is null (null dereference)
1621 ompt_sync_region_barrier, ompt_scope_begin, my_parallel_data,
1622 my_task_data, codeptr);
1623 }
1624 if (!KMP_MASTER_TID(ds_tid)((ds_tid) == 0))
1625 this_thr->th.ompt_thread_info.task_data = *OMPT_CUR_TASK_DATA(this_thr)(&(this_thr->th.th_current_task->ompt_task_info.task_data
))
;
1626#endif
1627 this_thr->th.ompt_thread_info.state = omp_state_wait_barrier_implicit;
1628 }
1629#endif
1630
1631 if (__kmp_tasking_mode == tskm_extra_barrier) {
1632 __kmp_tasking_barrier(team, this_thr, gtid);
1633 KA_TRACE(10, ("__kmp_join_barrier: T#%d(%d:%d) past taking barrier\n", gtid,if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_join_barrier: T#%d(%d:%d) past taking barrier\n"
, gtid, team_id, tid); }
1634 team_id, tid))if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_join_barrier: T#%d(%d:%d) past taking barrier\n"
, gtid, team_id, tid); }
;
1635 }
1636#ifdef KMP_DEBUG1
1637 if (__kmp_tasking_mode != tskm_immediate_exec) {
1638 KA_TRACE(20, ("__kmp_join_barrier: T#%d, old team = %d, old task_team = "if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_join_barrier: T#%d, old team = %d, old task_team = "
"%p, th_task_team = %p\n", __kmp_gtid_from_thread(this_thr),
team_id, team->t.t_task_team[this_thr->th.th_task_state
], this_thr->th.th_task_team); }
1639 "%p, th_task_team = %p\n",if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_join_barrier: T#%d, old team = %d, old task_team = "
"%p, th_task_team = %p\n", __kmp_gtid_from_thread(this_thr),
team_id, team->t.t_task_team[this_thr->th.th_task_state
], this_thr->th.th_task_team); }
1640 __kmp_gtid_from_thread(this_thr), team_id,if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_join_barrier: T#%d, old team = %d, old task_team = "
"%p, th_task_team = %p\n", __kmp_gtid_from_thread(this_thr),
team_id, team->t.t_task_team[this_thr->th.th_task_state
], this_thr->th.th_task_team); }
1641 team->t.t_task_team[this_thr->th.th_task_state],if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_join_barrier: T#%d, old team = %d, old task_team = "
"%p, th_task_team = %p\n", __kmp_gtid_from_thread(this_thr),
team_id, team->t.t_task_team[this_thr->th.th_task_state
], this_thr->th.th_task_team); }
1642 this_thr->th.th_task_team))if (kmp_a_debug >= 20) { __kmp_debug_printf ("__kmp_join_barrier: T#%d, old team = %d, old task_team = "
"%p, th_task_team = %p\n", __kmp_gtid_from_thread(this_thr),
team_id, team->t.t_task_team[this_thr->th.th_task_state
], this_thr->th.th_task_team); }
;
1643 KMP_DEBUG_ASSERT(this_thr->th.th_task_team ==if (!(this_thr->th.th_task_team == team->t.t_task_team[
this_thr->th.th_task_state])) { __kmp_debug_assert("this_thr->th.th_task_team == team->t.t_task_team[this_thr->th.th_task_state]"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1644); }
1644 team->t.t_task_team[this_thr->th.th_task_state])if (!(this_thr->th.th_task_team == team->t.t_task_team[
this_thr->th.th_task_state])) { __kmp_debug_assert("this_thr->th.th_task_team == team->t.t_task_team[this_thr->th.th_task_state]"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1644); }
;
1645 }
1646#endif /* KMP_DEBUG */
1647
1648 /* Copy the blocktime info to the thread, where __kmp_wait_template() can
1649 access it when the team struct is not guaranteed to exist. Doing these
1650 loads causes a cache miss slows down EPCC parallel by 2x. As a workaround,
1651 we do not perform the copy if blocktime=infinite, since the values are not
1652 used by __kmp_wait_template() in that case. */
1653 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME(2147483647)) {
1654#if KMP_USE_MONITOR
1655 this_thr->th.th_team_bt_intervals =
1656 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
1657 this_thr->th.th_team_bt_set =
1658 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
1659#else
1660 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid)((((team)->t.t_threads[(tid)]->th.th_current_task->td_icvs
.bt_set) ? ((team)->t.t_threads[(tid)]->th.th_current_task
->td_icvs.blocktime) : __kmp_dflt_blocktime) * __kmp_ticks_per_msec
)
;
1661#endif
1662 }
1663
1664#if USE_ITT_BUILD1
1665 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0)
1666 __kmp_itt_barrier_starting(gtid, itt_sync_obj);
1667#endif /* USE_ITT_BUILD */
1668
1669 switch (__kmp_barrier_gather_pattern[bs_forkjoin_barrier]) {
1670 case bp_hyper_bar: {
1671 KMP_ASSERT(__kmp_barrier_gather_branch_bits[bs_forkjoin_barrier])if (!(__kmp_barrier_gather_branch_bits[bs_forkjoin_barrier]))
{ __kmp_debug_assert("__kmp_barrier_gather_branch_bits[bs_forkjoin_barrier]"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1671); }
;
1672 __kmp_hyper_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
1673 NULL__null USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1674 break;
1675 }
1676 case bp_hierarchical_bar: {
1677 __kmp_hierarchical_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
1678 NULL__null USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1679 break;
1680 }
1681 case bp_tree_bar: {
1682 KMP_ASSERT(__kmp_barrier_gather_branch_bits[bs_forkjoin_barrier])if (!(__kmp_barrier_gather_branch_bits[bs_forkjoin_barrier]))
{ __kmp_debug_assert("__kmp_barrier_gather_branch_bits[bs_forkjoin_barrier]"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1682); }
;
1683 __kmp_tree_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
1684 NULL__null USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1685 break;
1686 }
1687 default: {
1688 __kmp_linear_barrier_gather(bs_forkjoin_barrier, this_thr, gtid, tid,
1689 NULL__null USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1690 }
1691 }
1692
1693 /* From this point on, the team data structure may be deallocated at any time
1694 by the master thread - it is unsafe to reference it in any of the worker
1695 threads. Any per-team data items that need to be referenced before the
1696 end of the barrier should be moved to the kmp_task_team_t structs. */
1697 if (KMP_MASTER_TID(tid)((tid) == 0)) {
1698 if (__kmp_tasking_mode != tskm_immediate_exec) {
1699 __kmp_task_team_wait(this_thr, team USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1700 }
1701#if KMP_STATS_ENABLED0
1702 // Have master thread flag the workers to indicate they are now waiting for
1703 // next parallel region, Also wake them up so they switch their timers to
1704 // idle.
1705 for (int i = 0; i < team->t.t_nproc; ++i) {
1706 kmp_info_t *team_thread = team->t.t_threads[i];
1707 if (team_thread == this_thr)
1708 continue;
1709 team_thread->th.th_stats->setIdleFlag();
1710 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME(2147483647) &&
1711 team_thread->th.th_sleep_loc != NULL__null)
1712 __kmp_null_resume_wrapper(__kmp_gtid_from_thread(team_thread),
1713 team_thread->th.th_sleep_loc);
1714 }
1715#endif
1716#if USE_ITT_BUILD1
1717 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0)
1718 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
1719#endif /* USE_ITT_BUILD */
1720
1721#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
1722 // Join barrier - report frame end
1723 if ((__itt_frame_submit_v3_ptr__kmp_itt_frame_submit_v3_ptr__3_0 || KMP_ITT_DEBUG0) &&
1724 __kmp_forkjoin_frames_mode &&
1725#if OMP_40_ENABLED(50 >= 40)
1726 this_thr->th.th_teams_microtask == NULL__null &&
1727#endif
1728 team->t.t_active_level == 1) {
1729 kmp_uint64 cur_time = __itt_get_timestamp(!__kmp_itt_get_timestamp_ptr__3_0) ? 0 : __kmp_itt_get_timestamp_ptr__3_0();
1730 ident_t *loc = team->t.t_ident;
1731 kmp_info_t **other_threads = team->t.t_threads;
1732 int nproc = this_thr->th.th_team_nproc;
1733 int i;
1734 switch (__kmp_forkjoin_frames_mode) {
1735 case 1:
1736 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
1737 loc, nproc);
1738 break;
1739 case 2:
1740 __kmp_itt_frame_submit(gtid, this_thr->th.th_bar_min_time, cur_time, 1,
1741 loc, nproc);
1742 break;
1743 case 3:
1744 if (__itt_metadata_add_ptr__kmp_itt_metadata_add_ptr__3_0) {
1745 // Initialize with master's wait time
1746 kmp_uint64 delta = cur_time - this_thr->th.th_bar_arrive_time;
1747 // Set arrive time to zero to be able to check it in
1748 // __kmp_invoke_task(); the same is done inside the loop below
1749 this_thr->th.th_bar_arrive_time = 0;
1750 for (i = 1; i < nproc; ++i) {
1751 delta += (cur_time - other_threads[i]->th.th_bar_arrive_time);
1752 other_threads[i]->th.th_bar_arrive_time = 0;
1753 }
1754 __kmp_itt_metadata_imbalance(gtid, this_thr->th.th_frame_time,
1755 cur_time, delta, 0);
1756 }
1757 __kmp_itt_frame_submit(gtid, this_thr->th.th_frame_time, cur_time, 0,
1758 loc, nproc);
1759 this_thr->th.th_frame_time = cur_time;
1760 break;
1761 }
1762 }
1763#endif /* USE_ITT_BUILD */
1764 }
1765#if USE_ITT_BUILD1
1766 else {
1767 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0)
1768 __kmp_itt_barrier_middle(gtid, itt_sync_obj);
1769 }
1770#endif /* USE_ITT_BUILD */
1771
1772#if KMP_DEBUG1
1773 if (KMP_MASTER_TID(tid)((tid) == 0)) {
1774 KA_TRACE(if (kmp_a_debug >= 15) { __kmp_debug_printf ("__kmp_join_barrier: T#%d(%d:%d) says all %d team threads arrived\n"
, gtid, team_id, tid, nproc); }
1775 15,if (kmp_a_debug >= 15) { __kmp_debug_printf ("__kmp_join_barrier: T#%d(%d:%d) says all %d team threads arrived\n"
, gtid, team_id, tid, nproc); }
1776 ("__kmp_join_barrier: T#%d(%d:%d) says all %d team threads arrived\n",if (kmp_a_debug >= 15) { __kmp_debug_printf ("__kmp_join_barrier: T#%d(%d:%d) says all %d team threads arrived\n"
, gtid, team_id, tid, nproc); }
1777 gtid, team_id, tid, nproc))if (kmp_a_debug >= 15) { __kmp_debug_printf ("__kmp_join_barrier: T#%d(%d:%d) says all %d team threads arrived\n"
, gtid, team_id, tid, nproc); }
;
1778 }
1779#endif /* KMP_DEBUG */
1780
1781 // TODO now, mark worker threads as done so they may be disbanded
1782 KMP_MB(); // Flush all pending memory write invalidates.
1783 KA_TRACE(10,if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_join_barrier: T#%d(%d:%d) leaving\n"
, gtid, team_id, tid); }
1784 ("__kmp_join_barrier: T#%d(%d:%d) leaving\n", gtid, team_id, tid))if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_join_barrier: T#%d(%d:%d) leaving\n"
, gtid, team_id, tid); }
;
1785
1786 ANNOTATE_BARRIER_END(&team->t.t_bar);
1787}
1788
1789// TODO release worker threads' fork barriers as we are ready instead of all at
1790// once
1791void __kmp_fork_barrier(int gtid, int tid) {
1792 KMP_TIME_PARTITIONED_BLOCK(OMP_fork_barrier)((void)0);
1793 KMP_SET_THREAD_STATE_BLOCK(FORK_JOIN_BARRIER)((void)0);
1794 kmp_info_t *this_thr = __kmp_threads[gtid];
1795 kmp_team_t *team = (tid == 0) ? this_thr->th.th_team : NULL__null;
1796#if USE_ITT_BUILD1
1797 void *itt_sync_obj = NULL__null;
1798#endif /* USE_ITT_BUILD */
1799 if (team)
1800 ANNOTATE_BARRIER_END(&team->t.t_bar);
1801
1802 KA_TRACE(10, ("__kmp_fork_barrier: T#%d(%d:%d) has arrived\n", gtid,if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d(%d:%d) has arrived\n"
, gtid, (team != __null) ? team->t.t_id : -1, tid); }
1803 (team != NULL) ? team->t.t_id : -1, tid))if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d(%d:%d) has arrived\n"
, gtid, (team != __null) ? team->t.t_id : -1, tid); }
;
1804
1805 // th_team pointer only valid for master thread here
1806 if (KMP_MASTER_TID(tid)((tid) == 0)) {
1807#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
1808 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0) {
1809 // Create itt barrier object
1810 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier, 1);
1811 __kmp_itt_barrier_middle(gtid, itt_sync_obj); // Call acquired/releasing
1812 }
1813#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
1814
1815#ifdef KMP_DEBUG1
1816 kmp_info_t **other_threads = team->t.t_threads;
1817 int i;
1818
1819 // Verify state
1820 KMP_MB();
1821
1822 for (i = 1; i < team->t.t_nproc; ++i) {
1823 KA_TRACE(500,if (kmp_a_debug >= 500) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d(%d:0) checking T#%d(%d:%d) fork go "
"== %u.\n", gtid, team->t.t_id, other_threads[i]->th.th_info
.ds.ds_gtid, team->t.t_id, other_threads[i]->th.th_info
.ds.ds_tid, other_threads[i]->th.th_bar[bs_forkjoin_barrier
].bb.b_go); }
1824 ("__kmp_fork_barrier: T#%d(%d:0) checking T#%d(%d:%d) fork go "if (kmp_a_debug >= 500) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d(%d:0) checking T#%d(%d:%d) fork go "
"== %u.\n", gtid, team->t.t_id, other_threads[i]->th.th_info
.ds.ds_gtid, team->t.t_id, other_threads[i]->th.th_info
.ds.ds_tid, other_threads[i]->th.th_bar[bs_forkjoin_barrier
].bb.b_go); }
1825 "== %u.\n",if (kmp_a_debug >= 500) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d(%d:0) checking T#%d(%d:%d) fork go "
"== %u.\n", gtid, team->t.t_id, other_threads[i]->th.th_info
.ds.ds_gtid, team->t.t_id, other_threads[i]->th.th_info
.ds.ds_tid, other_threads[i]->th.th_bar[bs_forkjoin_barrier
].bb.b_go); }
1826 gtid, team->t.t_id, other_threads[i]->th.th_info.ds.ds_gtid,if (kmp_a_debug >= 500) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d(%d:0) checking T#%d(%d:%d) fork go "
"== %u.\n", gtid, team->t.t_id, other_threads[i]->th.th_info
.ds.ds_gtid, team->t.t_id, other_threads[i]->th.th_info
.ds.ds_tid, other_threads[i]->th.th_bar[bs_forkjoin_barrier
].bb.b_go); }
1827 team->t.t_id, other_threads[i]->th.th_info.ds.ds_tid,if (kmp_a_debug >= 500) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d(%d:0) checking T#%d(%d:%d) fork go "
"== %u.\n", gtid, team->t.t_id, other_threads[i]->th.th_info
.ds.ds_gtid, team->t.t_id, other_threads[i]->th.th_info
.ds.ds_tid, other_threads[i]->th.th_bar[bs_forkjoin_barrier
].bb.b_go); }
1828 other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go))if (kmp_a_debug >= 500) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d(%d:0) checking T#%d(%d:%d) fork go "
"== %u.\n", gtid, team->t.t_id, other_threads[i]->th.th_info
.ds.ds_gtid, team->t.t_id, other_threads[i]->th.th_info
.ds.ds_tid, other_threads[i]->th.th_bar[bs_forkjoin_barrier
].bb.b_go); }
;
1829 KMP_DEBUG_ASSERT(if (!(((other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb
.b_go) & ~((1 << 0))) == 0)) { __kmp_debug_assert("((other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go) & ~((1 << 0))) == 0"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1831); }
1830 (TCR_4(other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go) &if (!(((other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb
.b_go) & ~((1 << 0))) == 0)) { __kmp_debug_assert("((other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go) & ~((1 << 0))) == 0"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1831); }
1831 ~(KMP_BARRIER_SLEEP_STATE)) == KMP_INIT_BARRIER_STATE)if (!(((other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb
.b_go) & ~((1 << 0))) == 0)) { __kmp_debug_assert("((other_threads[i]->th.th_bar[bs_forkjoin_barrier].bb.b_go) & ~((1 << 0))) == 0"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1831); }
;
1832 KMP_DEBUG_ASSERT(other_threads[i]->th.th_team == team)if (!(other_threads[i]->th.th_team == team)) { __kmp_debug_assert
("other_threads[i]->th.th_team == team", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1832); }
;
1833 }
1834#endif
1835
1836 if (__kmp_tasking_mode != tskm_immediate_exec) {
1837 // 0 indicates setup current task team if nthreads > 1
1838 __kmp_task_team_setup(this_thr, team, 0);
1839 }
1840
1841 /* The master thread may have changed its blocktime between the join barrier
1842 and the fork barrier. Copy the blocktime info to the thread, where
1843 __kmp_wait_template() can access it when the team struct is not
1844 guaranteed to exist. */
1845 // See note about the corresponding code in __kmp_join_barrier() being
1846 // performance-critical
1847 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME(2147483647)) {
1848#if KMP_USE_MONITOR
1849 this_thr->th.th_team_bt_intervals =
1850 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
1851 this_thr->th.th_team_bt_set =
1852 team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
1853#else
1854 this_thr->th.th_team_bt_intervals = KMP_BLOCKTIME_INTERVAL(team, tid)((((team)->t.t_threads[(tid)]->th.th_current_task->td_icvs
.bt_set) ? ((team)->t.t_threads[(tid)]->th.th_current_task
->td_icvs.blocktime) : __kmp_dflt_blocktime) * __kmp_ticks_per_msec
)
;
1855#endif
1856 }
1857 } // master
1858
1859 switch (__kmp_barrier_release_pattern[bs_forkjoin_barrier]) {
1860 case bp_hyper_bar: {
1861 KMP_ASSERT(__kmp_barrier_release_branch_bits[bs_forkjoin_barrier])if (!(__kmp_barrier_release_branch_bits[bs_forkjoin_barrier])
) { __kmp_debug_assert("__kmp_barrier_release_branch_bits[bs_forkjoin_barrier]"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1861); }
;
1862 __kmp_hyper_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
1863 TRUE(!0) USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1864 break;
1865 }
1866 case bp_hierarchical_bar: {
1867 __kmp_hierarchical_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
1868 TRUE(!0) USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1869 break;
1870 }
1871 case bp_tree_bar: {
1872 KMP_ASSERT(__kmp_barrier_release_branch_bits[bs_forkjoin_barrier])if (!(__kmp_barrier_release_branch_bits[bs_forkjoin_barrier])
) { __kmp_debug_assert("__kmp_barrier_release_branch_bits[bs_forkjoin_barrier]"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1872); }
;
1873 __kmp_tree_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
1874 TRUE(!0) USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1875 break;
1876 }
1877 default: {
1878 __kmp_linear_barrier_release(bs_forkjoin_barrier, this_thr, gtid, tid,
1879 TRUE(!0) USE_ITT_BUILD_ARG(itt_sync_obj), itt_sync_obj);
1880 }
1881 }
1882
1883#if OMPT_SUPPORT1
1884 if (ompt_enabled.enabled &&
1885 this_thr->th.ompt_thread_info.state == omp_state_wait_barrier_implicit) {
1886 int ds_tid = this_thr->th.th_info.ds.ds_tid;
1887 ompt_data_t *task_data = (team)
1888 ? OMPT_CUR_TASK_DATA(this_thr)(&(this_thr->th.th_current_task->ompt_task_info.task_data
))
1889 : &(this_thr->th.ompt_thread_info.task_data);
1890 this_thr->th.ompt_thread_info.state = omp_state_overhead;
1891#if OMPT_OPTIONAL1
1892 void *codeptr = NULL__null;
1893 if (KMP_MASTER_TID(ds_tid)((ds_tid) == 0) &&
1894 (ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)ompt_callback_sync_region_wait_callback ||
1895 ompt_callbacks.ompt_callback(ompt_callback_sync_region)ompt_callback_sync_region_callback))
1896 codeptr = team->t.ompt_team_info.master_return_address;
1897 if (ompt_enabled.ompt_callback_sync_region_wait) {
1898 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)ompt_callback_sync_region_wait_callback(
1899 ompt_sync_region_barrier, ompt_scope_end, NULL__null, task_data, codeptr);
1900 }
1901 if (ompt_enabled.ompt_callback_sync_region) {
1902 ompt_callbacks.ompt_callback(ompt_callback_sync_region)ompt_callback_sync_region_callback(
1903 ompt_sync_region_barrier, ompt_scope_end, NULL__null, task_data, codeptr);
1904 }
1905#endif
1906 if (!KMP_MASTER_TID(ds_tid)((ds_tid) == 0) && ompt_enabled.ompt_callback_implicit_task) {
1907 ompt_callbacks.ompt_callback(ompt_callback_implicit_task)ompt_callback_implicit_task_callback(
1908 ompt_scope_end, NULL__null, task_data, 0, ds_tid);
1909 }
1910 }
1911#endif
1912
1913 // Early exit for reaping threads releasing forkjoin barrier
1914 if (TCR_4(__kmp_global.g.g_done)(__kmp_global.g.g_done)) {
1915 this_thr->th.th_task_team = NULL__null;
1916
1917#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
1918 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0) {
1919 if (!KMP_MASTER_TID(tid)((tid) == 0)) {
1920 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
1921 if (itt_sync_obj)
1922 __kmp_itt_barrier_finished(gtid, itt_sync_obj);
1923 }
1924 }
1925#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
1926 KA_TRACE(10, ("__kmp_fork_barrier: T#%d is leaving early\n", gtid))if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d is leaving early\n"
, gtid); }
;
1927 return;
1928 }
1929
1930 /* We can now assume that a valid team structure has been allocated by the
1931 master and propagated to all worker threads. The current thread, however,
1932 may not be part of the team, so we can't blindly assume that the team
1933 pointer is non-null. */
1934 team = (kmp_team_t *)TCR_PTR(this_thr->th.th_team)((void *)(this_thr->th.th_team));
1935 KMP_DEBUG_ASSERT(team != NULL)if (!(team != __null)) { __kmp_debug_assert("team != __null",
"/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 1935); }
;
1936 tid = __kmp_tid_from_gtid(gtid);
1937
1938#if KMP_BARRIER_ICV_PULL
1939 /* Master thread's copy of the ICVs was set up on the implicit taskdata in
1940 __kmp_reinitialize_team. __kmp_fork_call() assumes the master thread's
1941 implicit task has this data before this function is called. We cannot
1942 modify __kmp_fork_call() to look at the fixed ICVs in the master's thread
1943 struct, because it is not always the case that the threads arrays have
1944 been allocated when __kmp_fork_call() is executed. */
1945 {
1946 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_icv_copy)((void)0);
1947 if (!KMP_MASTER_TID(tid)((tid) == 0)) { // master thread already has ICVs
1948 // Copy the initial ICVs from the master's thread struct to the implicit
1949 // task for this tid.
1950 KA_TRACE(10,if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d(%d) is PULLing ICVs\n"
, gtid, tid); }
1951 ("__kmp_fork_barrier: T#%d(%d) is PULLing ICVs\n", gtid, tid))if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d(%d) is PULLing ICVs\n"
, gtid, tid); }
;
1952 __kmp_init_implicit_task(team->t.t_ident, team->t.t_threads[tid], team,
1953 tid, FALSE0);
1954 copy_icvs(&team->t.t_implicit_task_taskdata[tid].td_icvs,
1955 &team->t.t_threads[0]
1956 ->th.th_bar[bs_forkjoin_barrier]
1957 .bb.th_fixed_icvs);
1958 }
1959 }
1960#endif // KMP_BARRIER_ICV_PULL
1961
1962 if (__kmp_tasking_mode != tskm_immediate_exec) {
1963 __kmp_task_team_sync(this_thr, team);
1964 }
1965
1966#if OMP_40_ENABLED(50 >= 40) && KMP_AFFINITY_SUPPORTED1
1967 kmp_proc_bind_t proc_bind = team->t.t_proc_bind;
1968 if (proc_bind == proc_bind_intel) {
1969#endif
1970#if KMP_AFFINITY_SUPPORTED1
1971 // Call dynamic affinity settings
1972 if (__kmp_affinity_type == affinity_balanced && team->t.t_size_changed) {
1973 __kmp_balanced_affinity(this_thr, team->t.t_nproc);
1974 }
1975#endif // KMP_AFFINITY_SUPPORTED
1976#if OMP_40_ENABLED(50 >= 40) && KMP_AFFINITY_SUPPORTED1
1977 } else if (proc_bind != proc_bind_false) {
1978 if (this_thr->th.th_new_place == this_thr->th.th_current_place) {
1979 KA_TRACE(100, ("__kmp_fork_barrier: T#%d already in correct place %d\n",if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d already in correct place %d\n"
, __kmp_gtid_from_thread(this_thr), this_thr->th.th_current_place
); }
1980 __kmp_gtid_from_thread(this_thr),if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d already in correct place %d\n"
, __kmp_gtid_from_thread(this_thr), this_thr->th.th_current_place
); }
1981 this_thr->th.th_current_place))if (kmp_a_debug >= 100) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d already in correct place %d\n"
, __kmp_gtid_from_thread(this_thr), this_thr->th.th_current_place
); }
;
1982 } else {
1983 __kmp_affinity_set_place(gtid);
1984 }
1985 }
1986#endif
1987#if OMP_50_ENABLED(50 >= 50)
1988 if (!KMP_MASTER_TID(tid)((tid) == 0))
1989 KMP_CHECK_UPDATE(this_thr->th.th_def_allocator, team->t.t_def_allocator)if ((this_thr->th.th_def_allocator) != (team->t.t_def_allocator
)) (this_thr->th.th_def_allocator) = (team->t.t_def_allocator
)
;
1990#endif
1991
1992#if USE_ITT_BUILD1 && USE_ITT_NOTIFY1
1993 if (__itt_sync_create_ptr__kmp_itt_sync_create_ptr__3_0 || KMP_ITT_DEBUG0) {
1994 if (!KMP_MASTER_TID(tid)((tid) == 0)) {
1995 // Get correct barrier object
1996 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
1997 __kmp_itt_barrier_finished(gtid, itt_sync_obj); // Workers call acquired
1998 } // (prepare called inside barrier_release)
1999 }
2000#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
2001 ANNOTATE_BARRIER_END(&team->t.t_bar);
2002 KA_TRACE(10, ("__kmp_fork_barrier: T#%d(%d:%d) is leaving\n", gtid,if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d(%d:%d) is leaving\n"
, gtid, team->t.t_id, tid); }
2003 team->t.t_id, tid))if (kmp_a_debug >= 10) { __kmp_debug_printf ("__kmp_fork_barrier: T#%d(%d:%d) is leaving\n"
, gtid, team->t.t_id, tid); }
;
2004}
2005
2006void __kmp_setup_icv_copy(kmp_team_t *team, int new_nproc,
2007 kmp_internal_control_t *new_icvs, ident_t *loc) {
2008 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(KMP_setup_icv_copy)((void)0);
2009
2010 KMP_DEBUG_ASSERT(team && new_nproc && new_icvs)if (!(team && new_nproc && new_icvs)) { __kmp_debug_assert
("team && new_nproc && new_icvs", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 2010); }
;
2011 KMP_DEBUG_ASSERT((!TCR_4(__kmp_init_parallel)) || new_icvs->nproc)if (!((!(__kmp_init_parallel)) || new_icvs->nproc)) { __kmp_debug_assert
("(!(__kmp_init_parallel)) || new_icvs->nproc", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 2011); }
;
2012
2013/* Master thread's copy of the ICVs was set up on the implicit taskdata in
2014 __kmp_reinitialize_team. __kmp_fork_call() assumes the master thread's
2015 implicit task has this data before this function is called. */
2016#if KMP_BARRIER_ICV_PULL
2017 /* Copy ICVs to master's thread structure into th_fixed_icvs (which remains
2018 untouched), where all of the worker threads can access them and make their
2019 own copies after the barrier. */
2020 KMP_DEBUG_ASSERT(team->t.t_threads[0])if (!(team->t.t_threads[0])) { __kmp_debug_assert("team->t.t_threads[0]"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 2020); }
; // The threads arrays should be
2021 // allocated at this point
2022 copy_icvs(
2023 &team->t.t_threads[0]->th.th_bar[bs_forkjoin_barrier].bb.th_fixed_icvs,
2024 new_icvs);
2025 KF_TRACE(10, ("__kmp_setup_icv_copy: PULL: T#%d this_thread=%p team=%p\n", 0,if (kmp_f_debug >= 10) { __kmp_debug_printf ("__kmp_setup_icv_copy: PULL: T#%d this_thread=%p team=%p\n"
, 0, team->t.t_threads[0], team); }
2026 team->t.t_threads[0], team))if (kmp_f_debug >= 10) { __kmp_debug_printf ("__kmp_setup_icv_copy: PULL: T#%d this_thread=%p team=%p\n"
, 0, team->t.t_threads[0], team); }
;
2027#elif KMP_BARRIER_ICV_PUSH1
2028 // The ICVs will be propagated in the fork barrier, so nothing needs to be
2029 // done here.
2030 KF_TRACE(10, ("__kmp_setup_icv_copy: PUSH: T#%d this_thread=%p team=%p\n", 0,if (kmp_f_debug >= 10) { __kmp_debug_printf ("__kmp_setup_icv_copy: PUSH: T#%d this_thread=%p team=%p\n"
, 0, team->t.t_threads[0], team); }
2031 team->t.t_threads[0], team))if (kmp_f_debug >= 10) { __kmp_debug_printf ("__kmp_setup_icv_copy: PUSH: T#%d this_thread=%p team=%p\n"
, 0, team->t.t_threads[0], team); }
;
2032#else
2033 // Copy the ICVs to each of the non-master threads. This takes O(nthreads)
2034 // time.
2035 ngo_load(new_icvs)((void)0);
2036 KMP_DEBUG_ASSERT(team->t.t_threads[0])if (!(team->t.t_threads[0])) { __kmp_debug_assert("team->t.t_threads[0]"
, "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp_barrier.cpp"
, 2036); }
; // The threads arrays should be
2037 // allocated at this point
2038 for (int f = 1; f < new_nproc; ++f) { // Skip the master thread
2039 // TODO: GEH - pass in better source location info since usually NULL here
2040 KF_TRACE(10, ("__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n",if (kmp_f_debug >= 10) { __kmp_debug_printf ("__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n"
, f, team->t.t_threads[f], team); }
2041 f, team->t.t_threads[f], team))if (kmp_f_debug >= 10) { __kmp_debug_printf ("__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n"
, f, team->t.t_threads[f], team); }
;
2042 __kmp_init_implicit_task(loc, team->t.t_threads[f], team, f, FALSE0);
2043 ngo_store_icvs(&team->t.t_implicit_task_taskdata[f].td_icvs, new_icvs)copy_icvs((&team->t.t_implicit_task_taskdata[f].td_icvs
), (new_icvs))
;
2044 KF_TRACE(10, ("__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n",if (kmp_f_debug >= 10) { __kmp_debug_printf ("__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n"
, f, team->t.t_threads[f], team); }
2045 f, team->t.t_threads[f], team))if (kmp_f_debug >= 10) { __kmp_debug_printf ("__kmp_setup_icv_copy: LINEAR: T#%d this_thread=%p team=%p\n"
, f, team->t.t_threads[f], team); }
;
2046 }
2047 ngo_sync()((void)0);
2048#endif // KMP_BARRIER_ICV_PULL
2049}

/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp.h

1/*! \file */
2/*
3 * kmp.h -- KPTS runtime header file.
4 */
5
6//===----------------------------------------------------------------------===//
7//
8// The LLVM Compiler Infrastructure
9//
10// This file is dual licensed under the MIT and the University of Illinois Open
11// Source Licenses. See LICENSE.txt for details.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef KMP_H
16#define KMP_H
17
18#include "kmp_config.h"
19
20/* #define BUILD_PARALLEL_ORDERED 1 */
21
22/* This fix replaces gettimeofday with clock_gettime for better scalability on
23 the Altix. Requires user code to be linked with -lrt. */
24//#define FIX_SGI_CLOCK
25
26/* Defines for OpenMP 3.0 tasking and auto scheduling */
27
28#ifndef KMP_STATIC_STEAL_ENABLED1
29#define KMP_STATIC_STEAL_ENABLED1 1
30#endif
31
32#define TASK_CURRENT_NOT_QUEUED0 0
33#define TASK_CURRENT_QUEUED1 1
34
35#ifdef BUILD_TIED_TASK_STACK
36#define TASK_STACK_EMPTY 0 // entries when the stack is empty
37#define TASK_STACK_BLOCK_BITS 5 // Used in TASK_STACK_SIZE and TASK_STACK_MASK
38// Number of entries in each task stack array
39#define TASK_STACK_BLOCK_SIZE (1 << TASK_STACK_BLOCK_BITS)
40// Mask for determining index into stack block
41#define TASK_STACK_INDEX_MASK (TASK_STACK_BLOCK_SIZE - 1)
42#endif // BUILD_TIED_TASK_STACK
43
44#define TASK_NOT_PUSHED1 1
45#define TASK_SUCCESSFULLY_PUSHED0 0
46#define TASK_TIED1 1
47#define TASK_UNTIED0 0
48#define TASK_EXPLICIT1 1
49#define TASK_IMPLICIT0 0
50#define TASK_PROXY1 1
51#define TASK_FULL0 0
52
53#define KMP_CANCEL_THREADS
54#define KMP_THREAD_ATTR
55
56// Android does not have pthread_cancel. Undefine KMP_CANCEL_THREADS if being
57// built on Android
58#if defined(__ANDROID__)
59#undef KMP_CANCEL_THREADS
60#endif
61
62#include <signal.h>
63#include <stdarg.h>
64#include <stddef.h>
65#include <stdio.h>
66#include <stdlib.h>
67#include <string.h>
68/* include <ctype.h> don't use; problems with /MD on Windows* OS NT due to bad
69 Microsoft library. Some macros provided below to replace these functions */
70#ifndef __ABSOFT_WIN
71#include <sys/types.h>
72#endif
73#include <limits.h>
74#include <time.h>
75
76#include <errno(*__errno_location ()).h>
77
78#include "kmp_os.h"
79
80#include "kmp_safe_c_api.h"
81
82#if KMP_STATS_ENABLED0
83class kmp_stats_list;
84#endif
85
86#if KMP_USE_HIER_SCHED0
87// Only include hierarchical scheduling if affinity is supported
88#undef KMP_USE_HIER_SCHED0
89#define KMP_USE_HIER_SCHED0 KMP_AFFINITY_SUPPORTED1
90#endif
91
92#if KMP_USE_HWLOC0 && KMP_AFFINITY_SUPPORTED1
93#include "hwloc.h"
94#ifndef HWLOC_OBJ_NUMANODE
95#define HWLOC_OBJ_NUMANODE HWLOC_OBJ_NODE
96#endif
97#ifndef HWLOC_OBJ_PACKAGE
98#define HWLOC_OBJ_PACKAGE HWLOC_OBJ_SOCKET
99#endif
100#endif
101
102#if KMP_ARCH_X860 || KMP_ARCH_X86_641
103#include <xmmintrin.h>
104#endif
105
106#include "kmp_debug.h"
107#include "kmp_lock.h"
108#include "kmp_version.h"
109#if USE_DEBUGGER0
110#include "kmp_debugger.h"
111#endif
112#include "kmp_i18n.h"
113
114#define KMP_HANDLE_SIGNALS(1 || 0) (KMP_OS_UNIX1 || KMP_OS_WINDOWS0)
115
116#include "kmp_wrapper_malloc.h"
117#if KMP_OS_UNIX1
118#include <unistd.h>
119#if !defined NSIG65 && defined _NSIG65
120#define NSIG65 _NSIG65
121#endif
122#endif
123
124#if KMP_OS_LINUX1
125#pragma weak clock_gettime
126#endif
127
128#if OMPT_SUPPORT1
129#include "ompt-internal.h"
130#endif
131
132// 0 - no fast memory allocation, alignment: 8-byte on x86, 16-byte on x64.
133// 3 - fast allocation using sync, non-sync free lists of any size, non-self
134// free lists of limited size.
135#ifndef USE_FAST_MEMORY3
136#define USE_FAST_MEMORY3 3
137#endif
138
139#ifndef KMP_NESTED_HOT_TEAMS1
140#define KMP_NESTED_HOT_TEAMS1 0
141#define USE_NESTED_HOT_ARG(x), x
142#else
143#if KMP_NESTED_HOT_TEAMS1
144#if OMP_40_ENABLED(50 >= 40)
145#define USE_NESTED_HOT_ARG(x), x , x
146#else
147// Nested hot teams feature depends on omp 4.0, disable it for earlier versions
148#undef KMP_NESTED_HOT_TEAMS1
149#define KMP_NESTED_HOT_TEAMS1 0
150#define USE_NESTED_HOT_ARG(x), x
151#endif
152#else
153#define USE_NESTED_HOT_ARG(x), x
154#endif
155#endif
156
157// Assume using BGET compare_exchange instruction instead of lock by default.
158#ifndef USE_CMP_XCHG_FOR_BGET1
159#define USE_CMP_XCHG_FOR_BGET1 1
160#endif
161
162// Test to see if queuing lock is better than bootstrap lock for bget
163// #ifndef USE_QUEUING_LOCK_FOR_BGET
164// #define USE_QUEUING_LOCK_FOR_BGET
165// #endif
166
167#define KMP_NSEC_PER_SEC1000000000L 1000000000L
168#define KMP_USEC_PER_SEC1000000L 1000000L
169
170/*!
171@ingroup BASIC_TYPES
172@{
173*/
174
175/*!
176Values for bit flags used in the ident_t to describe the fields.
177*/
178enum {
179 /*! Use trampoline for internal microtasks */
180 KMP_IDENT_IMB = 0x01,
181 /*! Use c-style ident structure */
182 KMP_IDENT_KMPC = 0x02,
183 /* 0x04 is no longer used */
184 /*! Entry point generated by auto-parallelization */
185 KMP_IDENT_AUTOPAR = 0x08,
186 /*! Compiler generates atomic reduction option for kmpc_reduce* */
187 KMP_IDENT_ATOMIC_REDUCE = 0x10,
188 /*! To mark a 'barrier' directive in user code */
189 KMP_IDENT_BARRIER_EXPL = 0x20,
190 /*! To Mark implicit barriers. */
191 KMP_IDENT_BARRIER_IMPL = 0x0040,
192 KMP_IDENT_BARRIER_IMPL_MASK = 0x01C0,
193 KMP_IDENT_BARRIER_IMPL_FOR = 0x0040,
194 KMP_IDENT_BARRIER_IMPL_SECTIONS = 0x00C0,
195
196 KMP_IDENT_BARRIER_IMPL_SINGLE = 0x0140,
197 KMP_IDENT_BARRIER_IMPL_WORKSHARE = 0x01C0,
198
199 /*! To mark a static loop in OMPT callbacks */
200 KMP_IDENT_WORK_LOOP = 0x200,
201 /*! To mark a sections directive in OMPT callbacks */
202 KMP_IDENT_WORK_SECTIONS = 0x400,
203 /*! To mark a distirbute construct in OMPT callbacks */
204 KMP_IDENT_WORK_DISTRIBUTE = 0x800,
205 /*! Atomic hint; bottom four bits as omp_sync_hint_t. Top four reserved and
206 not currently used. If one day we need more bits, then we can use
207 an invalid combination of hints to mean that another, larger field
208 should be used in a different flag. */
209 KMP_IDENT_ATOMIC_HINT_MASK = 0xFF0000,
210 KMP_IDENT_ATOMIC_HINT_UNCONTENDED = 0x010000,
211 KMP_IDENT_ATOMIC_HINT_CONTENDED = 0x020000,
212 KMP_IDENT_ATOMIC_HINT_NONSPECULATIVE = 0x040000,
213 KMP_IDENT_ATOMIC_HINT_SPECULATIVE = 0x080000,
214};
215
216/*!
217 * The ident structure that describes a source location.
218 */
219typedef struct ident {
220 kmp_int32 reserved_1; /**< might be used in Fortran; see above */
221 kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags; KMP_IDENT_KMPC
222 identifies this union member */
223 kmp_int32 reserved_2; /**< not really used in Fortran any more; see above */
224#if USE_ITT_BUILD1
225/* but currently used for storing region-specific ITT */
226/* contextual information. */
227#endif /* USE_ITT_BUILD */
228 kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for C++ */
229 char const *psource; /**< String describing the source location.
230 The string is composed of semi-colon separated fields
231 which describe the source file, the function and a pair
232 of line numbers that delimit the construct. */
233} ident_t;
234/*!
235@}
236*/
237
238// Some forward declarations.
239typedef union kmp_team kmp_team_t;
240typedef struct kmp_taskdata kmp_taskdata_t;
241typedef union kmp_task_team kmp_task_team_t;
242typedef union kmp_team kmp_team_p;
243typedef union kmp_info kmp_info_p;
244typedef union kmp_root kmp_root_p;
245
246#ifdef __cplusplus201103L
247extern "C" {
248#endif
249
250/* ------------------------------------------------------------------------ */
251
252/* Pack two 32-bit signed integers into a 64-bit signed integer */
253/* ToDo: Fix word ordering for big-endian machines. */
254#define KMP_PACK_64(HIGH_32, LOW_32)((kmp_int64)((((kmp_uint64)(HIGH_32)) << 32) | (kmp_uint64
)(LOW_32)))
\
255 ((kmp_int64)((((kmp_uint64)(HIGH_32)) << 32) | (kmp_uint64)(LOW_32)))
256
257// Generic string manipulation macros. Assume that _x is of type char *
258#define SKIP_WS(_x){ while (*(_x) == ' ' || *(_x) == '\t') (_x)++; } \
259 { \
260 while (*(_x) == ' ' || *(_x) == '\t') \
261 (_x)++; \
262 }
263#define SKIP_DIGITS(_x){ while (*(_x) >= '0' && *(_x) <= '9') (_x)++; } \
264 { \
265 while (*(_x) >= '0' && *(_x) <= '9') \
266 (_x)++; \
267 }
268#define SKIP_TOKEN(_x){ while ((*(_x) >= '0' && *(_x) <= '9') || (*(_x
) >= 'a' && *(_x) <= 'z') || (*(_x) >= 'A' &&
*(_x) <= 'Z') || *(_x) == '_') (_x)++; }
\
269 { \
270 while ((*(_x) >= '0' && *(_x) <= '9') || (*(_x) >= 'a' && *(_x) <= 'z') || \
271 (*(_x) >= 'A' && *(_x) <= 'Z') || *(_x) == '_') \
272 (_x)++; \
273 }
274#define SKIP_TO(_x, _c){ while (*(_x) != '\0' && *(_x) != (_c)) (_x)++; } \
275 { \
276 while (*(_x) != '\0' && *(_x) != (_c)) \
277 (_x)++; \
278 }
279
280/* ------------------------------------------------------------------------ */
281
282#define KMP_MAX(x, y)((x) > (y) ? (x) : (y)) ((x) > (y) ? (x) : (y))
283#define KMP_MIN(x, y)((x) < (y) ? (x) : (y)) ((x) < (y) ? (x) : (y))
284
285/* ------------------------------------------------------------------------ */
286/* Enumeration types */
287
288enum kmp_state_timer {
289 ts_stop,
290 ts_start,
291 ts_pause,
292
293 ts_last_state
294};
295
296enum dynamic_mode {
297 dynamic_default,
298#ifdef USE_LOAD_BALANCE1
299 dynamic_load_balance,
300#endif /* USE_LOAD_BALANCE */
301 dynamic_random,
302 dynamic_thread_limit,
303 dynamic_max
304};
305
306/* external schedule constants, duplicate enum omp_sched in omp.h in order to
307 * not include it here */
308#ifndef KMP_SCHED_TYPE_DEFINED
309#define KMP_SCHED_TYPE_DEFINED
310typedef enum kmp_sched {
311 kmp_sched_lower = 0, // lower and upper bounds are for routine parameter check
312 // Note: need to adjust __kmp_sch_map global array in case enum is changed
313 kmp_sched_static = 1, // mapped to kmp_sch_static_chunked (33)
314 kmp_sched_dynamic = 2, // mapped to kmp_sch_dynamic_chunked (35)
315 kmp_sched_guided = 3, // mapped to kmp_sch_guided_chunked (36)
316 kmp_sched_auto = 4, // mapped to kmp_sch_auto (38)
317 kmp_sched_upper_std = 5, // upper bound for standard schedules
318 kmp_sched_lower_ext = 100, // lower bound of Intel extension schedules
319 kmp_sched_trapezoidal = 101, // mapped to kmp_sch_trapezoidal (39)
320#if KMP_STATIC_STEAL_ENABLED1
321 kmp_sched_static_steal = 102, // mapped to kmp_sch_static_steal (44)
322#endif
323 kmp_sched_upper,
324 kmp_sched_default = kmp_sched_static // default scheduling
325} kmp_sched_t;
326#endif
327
328/*!
329 @ingroup WORK_SHARING
330 * Describes the loop schedule to be used for a parallel for loop.
331 */
332enum sched_type : kmp_int32 {
333 kmp_sch_lower = 32, /**< lower bound for unordered values */
334 kmp_sch_static_chunked = 33,
335 kmp_sch_static = 34, /**< static unspecialized */
336 kmp_sch_dynamic_chunked = 35,
337 kmp_sch_guided_chunked = 36, /**< guided unspecialized */
338 kmp_sch_runtime = 37,
339 kmp_sch_auto = 38, /**< auto */
340 kmp_sch_trapezoidal = 39,
341
342 /* accessible only through KMP_SCHEDULE environment variable */
343 kmp_sch_static_greedy = 40,
344 kmp_sch_static_balanced = 41,
345 /* accessible only through KMP_SCHEDULE environment variable */
346 kmp_sch_guided_iterative_chunked = 42,
347 kmp_sch_guided_analytical_chunked = 43,
348 /* accessible only through KMP_SCHEDULE environment variable */
349 kmp_sch_static_steal = 44,
350
351#if OMP_45_ENABLED(50 >= 45)
352 /* static with chunk adjustment (e.g., simd) */
353 kmp_sch_static_balanced_chunked = 45,
354 kmp_sch_guided_simd = 46, /**< guided with chunk adjustment */
355 kmp_sch_runtime_simd = 47, /**< runtime with chunk adjustment */
356#endif
357
358 /* accessible only through KMP_SCHEDULE environment variable */
359 kmp_sch_upper, /**< upper bound for unordered values */
360
361 kmp_ord_lower = 64, /**< lower bound for ordered values, must be power of 2 */
362 kmp_ord_static_chunked = 65,
363 kmp_ord_static = 66, /**< ordered static unspecialized */
364 kmp_ord_dynamic_chunked = 67,
365 kmp_ord_guided_chunked = 68,
366 kmp_ord_runtime = 69,
367 kmp_ord_auto = 70, /**< ordered auto */
368 kmp_ord_trapezoidal = 71,
369 kmp_ord_upper, /**< upper bound for ordered values */
370
371#if OMP_40_ENABLED(50 >= 40)
372 /* Schedules for Distribute construct */
373 kmp_distribute_static_chunked = 91, /**< distribute static chunked */
374 kmp_distribute_static = 92, /**< distribute static unspecialized */
375#endif
376
377 /* For the "nomerge" versions, kmp_dispatch_next*() will always return a
378 single iteration/chunk, even if the loop is serialized. For the schedule
379 types listed above, the entire iteration vector is returned if the loop is
380 serialized. This doesn't work for gcc/gcomp sections. */
381 kmp_nm_lower = 160, /**< lower bound for nomerge values */
382
383 kmp_nm_static_chunked =
384 (kmp_sch_static_chunked - kmp_sch_lower + kmp_nm_lower),
385 kmp_nm_static = 162, /**< static unspecialized */
386 kmp_nm_dynamic_chunked = 163,
387 kmp_nm_guided_chunked = 164, /**< guided unspecialized */
388 kmp_nm_runtime = 165,
389 kmp_nm_auto = 166, /**< auto */
390 kmp_nm_trapezoidal = 167,
391
392 /* accessible only through KMP_SCHEDULE environment variable */
393 kmp_nm_static_greedy = 168,
394 kmp_nm_static_balanced = 169,
395 /* accessible only through KMP_SCHEDULE environment variable */
396 kmp_nm_guided_iterative_chunked = 170,
397 kmp_nm_guided_analytical_chunked = 171,
398 kmp_nm_static_steal =
399 172, /* accessible only through OMP_SCHEDULE environment variable */
400
401 kmp_nm_ord_static_chunked = 193,
402 kmp_nm_ord_static = 194, /**< ordered static unspecialized */
403 kmp_nm_ord_dynamic_chunked = 195,
404 kmp_nm_ord_guided_chunked = 196,
405 kmp_nm_ord_runtime = 197,
406 kmp_nm_ord_auto = 198, /**< auto */
407 kmp_nm_ord_trapezoidal = 199,
408 kmp_nm_upper, /**< upper bound for nomerge values */
409
410#if OMP_45_ENABLED(50 >= 45)
411 /* Support for OpenMP 4.5 monotonic and nonmonotonic schedule modifiers. Since
412 we need to distinguish the three possible cases (no modifier, monotonic
413 modifier, nonmonotonic modifier), we need separate bits for each modifier.
414 The absence of monotonic does not imply nonmonotonic, especially since 4.5
415 says that the behaviour of the "no modifier" case is implementation defined
416 in 4.5, but will become "nonmonotonic" in 5.0.
417
418 Since we're passing a full 32 bit value, we can use a couple of high bits
419 for these flags; out of paranoia we avoid the sign bit.
420
421 These modifiers can be or-ed into non-static schedules by the compiler to
422 pass the additional information. They will be stripped early in the
423 processing in __kmp_dispatch_init when setting up schedules, so most of the
424 code won't ever see schedules with these bits set. */
425 kmp_sch_modifier_monotonic =
426 (1 << 29), /**< Set if the monotonic schedule modifier was present */
427 kmp_sch_modifier_nonmonotonic =
428 (1 << 30), /**< Set if the nonmonotonic schedule modifier was present */
429
430#define SCHEDULE_WITHOUT_MODIFIERS(s)(enum sched_type)( (s) & ~(kmp_sch_modifier_nonmonotonic |
kmp_sch_modifier_monotonic))
\
431 (enum sched_type)( \
432 (s) & ~(kmp_sch_modifier_nonmonotonic | kmp_sch_modifier_monotonic))
433#define SCHEDULE_HAS_MONOTONIC(s)(((s)&kmp_sch_modifier_monotonic) != 0) (((s)&kmp_sch_modifier_monotonic) != 0)
434#define SCHEDULE_HAS_NONMONOTONIC(s)(((s)&kmp_sch_modifier_nonmonotonic) != 0) (((s)&kmp_sch_modifier_nonmonotonic) != 0)
435#define SCHEDULE_HAS_NO_MODIFIERS(s)(((s) & (kmp_sch_modifier_nonmonotonic | kmp_sch_modifier_monotonic
)) == 0)
\
436 (((s) & (kmp_sch_modifier_nonmonotonic | kmp_sch_modifier_monotonic)) == 0)
437#else
438/* By doing this we hope to avoid multiple tests on OMP_45_ENABLED. Compilers
439 can now eliminate tests on compile time constants and dead code that results
440 from them, so we can leave code guarded by such an if in place. */
441#define SCHEDULE_WITHOUT_MODIFIERS(s)(enum sched_type)( (s) & ~(kmp_sch_modifier_nonmonotonic |
kmp_sch_modifier_monotonic))
(s)
442#define SCHEDULE_HAS_MONOTONIC(s)(((s)&kmp_sch_modifier_monotonic) != 0) false
443#define SCHEDULE_HAS_NONMONOTONIC(s)(((s)&kmp_sch_modifier_nonmonotonic) != 0) false
444#define SCHEDULE_HAS_NO_MODIFIERS(s)(((s) & (kmp_sch_modifier_nonmonotonic | kmp_sch_modifier_monotonic
)) == 0)
true
445#endif
446
447 kmp_sch_default = kmp_sch_static /**< default scheduling algorithm */
448};
449
450/* Type to keep runtime schedule set via OMP_SCHEDULE or omp_set_schedule() */
451typedef union kmp_r_sched {
452 struct {
453 enum sched_type r_sched_type;
454 int chunk;
455 };
456 kmp_int64 sched;
457} kmp_r_sched_t;
458
459extern enum sched_type __kmp_sch_map[]; // map OMP 3.0 schedule types with our
460// internal schedule types
461
462enum library_type {
463 library_none,
464 library_serial,
465 library_turnaround,
466 library_throughput
467};
468
469#if KMP_OS_LINUX1
470enum clock_function_type {
471 clock_function_gettimeofday,
472 clock_function_clock_gettime
473};
474#endif /* KMP_OS_LINUX */
475
476#if KMP_MIC_SUPPORTED((0 || 1) && (1 || 0))
477enum mic_type { non_mic, mic1, mic2, mic3, dummy };
478#endif
479
480/* -- fast reduction stuff ------------------------------------------------ */
481
482#undef KMP_FAST_REDUCTION_BARRIER1
483#define KMP_FAST_REDUCTION_BARRIER1 1
484
485#undef KMP_FAST_REDUCTION_CORE_DUO1
486#if KMP_ARCH_X860 || KMP_ARCH_X86_641
487#define KMP_FAST_REDUCTION_CORE_DUO1 1
488#endif
489
490enum _reduction_method {
491 reduction_method_not_defined = 0,
492 critical_reduce_block = (1 << 8),
493 atomic_reduce_block = (2 << 8),
494 tree_reduce_block = (3 << 8),
495 empty_reduce_block = (4 << 8)
496};
497
498// Description of the packed_reduction_method variable:
499// The packed_reduction_method variable consists of two enum types variables
500// that are packed together into 0-th byte and 1-st byte:
501// 0: (packed_reduction_method & 0x000000FF) is a 'enum barrier_type' value of
502// barrier that will be used in fast reduction: bs_plain_barrier or
503// bs_reduction_barrier
504// 1: (packed_reduction_method & 0x0000FF00) is a reduction method that will
505// be used in fast reduction;
506// Reduction method is of 'enum _reduction_method' type and it's defined the way
507// so that the bits of 0-th byte are empty, so no need to execute a shift
508// instruction while packing/unpacking
509
510#if KMP_FAST_REDUCTION_BARRIER1
511#define PACK_REDUCTION_METHOD_AND_BARRIER(reduction_method, barrier_type)((reduction_method) | (barrier_type)) \
512 ((reduction_method) | (barrier_type))
513
514#define UNPACK_REDUCTION_METHOD(packed_reduction_method)((enum _reduction_method)((packed_reduction_method) & (0x0000FF00
)))
\
515 ((enum _reduction_method)((packed_reduction_method) & (0x0000FF00)))
516
517#define UNPACK_REDUCTION_BARRIER(packed_reduction_method)((enum barrier_type)((packed_reduction_method) & (0x000000FF
)))
\
518 ((enum barrier_type)((packed_reduction_method) & (0x000000FF)))
519#else
520#define PACK_REDUCTION_METHOD_AND_BARRIER(reduction_method, barrier_type)((reduction_method) | (barrier_type)) \
521 (reduction_method)
522
523#define UNPACK_REDUCTION_METHOD(packed_reduction_method)((enum _reduction_method)((packed_reduction_method) & (0x0000FF00
)))
\
524 (packed_reduction_method)
525
526#define UNPACK_REDUCTION_BARRIER(packed_reduction_method)((enum barrier_type)((packed_reduction_method) & (0x000000FF
)))
(bs_plain_barrier)
527#endif
528
529#define TEST_REDUCTION_METHOD(packed_reduction_method, which_reduction_block)((((enum _reduction_method)((packed_reduction_method) & (
0x0000FF00)))) == (which_reduction_block))
\
530 ((UNPACK_REDUCTION_METHOD(packed_reduction_method)((enum _reduction_method)((packed_reduction_method) & (0x0000FF00
)))
) == \
531 (which_reduction_block))
532
533#if KMP_FAST_REDUCTION_BARRIER1
534#define TREE_REDUCE_BLOCK_WITH_REDUCTION_BARRIER(((tree_reduce_block) | (bs_reduction_barrier))) \
535 (PACK_REDUCTION_METHOD_AND_BARRIER(tree_reduce_block, bs_reduction_barrier)((tree_reduce_block) | (bs_reduction_barrier)))
536
537#define TREE_REDUCE_BLOCK_WITH_PLAIN_BARRIER(((tree_reduce_block) | (bs_plain_barrier))) \
538 (PACK_REDUCTION_METHOD_AND_BARRIER(tree_reduce_block, bs_plain_barrier)((tree_reduce_block) | (bs_plain_barrier)))
539#endif
540
541typedef int PACKED_REDUCTION_METHOD_T;
542
543/* -- end of fast reduction stuff ----------------------------------------- */
544
545#if KMP_OS_WINDOWS0
546#define USE_CBLKDATA
547#pragma warning(push)
548#pragma warning(disable : 271 310)
549#include <windows.h>
550#pragma warning(pop)
551#endif
552
553#if KMP_OS_UNIX1
554#include <dlfcn.h>
555#include <pthread.h>
556#endif
557
558/* Only Linux* OS and Windows* OS support thread affinity. */
559#if KMP_AFFINITY_SUPPORTED1
560
561// GROUP_AFFINITY is already defined for _MSC_VER>=1600 (VS2010 and later).
562#if KMP_OS_WINDOWS0
563#if _MSC_VER < 1600
564typedef struct GROUP_AFFINITY {
565 KAFFINITY Mask;
566 WORD Group;
567 WORD Reserved[3];
568} GROUP_AFFINITY;
569#endif /* _MSC_VER < 1600 */
570#if KMP_GROUP_AFFINITY0
571extern int __kmp_num_proc_groups;
572#else
573static const int __kmp_num_proc_groups = 1;
574#endif /* KMP_GROUP_AFFINITY */
575typedef DWORD (*kmp_GetActiveProcessorCount_t)(WORD);
576extern kmp_GetActiveProcessorCount_t __kmp_GetActiveProcessorCount;
577
578typedef WORD (*kmp_GetActiveProcessorGroupCount_t)(void);
579extern kmp_GetActiveProcessorGroupCount_t __kmp_GetActiveProcessorGroupCount;
580
581typedef BOOL (*kmp_GetThreadGroupAffinity_t)(HANDLE, GROUP_AFFINITY *);
582extern kmp_GetThreadGroupAffinity_t __kmp_GetThreadGroupAffinity;
583
584typedef BOOL (*kmp_SetThreadGroupAffinity_t)(HANDLE, const GROUP_AFFINITY *,
585 GROUP_AFFINITY *);
586extern kmp_SetThreadGroupAffinity_t __kmp_SetThreadGroupAffinity;
587#endif /* KMP_OS_WINDOWS */
588
589#if KMP_USE_HWLOC0
590extern hwloc_topology_t __kmp_hwloc_topology;
591extern int __kmp_hwloc_error;
592extern int __kmp_numa_detected;
593extern int __kmp_tile_depth;
594#endif
595
596extern size_t __kmp_affin_mask_size;
597#define KMP_AFFINITY_CAPABLE()(__kmp_affin_mask_size > 0) (__kmp_affin_mask_size > 0)
598#define KMP_AFFINITY_DISABLE()(__kmp_affin_mask_size = 0) (__kmp_affin_mask_size = 0)
599#define KMP_AFFINITY_ENABLE(mask_size)(__kmp_affin_mask_size = mask_size) (__kmp_affin_mask_size = mask_size)
600#define KMP_CPU_SET_ITERATE(i, mask)for (i = (mask)->begin(); (int)i != (mask)->end(); i = (
mask)->next(i))
\
601 for (i = (mask)->begin(); (int)i != (mask)->end(); i = (mask)->next(i))
602#define KMP_CPU_SET(i, mask)(mask)->set(i) (mask)->set(i)
603#define KMP_CPU_ISSET(i, mask)(mask)->is_set(i) (mask)->is_set(i)
604#define KMP_CPU_CLR(i, mask)(mask)->clear(i) (mask)->clear(i)
605#define KMP_CPU_ZERO(mask)(mask)->zero() (mask)->zero()
606#define KMP_CPU_COPY(dest, src)(dest)->copy(src) (dest)->copy(src)
607#define KMP_CPU_AND(dest, src)(dest)->bitwise_and(src) (dest)->bitwise_and(src)
608#define KMP_CPU_COMPLEMENT(max_bit_number, mask)(mask)->bitwise_not() (mask)->bitwise_not()
609#define KMP_CPU_UNION(dest, src)(dest)->bitwise_or(src) (dest)->bitwise_or(src)
610#define KMP_CPU_ALLOC(ptr)(ptr = __kmp_affinity_dispatch->allocate_mask()) (ptr = __kmp_affinity_dispatch->allocate_mask())
611#define KMP_CPU_FREE(ptr)__kmp_affinity_dispatch->deallocate_mask(ptr) __kmp_affinity_dispatch->deallocate_mask(ptr)
612#define KMP_CPU_ALLOC_ON_STACK(ptr)(ptr = __kmp_affinity_dispatch->allocate_mask()) KMP_CPU_ALLOC(ptr)(ptr = __kmp_affinity_dispatch->allocate_mask())
613#define KMP_CPU_FREE_FROM_STACK(ptr)__kmp_affinity_dispatch->deallocate_mask(ptr) KMP_CPU_FREE(ptr)__kmp_affinity_dispatch->deallocate_mask(ptr)
614#define KMP_CPU_INTERNAL_ALLOC(ptr)(ptr = __kmp_affinity_dispatch->allocate_mask()) KMP_CPU_ALLOC(ptr)(ptr = __kmp_affinity_dispatch->allocate_mask())
615#define KMP_CPU_INTERNAL_FREE(ptr)__kmp_affinity_dispatch->deallocate_mask(ptr) KMP_CPU_FREE(ptr)__kmp_affinity_dispatch->deallocate_mask(ptr)
616#define KMP_CPU_INDEX(arr, i)__kmp_affinity_dispatch->index_mask_array(arr, i) __kmp_affinity_dispatch->index_mask_array(arr, i)
617#define KMP_CPU_ALLOC_ARRAY(arr, n)(arr = __kmp_affinity_dispatch->allocate_mask_array(n)) \
618 (arr = __kmp_affinity_dispatch->allocate_mask_array(n))
619#define KMP_CPU_FREE_ARRAY(arr, n)__kmp_affinity_dispatch->deallocate_mask_array(arr) \
620 __kmp_affinity_dispatch->deallocate_mask_array(arr)
621#define KMP_CPU_INTERNAL_ALLOC_ARRAY(arr, n)(arr = __kmp_affinity_dispatch->allocate_mask_array(n)) KMP_CPU_ALLOC_ARRAY(arr, n)(arr = __kmp_affinity_dispatch->allocate_mask_array(n))
622#define KMP_CPU_INTERNAL_FREE_ARRAY(arr, n)__kmp_affinity_dispatch->deallocate_mask_array(arr) KMP_CPU_FREE_ARRAY(arr, n)__kmp_affinity_dispatch->deallocate_mask_array(arr)
623#define __kmp_get_system_affinity(mask, abort_bool)(mask)->get_system_affinity(abort_bool) \
624 (mask)->get_system_affinity(abort_bool)
625#define __kmp_set_system_affinity(mask, abort_bool)(mask)->set_system_affinity(abort_bool) \
626 (mask)->set_system_affinity(abort_bool)
627#define __kmp_get_proc_group(mask)(mask)->get_proc_group() (mask)->get_proc_group()
628
629class KMPAffinity {
630public:
631 class Mask {
632 public:
633 void *operator new(size_t n);
634 void operator delete(void *p);
635 void *operator new[](size_t n);
636 void operator delete[](void *p);
637 virtual ~Mask() {}
638 // Set bit i to 1
639 virtual void set(int i) {}
640 // Return bit i
641 virtual bool is_set(int i) const { return false; }
642 // Set bit i to 0
643 virtual void clear(int i) {}
644 // Zero out entire mask
645 virtual void zero() {}
646 // Copy src into this mask
647 virtual void copy(const Mask *src) {}
648 // this &= rhs
649 virtual void bitwise_and(const Mask *rhs) {}
650 // this |= rhs
651 virtual void bitwise_or(const Mask *rhs) {}
652 // this = ~this
653 virtual void bitwise_not() {}
654 // API for iterating over an affinity mask
655 // for (int i = mask->begin(); i != mask->end(); i = mask->next(i))
656 virtual int begin() const { return 0; }
657 virtual int end() const { return 0; }
658 virtual int next(int previous) const { return 0; }
659 // Set the system's affinity to this affinity mask's value
660 virtual int set_system_affinity(bool abort_on_error) const { return -1; }
661 // Set this affinity mask to the current system affinity
662 virtual int get_system_affinity(bool abort_on_error) { return -1; }
663 // Only 1 DWORD in the mask should have any procs set.
664 // Return the appropriate index, or -1 for an invalid mask.
665 virtual int get_proc_group() const { return -1; }
666 };
667 void *operator new(size_t n);
668 void operator delete(void *p);
669 // Need virtual destructor
670 virtual ~KMPAffinity() = default;
671 // Determine if affinity is capable
672 virtual void determine_capable(const char *env_var) {}
673 // Bind the current thread to os proc
674 virtual void bind_thread(int proc) {}
675 // Factory functions to allocate/deallocate a mask
676 virtual Mask *allocate_mask() { return nullptr; }
677 virtual void deallocate_mask(Mask *m) {}
678 virtual Mask *allocate_mask_array(int num) { return nullptr; }
679 virtual void deallocate_mask_array(Mask *m) {}
680 virtual Mask *index_mask_array(Mask *m, int index) { return nullptr; }
681 static void pick_api();
682 static void destroy_api();
683 enum api_type {
684 NATIVE_OS
685#if KMP_USE_HWLOC0
686 ,
687 HWLOC
688#endif
689 };
690 virtual api_type get_api_type() const {
691 KMP_ASSERT(0)if (!(0)) { __kmp_debug_assert("0", "/build/llvm-toolchain-snapshot-8~svn345461/projects/openmp/runtime/src/kmp.h"
, 691); }
;
692 return NATIVE_OS;
693 }
694
695private:
696 static bool picked_api;
697};
698
699typedef KMPAffinity::Mask kmp_affin_mask_t;
700extern KMPAffinity *__kmp_affinity_dispatch;
701
702// Declare local char buffers with this size for printing debug and info
703// messages, using __kmp_affinity_print_mask().
704#define KMP_AFFIN_MASK_PRINT_LEN1024 1024
705
706enum affinity_type {
707 affinity_none = 0,
708 affinity_physical,
709 affinity_logical,
710 affinity_compact,
711 affinity_scatter,
712 affinity_explicit,
713 affinity_balanced,
714 affinity_disabled, // not used outsize the env var parser
715 affinity_default
716};
717
718enum affinity_gran {
719 affinity_gran_fine = 0,
720 affinity_gran_thread,
721 affinity_gran_core,
722 affinity_gran_tile,
723 affinity_gran_numa,
724 affinity_gran_package,
725 affinity_gran_node,
726#if KMP_GROUP_AFFINITY0
727 // The "group" granularity isn't necesssarily coarser than all of the
728 // other levels, but we put it last in the enum.
729 affinity_gran_group,
730#endif /* KMP_GROUP_AFFINITY */
731 affinity_gran_default
732};
733
734enum affinity_top_method {
735 affinity_top_method_all = 0, // try all (supported) methods, in order
736#if KMP_ARCH_X860 || KMP_ARCH_X86_641
737 affinity_top_method_apicid,
738 affinity_top_method_x2apicid,
739#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
740 affinity_top_method_cpuinfo, // KMP_CPUINFO_FILE is usable on Windows* OS, too
741#if KMP_GROUP_AFFINITY0
742 affinity_top_method_group,
743#endif /* KMP_GROUP_AFFINITY */
744 affinity_top_method_flat,
745#if KMP_USE_HWLOC0
746 affinity_top_method_hwloc,
747#endif
748 affinity_top_method_default
749};
750
751#define affinity_respect_mask_default(-1) (-1)
752
753extern enum affinity_type __kmp_affinity_type; /* Affinity type */
754extern enum affinity_gran __kmp_affinity_gran; /* Affinity granularity */
755extern int __kmp_affinity_gran_levels; /* corresponding int value */
756extern int __kmp_affinity_dups; /* Affinity duplicate masks */
757extern enum affinity_top_method __kmp_affinity_top_method;
758extern int __kmp_affinity_compact; /* Affinity 'compact' value */
759extern int __kmp_affinity_offset; /* Affinity offset value */
760extern int __kmp_affinity_verbose; /* Was verbose specified for KMP_AFFINITY? */
761extern int __kmp_affinity_warnings; /* KMP_AFFINITY warnings enabled ? */
762extern int __kmp_affinity_respect_mask; // Respect process' init affinity mask?
763extern char *__kmp_affinity_proclist; /* proc ID list */
764extern kmp_affin_mask_t *__kmp_affinity_masks;
765extern unsigned __kmp_affinity_num_masks;
766extern void __kmp_affinity_bind_thread(int which);
767
768extern kmp_affin_mask_t *__kmp_affin_fullMask;
769extern char *__kmp_cpuinfo_file;
770
771#endif /* KMP_AFFINITY_SUPPORTED */
772
773#if OMP_40_ENABLED(50 >= 40)
774
775// This needs to be kept in sync with the values in omp.h !!!
776typedef enum kmp_proc_bind_t {
777 proc_bind_false = 0,
778 proc_bind_true,
779 proc_bind_master,
780 proc_bind_close,
781 proc_bind_spread,
782 proc_bind_intel, // use KMP_AFFINITY interface
783 proc_bind_default
784} kmp_proc_bind_t;
785
786typedef struct kmp_nested_proc_bind_t {
787 kmp_proc_bind_t *bind_types;
788 int size;
789 int used;
790} kmp_nested_proc_bind_t;
791
792extern kmp_nested_proc_bind_t __kmp_nested_proc_bind;
793
794#endif /* OMP_40_ENABLED */
795
796#if KMP_AFFINITY_SUPPORTED1
797#define KMP_PLACE_ALL(-1) (-1)
798#define KMP_PLACE_UNDEFINED(-2) (-2)
799// Is KMP_AFFINITY is being used instead of OMP_PROC_BIND/OMP_PLACES?
800#define KMP_AFFINITY_NON_PROC_BIND((__kmp_nested_proc_bind.bind_types[0] == proc_bind_false || __kmp_nested_proc_bind
.bind_types[0] == proc_bind_intel) && (__kmp_affinity_num_masks
> 0 || __kmp_affinity_type == affinity_balanced))
\
801 ((__kmp_nested_proc_bind.bind_types[0] == proc_bind_false || \
802 __kmp_nested_proc_bind.bind_types[0] == proc_bind_intel) && \
803 (__kmp_affinity_num_masks > 0 || __kmp_affinity_type == affinity_balanced))
804#endif /* KMP_AFFINITY_SUPPORTED */
805
806extern int __kmp_affinity_num_places;
807
808#if OMP_40_ENABLED(50 >= 40)
809typedef enum kmp_cancel_kind_t {
810 cancel_noreq = 0,
811 cancel_parallel = 1,
812 cancel_loop = 2,
813 cancel_sections = 3,
814 cancel_taskgroup = 4
815} kmp_cancel_kind_t;
816#endif // OMP_40_ENABLED
817
818// KMP_HW_SUBSET support:
819typedef struct kmp_hws_item {
820 int num;
821 int offset;
822} kmp_hws_item_t;
823
824extern kmp_hws_item_t __kmp_hws_socket;
825extern kmp_hws_item_t __kmp_hws_node;
826extern kmp_hws_item_t __kmp_hws_tile;
827extern kmp_hws_item_t __kmp_hws_core;
828extern kmp_hws_item_t __kmp_hws_proc;
829extern int __kmp_hws_requested;
830extern int __kmp_hws_abs_flag; // absolute or per-item number requested
831
832/* ------------------------------------------------------------------------ */
833
834#define KMP_PAD(type, sz)(sizeof(type) + (sz - ((sizeof(type) - 1) % (sz)) - 1)) \
835 (sizeof(type) + (sz - ((sizeof(type) - 1) % (sz)) - 1))
836
837// We need to avoid using -1 as a GTID as +1 is added to the gtid
838// when storing it in a lock, and the value 0 is reserved.
839#define KMP_GTID_DNE(-2) (-2) /* Does not exist */
840#define KMP_GTID_SHUTDOWN(-3) (-3) /* Library is shutting down */
841#define KMP_GTID_MONITOR(-4) (-4) /* Monitor thread ID */
842#define KMP_GTID_UNKNOWN(-5) (-5) /* Is not known */
843#define KMP_GTID_MIN(-6) (-6) /* Minimal gtid for low bound check in DEBUG */
844
845#if OMP_50_ENABLED(50 >= 50)
846/* OpenMP 5.0 Memory Management support */
847extern int __kmp_memkind_available;
848extern int __kmp_hbw_mem_available;
849typedef void *omp_allocator_t;
850extern const omp_allocator_t *OMP_NULL_ALLOCATOR;
851extern const omp_allocator_t *omp_default_mem_alloc;
852extern const omp_allocator_t *omp_large_cap_mem_alloc;
853extern const omp_allocator_t *omp_const_mem_alloc;
854extern const omp_allocator_t *omp_high_bw_mem_alloc;
855extern const omp_allocator_t *omp_low_lat_mem_alloc;
856extern const omp_allocator_t *omp_cgroup_mem_alloc;
857extern const omp_allocator_t *omp_pteam_mem_alloc;
858extern const omp_allocator_t *omp_thread_mem_alloc;
859extern const omp_allocator_t *__kmp_def_allocator;
860
861extern void __kmpc_set_default_allocator(int gtid, const omp_allocator_t *al);
862extern const omp_allocator_t *__kmpc_get_default_allocator(int gtid);
863extern void *__kmpc_alloc(int gtid, size_t sz, const omp_allocator_t *al);
864extern void __kmpc_free(int gtid, void *ptr, const omp_allocator_t *al);
865
866extern void __kmp_init_memkind();
867extern void __kmp_fini_memkind();
868#endif // OMP_50_ENABLED
869
870/* ------------------------------------------------------------------------ */
871
872#define KMP_UINT64_MAX(~((kmp_uint64)1 << ((sizeof(kmp_uint64) * (1 << 3
)) - 1)))
\
873 (~((kmp_uint64)1 << ((sizeof(kmp_uint64) * (1 << 3)) - 1)))
874
875#define KMP_MIN_NTH1 1
876
877#ifndef KMP_MAX_NTH2147483647
878#if defined(PTHREAD_THREADS_MAX) && PTHREAD_THREADS_MAX < INT_MAX2147483647
879#define KMP_MAX_NTH2147483647 PTHREAD_THREADS_MAX
880#else
881#define KMP_MAX_NTH2147483647 INT_MAX2147483647
882#endif
883#endif /* KMP_MAX_NTH */
884
885#ifdef PTHREAD_STACK_MIN16384
886#define KMP_MIN_STKSIZE16384 PTHREAD_STACK_MIN16384
887#else
888#define KMP_MIN_STKSIZE16384 ((size_t)(32 * 1024))
889#endif
890
891#define KMP_MAX_STKSIZE(~((size_t)1 << ((sizeof(size_t) * (1 << 3)) - 1)
))
(~((size_t)1 << ((sizeof(size_t) * (1 << 3)) - 1)))
892
893#if KMP_ARCH_X860
894#define KMP_DEFAULT_STKSIZE((size_t)(4 * 1024 * 1024)) ((size_t)(2 * 1024 * 1024))
895#elif KMP_ARCH_X86_641
896#define KMP_DEFAULT_STKSIZE((size_t)(4 * 1024 * 1024)) ((size_t)(4 * 1024 * 1024))
897#define KMP_BACKUP_STKSIZE((size_t)(2 * 1024 * 1024)) ((size_t)(2 * 1024 * 1024))
898#else
899#define KMP_DEFAULT_STKSIZE((size_t)(4 * 1024 * 1024)) ((size_t)(1024 * 1024))
900#endif
901
902#define KMP_DEFAULT_MALLOC_POOL_INCR((size_t)(1024 * 1024)) ((size_t)(1024 * 1024))
903#define KMP_MIN_MALLOC_POOL_INCR((size_t)(4 * 1024)) ((size_t)(4 * 1024))
904#define KMP_MAX_MALLOC_POOL_INCR(~((size_t)1 << ((sizeof(size_t) * (1 << 3)) - 1)
))
\
905 (~((size_t)1 << ((sizeof(size_t) * (1 << 3)) - 1)))
906
907#define KMP_MIN_STKOFFSET(0) (0)
908#define KMP_MAX_STKOFFSET(~((size_t)1 << ((sizeof(size_t) * (1 << 3)) - 1)
))
KMP_MAX_STKSIZE(~((size_t)1 << ((sizeof(size_t) * (1 << 3)) - 1)
))
909#if KMP_OS_DARWIN0
910#define KMP_DEFAULT_STKOFFSET64 KMP_MIN_STKOFFSET(0)
911#else
912#define KMP_DEFAULT_STKOFFSET64 CACHE_LINE64
913#endif
914
915#define KMP_MIN_STKPADDING(0) (0)
916#define KMP_MAX_STKPADDING(2 * 1024 * 1024) (2 * 1024 * 1024)
917
918#define KMP_BLOCKTIME_MULTIPLIER(1000) \
919 (1000) /* number of blocktime units per second */
920#define KMP_MIN_BLOCKTIME(0) (0)
921#define KMP_MAX_BLOCKTIME(2147483647) \
922 (INT_MAX2147483647) /* Must be this for "infinite" setting the work */
923#define KMP_DEFAULT_BLOCKTIME(200) (200) /* __kmp_blocktime is in milliseconds */
924
925#if KMP_USE_MONITOR
926#define KMP_DEFAULT_MONITOR_STKSIZE ((size_t)(64 * 1024))
927#define KMP_MIN_MONITOR_WAKEUPS (1) // min times monitor wakes up per second
928#define KMP_MAX_MONITOR_WAKEUPS (1000) // max times monitor can wake up per sec
929
930/* Calculate new number of monitor wakeups for a specific block time based on
931 previous monitor_wakeups. Only allow increasing number of wakeups */
932#define KMP_WAKEUPS_FROM_BLOCKTIME(blocktime, monitor_wakeups) \
933 (((blocktime) == KMP_MAX_BLOCKTIME(2147483647)) \
934 ? (monitor_wakeups) \
935 : ((blocktime) == KMP_MIN_BLOCKTIME(0)) \
936 ? KMP_MAX_MONITOR_WAKEUPS \
937 : ((monitor_wakeups) > (KMP_BLOCKTIME_MULTIPLIER(1000) / (blocktime))) \
938 ? (monitor_wakeups) \
939 : (KMP_BLOCKTIME_MULTIPLIER(1000)) / (blocktime))
940
941/* Calculate number of intervals for a specific block time based on
942 monitor_wakeups */
943#define KMP_INTERVALS_FROM_BLOCKTIME(blocktime, monitor_wakeups) \
944 (((blocktime) + (KMP_BLOCKTIME_MULTIPLIER(1000) / (monitor_wakeups)) - 1) / \
945 (KMP_BLOCKTIME_MULTIPLIER(1000) / (monitor_wakeups)))
946#else
947#define KMP_BLOCKTIME(team, tid)(((team)->t.t_threads[(tid)]->th.th_current_task->td_icvs
.bt_set) ? ((team)->t.t_threads[(tid)]->th.th_current_task
->td_icvs.blocktime) : __kmp_dflt_blocktime)
\
948 (get__bt_set(team, tid)((team)->t.t_threads[(tid)]->th.th_current_task->td_icvs
.bt_set)
? get__blocktime(team, tid)((team)->t.t_threads[(tid)]->th.th_current_task->td_icvs
.blocktime)
: __kmp_dflt_blocktime)
949#if KMP_OS_UNIX1 && (KMP_ARCH_X860 || KMP_ARCH_X86_641)
950// HW TSC is used to reduce overhead (clock tick instead of nanosecond).
951extern kmp_uint64 __kmp_ticks_per_msec;
952#if KMP_COMPILER_ICC0
953#define KMP_NOW()__kmp_hardware_timestamp() ((kmp_uint64)_rdtsc())
954#else
955#define KMP_NOW()__kmp_hardware_timestamp() __kmp_hardware_timestamp()
956#endif
957#define KMP_NOW_MSEC()(__kmp_hardware_timestamp() / __kmp_ticks_per_msec) (KMP_NOW()__kmp_hardware_timestamp() / __kmp_ticks_per_msec)
958#define KMP_BLOCKTIME_INTERVAL(team, tid)((((team)->t.t_threads[(tid)]->th.th_current_task->td_icvs
.bt_set) ? ((team)->t.t_threads[(tid)]->th.th_current_task
->td_icvs.blocktime) : __kmp_dflt_blocktime) * __kmp_ticks_per_msec
)
\
959 (KMP_BLOCKTIME(team, tid)(((team)->t.t_threads[(tid)]->th.th_current_task->td_icvs
.bt_set) ? ((team)->t.t_threads[(tid)]->th.th_current_task
->td_icvs.blocktime) : __kmp_dflt_blocktime)
* __kmp_ticks_per_msec)
960#define KMP_BLOCKING(goal, count)((goal) > __kmp_hardware_timestamp()) ((goal) > KMP_NOW()__kmp_hardware_timestamp())
961#else
962// System time is retrieved sporadically while blocking.
963extern kmp_uint64 __kmp_now_nsec();
964#define KMP_NOW()__kmp_hardware_timestamp() __kmp_now_nsec()
965#define KMP_NOW_MSEC()(__kmp_hardware_timestamp() / __kmp_ticks_per_msec) (KMP_NOW()__kmp_hardware_timestamp() / KMP_USEC_PER_SEC1000000L)
966#define KMP_BLOCKTIME_INTERVAL(team, tid)((((team)->t.t_threads[(tid)]->th.th_current_task->td_icvs
.bt_set) ? ((team)->t.t_threads[(tid)]->th.th_current_task
->td_icvs.blocktime) : __kmp_dflt_blocktime) * __kmp_ticks_per_msec
)
\
967 (KMP_BLOCKTIME(team, tid)(((team)->t.t_threads[(tid)]->th.th_current_task->td_icvs
.bt_set) ? ((team)->t.t_threads[(tid)]->th.th_current_task
->td_icvs.blocktime) : __kmp_dflt_blocktime)
* KMP_USEC_PER_SEC1000000L)
968#define KMP_BLOCKING(goal, count)((goal) > __kmp_hardware_timestamp()) ((count) % 1000 != 0 || (goal) > KMP_NOW()__kmp_hardware_timestamp())
969#endif
970#define KMP_YIELD_NOW()((__kmp_hardware_timestamp() / __kmp_ticks_per_msec) / ((__kmp_dflt_blocktime
) > (1) ? (__kmp_dflt_blocktime) : (1)) % (__kmp_yield_on_count
+ __kmp_yield_off_count) < (kmp_uint32)__kmp_yield_on_count
)
\
971 (KMP_NOW_MSEC()(__kmp_hardware_timestamp() / __kmp_ticks_per_msec) / KMP_MAX(__kmp_dflt_blocktime, 1)((__kmp_dflt_blocktime) > (1) ? (__kmp_dflt_blocktime) : (
1))
% \
972 (__kmp_yield_on_count + __kmp_yield_off_count) < \
973 (kmp_uint32)__kmp_yield_on_count)
974#endif // KMP_USE_MONITOR
975
976#define KMP_MIN_STATSCOLS40 40
977#define KMP_MAX_STATSCOLS4096 4096
978#define KMP_DEFAULT_STATSCOLS80 80
979
980#define KMP_MIN_INTERVAL0 0
981#define KMP_MAX_INTERVAL(2147483647 - 1) (INT_MAX2147483647 - 1)
982#define KMP_DEFAULT_INTERVAL0 0
983
984#define KMP_MIN_CHUNK1 1
985#define KMP_MAX_CHUNK(2147483647 - 1) (INT_MAX2147483647 - 1)
986#define KMP_DEFAULT_CHUNK1 1
987
988#define KMP_MIN_INIT_WAIT1 1
989#define KMP_MAX_INIT_WAIT(2147483647 / 2) (INT_MAX2147483647 / 2)
990#define KMP_DEFAULT_INIT_WAIT2048U 2048U
991
992#define KMP_MIN_NEXT_WAIT1 1
993#define KMP_MAX_NEXT_WAIT(2147483647 / 2) (INT_MAX2147483647 / 2)
994#define KMP_DEFAULT_NEXT_WAIT1024U 1024U
995
996#define KMP_DFLT_DISP_NUM_BUFF7 7
997#define KMP_MAX_ORDERED8 8
998
999#define KMP_MAX_FIELDS32 32
1000
1001#define KMP_MAX_BRANCH_BITS31 31
1002
1003#define KMP_MAX_ACTIVE_LEVELS_LIMIT2147483647 INT_MAX2147483647
1004
1005#define KMP_MAX_DEFAULT_DEVICE_LIMIT2147483647 INT_MAX2147483647
1006
1007#define KMP_MAX_TASK_PRIORITY_LIMIT2147483647 INT_MAX2147483647
1008
1009/* Minimum number of threads before switch to TLS gtid (experimentally
1010 determined) */
1011/* josh TODO: what about OS X* tuning? */
1012#if KMP_ARCH_X860 || KMP_ARCH_X86_641
1013#define KMP_TLS_GTID_MIN5 5
1014#else
1015#define KMP_TLS_GTID_MIN5 INT_MAX2147483647
1016#endif
1017
1018#define KMP_MASTER_TID(tid)((tid) == 0) ((tid) == 0)
1019#define KMP_WORKER_TID(tid)((tid) != 0) ((tid) != 0)
1020
1021#define KMP_MASTER_GTID(gtid)(__kmp_tid_from_gtid((gtid)) == 0) (__kmp_tid_from_gtid((gtid)) == 0)
1022#define KMP_WORKER_GTID(gtid)(__kmp_tid_from_gtid((gtid)) != 0) (__kmp_tid_from_gtid((gtid)) != 0)
1023#define KMP_INITIAL_GTID(gtid)((gtid) == 0) ((gtid) == 0)
1024
1025#ifndef TRUE(!0)
1026#define FALSE0 0
1027#define TRUE(!0) (!FALSE0)
1028#endif
1029
1030/* NOTE: all of the following constants must be even */
1031
1032#if KMP_OS_WINDOWS0
1033#define KMP_INIT_WAIT1024U 64U /* initial number of spin-tests */
1034#define KMP_NEXT_WAIT512U 32U /* susequent number of spin-tests */
1035#elif KMP_OS_CNK0
1036#define KMP_INIT_WAIT1024U 16U /* initial number of spin-tests */
1037#define KMP_NEXT_WAIT512U 8U /* susequent number of spin-tests */
1038#elif KMP_OS_LINUX1
1039#define KMP_INIT_WAIT1024U 1024U /* initial number of spin-tests */
1040#define KMP_NEXT_WAIT512U 512U /* susequent number of spin-tests */
1041#elif KMP_OS_DARWIN0
1042/* TODO: tune for KMP_OS_DARWIN */
1043#define KMP_INIT_WAIT1024U 1024U /* initial number of spin-tests */
1044#define KMP_NEXT_WAIT512U 512U /* susequent number of spin-tests */
1045#elif KMP_OS_FREEBSD0
1046/* TODO: tune for KMP_OS_FREEBSD */
1047#define KMP_INIT_WAIT1024U 1024U /* initial number of spin-tests */
1048#define KMP_NEXT_WAIT512U 512U /* susequent number of spin-tests */
1049#elif KMP_OS_NETBSD0
1050/* TODO: tune for KMP_OS_NETBSD */
1051#define KMP_INIT_WAIT1024U 1024U /* initial number of spin-tests */
1052#define KMP_NEXT_WAIT512U 512U /* susequent number of spin-tests */
1053#endif
1054
1055#if KMP_ARCH_X860 || KMP_ARCH_X86_641
1056typedef struct kmp_cpuid {
1057 kmp_uint32 eax;
1058 kmp_uint32 ebx;
1059 kmp_uint32 ecx;
1060 kmp_uint32 edx;
1061} kmp_cpuid_t;
1062extern void __kmp_x86_cpuid(int mode, int mode2, struct kmp_cpuid *p);
1063#if KMP_ARCH_X860
1064extern void __kmp_x86_pause(void);
1065#elif KMP_MIC0
1066// Performance testing on KNC (C0QS-7120 P/A/X/D, 61-core, 16 GB Memory) showed
1067// regression after removal of extra PAUSE from KMP_YIELD_SPIN(). Changing
1068// the delay from 100 to 300 showed even better performance than double PAUSE
1069// on Spec OMP2001 and LCPC tasking tests, no regressions on EPCC.
1070static inline void __kmp_x86_pause(void) { _mm_delay_32(300); }
1071#else
1072static inline void __kmp_x86_pause(void) { _mm_pause(); }
1073#endif
1074#define KMP_CPU_PAUSE()__kmp_x86_pause() __kmp_x86_pause()
1075#elif KMP_ARCH_PPC64(0 || 0)
1076#define KMP_PPC64_PRI_LOW() __asm__ volatile("or 1, 1, 1")
1077#define KMP_PPC64_PRI_MED() __asm__ volatile("or 2, 2, 2")
1078#define KMP_PPC64_PRI_LOC_MB() __asm__ volatile("" : : : "memory")
1079#define KMP_CPU_PAUSE()__kmp_x86_pause() \
1080 do { \
1081 KMP_PPC64_PRI_LOW(); \
1082 KMP_PPC64_PRI_MED(); \
1083 KMP_PPC64_PRI_LOC_MB(); \
1084 } while (0)
1085#else
1086#define KMP_CPU_PAUSE()__kmp_x86_pause() /* nothing to do */
1087#endif
1088
1089#define KMP_INIT_YIELD(count){ (count) = __kmp_yield_init; } \
1090 { (count) = __kmp_yield_init; }
1091
1092#define KMP_YIELD(cond){ __kmp_x86_pause(); __kmp_yield((cond)); } \
1093 { \
1094 KMP_CPU_PAUSE()__kmp_x86_pause(); \
1095 __kmp_yield((cond)); \
1096 }
1097
1098// Note the decrement of 2 in the following Macros. With KMP_LIBRARY=turnaround,
1099// there should be no yielding since initial value from KMP_INIT_YIELD() is odd.
1100
1101#define KMP_YIELD_WHEN(cond, count){ __kmp_x86_pause(); (count) -= 2; if (!(count)) { __kmp_yield
(cond); (count) = __kmp_yield_next; } }
\
1102 { \
1103 KMP_CPU_PAUSE()__kmp_x86_pause(); \
1104 (count) -= 2; \
1105 if (!(count)) { \
1106 __kmp_yield(cond); \
1107 (count) = __kmp_yield_next; \
1108 } \
1109 }
1110#define KMP_YIELD_SPIN(count){ __kmp_x86_pause(); (count) -= 2; if (!(count)) { __kmp_yield
(1); (count) = __kmp_yield_next; } }
\
1111 { \
1112 KMP_CPU_PAUSE()__kmp_x86_pause(); \
1113 (count) -= 2; \
1114 if (!(count)) { \
1115 __kmp_yield(1); \
1116 (count) = __kmp_yield_next; \
1117 } \
1118 }
1119
1120/* ------------------------------------------------------------------------ */
1121/* Support datatypes for the orphaned construct nesting checks. */
1122/* ------------------------------------------------------------------------ */
1123
1124enum cons_type {
1125 ct_none,
1126 ct_parallel,
1127 ct_pdo,
1128 ct_pdo_ordered,
1129 ct_psections,
1130 ct_psingle,
1131
1132 /* the following must be left in order and not split up */
1133 ct_taskq,
1134 ct_task, // really task inside non-ordered taskq, considered worksharing type
1135 ct_task_ordered, /* really task inside ordered taskq, considered a worksharing
1136 type */
1137 /* the preceding must be left in order and not split up */
1138
1139 ct_critical,
1140 ct_ordered_in_parallel,
1141 ct_ordered_in_pdo,
1142 ct_ordered_in_taskq,
1143 ct_master,
1144 ct_reduce,
1145 ct_barrier
1146};
1147
1148/* test to see if we are in a taskq construct */
1149#define IS_CONS_TYPE_TASKQ(ct)(((int)(ct)) >= ((int)ct_taskq) && ((int)(ct)) <=
((int)ct_task_ordered))
\
1150 (((int)(ct)) >= ((int)ct_taskq) && ((int)(ct)) <= ((int)ct_task_ordered))
1151#define IS_CONS_TYPE_ORDERED(ct)((ct) == ct_pdo_ordered || (ct) == ct_task_ordered) \
1152 ((ct) == ct_pdo_ordered || (ct) == ct_task_ordered)
1153
1154struct cons_data {
1155 ident_t const *ident;
1156 enum cons_type type;
1157 int prev;
1158 kmp_user_lock_p
1159 name; /* address exclusively for critical section name comparison */
1160};
1161
1162struct cons_header {
1163 int p_top, w_top, s_top;
1164 int stack_size, stack_top;
1165 struct cons_data *stack_data;
1166};
1167
1168struct kmp_region_info {
1169 char *text;
1170 int offset[KMP_MAX_FIELDS32];
1171 int length[KMP_MAX_FIELDS32];
1172};
1173
1174/* ---------------------------------------------------------------------- */
1175/* ---------------------------------------------------------------------- */
1176
1177#if KMP_OS_WINDOWS0
1178typedef HANDLE kmp_thread_t;
1179typedef DWORD kmp_key_t;
1180#endif /* KMP_OS_WINDOWS */
1181
1182#if KMP_OS_UNIX1
1183typedef pthread_t kmp_thread_t;
1184typedef pthread_key_t kmp_key_t;
1185#endif
1186
1187extern kmp_key_t __kmp_gtid_threadprivate_key;
1188
1189typedef struct kmp_sys_info {
1190 long maxrss; /* the maximum resident set size utilized (in kilobytes) */
1191 long minflt; /* the number of page faults serviced without any I/O */
1192 long majflt; /* the number of page faults serviced that required I/O */
1193 long nswap; /* the number of times a process was "swapped" out of memory */
1194 long inblock; /* the number of times the file system had to perform input */
1195 long oublock; /* the number of times the file system had to perform output */
1196 long nvcsw; /* the number of times a context switch was voluntarily */
1197 long nivcsw; /* the number of times a context switch was forced */
1198} kmp_sys_info_t;
1199
1200#if KMP_ARCH_X860 || KMP_ARCH_X86_641
1201typedef struct kmp_cpuinfo {
1202 int initialized; // If 0, other fields are not initialized.
1203 int signature; // CPUID(1).EAX
1204 int family; // CPUID(1).EAX[27:20]+CPUID(1).EAX[11:8] (Extended Family+Family)
1205 int model; // ( CPUID(1).EAX[19:16] << 4 ) + CPUID(1).EAX[7:4] ( ( Extended
1206 // Model << 4 ) + Model)
1207 int stepping; // CPUID(1).EAX[3:0] ( Stepping )
1208 int sse2; // 0 if SSE2 instructions are not supported, 1 otherwise.
1209 int rtm; // 0 if RTM instructions are not supported, 1 otherwise.
1210 int cpu_stackoffset;
1211 int apic_id;
1212 int physical_id;
1213 int logical_id;
1214 kmp_uint64 frequency; // Nominal CPU frequency in Hz.
1215 char name[3 * sizeof(kmp_cpuid_t)]; // CPUID(0x80000002,0x80000003,0x80000004)
1216} kmp_cpuinfo_t;
1217#endif
1218
1219#if USE_ITT_BUILD1
1220// We cannot include "kmp_itt.h" due to circular dependency. Declare the only
1221// required type here. Later we will check the type meets requirements.
1222typedef int kmp_itt_mark_t;
1223#define KMP_ITT_DEBUG0 0
1224#endif /* USE_ITT_BUILD */
1225
1226/* Taskq data structures */
1227
1228#define HIGH_WATER_MARK(nslots)(((nslots)*3) / 4) (((nslots)*3) / 4)
1229// num thunks that each thread can simultaneously execute from a task queue
1230#define __KMP_TASKQ_THUNKS_PER_TH1 1
1231
1232/* flags for taskq_global_flags, kmp_task_queue_t tq_flags, kmpc_thunk_t
1233 th_flags */
1234
1235#define TQF_IS_ORDERED0x0001 0x0001 // __kmpc_taskq interface, taskq ordered
1236// __kmpc_taskq interface, taskq with lastprivate list
1237#define TQF_IS_LASTPRIVATE0x0002 0x0002
1238#define TQF_IS_NOWAIT0x0004 0x0004 // __kmpc_taskq interface, end taskq nowait
1239// __kmpc_taskq interface, use heuristics to decide task queue size
1240#define TQF_HEURISTICS0x0008 0x0008
1241
1242// __kmpc_taskq interface, reserved for future use
1243#define TQF_INTERFACE_RESERVED10x0010 0x0010
1244// __kmpc_taskq interface, reserved for future use
1245#define TQF_INTERFACE_RESERVED20x0020 0x0020
1246// __kmpc_taskq interface, reserved for future use
1247#define TQF_INTERFACE_RESERVED30x0040 0x0040
1248// __kmpc_taskq interface, reserved for future use
1249#define TQF_INTERFACE_RESERVED40x0080 0x0080
1250
1251#define TQF_INTERFACE_FLAGS0x00ff 0x00ff // all the __kmpc_taskq interface flags
1252// internal/read by instrumentation; only used with TQF_IS_LASTPRIVATE
1253#define TQF_IS_LAST_TASK0x0100 0x0100
1254// internal use only; this thunk->th_task is the taskq_task
1255#define TQF_TASKQ_TASK0x0200 0x0200
1256// internal use only; must release worker threads once ANY queued task
1257// exists (global)
1258#define TQF_RELEASE_WORKERS0x0400 0x0400
1259// internal use only; notify workers that master has finished enqueuing tasks
1260#define TQF_ALL_TASKS_QUEUED0x0800 0x0800
1261// internal use only: this queue encountered in parallel context: not serialized
1262#define TQF_PARALLEL_CONTEXT0x1000 0x1000
1263// internal use only; this queue is on the freelist and not in use
1264#define TQF_DEALLOCATED0x2000 0x2000
1265
1266#define TQF_INTERNAL_FLAGS0x3f00 0x3f00 // all the internal use only flags
1267
1268typedef struct KMP_ALIGN_CACHE__attribute__((aligned(64))) kmpc_aligned_int32_t {
1269 kmp_int32 ai_data;
1270} kmpc_aligned_int32_t;
1271
1272typedef struct KMP_ALIGN_CACHE__attribute__((aligned(64))) kmpc_aligned_queue_slot_t {
1273 struct kmpc_thunk_t *qs_thunk;
1274} kmpc_aligned_queue_slot_t;
1275
1276typedef struct kmpc_task_queue_t {
1277 /* task queue linkage fields for n-ary tree of queues (locked with global
1278 taskq_tree_lck) */
1279 kmp_lock_t tq_link_lck; /* lock for child link, child next/prev links and
1280 child ref counts */
1281 union {
1282 struct kmpc_task_queue_t *tq_parent; // pointer to parent taskq, not locked
1283 // for taskq internal freelists, locked with global taskq_freelist_lck
1284 struct kmpc_task_queue_t *tq_next_free;
1285 } tq;
1286 // pointer to linked-list of children, locked by tq's tq_link_lck
1287 volatile struct kmpc_task_queue_t *tq_first_child;
1288 // next child in linked-list, locked by parent tq's tq_link_lck
1289 struct kmpc_task_queue_t *tq_next_child;
1290 // previous child in linked-list, locked by parent tq's tq_link_lck
1291 struct kmpc_task_queue_t *tq_prev_child;
1292 // reference count of threads with access to this task queue
1293 volatile kmp_int32 tq_ref_count;
1294 /* (other than the thread executing the kmpc_end_taskq call) */
1295 /* locked by parent tq's tq_link_lck */
1296
1297 /* shared data for task queue */
1298 /* per-thread array of pointers to shared variable structures */
1299 struct kmpc_aligned_shared_vars_t *tq_shareds;
1300 /* only one array element exists for all but outermost taskq */
1301
1302 /* bookkeeping for ordered task queue */
1303 kmp_uint32 tq_tasknum_queuing; // ordered task # assigned while queuing tasks
1304 // ordered number of next task to be served (executed)
1305 volatile kmp_uint32 tq_tasknum_serving;
1306
1307 /* thunk storage management for task queue */
1308 kmp_lock_t tq_free_thunks_lck; /* lock for thunk freelist manipulation */
1309 // thunk freelist, chained via th.th_next_free
1310 struct kmpc_thunk_t *tq_free_thunks;
1311 // space allocated for thunks for this task queue
1312 struct kmpc_thunk_t *tq_thunk_space;
1313
1314 /* data fields for queue itself */
1315 kmp_lock_t tq_queue_lck; /* lock for [de]enqueue operations: tq_queue,
1316 tq_head, tq_tail, tq_nfull */
1317 /* array of queue slots to hold thunks for tasks */
1318 kmpc_aligned_queue_slot_t *tq_queue;
1319 volatile struct kmpc_thunk_t *tq_taskq_slot; /* special slot for taskq task
1320 thunk, occupied if not NULL */
1321 kmp_int32 tq_nslots; /* # of tq_thunk_space thunks alloc'd (not incl.
1322 tq_taskq_slot space) */
1323 kmp_int32 tq_head; // enqueue puts item here (index into tq_queue array)
1324 kmp_int32 tq_tail; // dequeue takes item from here (index into tq_queue array)
1325 volatile kmp_int32 tq_nfull; // # of occupied entries in task queue right now
1326 kmp_int32 tq_hiwat; /* high-water mark for tq_nfull and queue scheduling */
1327 volatile kmp_int32 tq_flags; /* TQF_xxx */
1328
1329 /* bookkeeping for outstanding thunks */
1330
1331 /* per-thread array for # of regular thunks currently being executed */
1332 struct kmpc_aligned_int32_t *tq_th_thunks;
1333 kmp_int32 tq_nproc; /* number of thunks in the th_thunks array */
1334
1335 /* statistics library bookkeeping */
1336 ident_t *tq_loc; /* source location information for taskq directive */
1337} kmpc_task_queue_t;
1338
1339typedef void (*kmpc_task_t)(kmp_int32 global_tid, struct kmpc_thunk_t *thunk);
1340
1341/* sizeof_shareds passed as arg to __kmpc_taskq call */
1342typedef struct kmpc_shared_vars_t { /* aligned during dynamic allocation */
1343 kmpc_task_queue_t *sv_queue; /* (pointers to) shared vars */
1344} kmpc_shared_vars_t;
1345
1346typedef struct KMP_ALIGN_CACHE__attribute__((aligned(64))) kmpc_aligned_shared_vars_t {
1347 volatile struct kmpc_shared_vars_t *ai_data;
1348} kmpc_aligned_shared_vars_t;
1349
1350/* sizeof_thunk passed as arg to kmpc_taskq call */
1351typedef struct kmpc_thunk_t { /* aligned during dynamic allocation */
1352 union { /* field used for internal freelists too */
1353 kmpc_shared_vars_t *th_shareds;
1354 struct kmpc_thunk_t *th_next_free; /* freelist of individual thunks within
1355 queue, head at tq_free_thunks */
1356 } th;
1357 kmpc_task_t th_task; /* taskq_task if flags & TQF_TASKQ_TASK */
1358 struct kmpc_thunk_t *th_encl_thunk; /* pointer to dynamically enclosing thunk
1359 on this thread's call stack */
1360 // TQF_xxx(tq_flags interface plus possible internal flags)
1361 kmp_int32 th_flags;
1362
1363 kmp_int32 th_status;
1364 kmp_uint32 th_tasknum; /* task number assigned in order of queuing, used for
1365 ordered sections */
1366 /* private vars */
1367} kmpc_thunk_t;
1368
1369typedef struct KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_taskq {
1370 int tq_curr_thunk_capacity;
1371
1372 kmpc_task_queue_t *tq_root;
1373 kmp_int32 tq_global_flags;
1374
1375 kmp_lock_t tq_freelist_lck;
1376 kmpc_task_queue_t *tq_freelist;
1377
1378 kmpc_thunk_t **tq_curr_thunk;
1379} kmp_taskq_t;
1380
1381/* END Taskq data structures */
1382
1383typedef kmp_int32 kmp_critical_name[8];
1384
1385/*!
1386@ingroup PARALLEL
1387The type for a microtask which gets passed to @ref __kmpc_fork_call().
1388The arguments to the outlined function are
1389@param global_tid the global thread identity of the thread executing the
1390function.
1391@param bound_tid the local identitiy of the thread executing the function
1392@param ... pointers to shared variables accessed by the function.
1393*/
1394typedef void (*kmpc_micro)(kmp_int32 *global_tid, kmp_int32 *bound_tid, ...);
1395typedef void (*kmpc_micro_bound)(kmp_int32 *bound_tid, kmp_int32 *bound_nth,
1396 ...);
1397
1398/*!
1399@ingroup THREADPRIVATE
1400@{
1401*/
1402/* ---------------------------------------------------------------------------
1403 */
1404/* Threadprivate initialization/finalization function declarations */
1405
1406/* for non-array objects: __kmpc_threadprivate_register() */
1407
1408/*!
1409 Pointer to the constructor function.
1410 The first argument is the <tt>this</tt> pointer
1411*/
1412typedef void *(*kmpc_ctor)(void *);
1413
1414/*!
1415 Pointer to the destructor function.
1416 The first argument is the <tt>this</tt> pointer
1417*/
1418typedef void (*kmpc_dtor)(
1419 void * /*, size_t */); /* 2nd arg: magic number for KCC unused by Intel
1420 compiler */
1421/*!
1422 Pointer to an alternate constructor.
1423 The first argument is the <tt>this</tt> pointer.
1424*/
1425typedef void *(*kmpc_cctor)(void *, void *);
1426
1427/* for array objects: __kmpc_threadprivate_register_vec() */
1428/* First arg: "this" pointer */
1429/* Last arg: number of array elements */
1430/*!
1431 Array constructor.
1432 First argument is the <tt>this</tt> pointer
1433 Second argument the number of array elements.
1434*/
1435typedef void *(*kmpc_ctor_vec)(void *, size_t);
1436/*!
1437 Pointer to the array destructor function.
1438 The first argument is the <tt>this</tt> pointer
1439 Second argument the number of array elements.
1440*/
1441typedef void (*kmpc_dtor_vec)(void *, size_t);
1442/*!
1443 Array constructor.
1444 First argument is the <tt>this</tt> pointer
1445 Third argument the number of array elements.
1446*/
1447typedef void *(*kmpc_cctor_vec)(void *, void *,
1448 size_t); /* function unused by compiler */
1449
1450/*!
1451@}
1452*/
1453
1454/* keeps tracked of threadprivate cache allocations for cleanup later */
1455typedef struct kmp_cached_addr {
1456 void **addr; /* address of allocated cache */
1457 void ***compiler_cache; /* pointer to compiler's cache */
1458 void *data; /* pointer to global data */
1459 struct kmp_cached_addr *next; /* pointer to next cached address */
1460} kmp_cached_addr_t;
1461
1462struct private_data {
1463 struct private_data *next; /* The next descriptor in the list */
1464 void *data; /* The data buffer for this descriptor */
1465 int more; /* The repeat count for this descriptor */
1466 size_t size; /* The data size for this descriptor */
1467};
1468
1469struct private_common {
1470 struct private_common *next;
1471 struct private_common *link;
1472 void *gbl_addr;
1473 void *par_addr; /* par_addr == gbl_addr for MASTER thread */
1474 size_t cmn_size;
1475};
1476
1477struct shared_common {
1478 struct shared_common *next;
1479 struct private_data *pod_init;
1480 void *obj_init;
1481 void *gbl_addr;
1482 union {
1483 kmpc_ctor ctor;
1484 kmpc_ctor_vec ctorv;
1485 } ct;
1486 union {
1487 kmpc_cctor cctor;
1488 kmpc_cctor_vec cctorv;
1489 } cct;
1490 union {
1491 kmpc_dtor dtor;
1492 kmpc_dtor_vec dtorv;
1493 } dt;
1494 size_t vec_len;
1495 int is_vec;
1496 size_t cmn_size;
1497};
1498
1499#define KMP_HASH_TABLE_LOG29 9 /* log2 of the hash table size */
1500#define KMP_HASH_TABLE_SIZE(1 << 9) \
1501 (1 << KMP_HASH_TABLE_LOG29) /* size of the hash table */
1502#define KMP_HASH_SHIFT3 3 /* throw away this many low bits from the address */
1503#define KMP_HASH(x)((((kmp_uintptr_t)x) >> 3) & ((1 << 9) - 1)) \
1504 ((((kmp_uintptr_t)x) >> KMP_HASH_SHIFT3) & (KMP_HASH_TABLE_SIZE(1 << 9) - 1))
1505
1506struct common_table {
1507 struct private_common *data[KMP_HASH_TABLE_SIZE(1 << 9)];
1508};
1509
1510struct shared_table {
1511 struct shared_common *data[KMP_HASH_TABLE_SIZE(1 << 9)];
1512};
1513
1514/* ------------------------------------------------------------------------ */
1515
1516#if KMP_USE_HIER_SCHED0
1517// Shared barrier data that exists inside a single unit of the scheduling
1518// hierarchy
1519typedef struct kmp_hier_private_bdata_t {
1520 kmp_int32 num_active;
1521 kmp_uint64 index;
1522 kmp_uint64 wait_val[2];
1523} kmp_hier_private_bdata_t;
1524#endif
1525
1526typedef struct kmp_sched_flags {
1527 unsigned ordered : 1;
1528 unsigned nomerge : 1;
1529 unsigned contains_last : 1;
1530#if KMP_USE_HIER_SCHED0
1531 unsigned use_hier : 1;
1532 unsigned unused : 28;
1533#else
1534 unsigned unused : 29;
1535#endif
1536} kmp_sched_flags_t;
1537
1538KMP_BUILD_ASSERT(sizeof(kmp_sched_flags_t) == 4)static_assert(sizeof(kmp_sched_flags_t) == 4, "Build condition error"
)
;
1539
1540#if KMP_STATIC_STEAL_ENABLED1
1541typedef struct KMP_ALIGN_CACHE__attribute__((aligned(64))) dispatch_private_info32 {
1542 kmp_int32 count;
1543 kmp_int32 ub;
1544 /* Adding KMP_ALIGN_CACHE here doesn't help / can hurt performance */
1545 kmp_int32 lb;
1546 kmp_int32 st;
1547 kmp_int32 tc;
1548 kmp_int32 static_steal_counter; /* for static_steal only; maybe better to put
1549 after ub */
1550
1551 // KMP_ALIGN( 16 ) ensures ( if the KMP_ALIGN macro is turned on )
1552 // a) parm3 is properly aligned and
1553 // b) all parm1-4 are in the same cache line.
1554 // Because of parm1-4 are used together, performance seems to be better
1555 // if they are in the same line (not measured though).
1556
1557 struct KMP_ALIGN(32)__attribute__((aligned(32))) { // AC: changed 16 to 32 in order to simplify template
1558 kmp_int32 parm1; // structures in kmp_dispatch.cpp. This should
1559 kmp_int32 parm2; // make no real change at least while padding is off.
1560 kmp_int32 parm3;
1561 kmp_int32 parm4;
1562 };
1563
1564 kmp_uint32 ordered_lower;
1565 kmp_uint32 ordered_upper;
1566#if KMP_OS_WINDOWS0
1567 // This var can be placed in the hole between 'tc' and 'parm1', instead of
1568 // 'static_steal_counter'. It would be nice to measure execution times.
1569 // Conditional if/endif can be removed at all.
1570 kmp_int32 last_upper;
1571#endif /* KMP_OS_WINDOWS */
1572} dispatch_private_info32_t;
1573
1574typedef struct KMP_ALIGN_CACHE__attribute__((aligned(64))) dispatch_private_info64 {
1575 kmp_int64 count; // current chunk number for static & static-steal scheduling
1576 kmp_int64 ub; /* upper-bound */
1577 /* Adding KMP_ALIGN_CACHE here doesn't help / can hurt performance */
1578 kmp_int64 lb; /* lower-bound */
1579 kmp_int64 st; /* stride */
1580 kmp_int64 tc; /* trip count (number of iterations) */
1581 kmp_int64 static_steal_counter; /* for static_steal only; maybe better to put
1582 after ub */
1583
1584 /* parm[1-4] are used in different ways by different scheduling algorithms */
1585
1586 // KMP_ALIGN( 32 ) ensures ( if the KMP_ALIGN macro is turned on )
1587 // a) parm3 is properly aligned and
1588 // b) all parm1-4 are in the same cache line.
1589 // Because of parm1-4 are used together, performance seems to be better
1590 // if they are in the same line (not measured though).
1591
1592 struct KMP_ALIGN(32)__attribute__((aligned(32))) {
1593 kmp_int64 parm1;
1594 kmp_int64 parm2;
1595 kmp_int64 parm3;
1596 kmp_int64 parm4;
1597 };
1598
1599 kmp_uint64 ordered_lower;
1600 kmp_uint64 ordered_upper;
1601#if KMP_OS_WINDOWS0
1602 // This var can be placed in the hole between 'tc' and 'parm1', instead of
1603 // 'static_steal_counter'. It would be nice to measure execution times.
1604 // Conditional if/endif can be removed at all.
1605 kmp_int64 last_upper;
1606#endif /* KMP_OS_WINDOWS */
1607} dispatch_private_info64_t;
1608#else /* KMP_STATIC_STEAL_ENABLED */
1609typedef struct KMP_ALIGN_CACHE__attribute__((aligned(64))) dispatch_private_info32 {
1610 kmp_int32 lb;
1611 kmp_int32 ub;
1612 kmp_int32 st;
1613 kmp_int32 tc;
1614
1615 kmp_int32 parm1;
1616 kmp_int32 parm2;
1617 kmp_int32 parm3;
1618 kmp_int32 parm4;
1619
1620 kmp_int32 count;
1621
1622 kmp_uint32 ordered_lower;
1623 kmp_uint32 ordered_upper;
1624#if KMP_OS_WINDOWS0
1625 kmp_int32 last_upper;
1626#endif /* KMP_OS_WINDOWS */
1627} dispatch_private_info32_t;
1628
1629typedef struct KMP_ALIGN_CACHE__attribute__((aligned(64))) dispatch_private_info64 {
1630 kmp_int64 lb; /* lower-bound */
1631 kmp_int64 ub; /* upper-bound */
1632 kmp_int64 st; /* stride */
1633 kmp_int64 tc; /* trip count (number of iterations) */
1634
1635 /* parm[1-4] are used in different ways by different scheduling algorithms */
1636 kmp_int64 parm1;
1637 kmp_int64 parm2;
1638 kmp_int64 parm3;
1639 kmp_int64 parm4;
1640
1641 kmp_int64 count; /* current chunk number for static scheduling */
1642
1643 kmp_uint64 ordered_lower;
1644 kmp_uint64 ordered_upper;
1645#if KMP_OS_WINDOWS0
1646 kmp_int64 last_upper;
1647#endif /* KMP_OS_WINDOWS */
1648} dispatch_private_info64_t;
1649#endif /* KMP_STATIC_STEAL_ENABLED */
1650
1651typedef struct KMP_ALIGN_CACHE__attribute__((aligned(64))) dispatch_private_info {
1652 union private_info {
1653 dispatch_private_info32_t p32;
1654 dispatch_private_info64_t p64;
1655 } u;
1656 enum sched_type schedule; /* scheduling algorithm */
1657 kmp_sched_flags_t flags; /* flags (e.g., ordered, nomerge, etc.) */
1658 kmp_int32 ordered_bumped;
1659 // To retain the structure size after making ordered_iteration scalar
1660 kmp_int32 ordered_dummy[KMP_MAX_ORDERED8 - 3];
1661 // Stack of buffers for nest of serial regions
1662 struct dispatch_private_info *next;
1663 kmp_int32 type_size; /* the size of types in private_info */
1664#if KMP_USE_HIER_SCHED0
1665 kmp_int32 hier_id;
1666 void *parent; /* hierarchical scheduling parent pointer */
1667#endif
1668 enum cons_type pushed_ws;
1669} dispatch_private_info_t;
1670
1671typedef struct dispatch_shared_info32 {
1672 /* chunk index under dynamic, number of idle threads under static-steal;
1673 iteration index otherwise */
1674 volatile kmp_uint32 iteration;
1675 volatile kmp_uint32 num_done;
1676 volatile kmp_uint32 ordered_iteration;
1677 // Dummy to retain the structure size after making ordered_iteration scalar
1678 kmp_int32 ordered_dummy[KMP_MAX_ORDERED8 - 1];
1679} dispatch_shared_info32_t;
1680
1681typedef struct dispatch_shared_info64 {
1682 /* chunk index under dynamic, number of idle threads under static-steal;
1683 iteration index otherwise */
1684 volatile kmp_uint64 iteration;
1685 volatile kmp_uint64 num_done;
1686 volatile kmp_uint64 ordered_iteration;
1687 // Dummy to retain the structure size after making ordered_iteration scalar
1688 kmp_int64 ordered_dummy[KMP_MAX_ORDERED8 - 3];
1689} dispatch_shared_info64_t;
1690
1691typedef struct dispatch_shared_info {
1692 union shared_info {
1693 dispatch_shared_info32_t s32;
1694 dispatch_shared_info64_t s64;
1695 } u;
1696 volatile kmp_uint32 buffer_index;
1697#if OMP_45_ENABLED(50 >= 45)
1698 volatile kmp_int32 doacross_buf_idx; // teamwise index
1699 volatile kmp_uint32 *doacross_flags; // shared array of iteration flags (0/1)
1700 kmp_int32 doacross_num_done; // count finished threads
1701#endif
1702#if KMP_USE_HIER_SCHED0
1703 void *hier;
1704#endif
1705#if KMP_USE_HWLOC0
1706 // When linking with libhwloc, the ORDERED EPCC test slows down on big
1707 // machines (> 48 cores). Performance analysis showed that a cache thrash
1708 // was occurring and this padding helps alleviate the problem.
1709 char padding[64];
1710#endif
1711} dispatch_shared_info_t;
1712
1713typedef struct kmp_disp {
1714 /* Vector for ORDERED SECTION */
1715 void (*th_deo_fcn)(int *gtid, int *cid, ident_t *);
1716 /* Vector for END ORDERED SECTION */
1717 void (*th_dxo_fcn)(int *gtid, int *cid, ident_t *);
1718
1719 dispatch_shared_info_t *th_dispatch_sh_current;
1720 dispatch_private_info_t *th_dispatch_pr_current;
1721
1722 dispatch_private_info_t *th_disp_buffer;
1723 kmp_int32 th_disp_index;
1724#if OMP_45_ENABLED(50 >= 45)
1725 kmp_int32 th_doacross_buf_idx; // thread's doacross buffer index
1726 volatile kmp_uint32 *th_doacross_flags; // pointer to shared array of flags
1727 union { // we can use union here because doacross cannot be used in
1728 // nonmonotonic loops
1729 kmp_int64 *th_doacross_info; // info on loop bounds
1730 kmp_lock_t *th_steal_lock; // lock used for chunk stealing (8-byte variable)
1731 };
1732#else
1733#if KMP_STATIC_STEAL_ENABLED1
1734 kmp_lock_t *th_steal_lock; // lock used for chunk stealing (8-byte variable)
1735 void *dummy_padding[1]; // make it 64 bytes on Intel(R) 64
1736#else
1737 void *dummy_padding[2]; // make it 64 bytes on Intel(R) 64
1738#endif
1739#endif
1740#if KMP_USE_INTERNODE_ALIGNMENT0
1741 char more_padding[INTERNODE_CACHE_LINE4096];
1742#endif
1743} kmp_disp_t;
1744
1745/* ------------------------------------------------------------------------ */
1746/* Barrier stuff */
1747
1748/* constants for barrier state update */
1749#define KMP_INIT_BARRIER_STATE0 0 /* should probably start from zero */
1750#define KMP_BARRIER_SLEEP_BIT0 0 /* bit used for suspend/sleep part of state */
1751#define KMP_BARRIER_UNUSED_BIT1 1 // bit that must never be set for valid state
1752#define KMP_BARRIER_BUMP_BIT2 2 /* lsb used for bump of go/arrived state */
1753
1754#define KMP_BARRIER_SLEEP_STATE(1 << 0) (1 << KMP_BARRIER_SLEEP_BIT0)
1755#define KMP_BARRIER_UNUSED_STATE(1 << 1) (1 << KMP_BARRIER_UNUSED_BIT1)
1756#define KMP_BARRIER_STATE_BUMP(1 << 2) (1 << KMP_BARRIER_BUMP_BIT2)
1757
1758#if (KMP_BARRIER_SLEEP_BIT0 >= KMP_BARRIER_BUMP_BIT2)
1759#error "Barrier sleep bit must be smaller than barrier bump bit"
1760#endif
1761#if (KMP_BARRIER_UNUSED_BIT1 >= KMP_BARRIER_BUMP_BIT2)
1762#error "Barrier unused bit must be smaller than barrier bump bit"
1763#endif
1764
1765// Constants for release barrier wait state: currently, hierarchical only
1766#define KMP_BARRIER_NOT_WAITING0 0 // Normal state; worker not in wait_sleep
1767#define KMP_BARRIER_OWN_FLAG1 \
1768 1 // Normal state; worker waiting on own b_go flag in release
1769#define KMP_BARRIER_PARENT_FLAG2 \
1770 2 // Special state; worker waiting on parent's b_go flag in release
1771#define KMP_BARRIER_SWITCH_TO_OWN_FLAG3 \
1772 3 // Special state; tells worker to shift from parent to own b_go
1773#define KMP_BARRIER_SWITCHING4 \
1774 4 // Special state; worker resets appropriate flag on wake-up
1775
1776#define KMP_NOT_SAFE_TO_REAP0 \
1777 0 // Thread th_reap_state: not safe to reap (tasking)
1778#define KMP_SAFE_TO_REAP1 1 // Thread th_reap_state: safe to reap (not tasking)
1779
1780enum barrier_type {
1781 bs_plain_barrier = 0, /* 0, All non-fork/join barriers (except reduction
1782 barriers if enabled) */
1783 bs_forkjoin_barrier, /* 1, All fork/join (parallel region) barriers */
1784#if KMP_FAST_REDUCTION_BARRIER1
1785 bs_reduction_barrier, /* 2, All barriers that are used in reduction */
1786#endif // KMP_FAST_REDUCTION_BARRIER
1787 bs_last_barrier /* Just a placeholder to mark the end */
1788};
1789
1790// to work with reduction barriers just like with plain barriers
1791#if !KMP_FAST_REDUCTION_BARRIER1
1792#define bs_reduction_barrier bs_plain_barrier
1793#endif // KMP_FAST_REDUCTION_BARRIER
1794
1795typedef enum kmp_bar_pat { /* Barrier communication patterns */
1796 bp_linear_bar =
1797 0, /* Single level (degenerate) tree */
1798 bp_tree_bar =
1799 1, /* Balanced tree with branching factor 2^n */
1800 bp_hyper_bar =
1801 2, /* Hypercube-embedded tree with min branching
1802 factor 2^n */
1803 bp_hierarchical_bar = 3, /* Machine hierarchy tree */
1804 bp_last_bar /* Placeholder to mark the end */
1805} kmp_bar_pat_e;
1806
1807#define KMP_BARRIER_ICV_PUSH1 1
1808
1809/* Record for holding the values of the internal controls stack records */
1810typedef struct kmp_internal_control {
1811 int serial_nesting_level; /* corresponds to the value of the
1812 th_team_serialized field */
1813 kmp_int8 nested; /* internal control for nested parallelism (per thread) */
1814 kmp_int8 dynamic; /* internal control for dynamic adjustment of threads (per
1815 thread) */
1816 kmp_int8
1817 bt_set; /* internal control for whether blocktime is explicitly set */
1818 int blocktime; /* internal control for blocktime */
1819#if KMP_USE_MONITOR
1820 int bt_intervals; /* internal control for blocktime intervals */
1821#endif
1822 int nproc; /* internal control for #threads for next parallel region (per
1823 thread) */
1824 int max_active_levels; /* internal control for max_active_levels */
1825 kmp_r_sched_t
1826 sched; /* internal control for runtime schedule {sched,chunk} pair */
1827#if OMP_40_ENABLED(50 >= 40)
1828 kmp_proc_bind_t proc_bind; /* internal control for affinity */
1829 kmp_int32 default_device; /* internal control for default device */
1830#endif // OMP_40_ENABLED
1831 struct kmp_internal_control *next;
1832} kmp_internal_control_t;
1833
1834static inline void copy_icvs(kmp_internal_control_t *dst,
1835 kmp_internal_control_t *src) {
1836 *dst = *src;
1837}
1838
1839/* Thread barrier needs volatile barrier fields */
1840typedef struct KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_bstate {
1841 // th_fixed_icvs is aligned by virtue of kmp_bstate being aligned (and all
1842 // uses of it). It is not explicitly aligned below, because we *don't* want
1843 // it to be padded -- instead, we fit b_go into the same cache line with
1844 // th_fixed_icvs, enabling NGO cache lines stores in the hierarchical barrier.
1845 kmp_internal_control_t th_fixed_icvs; // Initial ICVs for the thread
1846 // Tuck b_go into end of th_fixed_icvs cache line, so it can be stored with
1847 // same NGO store
1848 volatile kmp_uint64 b_go; // STATE => task should proceed (hierarchical)
1849 KMP_ALIGN_CACHE__attribute__((aligned(64))) volatile kmp_uint64
1850 b_arrived; // STATE => task reached synch point.
1851 kmp_uint32 *skip_per_level;
1852 kmp_uint32 my_level;
1853 kmp_int32 parent_tid;
1854 kmp_int32 old_tid;
1855 kmp_uint32 depth;
1856 struct kmp_bstate *parent_bar;
1857 kmp_team_t *team;
1858 kmp_uint64 leaf_state;
1859 kmp_uint32 nproc;
1860 kmp_uint8 base_leaf_kids;
1861 kmp_uint8 leaf_kids;
1862 kmp_uint8 offset;
1863 kmp_uint8 wait_flag;
1864 kmp_uint8 use_oncore_barrier;
1865#if USE_DEBUGGER0
1866 // The following field is intended for the debugger solely. Only the worker
1867 // thread itself accesses this field: the worker increases it by 1 when it
1868 // arrives to a barrier.
1869 KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_uint b_worker_arrived;
1870#endif /* USE_DEBUGGER */
1871} kmp_bstate_t;
1872
1873union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_barrier_union {
1874 double b_align; /* use worst case alignment */
1875 char b_pad[KMP_PAD(kmp_bstate_t, CACHE_LINE)(sizeof(kmp_bstate_t) + (64 - ((sizeof(kmp_bstate_t) - 1) % (
64)) - 1))
];
1876 kmp_bstate_t bb;
1877};
1878
1879typedef union kmp_barrier_union kmp_balign_t;
1880
1881/* Team barrier needs only non-volatile arrived counter */
1882union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_barrier_team_union {
1883 double b_align; /* use worst case alignment */
1884 char b_pad[CACHE_LINE64];
1885 struct {
1886 kmp_uint64 b_arrived; /* STATE => task reached synch point. */
1887#if USE_DEBUGGER0
1888 // The following two fields are indended for the debugger solely. Only
1889 // master of the team accesses these fields: the first one is increased by
1890 // 1 when master arrives to a barrier, the second one is increased by one
1891 // when all the threads arrived.
1892 kmp_uint b_master_arrived;
1893 kmp_uint b_team_arrived;
1894#endif
1895 };
1896};
1897
1898typedef union kmp_barrier_team_union kmp_balign_team_t;
1899
1900/* Padding for Linux* OS pthreads condition variables and mutexes used to signal
1901 threads when a condition changes. This is to workaround an NPTL bug where
1902 padding was added to pthread_cond_t which caused the initialization routine
1903 to write outside of the structure if compiled on pre-NPTL threads. */
1904#if KMP_OS_WINDOWS0
1905typedef struct kmp_win32_mutex {
1906 /* The Lock */
1907 CRITICAL_SECTION cs;
1908} kmp_win32_mutex_t;
1909
1910typedef struct kmp_win32_cond {
1911 /* Count of the number of waiters. */
1912 int waiters_count_;
1913
1914 /* Serialize access to <waiters_count_> */
1915 kmp_win32_mutex_t waiters_count_lock_;
1916
1917 /* Number of threads to release via a <cond_broadcast> or a <cond_signal> */
1918 int release_count_;
1919
1920 /* Keeps track of the current "generation" so that we don't allow */
1921 /* one thread to steal all the "releases" from the broadcast. */
1922 int wait_generation_count_;
1923
1924 /* A manual-reset event that's used to block and release waiting threads. */
1925 HANDLE event_;
1926} kmp_win32_cond_t;
1927#endif
1928
1929#if KMP_OS_UNIX1
1930
1931union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_cond_union {
1932 double c_align;
1933 char c_pad[CACHE_LINE64];
1934 pthread_cond_t c_cond;
1935};
1936
1937typedef union kmp_cond_union kmp_cond_align_t;
1938
1939union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_mutex_union {
1940 double m_align;
1941 char m_pad[CACHE_LINE64];
1942 pthread_mutex_t m_mutex;
1943};
1944
1945typedef union kmp_mutex_union kmp_mutex_align_t;
1946
1947#endif /* KMP_OS_UNIX */
1948
1949typedef struct kmp_desc_base {
1950 void *ds_stackbase;
1951 size_t ds_stacksize;
1952 int ds_stackgrow;
1953 kmp_thread_t ds_thread;
1954 volatile int ds_tid;
1955 int ds_gtid;
1956#if KMP_OS_WINDOWS0
1957 volatile int ds_alive;
1958 DWORD ds_thread_id;
1959/* ds_thread keeps thread handle on Windows* OS. It is enough for RTL purposes.
1960 However, debugger support (libomp_db) cannot work with handles, because they
1961 uncomparable. For example, debugger requests info about thread with handle h.
1962 h is valid within debugger process, and meaningless within debugee process.
1963 Even if h is duped by call to DuplicateHandle(), so the result h' is valid
1964 within debugee process, but it is a *new* handle which does *not* equal to
1965 any other handle in debugee... The only way to compare handles is convert
1966 them to system-wide ids. GetThreadId() function is available only in
1967 Longhorn and Server 2003. :-( In contrast, GetCurrentThreadId() is available
1968 on all Windows* OS flavours (including Windows* 95). Thus, we have to get
1969 thread id by call to GetCurrentThreadId() from within the thread and save it
1970 to let libomp_db identify threads. */
1971#endif /* KMP_OS_WINDOWS */
1972} kmp_desc_base_t;
1973
1974typedef union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_desc {
1975 double ds_align; /* use worst case alignment */
1976 char ds_pad[KMP_PAD(kmp_desc_base_t, CACHE_LINE)(sizeof(kmp_desc_base_t) + (64 - ((sizeof(kmp_desc_base_t) - 1
) % (64)) - 1))
];
1977 kmp_desc_base_t ds;
1978} kmp_desc_t;
1979
1980typedef struct kmp_local {
1981 volatile int this_construct; /* count of single's encountered by thread */
1982 void *reduce_data;
1983#if KMP_USE_BGET1
1984 void *bget_data;
1985 void *bget_list;
1986#if !USE_CMP_XCHG_FOR_BGET1
1987#ifdef USE_QUEUING_LOCK_FOR_BGET
1988 kmp_lock_t bget_lock; /* Lock for accessing bget free list */
1989#else
1990 kmp_bootstrap_lock_t bget_lock; // Lock for accessing bget free list. Must be
1991// bootstrap lock so we can use it at library
1992// shutdown.
1993#endif /* USE_LOCK_FOR_BGET */
1994#endif /* ! USE_CMP_XCHG_FOR_BGET */
1995#endif /* KMP_USE_BGET */
1996
1997 PACKED_REDUCTION_METHOD_T
1998 packed_reduction_method; /* stored by __kmpc_reduce*(), used by
1999 __kmpc_end_reduce*() */
2000
2001} kmp_local_t;
2002
2003#define KMP_CHECK_UPDATE(a, b)if ((a) != (b)) (a) = (b) \
2004 if ((a) != (b)) \
2005 (a) = (b)
2006#define KMP_CHECK_UPDATE_SYNC(a, b)if ((a) != (b)) (((a))) = (((b))) \
2007 if ((a) != (b)) \
2008 TCW_SYNC_PTR((a), (b))(((a))) = (((b)))
2009
2010#define get__blocktime(xteam, xtid)((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs
.blocktime)
\
2011 ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.blocktime)
2012#define get__bt_set(xteam, xtid)((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs
.bt_set)
\
2013 ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_set)
2014#if KMP_USE_MONITOR
2015#define get__bt_intervals(xteam, xtid) \
2016 ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_intervals)
2017#endif
2018
2019#define get__nested_2(xteam, xtid)((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs
.nested)
\
2020 ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.nested)
2021#define get__dynamic_2(xteam, xtid)((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs
.dynamic)
\
2022 ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.dynamic)
2023#define get__nproc_2(xteam, xtid)((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs
.nproc)
\
2024 ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.nproc)
2025#define get__sched_2(xteam, xtid)((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs
.sched)
\
2026 ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.sched)
2027
2028#define set__blocktime_team(xteam, xtid, xval)(((xteam)->t.t_threads[(xtid)]->th.th_current_task->
td_icvs.blocktime) = (xval))
\
2029 (((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.blocktime) = \
2030 (xval))
2031
2032#if KMP_USE_MONITOR
2033#define set__bt_intervals_team(xteam, xtid, xval) \
2034 (((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_intervals) = \
2035 (xval))
2036#endif
2037
2038#define set__bt_set_team(xteam, xtid, xval)(((xteam)->t.t_threads[(xtid)]->th.th_current_task->
td_icvs.bt_set) = (xval))
\
2039 (((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_set) = (xval))
2040
2041#define set__nested(xthread, xval)(((xthread)->th.th_current_task->td_icvs.nested) = (xval
))
\
2042 (((xthread)->th.th_current_task->td_icvs.nested) = (xval))
2043#define get__nested(xthread)(((xthread)->th.th_current_task->td_icvs.nested) ? ((!0
)) : (0))
\
2044 (((xthread)->th.th_current_task->td_icvs.nested) ? (FTN_TRUE(!0)) : (FTN_FALSE0))
2045
2046#define set__dynamic(xthread, xval)(((xthread)->th.th_current_task->td_icvs.dynamic) = (xval
))
\
2047 (((xthread)->th.th_current_task->td_icvs.dynamic) = (xval))
2048#define get__dynamic(xthread)(((xthread)->th.th_current_task->td_icvs.dynamic) ? ((!
0)) : (0))
\
2049 (((xthread)->th.th_current_task->td_icvs.dynamic) ? (FTN_TRUE(!0)) : (FTN_FALSE0))
2050
2051#define set__nproc(xthread, xval)(((xthread)->th.th_current_task->td_icvs.nproc) = (xval
))
\
2052 (((xthread)->th.th_current_task->td_icvs.nproc) = (xval))
2053
2054#define set__max_active_levels(xthread, xval)(((xthread)->th.th_current_task->td_icvs.max_active_levels
) = (xval))
\
2055 (((xthread)->th.th_current_task->td_icvs.max_active_levels) = (xval))
2056
2057#define set__sched(xthread, xval)(((xthread)->th.th_current_task->td_icvs.sched) = (xval
))
\
2058 (((xthread)->th.th_current_task->td_icvs.sched) = (xval))
2059
2060#if OMP_40_ENABLED(50 >= 40)
2061
2062#define set__proc_bind(xthread, xval)(((xthread)->th.th_current_task->td_icvs.proc_bind) = (
xval))
\
2063 (((xthread)->th.th_current_task->td_icvs.proc_bind) = (xval))
2064#define get__proc_bind(xthread)((xthread)->th.th_current_task->td_icvs.proc_bind) \
2065 ((xthread)->th.th_current_task->td_icvs.proc_bind)
2066
2067#endif /* OMP_40_ENABLED */
2068
2069// OpenMP tasking data structures
2070
2071typedef enum kmp_tasking_mode {
2072 tskm_immediate_exec = 0,
2073 tskm_extra_barrier = 1,
2074 tskm_task_teams = 2,
2075 tskm_max = 2
2076} kmp_tasking_mode_t;
2077
2078extern kmp_tasking_mode_t
2079 __kmp_tasking_mode; /* determines how/when to execute tasks */
2080extern int __kmp_task_stealing_constraint;
2081#if OMP_40_ENABLED(50 >= 40)
2082extern kmp_int32 __kmp_default_device; // Set via OMP_DEFAULT_DEVICE if
2083// specified, defaults to 0 otherwise
2084#endif
2085#if OMP_45_ENABLED(50 >= 45)
2086// Set via OMP_MAX_TASK_PRIORITY if specified, defaults to 0 otherwise
2087extern kmp_int32 __kmp_max_task_priority;
2088// Set via KMP_TASKLOOP_MIN_TASKS if specified, defaults to 0 otherwise
2089extern kmp_uint64 __kmp_taskloop_min_tasks;
2090#endif
2091
2092/* NOTE: kmp_taskdata_t and kmp_task_t structures allocated in single block with
2093 taskdata first */
2094#define KMP_TASK_TO_TASKDATA(task)(((kmp_taskdata_t *)task) - 1) (((kmp_taskdata_t *)task) - 1)
2095#define KMP_TASKDATA_TO_TASK(taskdata)(kmp_task_t *)(taskdata + 1) (kmp_task_t *)(taskdata + 1)
2096
2097// The tt_found_tasks flag is a signal to all threads in the team that tasks
2098// were spawned and queued since the previous barrier release.
2099#define KMP_TASKING_ENABLED(task_team)(((task_team)->tt.tt_found_tasks) == (!0)) \
2100 (TCR_SYNC_4((task_team)->tt.tt_found_tasks)((task_team)->tt.tt_found_tasks) == TRUE(!0))
2101/*!
2102@ingroup BASIC_TYPES
2103@{
2104*/
2105
2106/*!
2107 */
2108typedef kmp_int32 (*kmp_routine_entry_t)(kmp_int32, void *);
2109
2110#if OMP_40_ENABLED(50 >= 40) || OMP_45_ENABLED(50 >= 45)
2111typedef union kmp_cmplrdata {
2112#if OMP_45_ENABLED(50 >= 45)
2113 kmp_int32 priority; /**< priority specified by user for the task */
2114#endif // OMP_45_ENABLED
2115#if OMP_40_ENABLED(50 >= 40)
2116 kmp_routine_entry_t
2117 destructors; /* pointer to function to invoke deconstructors of
2118 firstprivate C++ objects */
2119#endif // OMP_40_ENABLED
2120 /* future data */
2121} kmp_cmplrdata_t;
2122#endif
2123
2124/* sizeof_kmp_task_t passed as arg to kmpc_omp_task call */
2125/*!
2126 */
2127typedef struct kmp_task { /* GEH: Shouldn't this be aligned somehow? */
2128 void *shareds; /**< pointer to block of pointers to shared vars */
2129 kmp_routine_entry_t
2130 routine; /**< pointer to routine to call for executing task */
2131 kmp_int32 part_id; /**< part id for the task */
2132#if OMP_40_ENABLED(50 >= 40) || OMP_45_ENABLED(50 >= 45)
2133 kmp_cmplrdata_t
2134 data1; /* Two known optional additions: destructors and priority */
2135 kmp_cmplrdata_t data2; /* Process destructors first, priority second */
2136/* future data */
2137#endif
2138 /* private vars */
2139} kmp_task_t;
2140
2141/*!
2142@}
2143*/
2144
2145#if OMP_40_ENABLED(50 >= 40)
2146typedef struct kmp_taskgroup {
2147 std::atomic<kmp_int32> count; // number of allocated and incomplete tasks
2148 std::atomic<kmp_int32>
2149 cancel_request; // request for cancellation of this taskgroup
2150 struct kmp_taskgroup *parent; // parent taskgroup
2151#if OMP_50_ENABLED(50 >= 50)
2152 // Block of data to perform task reduction
2153 void *reduce_data; // reduction related info
2154 kmp_int32 reduce_num_data; // number of data items to reduce
2155#endif
2156} kmp_taskgroup_t;
2157
2158// forward declarations
2159typedef union kmp_depnode kmp_depnode_t;
2160typedef struct kmp_depnode_list kmp_depnode_list_t;
2161typedef struct kmp_dephash_entry kmp_dephash_entry_t;
2162
2163typedef struct kmp_depend_info {
2164 kmp_intptr_t base_addr;
2165 size_t len;
2166 struct {
2167 bool in : 1;
2168 bool out : 1;
2169 } flags;
2170} kmp_depend_info_t;
2171
2172struct kmp_depnode_list {
2173 kmp_depnode_t *node;
2174 kmp_depnode_list_t *next;
2175};
2176
2177typedef struct kmp_base_depnode {
2178 kmp_depnode_list_t *successors;
2179 kmp_task_t *task;
2180
2181 kmp_lock_t lock;
2182
2183#if KMP_SUPPORT_GRAPH_OUTPUT
2184 kmp_uint32 id;
2185#endif
2186
2187 std::atomic<kmp_int32> npredecessors;
2188 std::atomic<kmp_int32> nrefs;
2189} kmp_base_depnode_t;
2190
2191union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_depnode {
2192 double dn_align; /* use worst case alignment */
2193 char dn_pad[KMP_PAD(kmp_base_depnode_t, CACHE_LINE)(sizeof(kmp_base_depnode_t) + (64 - ((sizeof(kmp_base_depnode_t
) - 1) % (64)) - 1))
];
2194 kmp_base_depnode_t dn;
2195};
2196
2197struct kmp_dephash_entry {
2198 kmp_intptr_t addr;
2199 kmp_depnode_t *last_out;
2200 kmp_depnode_list_t *last_ins;
2201 kmp_dephash_entry_t *next_in_bucket;
2202};
2203
2204typedef struct kmp_dephash {
2205 kmp_dephash_entry_t **buckets;
2206 size_t size;
2207#ifdef KMP_DEBUG1
2208 kmp_uint32 nelements;
2209 kmp_uint32 nconflicts;
2210#endif
2211} kmp_dephash_t;
2212
2213#endif
2214
2215#ifdef BUILD_TIED_TASK_STACK
2216
2217/* Tied Task stack definitions */
2218typedef struct kmp_stack_block {
2219 kmp_taskdata_t *sb_block[TASK_STACK_BLOCK_SIZE];
2220 struct kmp_stack_block *sb_next;
2221 struct kmp_stack_block *sb_prev;
2222} kmp_stack_block_t;
2223
2224typedef struct kmp_task_stack {
2225 kmp_stack_block_t ts_first_block; // first block of stack entries
2226 kmp_taskdata_t **ts_top; // pointer to the top of stack
2227 kmp_int32 ts_entries; // number of entries on the stack
2228} kmp_task_stack_t;
2229
2230#endif // BUILD_TIED_TASK_STACK
2231
2232typedef struct kmp_tasking_flags { /* Total struct must be exactly 32 bits */
2233 /* Compiler flags */ /* Total compiler flags must be 16 bits */
2234 unsigned tiedness : 1; /* task is either tied (1) or untied (0) */
2235 unsigned final : 1; /* task is final(1) so execute immediately */
2236 unsigned merged_if0 : 1; /* no __kmpc_task_{begin/complete}_if0 calls in if0
2237 code path */
2238#if OMP_40_ENABLED(50 >= 40)
2239 unsigned destructors_thunk : 1; /* set if the compiler creates a thunk to
2240 invoke destructors from the runtime */
2241#if OMP_45_ENABLED(50 >= 45)
2242 unsigned proxy : 1; /* task is a proxy task (it will be executed outside the
2243 context of the RTL) */
2244 unsigned priority_specified : 1; /* set if the compiler provides priority
2245 setting for the task */
2246 unsigned reserved : 10; /* reserved for compiler use */
2247#else
2248 unsigned reserved : 12; /* reserved for compiler use */
2249#endif
2250#else // OMP_40_ENABLED
2251 unsigned reserved : 13; /* reserved for compiler use */
2252#endif // OMP_40_ENABLED
2253
2254 /* Library flags */ /* Total library flags must be 16 bits */
2255 unsigned tasktype : 1; /* task is either explicit(1) or implicit (0) */
2256 unsigned task_serial : 1; // task is executed immediately (1) or deferred (0)
2257 unsigned tasking_ser : 1; // all tasks in team are either executed immediately
2258 // (1) or may be deferred (0)
2259 unsigned team_serial : 1; // entire team is serial (1) [1 thread] or parallel
2260 // (0) [>= 2 threads]
2261 /* If either team_serial or tasking_ser is set, task team may be NULL */
2262 /* Task State Flags: */
2263 unsigned started : 1; /* 1==started, 0==not started */
2264 unsigned executing : 1; /* 1==executing, 0==not executing */
2265 unsigned complete : 1; /* 1==complete, 0==not complete */
2266 unsigned freed : 1; /* 1==freed, 0==allocateed */
2267 unsigned native : 1; /* 1==gcc-compiled task, 0==intel */
2268 unsigned reserved31 : 7; /* reserved for library use */
2269
2270} kmp_tasking_flags_t;
2271
2272struct kmp_taskdata { /* aligned during dynamic allocation */
2273 kmp_int32 td_task_id; /* id, assigned by debugger */
2274 kmp_tasking_flags_t td_flags; /* task flags */
2275 kmp_team_t *td_team; /* team for this task */
2276 kmp_info_p *td_alloc_thread; /* thread that allocated data structures */
2277 /* Currently not used except for perhaps IDB */
2278 kmp_taskdata_t *td_parent; /* parent task */
2279 kmp_int32 td_level; /* task nesting level */
2280 std::atomic<kmp_int32> td_untied_count; // untied task active parts counter
2281 ident_t *td_ident; /* task identifier */
2282 // Taskwait data.
2283 ident_t *td_taskwait_ident;
2284 kmp_uint32 td_taskwait_counter;
2285 kmp_int32 td_taskwait_thread; /* gtid + 1 of thread encountered taskwait */
2286 KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_internal_control_t
2287 td_icvs; /* Internal control variables for the task */
2288 KMP_ALIGN_CACHE__attribute__((aligned(64))) std::atomic<kmp_int32>
2289 td_allocated_child_tasks; /* Child tasks (+ current task) not yet
2290 deallocated */
2291 std::atomic<kmp_int32>
2292 td_incomplete_child_tasks; /* Child tasks not yet complete */
2293#if OMP_40_ENABLED(50 >= 40)
2294 kmp_taskgroup_t
2295 *td_taskgroup; // Each task keeps pointer to its current taskgroup
2296 kmp_dephash_t
2297 *td_dephash; // Dependencies for children tasks are tracked from here
2298 kmp_depnode_t
2299 *td_depnode; // Pointer to graph node if this task has dependencies
2300#endif // OMP_40_ENABLED
2301#if OMP_45_ENABLED(50 >= 45)
2302 kmp_task_team_t *td_task_team;
2303 kmp_int32 td_size_alloc; // The size of task structure, including shareds etc.
2304#if defined(KMP_GOMP_COMPAT)
2305 // 4 or 8 byte integers for the loop bounds in GOMP_taskloop
2306 kmp_int32 td_size_loop_bounds;
2307#endif
2308#endif // OMP_45_ENABLED
2309 kmp_taskdata_t *td_last_tied; // keep tied task for task scheduling constraint
2310#if defined(KMP_GOMP_COMPAT) && OMP_45_ENABLED(50 >= 45)
2311 // GOMP sends in a copy function for copy constructors
2312 void (*td_copy_func)(void *, void *);
2313#endif
2314#if OMPT_SUPPORT1
2315 ompt_task_info_t ompt_task_info;
2316#endif
2317}; // struct kmp_taskdata
2318
2319// Make sure padding above worked
2320KMP_BUILD_ASSERT(sizeof(kmp_taskdata_t) % sizeof(void *) == 0)static_assert(sizeof(kmp_taskdata_t) % sizeof(void *) == 0, "Build condition error"
)
;
2321
2322// Data for task team but per thread
2323typedef struct kmp_base_thread_data {
2324 kmp_info_p *td_thr; // Pointer back to thread info
2325 // Used only in __kmp_execute_tasks_template, maybe not avail until task is
2326 // queued?
2327 kmp_bootstrap_lock_t td_deque_lock; // Lock for accessing deque
2328 kmp_taskdata_t *
2329 *td_deque; // Deque of tasks encountered by td_thr, dynamically allocated
2330 kmp_int32 td_deque_size; // Size of deck
2331 kmp_uint32 td_deque_head; // Head of deque (will wrap)
2332 kmp_uint32 td_deque_tail; // Tail of deque (will wrap)
2333 kmp_int32 td_deque_ntasks; // Number of tasks in deque
2334 // GEH: shouldn't this be volatile since used in while-spin?
2335 kmp_int32 td_deque_last_stolen; // Thread number of last successful steal
2336#ifdef BUILD_TIED_TASK_STACK
2337 kmp_task_stack_t td_susp_tied_tasks; // Stack of suspended tied tasks for task
2338// scheduling constraint
2339#endif // BUILD_TIED_TASK_STACK
2340} kmp_base_thread_data_t;
2341
2342#define TASK_DEQUE_BITS8 8 // Used solely to define INITIAL_TASK_DEQUE_SIZE
2343#define INITIAL_TASK_DEQUE_SIZE(1 << 8) (1 << TASK_DEQUE_BITS8)
2344
2345#define TASK_DEQUE_SIZE(td)((td).td_deque_size) ((td).td_deque_size)
2346#define TASK_DEQUE_MASK(td)((td).td_deque_size - 1) ((td).td_deque_size - 1)
2347
2348typedef union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_thread_data {
2349 kmp_base_thread_data_t td;
2350 double td_align; /* use worst case alignment */
2351 char td_pad[KMP_PAD(kmp_base_thread_data_t, CACHE_LINE)(sizeof(kmp_base_thread_data_t) + (64 - ((sizeof(kmp_base_thread_data_t
) - 1) % (64)) - 1))
];
2352} kmp_thread_data_t;
2353
2354// Data for task teams which are used when tasking is enabled for the team
2355typedef struct kmp_base_task_team {
2356 kmp_bootstrap_lock_t
2357 tt_threads_lock; /* Lock used to allocate per-thread part of task team */
2358 /* must be bootstrap lock since used at library shutdown*/
2359 kmp_task_team_t *tt_next; /* For linking the task team free list */
2360 kmp_thread_data_t
2361 *tt_threads_data; /* Array of per-thread structures for task team */
2362 /* Data survives task team deallocation */
2363 kmp_int32 tt_found_tasks; /* Have we found tasks and queued them while
2364 executing this team? */
2365 /* TRUE means tt_threads_data is set up and initialized */
2366 kmp_int32 tt_nproc; /* #threads in team */
2367 kmp_int32
2368 tt_max_threads; /* number of entries allocated for threads_data array */
2369#if OMP_45_ENABLED(50 >= 45)
2370 kmp_int32
2371 tt_found_proxy_tasks; /* Have we found proxy tasks since last barrier */
2372#endif
2373 kmp_int32 tt_untied_task_encountered;
2374
2375 KMP_ALIGN_CACHE__attribute__((aligned(64)))
2376 std::atomic<kmp_int32> tt_unfinished_threads; /* #threads still active */
2377
2378 KMP_ALIGN_CACHE__attribute__((aligned(64)))
2379 volatile kmp_uint32
2380 tt_active; /* is the team still actively executing tasks */
2381} kmp_base_task_team_t;
2382
2383union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_task_team {
2384 kmp_base_task_team_t tt;
2385 double tt_align; /* use worst case alignment */
2386 char tt_pad[KMP_PAD(kmp_base_task_team_t, CACHE_LINE)(sizeof(kmp_base_task_team_t) + (64 - ((sizeof(kmp_base_task_team_t
) - 1) % (64)) - 1))
];
2387};
2388
2389#if (USE_FAST_MEMORY3 == 3) || (USE_FAST_MEMORY3 == 5)
2390// Free lists keep same-size free memory slots for fast memory allocation
2391// routines
2392typedef struct kmp_free_list {
2393 void *th_free_list_self; // Self-allocated tasks free list
2394 void *th_free_list_sync; // Self-allocated tasks stolen/returned by other
2395 // threads
2396 void *th_free_list_other; // Non-self free list (to be returned to owner's
2397 // sync list)
2398} kmp_free_list_t;
2399#endif
2400#if KMP_NESTED_HOT_TEAMS1
2401// Hot teams array keeps hot teams and their sizes for given thread. Hot teams
2402// are not put in teams pool, and they don't put threads in threads pool.
2403typedef struct kmp_hot_team_ptr {
2404 kmp_team_p *hot_team; // pointer to hot_team of given nesting level
2405 kmp_int32 hot_team_nth; // number of threads allocated for the hot_team
2406} kmp_hot_team_ptr_t;
2407#endif
2408#if OMP_40_ENABLED(50 >= 40)
2409typedef struct kmp_teams_size {
2410 kmp_int32 nteams; // number of teams in a league
2411 kmp_int32 nth; // number of threads in each team of the league
2412} kmp_teams_size_t;
2413#endif
2414
2415// OpenMP thread data structures
2416
2417typedef struct KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_base_info {
2418 /* Start with the readonly data which is cache aligned and padded. This is
2419 written before the thread starts working by the master. Uber masters may
2420 update themselves later. Usage does not consider serialized regions. */
2421 kmp_desc_t th_info;
2422 kmp_team_p *th_team; /* team we belong to */
2423 kmp_root_p *th_root; /* pointer to root of task hierarchy */
2424 kmp_info_p *th_next_pool; /* next available thread in the pool */
2425 kmp_disp_t *th_dispatch; /* thread's dispatch data */
2426 int th_in_pool; /* in thread pool (32 bits for TCR/TCW) */
2427
2428 /* The following are cached from the team info structure */
2429 /* TODO use these in more places as determined to be needed via profiling */
2430 int th_team_nproc; /* number of threads in a team */
2431 kmp_info_p *th_team_master; /* the team's master thread */
2432 int th_team_serialized; /* team is serialized */
2433#if OMP_40_ENABLED(50 >= 40)
2434 microtask_t th_teams_microtask; /* save entry address for teams construct */
2435 int th_teams_level; /* save initial level of teams construct */
2436/* it is 0 on device but may be any on host */
2437#endif
2438
2439/* The blocktime info is copied from the team struct to the thread sruct */
2440/* at the start of a barrier, and the values stored in the team are used */
2441/* at points in the code where the team struct is no longer guaranteed */
2442/* to exist (from the POV of worker threads). */
2443#if KMP_USE_MONITOR
2444 int th_team_bt_intervals;
2445 int th_team_bt_set;
2446#else
2447 kmp_uint64 th_team_bt_intervals;
2448#endif
2449
2450#if KMP_AFFINITY_SUPPORTED1
2451 kmp_affin_mask_t *th_affin_mask; /* thread's current affinity mask */
2452#endif
2453#if OMP_50_ENABLED(50 >= 50)
2454 void *const *th_def_allocator; /* per implicit task default allocator */
2455#endif
2456 /* The data set by the master at reinit, then R/W by the worker */
2457 KMP_ALIGN_CACHE__attribute__((aligned(64))) int
2458 th_set_nproc; /* if > 0, then only use this request for the next fork */
2459#if KMP_NESTED_HOT_TEAMS1
2460 kmp_hot_team_ptr_t *th_hot_teams; /* array of hot teams */
2461#endif
2462#if OMP_40_ENABLED(50 >= 40)
2463 kmp_proc_bind_t
2464 th_set_proc_bind; /* if != proc_bind_default, use request for next fork */
2465 kmp_teams_size_t
2466 th_teams_size; /* number of teams/threads in teams construct */
2467#if KMP_AFFINITY_SUPPORTED1
2468 int th_current_place; /* place currently bound to */
2469 int th_new_place; /* place to bind to in par reg */
2470 int th_first_place; /* first place in partition */
2471 int th_last_place; /* last place in partition */
2472#endif
2473#endif
2474#if USE_ITT_BUILD1
2475 kmp_uint64 th_bar_arrive_time; /* arrival to barrier timestamp */
2476 kmp_uint64 th_bar_min_time; /* minimum arrival time at the barrier */
2477 kmp_uint64 th_frame_time; /* frame timestamp */
2478#endif /* USE_ITT_BUILD */
2479 kmp_local_t th_local;
2480 struct private_common *th_pri_head;
2481
2482 /* Now the data only used by the worker (after initial allocation) */
2483 /* TODO the first serial team should actually be stored in the info_t
2484 structure. this will help reduce initial allocation overhead */
2485 KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_team_p
2486 *th_serial_team; /*serialized team held in reserve*/
2487
2488#if OMPT_SUPPORT1
2489 ompt_thread_info_t ompt_thread_info;
2490#endif
2491
2492 /* The following are also read by the master during reinit */
2493 struct common_table *th_pri_common;
2494
2495 volatile kmp_uint32 th_spin_here; /* thread-local location for spinning */
2496 /* while awaiting queuing lock acquire */
2497
2498 volatile void *th_sleep_loc; // this points at a kmp_flag<T>
2499
2500 ident_t *th_ident;
2501 unsigned th_x; // Random number generator data
2502 unsigned th_a; // Random number generator data
2503
2504 /* Tasking-related data for the thread */
2505 kmp_task_team_t *th_task_team; // Task team struct
2506 kmp_taskdata_t *th_current_task; // Innermost Task being executed
2507 kmp_uint8 th_task_state; // alternating 0/1 for task team identification
2508 kmp_uint8 *th_task_state_memo_stack; // Stack holding memos of th_task_state
2509 // at nested levels
2510 kmp_uint32 th_task_state_top; // Top element of th_task_state_memo_stack
2511 kmp_uint32 th_task_state_stack_sz; // Size of th_task_state_memo_stack
2512 kmp_uint32 th_reap_state; // Non-zero indicates thread is not
2513 // tasking, thus safe to reap
2514
2515 /* More stuff for keeping track of active/sleeping threads (this part is
2516 written by the worker thread) */
2517 kmp_uint8 th_active_in_pool; // included in count of #active threads in pool
2518 int th_active; // ! sleeping; 32 bits for TCR/TCW
2519 struct cons_header *th_cons; // used for consistency check
2520#if KMP_USE_HIER_SCHED0
2521 // used for hierarchical scheduling
2522 kmp_hier_private_bdata_t *th_hier_bar_data;
2523#endif
2524
2525 /* Add the syncronizing data which is cache aligned and padded. */
2526 KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_balign_t th_bar[bs_last_barrier];
2527
2528 KMP_ALIGN_CACHE__attribute__((aligned(64))) volatile kmp_int32
2529 th_next_waiting; /* gtid+1 of next thread on lock wait queue, 0 if none */
2530
2531#if (USE_FAST_MEMORY3 == 3) || (USE_FAST_MEMORY3 == 5)
2532#define NUM_LISTS4 4
2533 kmp_free_list_t th_free_lists[NUM_LISTS4]; // Free lists for fast memory
2534// allocation routines
2535#endif
2536
2537#if KMP_OS_WINDOWS0
2538 kmp_win32_cond_t th_suspend_cv;
2539 kmp_win32_mutex_t th_suspend_mx;
2540 int th_suspend_init;
2541#endif
2542#if KMP_OS_UNIX1
2543 kmp_cond_align_t th_suspend_cv;
2544 kmp_mutex_align_t th_suspend_mx;
2545 int th_suspend_init_count;
2546#endif
2547
2548#if USE_ITT_BUILD1
2549 kmp_itt_mark_t th_itt_mark_single;
2550// alignment ???
2551#endif /* USE_ITT_BUILD */
2552#if KMP_STATS_ENABLED0
2553 kmp_stats_list *th_stats;
2554#endif
2555#if KMP_OS_UNIX1
2556 std::atomic<bool> th_blocking;
2557#endif
2558} kmp_base_info_t;
2559
2560typedef union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_info {
2561 double th_align; /* use worst case alignment */
2562 char th_pad[KMP_PAD(kmp_base_info_t, CACHE_LINE)(sizeof(kmp_base_info_t) + (64 - ((sizeof(kmp_base_info_t) - 1
) % (64)) - 1))
];
2563 kmp_base_info_t th;
2564} kmp_info_t;
2565
2566// OpenMP thread team data structures
2567
2568typedef struct kmp_base_data { volatile kmp_uint32 t_value; } kmp_base_data_t;
2569
2570typedef union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_sleep_team {
2571 double dt_align; /* use worst case alignment */
2572 char dt_pad[KMP_PAD(kmp_base_data_t, CACHE_LINE)(sizeof(kmp_base_data_t) + (64 - ((sizeof(kmp_base_data_t) - 1
) % (64)) - 1))
];
2573 kmp_base_data_t dt;
2574} kmp_sleep_team_t;
2575
2576typedef union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_ordered_team {
2577 double dt_align; /* use worst case alignment */
2578 char dt_pad[KMP_PAD(kmp_base_data_t, CACHE_LINE)(sizeof(kmp_base_data_t) + (64 - ((sizeof(kmp_base_data_t) - 1
) % (64)) - 1))
];
2579 kmp_base_data_t dt;
2580} kmp_ordered_team_t;
2581
2582typedef int (*launch_t)(int gtid);
2583
2584/* Minimum number of ARGV entries to malloc if necessary */
2585#define KMP_MIN_MALLOC_ARGV_ENTRIES100 100
2586
2587// Set up how many argv pointers will fit in cache lines containing
2588// t_inline_argv. Historically, we have supported at least 96 bytes. Using a
2589// larger value for more space between the master write/worker read section and
2590// read/write by all section seems to buy more performance on EPCC PARALLEL.
2591#if KMP_ARCH_X860 || KMP_ARCH_X86_641
2592#define KMP_INLINE_ARGV_BYTES(4 * 64 - ((3 * (sizeof(void *)) + 2 * sizeof(int) + 2 * sizeof
(kmp_int8) + sizeof(kmp_int16) + sizeof(kmp_uint32)) % 64))
\
2593 (4 * CACHE_LINE64 - \
2594 ((3 * KMP_PTR_SKIP(sizeof(void *)) + 2 * sizeof(int) + 2 * sizeof(kmp_int8) + \
2595 sizeof(kmp_int16) + sizeof(kmp_uint32)) % \
2596 CACHE_LINE64))
2597#else
2598#define KMP_INLINE_ARGV_BYTES(4 * 64 - ((3 * (sizeof(void *)) + 2 * sizeof(int) + 2 * sizeof
(kmp_int8) + sizeof(kmp_int16) + sizeof(kmp_uint32)) % 64))
\
2599 (2 * CACHE_LINE64 - ((3 * KMP_PTR_SKIP(sizeof(void *)) + 2 * sizeof(int)) % CACHE_LINE64))
2600#endif
2601#define KMP_INLINE_ARGV_ENTRIES(int)((4 * 64 - ((3 * (sizeof(void *)) + 2 * sizeof(int) + 2 *
sizeof(kmp_int8) + sizeof(kmp_int16) + sizeof(kmp_uint32)) %
64)) / (sizeof(void *)))
(int)(KMP_INLINE_ARGV_BYTES(4 * 64 - ((3 * (sizeof(void *)) + 2 * sizeof(int) + 2 * sizeof
(kmp_int8) + sizeof(kmp_int16) + sizeof(kmp_uint32)) % 64))
/ KMP_PTR_SKIP(sizeof(void *)))
2602
2603typedef struct KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_base_team {
2604 // Synchronization Data
2605 // ---------------------------------------------------------------------------
2606 KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_ordered_team_t t_ordered;
2607 kmp_balign_team_t t_bar[bs_last_barrier];
2608 std::atomic<int> t_construct; // count of single directive encountered by team
2609 char pad[sizeof(kmp_lock_t)]; // padding to maintain performance on big iron
2610
2611 // Master only
2612 // ---------------------------------------------------------------------------
2613 KMP_ALIGN_CACHE__attribute__((aligned(64))) int t_master_tid; // tid of master in parent team
2614 int t_master_this_cons; // "this_construct" single counter of master in parent
2615 // team
2616 ident_t *t_ident; // if volatile, have to change too much other crud to
2617 // volatile too
2618 kmp_team_p *t_parent; // parent team
2619 kmp_team_p *t_next_pool; // next free team in the team pool
2620 kmp_disp_t *t_dispatch; // thread's dispatch data
2621 kmp_task_team_t *t_task_team[2]; // Task team struct; switch between 2
2622#if OMP_40_ENABLED(50 >= 40)
2623 kmp_proc_bind_t t_proc_bind; // bind type for par region
2624#endif // OMP_40_ENABLED
2625#if USE_ITT_BUILD1
2626 kmp_uint64 t_region_time; // region begin timestamp
2627#endif /* USE_ITT_BUILD */
2628
2629 // Master write, workers read
2630 // --------------------------------------------------------------------------
2631 KMP_ALIGN_CACHE__attribute__((aligned(64))) void **t_argv;
2632 int t_argc;
2633 int t_nproc; // number of threads in team
2634 microtask_t t_pkfn;
2635 launch_t t_invoke; // procedure to launch the microtask
2636
2637#if OMPT_SUPPORT1
2638 ompt_team_info_t ompt_team_info;
2639 ompt_lw_taskteam_t *ompt_serialized_team_info;
2640#endif
2641
2642#if KMP_ARCH_X860 || KMP_ARCH_X86_641
2643 kmp_int8 t_fp_control_saved;
2644 kmp_int8 t_pad2b;
2645 kmp_int16 t_x87_fpu_control_word; // FP control regs
2646 kmp_uint32 t_mxcsr;
2647#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2648
2649 void *t_inline_argv[KMP_INLINE_ARGV_ENTRIES(int)((4 * 64 - ((3 * (sizeof(void *)) + 2 * sizeof(int) + 2 *
sizeof(kmp_int8) + sizeof(kmp_int16) + sizeof(kmp_uint32)) %
64)) / (sizeof(void *)))
];
2650
2651 KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_info_t **t_threads;
2652 kmp_taskdata_t
2653 *t_implicit_task_taskdata; // Taskdata for the thread's implicit task
2654 int t_level; // nested parallel level
2655
2656 KMP_ALIGN_CACHE__attribute__((aligned(64))) int t_max_argc;
2657 int t_max_nproc; // max threads this team can handle (dynamicly expandable)
2658 int t_serialized; // levels deep of serialized teams
2659 dispatch_shared_info_t *t_disp_buffer; // buffers for dispatch system
2660 int t_id; // team's id, assigned by debugger.
2661 int t_active_level; // nested active parallel level
2662 kmp_r_sched_t t_sched; // run-time schedule for the team
2663#if OMP_40_ENABLED(50 >= 40) && KMP_AFFINITY_SUPPORTED1
2664 int t_first_place; // first & last place in parent thread's partition.
2665 int t_last_place; // Restore these values to master after par region.
2666#endif // OMP_40_ENABLED && KMP_AFFINITY_SUPPORTED
2667 int t_size_changed; // team size was changed?: 0: no, 1: yes, -1: changed via
2668// omp_set_num_threads() call
2669#if OMP_50_ENABLED(50 >= 50)
2670 void *const *t_def_allocator; /* per implicit task default allocator */
2671#endif
2672
2673// Read/write by workers as well
2674#if (KMP_ARCH_X860 || KMP_ARCH_X86_641)
2675 // Using CACHE_LINE=64 reduces memory footprint, but causes a big perf
2676 // regression of epcc 'parallel' and 'barrier' on fxe256lin01. This extra
2677 // padding serves to fix the performance of epcc 'parallel' and 'barrier' when
2678 // CACHE_LINE=64. TODO: investigate more and get rid if this padding.
2679 char dummy_padding[1024];
2680#endif
2681 // Internal control stack for additional nested teams.
2682 KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_internal_control_t *t_control_stack_top;
2683// for SERIALIZED teams nested 2 or more levels deep
2684#if OMP_40_ENABLED(50 >= 40)
2685 // typed flag to store request state of cancellation
2686 std::atomic<kmp_int32> t_cancel_request;
2687#endif
2688 int t_master_active; // save on fork, restore on join
2689 kmp_taskq_t t_taskq; // this team's task queue
2690 void *t_copypriv_data; // team specific pointer to copyprivate data array
2691#if KMP_OS_WINDOWS0
2692 std::atomic<kmp_uint32> t_copyin_counter;
2693#endif
2694#if USE_ITT_BUILD1
2695 void *t_stack_id; // team specific stack stitching id (for ittnotify)
2696#endif /* USE_ITT_BUILD */
2697} kmp_base_team_t;
2698
2699union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_team {
2700 kmp_base_team_t t;
2701 double t_align; /* use worst case alignment */
2702 char t_pad[KMP_PAD(kmp_base_team_t, CACHE_LINE)(sizeof(kmp_base_team_t) + (64 - ((sizeof(kmp_base_team_t) - 1
) % (64)) - 1))
];
2703};
2704
2705typedef union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_time_global {
2706 double dt_align; /* use worst case alignment */
2707 char dt_pad[KMP_PAD(kmp_base_data_t, CACHE_LINE)(sizeof(kmp_base_data_t) + (64 - ((sizeof(kmp_base_data_t) - 1
) % (64)) - 1))
];
2708 kmp_base_data_t dt;
2709} kmp_time_global_t;
2710
2711typedef struct kmp_base_global {
2712 /* cache-aligned */
2713 kmp_time_global_t g_time;
2714
2715 /* non cache-aligned */
2716 volatile int g_abort;
2717 volatile int g_done;
2718
2719 int g_dynamic;
2720 enum dynamic_mode g_dynamic_mode;
2721} kmp_base_global_t;
2722
2723typedef union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_global {
2724 kmp_base_global_t g;
2725 double g_align; /* use worst case alignment */
2726 char g_pad[KMP_PAD(kmp_base_global_t, CACHE_LINE)(sizeof(kmp_base_global_t) + (64 - ((sizeof(kmp_base_global_t
) - 1) % (64)) - 1))
];
2727} kmp_global_t;
2728
2729typedef struct kmp_base_root {
2730 // TODO: GEH - combine r_active with r_in_parallel then r_active ==
2731 // (r_in_parallel>= 0)
2732 // TODO: GEH - then replace r_active with t_active_levels if we can to reduce
2733 // the synch overhead or keeping r_active
2734 volatile int r_active; /* TRUE if some region in a nest has > 1 thread */
2735 // GEH: This is misnamed, should be r_in_parallel
2736 volatile int r_nested; // TODO: GEH - This is unused, just remove it entirely.
2737 // keeps a count of active parallel regions per root
2738 std::atomic<int> r_in_parallel;
2739 // GEH: This is misnamed, should be r_active_levels
2740 kmp_team_t *r_root_team;
2741 kmp_team_t *r_hot_team;
2742 kmp_info_t *r_uber_thread;
2743 kmp_lock_t r_begin_lock;
2744 volatile int r_begin;
2745 int r_blocktime; /* blocktime for this root and descendants */
2746 int r_cg_nthreads; // count of active threads in a contention group
2747} kmp_base_root_t;
2748
2749typedef union KMP_ALIGN_CACHE__attribute__((aligned(64))) kmp_root {
2750 kmp_base_root_t r;
2751 double r_align; /* use worst case alignment */
2752 char r_pad[KMP_PAD(kmp_base_root_t, CACHE_LINE)(sizeof(kmp_base_root_t) + (64 - ((sizeof(kmp_base_root_t) - 1
) % (64)) - 1))
];
2753} kmp_root_t;
2754
2755struct fortran_inx_info {
2756 kmp_int32 data;
2757};
2758
2759/* ------------------------------------------------------------------------ */
2760
2761extern int __kmp_settings;
2762extern int __kmp_duplicate_library_ok;
2763#if USE_ITT_BUILD1
2764extern int __kmp_forkjoin_frames;
2765extern int __kmp_forkjoin_frames_mode;
2766#endif
2767extern PACKED_REDUCTION_METHOD_T __kmp_force_reduction_method;
2768extern int __kmp_determ_red;
2769
2770#ifdef KMP_DEBUG1
2771extern int kmp_a_debug;
2772extern int kmp_b_debug;
2773extern int kmp_c_debug;
2774extern int kmp_d_debug;
2775extern int kmp_e_debug;
2776extern int kmp_f_debug;
2777#endif /* KMP_DEBUG */
2778
2779/* For debug information logging using rotating buffer */
2780#define KMP_DEBUG_BUF_LINES_INIT512 512
2781#define KMP_DEBUG_BUF_LINES_MIN1 1
2782
2783#define KMP_DEBUG_BUF_CHARS_INIT128 128
2784#define KMP_DEBUG_BUF_CHARS_MIN2 2
2785
2786extern int
2787 __kmp_debug_buf; /* TRUE means use buffer, FALSE means print to stderr */
2788extern int __kmp_debug_buf_lines; /* How many lines of debug stored in buffer */
2789extern int
2790 __kmp_debug_buf_chars; /* How many characters allowed per line in buffer */
2791extern int __kmp_debug_buf_atomic; /* TRUE means use atomic update of buffer
2792 entry pointer */
2793
2794extern char *__kmp_debug_buffer; /* Debug buffer itself */
2795extern std::atomic<int> __kmp_debug_count; /* Counter for number of lines
2796 printed in buffer so far */
2797extern int __kmp_debug_buf_warn_chars; /* Keep track of char increase
2798 recommended in warnings */
2799/* end rotating debug buffer */
2800
2801#ifdef KMP_DEBUG1
2802extern int __kmp_par_range; /* +1 => only go par for constructs in range */
2803
2804#define KMP_PAR_RANGE_ROUTINE_LEN1024 1024
2805extern char __kmp_par_range_routine[KMP_PAR_RANGE_ROUTINE_LEN1024];
2806#define KMP_PAR_RANGE_FILENAME_LEN1024 1024
2807extern char __kmp_par_range_filename[KMP_PAR_RANGE_FILENAME_LEN1024];
2808extern int __kmp_par_range_lb;
2809extern int __kmp_par_range_ub;
2810#endif
2811
2812/* For printing out dynamic storage map for threads and teams */
2813extern int
2814 __kmp_storage_map; /* True means print storage map for threads and teams */
2815extern int __kmp_storage_map_verbose; /* True means storage map includes
2816 placement info */
2817extern int __kmp_storage_map_verbose_specified;
2818
2819#if KMP_ARCH_X860 || KMP_ARCH_X86_641
2820extern kmp_cpuinfo_t __kmp_cpuinfo;
2821#endif
2822
2823extern volatile int __kmp_init_serial;
2824extern volatile int __kmp_init_gtid;
2825extern volatile int __kmp_init_common;
2826extern volatile int __kmp_init_middle;
2827extern volatile int __kmp_init_parallel;
2828#if KMP_USE_MONITOR
2829extern volatile int __kmp_init_monitor;
2830#endif
2831extern volatile int __kmp_init_user_locks;
2832extern int __kmp_init_counter;
2833extern int __kmp_root_counter;
2834extern int __kmp_version;
2835
2836/* list of address of allocated caches for commons */
2837extern kmp_cached_addr_t *__kmp_threadpriv_cache_list;
2838
2839/* Barrier algorithm types and options */
2840extern kmp_uint32 __kmp_barrier_gather_bb_dflt;
2841extern kmp_uint32 __kmp_barrier_release_bb_dflt;
2842extern kmp_bar_pat_e __kmp_barrier_gather_pat_dflt;
2843extern kmp_bar_pat_e __kmp_barrier_release_pat_dflt;
2844extern kmp_uint32 __kmp_barrier_gather_branch_bits[bs_last_barrier];
2845extern kmp_uint32 __kmp_barrier_release_branch_bits[bs_last_barrier];
2846extern kmp_bar_pat_e __kmp_barrier_gather_pattern[bs_last_barrier];
2847extern kmp_bar_pat_e __kmp_barrier_release_pattern[bs_last_barrier];
2848extern char const *__kmp_barrier_branch_bit_env_name[bs_last_barrier];
2849extern char const *__kmp_barrier_pattern_env_name[bs_last_barrier];
2850extern char const *__kmp_barrier_type_name[bs_last_barrier];
2851extern char const *__kmp_barrier_pattern_name[bp_last_bar];
2852
2853/* Global Locks */
2854extern kmp_bootstrap_lock_t __kmp_initz_lock; /* control initialization */
2855extern kmp_bootstrap_lock_t __kmp_forkjoin_lock; /* control fork/join access */
2856extern kmp_bootstrap_lock_t __kmp_task_team_lock;
2857extern kmp_bootstrap_lock_t
2858 __kmp_exit_lock; /* exit() is not always thread-safe */
2859#if KMP_USE_MONITOR
2860extern kmp_bootstrap_lock_t
2861 __kmp_monitor_lock; /* control monitor thread creation */
2862#endif
2863extern kmp_bootstrap_lock_t
2864 __kmp_tp_cached_lock; /* used for the hack to allow threadprivate cache and
2865 __kmp_threads expansion to co-exist */
2866
2867extern kmp_lock_t __kmp_global_lock; /* control OS/global access */
2868extern kmp_queuing_lock_t __kmp_dispatch_lock; /* control dispatch access */
2869extern kmp_lock_t __kmp_debug_lock; /* control I/O access for KMP_DEBUG */
2870
2871/* used for yielding spin-waits */
2872extern unsigned int __kmp_init_wait; /* initial number of spin-tests */
2873extern unsigned int __kmp_next_wait; /* susequent number of spin-tests */
2874
2875extern enum library_type __kmp_library;
2876
2877extern enum sched_type __kmp_sched; /* default runtime scheduling */
2878extern enum sched_type __kmp_static; /* default static scheduling method */
2879extern enum sched_type __kmp_guided; /* default guided scheduling method */
2880extern enum sched_type __kmp_auto; /* default auto scheduling method */
2881extern int __kmp_chunk; /* default runtime chunk size */
2882
2883extern size_t __kmp_stksize; /* stack size per thread */
2884#if KMP_USE_MONITOR
2885extern size_t __kmp_monitor_stksize; /* stack size for monitor thread */
2886#endif
2887extern size_t __kmp_stkoffset; /* stack offset per thread */
2888extern int __kmp_stkpadding; /* Should we pad root thread(s) stack */
2889
2890extern size_t
2891 __kmp_malloc_pool_incr; /* incremental size of pool for kmp_malloc() */
2892extern int __kmp_env_stksize; /* was KMP_STACKSIZE specified? */
2893extern int __kmp_env_blocktime; /* was KMP_BLOCKTIME specified? */
2894extern int __kmp_env_checks; /* was KMP_CHECKS specified? */
2895extern int __kmp_env_consistency_check; // was KMP_CONSISTENCY_CHECK specified?
2896extern int __kmp_generate_warnings; /* should we issue warnings? */
2897extern int __kmp_reserve_warn; /* have we issued reserve_threads warning? */
2898
2899#ifdef DEBUG_SUSPEND
2900extern int __kmp_suspend_count; /* count inside __kmp_suspend_template() */
2901#endif
2902
2903extern kmp_uint32 __kmp_yield_init;
2904extern kmp_uint32 __kmp_yield_next;
2905
2906#if KMP_USE_MONITOR
2907extern kmp_uint32 __kmp_yielding_on;
2908#endif
2909extern kmp_uint32 __kmp_yield_cycle;
2910extern kmp_int32 __kmp_yield_on_count;
2911extern kmp_int32 __kmp_yield_off_count;
2912
2913/* ------------------------------------------------------------------------- */
2914extern int __kmp_allThreadsSpecified;
2915
2916extern size_t __kmp_align_alloc;
2917/* following data protected by initialization routines */
2918extern int __kmp_xproc; /* number of processors in the system */
2919extern int __kmp_avail_proc; /* number of processors available to the process */
2920extern size_t __kmp_sys_min_stksize; /* system-defined minimum stack size */
2921extern int __kmp_sys_max_nth; /* system-imposed maximum number of threads */
2922// maximum total number of concurrently-existing threads on device
2923extern int __kmp_max_nth;
2924// maximum total number of concurrently-existing threads in a contention group
2925extern int __kmp_cg_max_nth;
2926extern int __kmp_teams_max_nth; // max threads used in a teams construct
2927extern int __kmp_threads_capacity; /* capacity of the arrays __kmp_threads and
2928 __kmp_root */
2929extern int __kmp_dflt_team_nth; /* default number of threads in a parallel
2930 region a la OMP_NUM_THREADS */
2931extern int __kmp_dflt_team_nth_ub; /* upper bound on "" determined at serial
2932 initialization */
2933extern int __kmp_tp_capacity; /* capacity of __kmp_threads if threadprivate is
2934 used (fixed) */
2935extern int __kmp_tp_cached; /* whether threadprivate cache has been created
2936 (__kmpc_threadprivate_cached()) */
2937extern int __kmp_dflt_nested; /* nested parallelism enabled by default a la
2938 OMP_NESTED */
2939extern int __kmp_dflt_blocktime; /* number of milliseconds to wait before
2940 blocking (env setting) */
2941#if KMP_USE_MONITOR
2942extern int
2943 __kmp_monitor_wakeups; /* number of times monitor wakes up per second */
2944extern int __kmp_bt_intervals; /* number of monitor timestamp intervals before
2945 blocking */
2946#endif
2947#ifdef KMP_ADJUST_BLOCKTIME1
2948extern int __kmp_zero_bt; /* whether blocktime has been forced to zero */
2949#endif /* KMP_ADJUST_BLOCKTIME */
2950#ifdef KMP_DFLT_NTH_CORES
2951extern int __kmp_ncores; /* Total number of cores for threads placement */
2952#endif
2953/* Number of millisecs to delay on abort for Intel(R) VTune(TM) tools */
2954extern int __kmp_abort_delay;
2955
2956extern int __kmp_need_register_atfork_specified;
2957extern int
2958 __kmp_need_register_atfork; /* At initialization, call pthread_atfork to
2959 install fork handler */
2960extern int __kmp_gtid_mode; /* Method of getting gtid, values:
2961 0 - not set, will be set at runtime
2962 1 - using stack search
2963 2 - dynamic TLS (pthread_getspecific(Linux* OS/OS
2964 X*) or TlsGetValue(Windows* OS))
2965 3 - static TLS (__declspec(thread) __kmp_gtid),
2966 Linux* OS .so only. */
2967extern int
2968 __kmp_adjust_gtid_mode; /* If true, adjust method based on #threads */
2969#ifdef KMP_TDATA_GTID1
2970extern KMP_THREAD_LOCAL__thread int __kmp_gtid;
2971#endif
2972extern int __kmp_tls_gtid_min; /* #threads below which use sp search for gtid */
2973extern int __kmp_foreign_tp; // If true, separate TP var for each foreign thread
2974#if KMP_ARCH_X860 || KMP_ARCH_X86_641
2975extern int __kmp_inherit_fp_control; // copy fp creg(s) parent->workers at fork
2976extern kmp_int16 __kmp_init_x87_fpu_control_word; // init thread's FP ctrl reg
2977extern kmp_uint32 __kmp_init_mxcsr; /* init thread's mxscr */
2978#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
2979
2980extern int __kmp_dflt_max_active_levels; /* max_active_levels for nested
2981 parallelism enabled by default via
2982 OMP_MAX_ACTIVE_LEVELS */
2983extern int __kmp_dispatch_num_buffers; /* max possible dynamic loops in
2984 concurrent execution per team */
2985#if KMP_NESTED_HOT_TEAMS1
2986extern int __kmp_hot_teams_mode;
2987extern int __kmp_hot_teams_max_level;
2988#endif
2989
2990#if KMP_OS_LINUX1
2991extern enum clock_function_type __kmp_clock_function;
2992extern int __kmp_clock_function_param;
2993#endif /* KMP_OS_LINUX */
2994
2995#if KMP_MIC_SUPPORTED((0 || 1) && (1 || 0))
2996extern enum mic_type __kmp_mic_type;
2997#endif
2998
2999#ifdef USE_LOAD_BALANCE1
3000extern double __kmp_load_balance_interval; // load balance algorithm interval
3001#endif /* USE_LOAD_BALANCE */
3002
3003// OpenMP 3.1 - Nested num threads array
3004typedef struct kmp_nested_nthreads_t {
3005 int *nth;
3006 int size;
3007 int used;
3008} kmp_nested_nthreads_t;
3009
3010extern kmp_nested_nthreads_t __kmp_nested_nth;
3011
3012#if KMP_USE_ADAPTIVE_LOCKS(0 || 1) && !0
3013
3014// Parameters for the speculative lock backoff system.
3015struct kmp_adaptive_backoff_params_t {
3016 // Number of soft retries before it counts as a hard retry.
3017 kmp_uint32 max_soft_retries;
3018 // Badness is a bit mask : 0,1,3,7,15,... on each hard failure we move one to
3019 // the right
3020 kmp_uint32 max_badness;
3021};
3022
3023extern kmp_adaptive_backoff_params_t __kmp_adaptive_backoff_params;
3024
3025#if KMP_DEBUG_ADAPTIVE_LOCKS0
3026extern const char *__kmp_speculative_statsfile;
3027#endif
3028
3029#endif // KMP_USE_ADAPTIVE_LOCKS
3030
3031#if OMP_40_ENABLED(50 >= 40)
3032extern int __kmp_display_env; /* TRUE or FALSE */
3033extern int __kmp_display_env_verbose; /* TRUE if OMP_DISPLAY_ENV=VERBOSE */
3034extern int __kmp_omp_cancellation; /* TRUE or FALSE */
3035#endif
3036
3037/* ------------------------------------------------------------------------- */
3038
3039/* the following are protected by the fork/join lock */
3040/* write: lock read: anytime */
3041extern kmp_info_t **__kmp_threads; /* Descriptors for the threads */
3042/* read/write: lock */
3043extern volatile kmp_team_t *__kmp_team_pool;
3044extern volatile kmp_info_t *__kmp_thread_pool;
3045extern kmp_info_t *__kmp_thread_pool_insert_pt;
3046
3047// total num threads reachable from some root thread including all root threads
3048extern volatile int __kmp_nth;
3049/* total number of threads reachable from some root thread including all root
3050 threads, and those in the thread pool */
3051extern volatile int __kmp_all_nth;
3052extern int __kmp_thread_pool_nth;
3053extern std::atomic<int> __kmp_thread_pool_active_nth;
3054
3055extern kmp_root_t **__kmp_root; /* root of thread hierarchy */
3056/* end data protected by fork/join lock */
3057/* ------------------------------------------------------------------------- */
3058
3059#define __kmp_get_gtid()__kmp_get_global_thread_id() __kmp_get_global