LLVM OpenMP 19.0.0git
kmp_wait_release.h
Go to the documentation of this file.
1/*
2 * kmp_wait_release.h -- Wait/Release implementation
3 */
4
5//===----------------------------------------------------------------------===//
6//
7// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8// See https://llvm.org/LICENSE.txt for license information.
9// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef KMP_WAIT_RELEASE_H
14#define KMP_WAIT_RELEASE_H
15
16#include "kmp.h"
17#include "kmp_itt.h"
18#include "kmp_stats.h"
19#if OMPT_SUPPORT
20#include "ompt-specific.h"
21#endif
22
23/*!
24@defgroup WAIT_RELEASE Wait/Release operations
25
26The definitions and functions here implement the lowest level thread
27synchronizations of suspending a thread and awaking it. They are used to build
28higher level operations such as barriers and fork/join.
29*/
30
31/*!
32@ingroup WAIT_RELEASE
33@{
34*/
35
37 unsigned int type : 16;
38 unsigned int reserved : 16;
39};
40
41template <enum flag_type FlagType> struct flag_traits {};
42
43template <> struct flag_traits<flag32> {
45 static const flag_type t = flag32;
46 static inline flag_t tcr(flag_t f) { return TCR_4(f); }
47 static inline flag_t test_then_add4(volatile flag_t *f) {
48 return KMP_TEST_THEN_ADD4_32(RCAST(volatile kmp_int32 *, f));
49 }
50 static inline flag_t test_then_or(volatile flag_t *f, flag_t v) {
51 return KMP_TEST_THEN_OR32(f, v);
52 }
53 static inline flag_t test_then_and(volatile flag_t *f, flag_t v) {
54 return KMP_TEST_THEN_AND32(f, v);
55 }
56};
57
58template <> struct flag_traits<atomic_flag64> {
60 static const flag_type t = atomic_flag64;
61 static inline flag_t tcr(flag_t f) { return TCR_8(f); }
62 static inline flag_t test_then_add4(volatile flag_t *f) {
63 return KMP_TEST_THEN_ADD4_64(RCAST(volatile kmp_int64 *, f));
64 }
65 static inline flag_t test_then_or(volatile flag_t *f, flag_t v) {
66 return KMP_TEST_THEN_OR64(f, v);
67 }
68 static inline flag_t test_then_and(volatile flag_t *f, flag_t v) {
69 return KMP_TEST_THEN_AND64(f, v);
70 }
71};
72
73template <> struct flag_traits<flag64> {
75 static const flag_type t = flag64;
76 static inline flag_t tcr(flag_t f) { return TCR_8(f); }
77 static inline flag_t test_then_add4(volatile flag_t *f) {
78 return KMP_TEST_THEN_ADD4_64(RCAST(volatile kmp_int64 *, f));
79 }
80 static inline flag_t test_then_or(volatile flag_t *f, flag_t v) {
81 return KMP_TEST_THEN_OR64(f, v);
82 }
83 static inline flag_t test_then_and(volatile flag_t *f, flag_t v) {
84 return KMP_TEST_THEN_AND64(f, v);
85 }
86};
87
88template <> struct flag_traits<flag_oncore> {
90 static const flag_type t = flag_oncore;
91 static inline flag_t tcr(flag_t f) { return TCR_8(f); }
92 static inline flag_t test_then_add4(volatile flag_t *f) {
93 return KMP_TEST_THEN_ADD4_64(RCAST(volatile kmp_int64 *, f));
94 }
95 static inline flag_t test_then_or(volatile flag_t *f, flag_t v) {
96 return KMP_TEST_THEN_OR64(f, v);
97 }
98 static inline flag_t test_then_and(volatile flag_t *f, flag_t v) {
99 return KMP_TEST_THEN_AND64(f, v);
100 }
101};
102
103/*! Base class for all flags */
104template <flag_type FlagType> class kmp_flag {
105protected:
106 flag_properties t; /**< "Type" of the flag in loc */
107 kmp_info_t *waiting_threads[1]; /**< Threads sleeping on this thread. */
108 kmp_uint32 num_waiting_threads; /**< Num threads sleeping on this thread. */
109 std::atomic<bool> *sleepLoc;
110
111public:
113 kmp_flag() : t({FlagType, 0U}), num_waiting_threads(0), sleepLoc(nullptr) {}
114 kmp_flag(int nwaiters)
115 : t({FlagType, 0U}), num_waiting_threads(nwaiters), sleepLoc(nullptr) {}
116 kmp_flag(std::atomic<bool> *sloc)
117 : t({FlagType, 0U}), num_waiting_threads(0), sleepLoc(sloc) {}
118 /*! @result the flag_type */
120
121 /*! param i in index into waiting_threads
122 * @result the thread that is waiting at index i */
125 return waiting_threads[i];
126 }
127 /*! @result num_waiting_threads */
129 /*! @param thr in the thread which is now waiting
130 * Insert a waiting thread at index 0. */
132 waiting_threads[0] = thr;
134 }
136};
137
138/*! Base class for wait/release volatile flag */
139template <typename PtrType, flag_type FlagType, bool Sleepable>
140class kmp_flag_native : public kmp_flag<FlagType> {
141protected:
142 volatile PtrType *loc;
143 PtrType checker; /**< When flag==checker, it has been released. */
145
146public:
147 typedef PtrType flag_t;
148 kmp_flag_native(volatile PtrType *p) : kmp_flag<FlagType>(), loc(p) {}
149 kmp_flag_native(volatile PtrType *p, kmp_info_t *thr)
150 : kmp_flag<FlagType>(1), loc(p) {
151 this->waiting_threads[0] = thr;
152 }
153 kmp_flag_native(volatile PtrType *p, PtrType c)
154 : kmp_flag<FlagType>(), loc(p), checker(c) {}
155 kmp_flag_native(volatile PtrType *p, PtrType c, std::atomic<bool> *sloc)
156 : kmp_flag<FlagType>(sloc), loc(p), checker(c) {}
157 virtual ~kmp_flag_native() {}
158 void *operator new(size_t size) { return __kmp_allocate(size); }
159 void operator delete(void *p) { __kmp_free(p); }
160 volatile PtrType *get() { return loc; }
161 void *get_void_p() { return RCAST(void *, CCAST(PtrType *, loc)); }
162 void set(volatile PtrType *new_loc) { loc = new_loc; }
163 PtrType load() { return *loc; }
164 void store(PtrType val) { *loc = val; }
165 /*! @result true if the flag object has been released. */
166 virtual bool done_check() {
167 if (Sleepable && !(this->sleepLoc))
168 return (traits_type::tcr(*(this->get())) & ~KMP_BARRIER_SLEEP_STATE) ==
169 checker;
170 else
171 return traits_type::tcr(*(this->get())) == checker;
172 }
173 /*! @param old_loc in old value of flag
174 * @result true if the flag's old value indicates it was released. */
175 virtual bool done_check_val(PtrType old_loc) { return old_loc == checker; }
176 /*! @result true if the flag object is not yet released.
177 * Used in __kmp_wait_template like:
178 * @code
179 * while (flag.notdone_check()) { pause(); }
180 * @endcode */
181 virtual bool notdone_check() {
182 return traits_type::tcr(*(this->get())) != checker;
183 }
184 /*! @result Actual flag value before release was applied.
185 * Trigger all waiting threads to run by modifying flag to release state. */
187 (void)traits_type::test_then_add4((volatile PtrType *)this->get());
188 }
189 /*! @result Actual flag value before sleep bit(s) set.
190 * Notes that there is at least one thread sleeping on the flag by setting
191 * sleep bit(s). */
192 PtrType set_sleeping() {
193 if (this->sleepLoc) {
194 this->sleepLoc->store(true);
195 return *(this->get());
196 }
197 return traits_type::test_then_or((volatile PtrType *)this->get(),
199 }
200 /*! @result Actual flag value before sleep bit(s) cleared.
201 * Notes that there are no longer threads sleeping on the flag by clearing
202 * sleep bit(s). */
204 if (this->sleepLoc) {
205 this->sleepLoc->store(false);
206 return;
207 }
208 traits_type::test_then_and((volatile PtrType *)this->get(),
210 }
211 /*! @param old_loc in old value of flag
212 * Test if there are threads sleeping on the flag's old value in old_loc. */
213 bool is_sleeping_val(PtrType old_loc) {
214 if (this->sleepLoc)
215 return this->sleepLoc->load();
216 return old_loc & KMP_BARRIER_SLEEP_STATE;
217 }
218 /*! Test whether there are threads sleeping on the flag. */
219 bool is_sleeping() {
220 if (this->sleepLoc)
221 return this->sleepLoc->load();
222 return is_sleeping_val(*(this->get()));
223 }
225 if (this->sleepLoc)
226 return this->sleepLoc->load();
227 return is_sleeping_val(*(this->get()));
228 }
229 kmp_uint8 *get_stolen() { return NULL; }
230};
231
232/*! Base class for wait/release atomic flag */
233template <typename PtrType, flag_type FlagType, bool Sleepable>
234class kmp_flag_atomic : public kmp_flag<FlagType> {
235protected:
236 std::atomic<PtrType> *loc; /**< Pointer to flag location to wait on */
237 PtrType checker; /**< Flag == checker means it has been released. */
238public:
240 typedef PtrType flag_t;
241 kmp_flag_atomic(std::atomic<PtrType> *p) : kmp_flag<FlagType>(), loc(p) {}
242 kmp_flag_atomic(std::atomic<PtrType> *p, kmp_info_t *thr)
243 : kmp_flag<FlagType>(1), loc(p) {
244 this->waiting_threads[0] = thr;
245 }
246 kmp_flag_atomic(std::atomic<PtrType> *p, PtrType c)
247 : kmp_flag<FlagType>(), loc(p), checker(c) {}
248 kmp_flag_atomic(std::atomic<PtrType> *p, PtrType c, std::atomic<bool> *sloc)
249 : kmp_flag<FlagType>(sloc), loc(p), checker(c) {}
250 /*! @result the pointer to the actual flag */
251 std::atomic<PtrType> *get() { return loc; }
252 /*! @result void* pointer to the actual flag */
253 void *get_void_p() { return RCAST(void *, loc); }
254 /*! @param new_loc in set loc to point at new_loc */
255 void set(std::atomic<PtrType> *new_loc) { loc = new_loc; }
256 /*! @result flag value */
257 PtrType load() { return loc->load(std::memory_order_acquire); }
258 /*! @param val the new flag value to be stored */
259 void store(PtrType val) { loc->store(val, std::memory_order_release); }
260 /*! @result true if the flag object has been released. */
261 bool done_check() {
262 if (Sleepable && !(this->sleepLoc))
263 return (this->load() & ~KMP_BARRIER_SLEEP_STATE) == checker;
264 else
265 return this->load() == checker;
266 }
267 /*! @param old_loc in old value of flag
268 * @result true if the flag's old value indicates it was released. */
269 bool done_check_val(PtrType old_loc) { return old_loc == checker; }
270 /*! @result true if the flag object is not yet released.
271 * Used in __kmp_wait_template like:
272 * @code
273 * while (flag.notdone_check()) { pause(); }
274 * @endcode */
275 bool notdone_check() { return this->load() != checker; }
276 /*! @result Actual flag value before release was applied.
277 * Trigger all waiting threads to run by modifying flag to release state. */
278 void internal_release() { KMP_ATOMIC_ADD(this->get(), 4); }
279 /*! @result Actual flag value before sleep bit(s) set.
280 * Notes that there is at least one thread sleeping on the flag by setting
281 * sleep bit(s). */
282 PtrType set_sleeping() {
283 if (this->sleepLoc) {
284 this->sleepLoc->store(true);
285 return *(this->get());
286 }
288 }
289 /*! @result Actual flag value before sleep bit(s) cleared.
290 * Notes that there are no longer threads sleeping on the flag by clearing
291 * sleep bit(s). */
293 if (this->sleepLoc) {
294 this->sleepLoc->store(false);
295 return;
296 }
298 }
299 /*! @param old_loc in old value of flag
300 * Test whether there are threads sleeping on flag's old value in old_loc. */
301 bool is_sleeping_val(PtrType old_loc) {
302 if (this->sleepLoc)
303 return this->sleepLoc->load();
304 return old_loc & KMP_BARRIER_SLEEP_STATE;
305 }
306 /*! Test whether there are threads sleeping on the flag. */
307 bool is_sleeping() {
308 if (this->sleepLoc)
309 return this->sleepLoc->load();
310 return is_sleeping_val(this->load());
311 }
313 if (this->sleepLoc)
314 return this->sleepLoc->load();
315 return is_sleeping_val(this->load());
316 }
317 kmp_uint8 *get_stolen() { return NULL; }
318};
319
320#if OMPT_SUPPORT
322static void __ompt_implicit_task_end(kmp_info_t *this_thr,
323 ompt_state_t ompt_state,
324 ompt_data_t *tId) {
325 int ds_tid = this_thr->th.th_info.ds.ds_tid;
326 if (ompt_state == ompt_state_wait_barrier_implicit) {
327 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
328#if OMPT_OPTIONAL
329 void *codeptr = NULL;
330 if (ompt_enabled.ompt_callback_sync_region_wait) {
331 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
332 ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, tId,
333 codeptr);
334 }
335 if (ompt_enabled.ompt_callback_sync_region) {
336 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
337 ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, tId,
338 codeptr);
339 }
340#endif
341 if (!KMP_MASTER_TID(ds_tid)) {
342 if (ompt_enabled.ompt_callback_implicit_task) {
343 int flags = this_thr->th.ompt_thread_info.parallel_flags;
344 flags = (flags & ompt_parallel_league) ? ompt_task_initial
345 : ompt_task_implicit;
346 ompt_callbacks.ompt_callback(ompt_callback_implicit_task)(
347 ompt_scope_end, NULL, tId, 0, ds_tid, flags);
348 }
349 // return to idle state
350 this_thr->th.ompt_thread_info.state = ompt_state_idle;
351 } else {
352 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
353 }
354 }
355}
356#endif
357
358/* Spin wait loop that first does pause/yield, then sleep. A thread that calls
359 __kmp_wait_* must make certain that another thread calls __kmp_release
360 to wake it back up to prevent deadlocks!
361
362 NOTE: We may not belong to a team at this point. */
363template <class C, bool final_spin, bool Cancellable = false,
364 bool Sleepable = true>
365static inline bool
367 C *flag USE_ITT_BUILD_ARG(void *itt_sync_obj)) {
368#if USE_ITT_BUILD && USE_ITT_NOTIFY
369 volatile void *spin = flag->get();
370#endif
371 kmp_uint32 spins;
372 int th_gtid;
373 int tasks_completed = FALSE;
374#if !KMP_USE_MONITOR
375 kmp_uint64 poll_count;
376 kmp_uint64 hibernate_goal;
377#else
378 kmp_uint32 hibernate;
379#endif
380 kmp_uint64 time;
381
382 KMP_FSYNC_SPIN_INIT(spin, NULL);
383 if (flag->done_check()) {
384 KMP_FSYNC_SPIN_ACQUIRED(CCAST(void *, spin));
385 return false;
386 }
387 th_gtid = this_thr->th.th_info.ds.ds_gtid;
388 if (Cancellable) {
389 kmp_team_t *team = this_thr->th.th_team;
390 if (team && team->t.t_cancel_request == cancel_parallel)
391 return true;
392 }
393#if KMP_OS_UNIX
394 if (final_spin)
395 KMP_ATOMIC_ST_REL(&this_thr->th.th_blocking, true);
396#endif
397 KA_TRACE(20,
398 ("__kmp_wait_sleep: T#%d waiting for flag(%p)\n", th_gtid, flag));
399#if KMP_STATS_ENABLED
400 stats_state_e thread_state = KMP_GET_THREAD_STATE();
401#endif
402
403/* OMPT Behavior:
404THIS function is called from
405 __kmp_barrier (2 times) (implicit or explicit barrier in parallel regions)
406 these have join / fork behavior
407
408 In these cases, we don't change the state or trigger events in THIS
409function.
410 Events are triggered in the calling code (__kmp_barrier):
411
412 state := ompt_state_overhead
413 barrier-begin
414 barrier-wait-begin
415 state := ompt_state_wait_barrier
416 call join-barrier-implementation (finally arrive here)
417 {}
418 call fork-barrier-implementation (finally arrive here)
419 {}
420 state := ompt_state_overhead
421 barrier-wait-end
422 barrier-end
423 state := ompt_state_work_parallel
424
425
426 __kmp_fork_barrier (after thread creation, before executing implicit task)
427 call fork-barrier-implementation (finally arrive here)
428 {} // worker arrive here with state = ompt_state_idle
429
430
431 __kmp_join_barrier (implicit barrier at end of parallel region)
432 state := ompt_state_barrier_implicit
433 barrier-begin
434 barrier-wait-begin
435 call join-barrier-implementation (finally arrive here
436final_spin=FALSE)
437 {
438 }
439 __kmp_fork_barrier (implicit barrier at end of parallel region)
440 call fork-barrier-implementation (finally arrive here final_spin=TRUE)
441
442 Worker after task-team is finished:
443 barrier-wait-end
444 barrier-end
445 implicit-task-end
446 idle-begin
447 state := ompt_state_idle
448
449 Before leaving, if state = ompt_state_idle
450 idle-end
451 state := ompt_state_overhead
452*/
453#if OMPT_SUPPORT
454 ompt_state_t ompt_entry_state;
455 ompt_data_t *tId;
456 if (ompt_enabled.enabled) {
457 ompt_entry_state = this_thr->th.ompt_thread_info.state;
458 if (!final_spin || ompt_entry_state != ompt_state_wait_barrier_implicit ||
459 KMP_MASTER_TID(this_thr->th.th_info.ds.ds_tid)) {
460 ompt_lw_taskteam_t *team = NULL;
461 if (this_thr->th.th_team)
462 team = this_thr->th.th_team->t.ompt_serialized_team_info;
463 if (team) {
464 tId = &(team->ompt_task_info.task_data);
465 } else {
466 tId = OMPT_CUR_TASK_DATA(this_thr);
467 }
468 } else {
469 tId = &(this_thr->th.ompt_thread_info.task_data);
470 }
471 if (final_spin && (__kmp_tasking_mode == tskm_immediate_exec ||
472 this_thr->th.th_task_team == NULL)) {
473 // implicit task is done. Either no taskqueue, or task-team finished
474 __ompt_implicit_task_end(this_thr, ompt_entry_state, tId);
475 }
476 }
477#endif
478
479 KMP_INIT_YIELD(spins); // Setup for waiting
480 KMP_INIT_BACKOFF(time);
481
484#if KMP_USE_MONITOR
485// The worker threads cannot rely on the team struct existing at this point.
486// Use the bt values cached in the thread struct instead.
487#ifdef KMP_ADJUST_BLOCKTIME
489 (__kmp_zero_bt && !this_thr->th.th_team_bt_set))
490 // Force immediate suspend if not set by user and more threads than
491 // available procs
492 hibernate = 0;
493 else
494 hibernate = this_thr->th.th_team_bt_intervals;
495#else
496 hibernate = this_thr->th.th_team_bt_intervals;
497#endif /* KMP_ADJUST_BLOCKTIME */
498
499 /* If the blocktime is nonzero, we want to make sure that we spin wait for
500 the entirety of the specified #intervals, plus up to one interval more.
501 This increment make certain that this thread doesn't go to sleep too
502 soon. */
503 if (hibernate != 0)
504 hibernate++;
505
506 // Add in the current time value.
507 hibernate += TCR_4(__kmp_global.g.g_time.dt.t_value);
508 KF_TRACE(20, ("__kmp_wait_sleep: T#%d now=%d, hibernate=%d, intervals=%d\n",
509 th_gtid, __kmp_global.g.g_time.dt.t_value, hibernate,
510 hibernate - __kmp_global.g.g_time.dt.t_value));
511#else
513 // Force immediate suspend
514 hibernate_goal = KMP_NOW();
515 } else
516 hibernate_goal = KMP_NOW() + this_thr->th.th_team_bt_intervals;
517 poll_count = 0;
518 (void)poll_count;
519#endif // KMP_USE_MONITOR
520 }
521
522 KMP_MB();
523
524 // Main wait spin loop
525 while (flag->notdone_check()) {
526 kmp_task_team_t *task_team = NULL;
528 task_team = this_thr->th.th_task_team;
529 /* If the thread's task team pointer is NULL, it means one of 3 things:
530 1) A newly-created thread is first being released by
531 __kmp_fork_barrier(), and its task team has not been set up yet.
532 2) All tasks have been executed to completion.
533 3) Tasking is off for this region. This could be because we are in a
534 serialized region (perhaps the outer one), or else tasking was manually
535 disabled (KMP_TASKING=0). */
536 if (task_team != NULL) {
537 if (TCR_SYNC_4(task_team->tt.tt_active)) {
538 if (KMP_TASKING_ENABLED(task_team)) {
539 flag->execute_tasks(
540 this_thr, th_gtid, final_spin,
541 &tasks_completed USE_ITT_BUILD_ARG(itt_sync_obj), 0);
542 } else
543 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
544 } else {
545 KMP_DEBUG_ASSERT(!KMP_MASTER_TID(this_thr->th.th_info.ds.ds_tid));
546#if OMPT_SUPPORT
547 // task-team is done now, other cases should be catched above
548 if (final_spin && ompt_enabled.enabled)
549 __ompt_implicit_task_end(this_thr, ompt_entry_state, tId);
550#endif
551 this_thr->th.th_task_team = NULL;
552 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
553 }
554 } else {
555 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
556 } // if
557 } // if
558
559 KMP_FSYNC_SPIN_PREPARE(CCAST(void *, spin));
560 if (TCR_4(__kmp_global.g.g_done)) {
561 if (__kmp_global.g.g_abort)
563 break;
564 }
565
566 // If we are oversubscribed, or have waited a bit (and
567 // KMP_LIBRARY=throughput), then yield
568 KMP_YIELD_OVERSUB_ELSE_SPIN(spins, time);
569
570#if KMP_STATS_ENABLED
571 // Check if thread has been signalled to idle state
572 // This indicates that the logical "join-barrier" has finished
573 if (this_thr->th.th_stats->isIdle() &&
574 KMP_GET_THREAD_STATE() == FORK_JOIN_BARRIER) {
577 }
578#endif
579 // Check if the barrier surrounding this wait loop has been cancelled
580 if (Cancellable) {
581 kmp_team_t *team = this_thr->th.th_team;
582 if (team && team->t.t_cancel_request == cancel_parallel)
583 break;
584 }
585
586 // For hidden helper thread, if task_team is nullptr, it means the main
587 // thread has not released the barrier. We cannot wait here because once the
588 // main thread releases all children barriers, all hidden helper threads are
589 // still sleeping. This leads to a problem that following configuration,
590 // such as task team sync, will not be performed such that this thread does
591 // not have task team. Usually it is not bad. However, a corner case is,
592 // when the first task encountered is an untied task, the check in
593 // __kmp_task_alloc will crash because it uses the task team pointer without
594 // checking whether it is nullptr. It is probably under some kind of
595 // assumption.
596 if (task_team && KMP_HIDDEN_HELPER_WORKER_THREAD(th_gtid) &&
598 // If there is still hidden helper tasks to be executed, the hidden helper
599 // thread will not enter a waiting status.
602 }
603 continue;
604 }
605
606 // Don't suspend if KMP_BLOCKTIME is set to "infinite"
609 continue;
610
611 // Don't suspend if there is a likelihood of new tasks being spawned.
612 if (task_team != NULL && TCR_4(task_team->tt.tt_found_tasks) &&
614 continue;
615
616#if KMP_USE_MONITOR
617 // If we have waited a bit more, fall asleep
618 if (TCR_4(__kmp_global.g.g_time.dt.t_value) < hibernate)
619 continue;
620#else
621 if (KMP_BLOCKING(hibernate_goal, poll_count++))
622 continue;
623#endif
624 // Don't suspend if wait loop designated non-sleepable
625 // in template parameters
626 if (!Sleepable)
627 continue;
628
629#if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
630 if (__kmp_mwait_enabled || __kmp_umwait_enabled) {
631 KF_TRACE(50, ("__kmp_wait_sleep: T#%d using monitor/mwait\n", th_gtid));
632 flag->mwait(th_gtid);
633 } else {
634#endif
635 KF_TRACE(50, ("__kmp_wait_sleep: T#%d suspend time reached\n", th_gtid));
636#if KMP_OS_UNIX
637 if (final_spin)
638 KMP_ATOMIC_ST_REL(&this_thr->th.th_blocking, false);
639#endif
640 flag->suspend(th_gtid);
641#if KMP_OS_UNIX
642 if (final_spin)
643 KMP_ATOMIC_ST_REL(&this_thr->th.th_blocking, true);
644#endif
645#if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
646 }
647#endif
648
649 if (TCR_4(__kmp_global.g.g_done)) {
650 if (__kmp_global.g.g_abort)
652 break;
654 this_thr->th.th_reap_state == KMP_SAFE_TO_REAP) {
655 this_thr->th.th_reap_state = KMP_NOT_SAFE_TO_REAP;
656 }
657 // TODO: If thread is done with work and times out, disband/free
658 }
659
660#if OMPT_SUPPORT
661 ompt_state_t ompt_exit_state = this_thr->th.ompt_thread_info.state;
662 if (ompt_enabled.enabled && ompt_exit_state != ompt_state_undefined) {
663#if OMPT_OPTIONAL
664 if (final_spin) {
665 __ompt_implicit_task_end(this_thr, ompt_exit_state, tId);
666 ompt_exit_state = this_thr->th.ompt_thread_info.state;
667 }
668#endif
669 if (ompt_exit_state == ompt_state_idle) {
670 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
671 }
672 }
673#endif
674#if KMP_STATS_ENABLED
675 // If we were put into idle state, pop that off the state stack
676 if (KMP_GET_THREAD_STATE() == IDLE) {
678 KMP_SET_THREAD_STATE(thread_state);
679 this_thr->th.th_stats->resetIdleFlag();
680 }
681#endif
682
683#if KMP_OS_UNIX
684 if (final_spin)
685 KMP_ATOMIC_ST_REL(&this_thr->th.th_blocking, false);
686#endif
687 KMP_FSYNC_SPIN_ACQUIRED(CCAST(void *, spin));
688 if (Cancellable) {
689 kmp_team_t *team = this_thr->th.th_team;
690 if (team && team->t.t_cancel_request == cancel_parallel) {
691 if (tasks_completed) {
692 // undo the previous decrement of unfinished_threads so that the
693 // thread can decrement at the join barrier with no problem
694 kmp_task_team_t *task_team = this_thr->th.th_task_team;
695 std::atomic<kmp_int32> *unfinished_threads =
696 &(task_team->tt.tt_unfinished_threads);
697 KMP_ATOMIC_INC(unfinished_threads);
698 }
699 return true;
700 }
701 }
702 return false;
703}
704
705#if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
706// Set up a monitor on the flag variable causing the calling thread to wait in
707// a less active state until the flag variable is modified.
708template <class C>
709static inline void __kmp_mwait_template(int th_gtid, C *flag) {
711 kmp_info_t *th = __kmp_threads[th_gtid];
712
713 KF_TRACE(30, ("__kmp_mwait_template: T#%d enter for flag = %p\n", th_gtid,
714 flag->get()));
715
716 // User-level mwait is available
717 KMP_DEBUG_ASSERT(__kmp_mwait_enabled || __kmp_umwait_enabled);
718
721
722 volatile void *spin = flag->get();
723 void *cacheline = (void *)(kmp_uintptr_t(spin) & ~(CACHE_LINE - 1));
724
725 if (!flag->done_check()) {
726 // Mark thread as no longer active
727 th->th.th_active = FALSE;
728 if (th->th.th_active_in_pool) {
729 th->th.th_active_in_pool = FALSE;
732 }
733 flag->set_sleeping();
734 KF_TRACE(50, ("__kmp_mwait_template: T#%d calling monitor\n", th_gtid));
735#if KMP_HAVE_UMWAIT
736 if (__kmp_umwait_enabled) {
737 __kmp_umonitor(cacheline);
738 }
739#elif KMP_HAVE_MWAIT
740 if (__kmp_mwait_enabled) {
741 __kmp_mm_monitor(cacheline, 0, 0);
742 }
743#endif
744 // To avoid a race, check flag between 'monitor' and 'mwait'. A write to
745 // the address could happen after the last time we checked and before
746 // monitoring started, in which case monitor can't detect the change.
747 if (flag->done_check())
748 flag->unset_sleeping();
749 else {
750 // if flag changes here, wake-up happens immediately
751 TCW_PTR(th->th.th_sleep_loc, (void *)flag);
752 th->th.th_sleep_loc_type = flag->get_type();
754 KF_TRACE(50, ("__kmp_mwait_template: T#%d calling mwait\n", th_gtid));
755#if KMP_HAVE_UMWAIT
756 if (__kmp_umwait_enabled) {
757 __kmp_umwait(1, 100); // to do: enable ctrl via hints, backoff counter
758 }
759#elif KMP_HAVE_MWAIT
760 if (__kmp_mwait_enabled) {
761 __kmp_mm_mwait(0, __kmp_mwait_hints);
762 }
763#endif
764 KF_TRACE(50, ("__kmp_mwait_template: T#%d mwait done\n", th_gtid));
766 // Clean up sleep info; doesn't matter how/why this thread stopped waiting
767 if (flag->is_sleeping())
768 flag->unset_sleeping();
769 TCW_PTR(th->th.th_sleep_loc, NULL);
770 th->th.th_sleep_loc_type = flag_unset;
771 }
772 // Mark thread as active again
773 th->th.th_active = TRUE;
774 if (TCR_4(th->th.th_in_pool)) {
776 th->th.th_active_in_pool = TRUE;
777 }
778 } // Drop out to main wait loop to check flag, handle tasks, etc.
780 KF_TRACE(30, ("__kmp_mwait_template: T#%d exit\n", th_gtid));
781}
782#endif // KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
783
784/* Release any threads specified as waiting on the flag by releasing the flag
785 and resume the waiting thread if indicated by the sleep bit(s). A thread that
786 calls __kmp_wait_template must call this function to wake up the potentially
787 sleeping thread and prevent deadlocks! */
788template <class C> static inline void __kmp_release_template(C *flag) {
789#ifdef KMP_DEBUG
790 int gtid = TCR_4(__kmp_init_gtid) ? __kmp_get_gtid() : -1;
791#endif
792 KF_TRACE(20, ("__kmp_release: T#%d releasing flag(%x)\n", gtid, flag->get()));
793 KMP_DEBUG_ASSERT(flag->get());
794 KMP_FSYNC_RELEASING(flag->get_void_p());
795
796 flag->internal_release();
797
798 KF_TRACE(100, ("__kmp_release: T#%d set new spin=%d\n", gtid, flag->get(),
799 flag->load()));
800
802 // Only need to check sleep stuff if infinite block time not set.
803 // Are *any* threads waiting on flag sleeping?
804 if (flag->is_any_sleeping()) {
805 for (unsigned int i = 0; i < flag->get_num_waiters(); ++i) {
806 // if sleeping waiter exists at i, sets current_waiter to i inside flag
807 kmp_info_t *waiter = flag->get_waiter(i);
808 if (waiter) {
809 int wait_gtid = waiter->th.th_info.ds.ds_gtid;
810 // Wake up thread if needed
811 KF_TRACE(50, ("__kmp_release: T#%d waking up thread T#%d since sleep "
812 "flag(%p) set\n",
813 gtid, wait_gtid, flag->get()));
814 flag->resume(wait_gtid); // unsets flag's current_waiter when done
815 }
816 }
817 }
818 }
819}
820
821template <bool Cancellable, bool Sleepable>
822class kmp_flag_32 : public kmp_flag_atomic<kmp_uint32, flag32, Sleepable> {
823public:
824 kmp_flag_32(std::atomic<kmp_uint32> *p)
825 : kmp_flag_atomic<kmp_uint32, flag32, Sleepable>(p) {}
826 kmp_flag_32(std::atomic<kmp_uint32> *p, kmp_info_t *thr)
827 : kmp_flag_atomic<kmp_uint32, flag32, Sleepable>(p, thr) {}
828 kmp_flag_32(std::atomic<kmp_uint32> *p, kmp_uint32 c)
829 : kmp_flag_atomic<kmp_uint32, flag32, Sleepable>(p, c) {}
830 void suspend(int th_gtid) { __kmp_suspend_32(th_gtid, this); }
831#if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
832 void mwait(int th_gtid) { __kmp_mwait_32(th_gtid, this); }
833#endif
834 void resume(int th_gtid) { __kmp_resume_32(th_gtid, this); }
835 int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid, int final_spin,
836 int *thread_finished USE_ITT_BUILD_ARG(void *itt_sync_obj),
837 kmp_int32 is_constrained) {
839 this_thr, gtid, this, final_spin,
840 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
841 }
842 bool wait(kmp_info_t *this_thr,
843 int final_spin USE_ITT_BUILD_ARG(void *itt_sync_obj)) {
844 if (final_spin)
845 return __kmp_wait_template<kmp_flag_32, TRUE, Cancellable, Sleepable>(
846 this_thr, this USE_ITT_BUILD_ARG(itt_sync_obj));
847 else
848 return __kmp_wait_template<kmp_flag_32, FALSE, Cancellable, Sleepable>(
849 this_thr, this USE_ITT_BUILD_ARG(itt_sync_obj));
850 }
853};
854
855template <bool Cancellable, bool Sleepable>
856class kmp_flag_64 : public kmp_flag_native<kmp_uint64, flag64, Sleepable> {
857public:
859 : kmp_flag_native<kmp_uint64, flag64, Sleepable>(p) {}
861 : kmp_flag_native<kmp_uint64, flag64, Sleepable>(p, thr) {}
863 : kmp_flag_native<kmp_uint64, flag64, Sleepable>(p, c) {}
864 kmp_flag_64(volatile kmp_uint64 *p, kmp_uint64 c, std::atomic<bool> *loc)
865 : kmp_flag_native<kmp_uint64, flag64, Sleepable>(p, c, loc) {}
866 void suspend(int th_gtid) { __kmp_suspend_64(th_gtid, this); }
867#if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
868 void mwait(int th_gtid) { __kmp_mwait_64(th_gtid, this); }
869#endif
870 void resume(int th_gtid) { __kmp_resume_64(th_gtid, this); }
871 int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid, int final_spin,
872 int *thread_finished USE_ITT_BUILD_ARG(void *itt_sync_obj),
873 kmp_int32 is_constrained) {
875 this_thr, gtid, this, final_spin,
876 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
877 }
878 bool wait(kmp_info_t *this_thr,
879 int final_spin USE_ITT_BUILD_ARG(void *itt_sync_obj)) {
880 if (final_spin)
881 return __kmp_wait_template<kmp_flag_64, TRUE, Cancellable, Sleepable>(
882 this_thr, this USE_ITT_BUILD_ARG(itt_sync_obj));
883 else
884 return __kmp_wait_template<kmp_flag_64, FALSE, Cancellable, Sleepable>(
885 this_thr, this USE_ITT_BUILD_ARG(itt_sync_obj));
886 }
889};
890
891template <bool Cancellable, bool Sleepable>
893 : public kmp_flag_atomic<kmp_uint64, atomic_flag64, Sleepable> {
894public:
895 kmp_atomic_flag_64(std::atomic<kmp_uint64> *p)
896 : kmp_flag_atomic<kmp_uint64, atomic_flag64, Sleepable>(p) {}
897 kmp_atomic_flag_64(std::atomic<kmp_uint64> *p, kmp_info_t *thr)
898 : kmp_flag_atomic<kmp_uint64, atomic_flag64, Sleepable>(p, thr) {}
899 kmp_atomic_flag_64(std::atomic<kmp_uint64> *p, kmp_uint64 c)
900 : kmp_flag_atomic<kmp_uint64, atomic_flag64, Sleepable>(p, c) {}
901 kmp_atomic_flag_64(std::atomic<kmp_uint64> *p, kmp_uint64 c,
902 std::atomic<bool> *loc)
903 : kmp_flag_atomic<kmp_uint64, atomic_flag64, Sleepable>(p, c, loc) {}
904 void suspend(int th_gtid) { __kmp_atomic_suspend_64(th_gtid, this); }
905 void mwait(int th_gtid) { __kmp_atomic_mwait_64(th_gtid, this); }
906 void resume(int th_gtid) { __kmp_atomic_resume_64(th_gtid, this); }
907 int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid, int final_spin,
908 int *thread_finished USE_ITT_BUILD_ARG(void *itt_sync_obj),
909 kmp_int32 is_constrained) {
911 this_thr, gtid, this, final_spin,
912 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
913 }
914 bool wait(kmp_info_t *this_thr,
915 int final_spin USE_ITT_BUILD_ARG(void *itt_sync_obj)) {
916 if (final_spin)
917 return __kmp_wait_template<kmp_atomic_flag_64, TRUE, Cancellable,
918 Sleepable>(
919 this_thr, this USE_ITT_BUILD_ARG(itt_sync_obj));
920 else
921 return __kmp_wait_template<kmp_atomic_flag_64, FALSE, Cancellable,
922 Sleepable>(
923 this_thr, this USE_ITT_BUILD_ARG(itt_sync_obj));
924 }
927};
928
929// Hierarchical 64-bit on-core barrier instantiation
930class kmp_flag_oncore : public kmp_flag_native<kmp_uint64, flag_oncore, false> {
931 kmp_uint32 offset; /**< Portion of flag of interest for an operation. */
932 bool flag_switch; /**< Indicates a switch in flag location. */
933 enum barrier_type bt; /**< Barrier type. */
934 kmp_info_t *this_thr; /**< Thread to redirect to different flag location. */
935#if USE_ITT_BUILD
936 void *itt_sync_obj; /**< ITT object to pass to new flag location. */
937#endif
938 unsigned char &byteref(volatile kmp_uint64 *loc, size_t offset) {
939 return (RCAST(unsigned char *, CCAST(kmp_uint64 *, loc)))[offset];
940 }
941
942public:
944 : kmp_flag_native<kmp_uint64, flag_oncore, false>(p), flag_switch(false) {
945 }
947 : kmp_flag_native<kmp_uint64, flag_oncore, false>(p), offset(idx),
948 flag_switch(false),
949 bt(bs_last_barrier) USE_ITT_BUILD_ARG(itt_sync_obj(nullptr)) {}
951 enum barrier_type bar_t,
952 kmp_info_t *thr USE_ITT_BUILD_ARG(void *itt))
953 : kmp_flag_native<kmp_uint64, flag_oncore, false>(p, c), offset(idx),
954 flag_switch(false), bt(bar_t),
955 this_thr(thr) USE_ITT_BUILD_ARG(itt_sync_obj(itt)) {}
956 virtual ~kmp_flag_oncore() override {}
957 void *operator new(size_t size) { return __kmp_allocate(size); }
958 void operator delete(void *p) { __kmp_free(p); }
959 bool done_check_val(kmp_uint64 old_loc) override {
960 return byteref(&old_loc, offset) == checker;
961 }
962 bool done_check() override { return done_check_val(*get()); }
963 bool notdone_check() override {
964 // Calculate flag_switch
965 if (this_thr->th.th_bar[bt].bb.wait_flag == KMP_BARRIER_SWITCH_TO_OWN_FLAG)
966 flag_switch = true;
967 if (byteref(get(), offset) != 1 && !flag_switch)
968 return true;
969 else if (flag_switch) {
970 this_thr->th.th_bar[bt].bb.wait_flag = KMP_BARRIER_SWITCHING;
971 kmp_flag_64<> flag(&this_thr->th.th_bar[bt].bb.b_go,
973 __kmp_wait_64(this_thr, &flag, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
974 }
975 return false;
976 }
978 // Other threads can write their own bytes simultaneously.
980 byteref(get(), offset) = 1;
981 } else {
982 kmp_uint64 mask = 0;
983 byteref(&mask, offset) = 1;
985 }
986 }
987 void wait(kmp_info_t *this_thr, int final_spin) {
988 if (final_spin)
989 __kmp_wait_template<kmp_flag_oncore, TRUE>(
990 this_thr, this USE_ITT_BUILD_ARG(itt_sync_obj));
991 else
992 __kmp_wait_template<kmp_flag_oncore, FALSE>(
993 this_thr, this USE_ITT_BUILD_ARG(itt_sync_obj));
994 }
996 void suspend(int th_gtid) { __kmp_suspend_oncore(th_gtid, this); }
997#if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
998 void mwait(int th_gtid) { __kmp_mwait_oncore(th_gtid, this); }
999#endif
1000 void resume(int th_gtid) { __kmp_resume_oncore(th_gtid, this); }
1001 int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid, int final_spin,
1002 int *thread_finished USE_ITT_BUILD_ARG(void *itt_sync_obj),
1003 kmp_int32 is_constrained) {
1004#if OMPD_SUPPORT
1006 this_thr, gtid, this, final_spin,
1007 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
1008 if (ompd_state & OMPD_ENABLE_BP)
1009 ompd_bp_task_end();
1010 return ret;
1011#else
1013 this_thr, gtid, this, final_spin,
1014 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
1015#endif
1016 }
1017 enum barrier_type get_bt() { return bt; }
1019};
1020
1021static inline void __kmp_null_resume_wrapper(kmp_info_t *thr) {
1022 int gtid = __kmp_gtid_from_thread(thr);
1023 void *flag = CCAST(void *, thr->th.th_sleep_loc);
1024 flag_type type = thr->th.th_sleep_loc_type;
1025 if (!flag)
1026 return;
1027 // Attempt to wake up a thread: examine its type and call appropriate template
1028 switch (type) {
1029 case flag32:
1031 break;
1032 case flag64:
1034 break;
1035 case atomic_flag64:
1037 break;
1038 case flag_oncore:
1040 break;
1041 case flag_unset:
1042 KF_TRACE(100, ("__kmp_null_resume_wrapper: flag type %d is unset\n", type));
1043 break;
1044 }
1045}
1046
1047/*!
1048@}
1049*/
1050
1051#endif // KMP_WAIT_RELEASE_H
uint8_t kmp_uint8
int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid, int final_spin, int *thread_finished USE_ITT_BUILD_ARG(void *itt_sync_obj), kmp_int32 is_constrained)
kmp_atomic_flag_64(std::atomic< kmp_uint64 > *p, kmp_uint64 c, std::atomic< bool > *loc)
bool wait(kmp_info_t *this_thr, int final_spin USE_ITT_BUILD_ARG(void *itt_sync_obj))
void resume(int th_gtid)
kmp_atomic_flag_64(std::atomic< kmp_uint64 > *p, kmp_uint64 c)
void suspend(int th_gtid)
void mwait(int th_gtid)
flag_type get_ptr_type()
kmp_atomic_flag_64(std::atomic< kmp_uint64 > *p)
kmp_atomic_flag_64(std::atomic< kmp_uint64 > *p, kmp_info_t *thr)
kmp_flag_32(std::atomic< kmp_uint32 > *p, kmp_uint32 c)
bool wait(kmp_info_t *this_thr, int final_spin USE_ITT_BUILD_ARG(void *itt_sync_obj))
flag_type get_ptr_type()
kmp_flag_32(std::atomic< kmp_uint32 > *p, kmp_info_t *thr)
kmp_flag_32(std::atomic< kmp_uint32 > *p)
void suspend(int th_gtid)
void resume(int th_gtid)
int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid, int final_spin, int *thread_finished USE_ITT_BUILD_ARG(void *itt_sync_obj), kmp_int32 is_constrained)
bool wait(kmp_info_t *this_thr, int final_spin USE_ITT_BUILD_ARG(void *itt_sync_obj))
kmp_flag_64(volatile kmp_uint64 *p, kmp_info_t *thr)
int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid, int final_spin, int *thread_finished USE_ITT_BUILD_ARG(void *itt_sync_obj), kmp_int32 is_constrained)
void resume(int th_gtid)
kmp_flag_64(volatile kmp_uint64 *p)
kmp_flag_64(volatile kmp_uint64 *p, kmp_uint64 c)
flag_type get_ptr_type()
void suspend(int th_gtid)
kmp_flag_64(volatile kmp_uint64 *p, kmp_uint64 c, std::atomic< bool > *loc)
Base class for wait/release atomic flag.
std::atomic< PtrType > * loc
Pointer to flag location to wait on.
void store(PtrType val)
bool is_sleeping_val(PtrType old_loc)
PtrType set_sleeping()
bool is_sleeping()
Test whether there are threads sleeping on the flag.
kmp_flag_atomic(std::atomic< PtrType > *p, PtrType c)
kmp_flag_atomic(std::atomic< PtrType > *p)
kmp_flag_atomic(std::atomic< PtrType > *p, kmp_info_t *thr)
bool done_check_val(PtrType old_loc)
kmp_flag_atomic(std::atomic< PtrType > *p, PtrType c, std::atomic< bool > *sloc)
void set(std::atomic< PtrType > *new_loc)
kmp_uint8 * get_stolen()
PtrType checker
Flag == checker means it has been released.
std::atomic< PtrType > * get()
flag_traits< FlagType > traits_type
Base class for wait/release volatile flag.
void store(PtrType val)
kmp_flag_native(volatile PtrType *p, PtrType c)
kmp_flag_native(volatile PtrType *p)
PtrType checker
When flag==checker, it has been released.
volatile PtrType * loc
void set(volatile PtrType *new_loc)
flag_traits< FlagType > traits_type
bool is_sleeping_val(PtrType old_loc)
virtual bool notdone_check()
virtual bool done_check_val(PtrType old_loc)
kmp_uint8 * get_stolen()
virtual ~kmp_flag_native()
bool is_sleeping()
Test whether there are threads sleeping on the flag.
volatile PtrType * get()
virtual bool done_check()
kmp_flag_native(volatile PtrType *p, kmp_info_t *thr)
PtrType set_sleeping()
kmp_flag_native(volatile PtrType *p, PtrType c, std::atomic< bool > *sloc)
flag_type get_ptr_type()
bool done_check() override
void wait(kmp_info_t *this_thr, int final_spin)
int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid, int final_spin, int *thread_finished USE_ITT_BUILD_ARG(void *itt_sync_obj), kmp_int32 is_constrained)
void suspend(int th_gtid)
virtual ~kmp_flag_oncore() override
kmp_flag_oncore(volatile kmp_uint64 *p, kmp_uint64 c, kmp_uint32 idx, enum barrier_type bar_t, kmp_info_t *thr USE_ITT_BUILD_ARG(void *itt))
bool done_check_val(kmp_uint64 old_loc) override
kmp_flag_oncore(volatile kmp_uint64 *p)
kmp_flag_oncore(volatile kmp_uint64 *p, kmp_uint32 idx)
enum barrier_type get_bt()
void resume(int th_gtid)
bool notdone_check() override
Base class for all flags.
flag_properties t
"Type" of the flag in loc
kmp_flag(std::atomic< bool > *sloc)
kmp_uint32 num_waiting_threads
Num threads sleeping on this thread.
kmp_info_t * waiting_threads[1]
Threads sleeping on this thread.
flag_type get_type()
kmp_uint32 get_num_waiters()
flag_traits< FlagType > traits_type
enum barrier_type get_bt()
kmp_info_t * get_waiter(kmp_uint32 i)
param i in index into waiting_threads
std::atomic< bool > * sleepLoc
kmp_flag(int nwaiters)
void set_waiter(kmp_info_t *thr)
int64_t kmp_int64
Definition: common.h:10
void
Definition: ittnotify.h:3324
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int mask
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t size
void const char const char int ITT_FORMAT __itt_group_sync p
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
#define __kmp_free(ptr)
Definition: kmp.h:3756
kmp_global_t __kmp_global
Definition: kmp_global.cpp:467
#define KMP_YIELD_OVERSUB_ELSE_SPIN(count, time)
Definition: kmp.h:1640
kmp_pause_status_t __kmp_pause_status
Definition: kmp_global.cpp:558
#define KMP_MAX_BLOCKTIME
Definition: kmp.h:1228
@ kmp_soft_paused
Definition: kmp.h:4526
#define KMP_NOT_SAFE_TO_REAP
Definition: kmp.h:2118
void __kmp_unlock_suspend_mx(kmp_info_t *th)
int __kmp_execute_tasks_oncore(kmp_info_t *thread, kmp_int32 gtid, kmp_flag_oncore *flag, int final_spin, int *thread_finished, kmp_int32 is_constrained)
kmp_tasking_mode_t __kmp_tasking_mode
Definition: kmp_global.cpp:299
void __kmp_abort_thread(void)
int __kmp_dflt_blocktime
Definition: kmp_global.cpp:158
volatile int __kmp_init_gtid
Definition: kmp_global.cpp:45
void __kmp_suspend_64(int th_gtid, kmp_flag_64< C, S > *flag)
flag_type
Definition: kmp.h:2123
@ flag_unset
Definition: kmp.h:2128
@ atomic_flag64
atomic 64 bit flags
Definition: kmp.h:2126
@ flag64
64 bit flags
Definition: kmp.h:2125
@ flag_oncore
special 64-bit flag for on-core barrier (hierarchical)
Definition: kmp.h:2127
@ flag32
atomic 32 bit flags
Definition: kmp.h:2124
#define KMP_BARRIER_SLEEP_STATE
Definition: kmp.h:2096
#define KMP_NOW()
Definition: kmp.h:1271
void __kmp_suspend_32(int th_gtid, kmp_flag_32< C, S > *flag)
void __kmp_hidden_helper_worker_thread_wait()
@ cancel_parallel
Definition: kmp.h:999
int __kmp_execute_tasks_64(kmp_info_t *thread, kmp_int32 gtid, kmp_flag_64< C, S > *flag, int final_spin, int *thread_finished, kmp_int32 is_constrained)
std::atomic< int > __kmp_thread_pool_active_nth
Definition: kmp_global.cpp:462
#define KMP_MASTER_TID(tid)
Definition: kmp.h:1315
#define KMP_TASKING_ENABLED(task_team)
Definition: kmp.h:2441
kmp_info_t ** __kmp_threads
Definition: kmp_global.cpp:450
#define KMP_BARRIER_SWITCH_TO_OWN_FLAG
Definition: kmp.h:2113
void __kmp_suspend_oncore(int th_gtid, kmp_flag_oncore *flag)
#define KMP_INIT_YIELD(count)
Definition: kmp.h:1567
void __kmp_lock_suspend_mx(kmp_info_t *th)
#define KMP_BLOCKING(goal, count)
Definition: kmp.h:1274
#define KMP_INIT_BACKOFF(time)
Definition: kmp.h:1570
#define __kmp_allocate(size)
Definition: kmp.h:3754
#define TRUE
Definition: kmp.h:1324
#define FALSE
Definition: kmp.h:1323
@ tskm_immediate_exec
Definition: kmp.h:2417
volatile int __kmp_hidden_helper_team_done
Definition: kmp_global.cpp:52
std::atomic< kmp_int32 > __kmp_unexecuted_hidden_helper_tasks
#define KMP_HIDDEN_HELPER_WORKER_THREAD(gtid)
Definition: kmp.h:4578
void __kmp_resume_oncore(int target_gtid, kmp_flag_oncore *flag)
bool __kmp_wpolicy_passive
Definition: kmp_global.cpp:160
#define KMP_BARRIER_SWITCHING
Definition: kmp.h:2115
#define KMP_SAFE_TO_REAP
Definition: kmp.h:2120
barrier_type
Definition: kmp.h:2131
@ bs_last_barrier
Definition: kmp.h:2138
void __kmp_resume_64(int target_gtid, kmp_flag_64< C, S > *flag)
void __kmp_resume_32(int target_gtid, kmp_flag_32< C, S > *flag)
int __kmp_execute_tasks_32(kmp_info_t *thread, kmp_int32 gtid, kmp_flag_32< C, S > *flag, int final_spin, int *thread_finished, kmp_int32 is_constrained)
#define __kmp_get_gtid()
Definition: kmp.h:3600
void __kmp_atomic_suspend_64(int th_gtid, kmp_atomic_flag_64< C, S > *flag)
int __kmp_atomic_execute_tasks_64(kmp_info_t *thread, kmp_int32 gtid, kmp_atomic_flag_64< C, S > *flag, int final_spin, int *thread_finished, kmp_int32 is_constrained)
#define KMP_BARRIER_STATE_BUMP
Definition: kmp.h:2098
void __kmp_atomic_resume_64(int target_gtid, kmp_atomic_flag_64< C, S > *flag)
static int __kmp_gtid_from_thread(const kmp_info_t *thr)
Definition: kmp.h:3629
void __kmp_suspend_initialize_thread(kmp_info_t *th)
void __kmp_wait_64(kmp_info_t *this_thr, kmp_flag_64<> *flag, int final_spin)
union KMP_ALIGN_CACHE kmp_info kmp_info_t
#define KA_TRACE(d, x)
Definition: kmp_debug.h:157
#define KF_TRACE(d, x)
Definition: kmp_debug.h:162
#define KMP_DEBUG_ASSERT(cond)
Definition: kmp_debug.h:61
unsigned long long kmp_uint64
#define KMP_FSYNC_RELEASING(obj)
Definition: kmp_itt.h:335
#define KMP_FSYNC_SPIN_ACQUIRED(obj)
Definition: kmp_itt.h:339
#define KMP_FSYNC_SPIN_PREPARE(obj)
Definition: kmp_itt.h:338
#define USE_ITT_BUILD_ARG(x)
Definition: kmp_itt.h:346
#define KMP_FSYNC_SPIN_INIT(obj, spin)
Definition: kmp_itt.h:337
#define KMP_ATOMIC_ADD(p, v)
Definition: kmp_os.h:1263
#define TCW_PTR(a, b)
Definition: kmp_os.h:1165
#define KMP_TEST_THEN_OR32(p, v)
Definition: kmp_os.h:783
#define KMP_ATOMIC_AND(p, v)
Definition: kmp_os.h:1265
#define KMP_TEST_THEN_ADD4_32(p)
Definition: kmp_os.h:739
#define KMP_ATOMIC_ST_REL(p, v)
Definition: kmp_os.h:1259
#define KMP_TEST_THEN_AND64(p, v)
Definition: kmp_os.h:797
#define RCAST(type, var)
Definition: kmp_os.h:291
#define KMP_TEST_THEN_ADD4_64(p)
Definition: kmp_os.h:753
#define CACHE_LINE
Definition: kmp_os.h:339
#define KMP_ATOMIC_LD_ACQ(p)
Definition: kmp_os.h:1257
#define CCAST(type, var)
Definition: kmp_os.h:290
#define KMP_MB()
Definition: kmp_os.h:1064
#define KMP_TEST_THEN_AND32(p, v)
Definition: kmp_os.h:785
#define TCR_4(a)
Definition: kmp_os.h:1135
#define KMP_ATOMIC_DEC(p)
Definition: kmp_os.h:1268
#define TCR_8(a)
Definition: kmp_os.h:1139
unsigned long kmp_uintptr_t
Definition: kmp_os.h:205
#define KMP_ATOMIC_OR(p, v)
Definition: kmp_os.h:1266
#define TCR_SYNC_4(a)
Definition: kmp_os.h:1143
#define KMP_TEST_THEN_OR64(p, v)
Definition: kmp_os.h:795
#define KMP_ATOMIC_INC(p)
Definition: kmp_os.h:1267
Functions for collecting statistics.
#define KMP_PUSH_PARTITIONED_TIMER(name)
Definition: kmp_stats.h:1014
#define KMP_GET_THREAD_STATE()
Definition: kmp_stats.h:1017
#define KMP_POP_PARTITIONED_TIMER()
Definition: kmp_stats.h:1015
#define KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(n)
Definition: kmp_stats.h:1008
#define KMP_SET_THREAD_STATE(state_name)
Definition: kmp_stats.h:1016
#define i
Definition: kmp_stub.cpp:87
static void __kmp_null_resume_wrapper(kmp_info_t *thr)
static void __kmp_release_template(C *flag)
static bool __kmp_wait_template(kmp_info_t *this_thr, C *flag USE_ITT_BUILD_ARG(void *itt_sync_obj))
int32_t kmp_int32
#define C
ompt_callbacks_active_t ompt_enabled
return ret
ompt_callbacks_internal_t ompt_callbacks
#define OMPT_NOINLINE
volatile int flag
unsigned int reserved
unsigned int type
static flag_t tcr(flag_t f)
static flag_t test_then_add4(volatile flag_t *f)
static flag_t test_then_and(volatile flag_t *f, flag_t v)
static flag_t test_then_or(volatile flag_t *f, flag_t v)
static flag_t test_then_add4(volatile flag_t *f)
static flag_t tcr(flag_t f)
static flag_t test_then_and(volatile flag_t *f, flag_t v)
static flag_t test_then_or(volatile flag_t *f, flag_t v)
static flag_t test_then_add4(volatile flag_t *f)
static flag_t test_then_or(volatile flag_t *f, flag_t v)
static flag_t tcr(flag_t f)
static flag_t test_then_and(volatile flag_t *f, flag_t v)
static flag_t test_then_add4(volatile flag_t *f)
static flag_t test_then_or(volatile flag_t *f, flag_t v)
static flag_t test_then_and(volatile flag_t *f, flag_t v)
static flag_t tcr(flag_t f)
KMP_ALIGN_CACHE std::atomic< kmp_int32 > tt_unfinished_threads
Definition: kmp.h:2861
KMP_ALIGN_CACHE volatile kmp_uint32 tt_active
Definition: kmp.h:2865
kmp_int32 tt_found_tasks
Definition: kmp.h:2848
ompt_task_info_t ompt_task_info
Definition: ompt-internal.h:70
ompt_data_t task_data
Definition: ompt-internal.h:57
kmp_base_task_team_t tt
Definition: kmp.h:2869
Definition: kmp.h:3215
kmp_base_team_t t
Definition: kmp.h:3216