16 #include "kmp_stats.h"
17 #include "kmp_wait_release.h"
18 #include "kmp_taskdeps.h"
21 #include "ompt-specific.h"
25 static void __kmp_enable_tasking(kmp_task_team_t *task_team,
26 kmp_info_t *this_thr);
27 static void __kmp_alloc_task_deque(kmp_info_t *thread,
28 kmp_thread_data_t *thread_data);
29 static int __kmp_realloc_task_threads_data(kmp_info_t *thread,
30 kmp_task_team_t *task_team);
31 static void __kmp_bottom_half_finish_proxy(kmp_int32 gtid, kmp_task_t *ptask);
33 #ifdef BUILD_TIED_TASK_STACK
42 static void __kmp_trace_task_stack(kmp_int32 gtid,
43 kmp_thread_data_t *thread_data,
44 int threshold,
char *location) {
45 kmp_task_stack_t *task_stack = &thread_data->td.td_susp_tied_tasks;
46 kmp_taskdata_t **stack_top = task_stack->ts_top;
47 kmp_int32 entries = task_stack->ts_entries;
48 kmp_taskdata_t *tied_task;
52 (
"__kmp_trace_task_stack(start): location = %s, gtid = %d, entries = %d, "
53 "first_block = %p, stack_top = %p \n",
54 location, gtid, entries, task_stack->ts_first_block, stack_top));
56 KMP_DEBUG_ASSERT(stack_top != NULL);
57 KMP_DEBUG_ASSERT(entries > 0);
59 while (entries != 0) {
60 KMP_DEBUG_ASSERT(stack_top != &task_stack->ts_first_block.sb_block[0]);
62 if (entries & TASK_STACK_INDEX_MASK == 0) {
63 kmp_stack_block_t *stack_block = (kmp_stack_block_t *)(stack_top);
65 stack_block = stack_block->sb_prev;
66 stack_top = &stack_block->sb_block[TASK_STACK_BLOCK_SIZE];
73 tied_task = *stack_top;
75 KMP_DEBUG_ASSERT(tied_task != NULL);
76 KMP_DEBUG_ASSERT(tied_task->td_flags.tasktype == TASK_TIED);
79 (
"__kmp_trace_task_stack(%s): gtid=%d, entry=%d, "
80 "stack_top=%p, tied_task=%p\n",
81 location, gtid, entries, stack_top, tied_task));
83 KMP_DEBUG_ASSERT(stack_top == &task_stack->ts_first_block.sb_block[0]);
86 (
"__kmp_trace_task_stack(exit): location = %s, gtid = %d\n",
96 static void __kmp_init_task_stack(kmp_int32 gtid,
97 kmp_thread_data_t *thread_data) {
98 kmp_task_stack_t *task_stack = &thread_data->td.td_susp_tied_tasks;
99 kmp_stack_block_t *first_block;
102 first_block = &task_stack->ts_first_block;
103 task_stack->ts_top = (kmp_taskdata_t **)first_block;
104 memset((
void *)first_block,
'\0',
105 TASK_STACK_BLOCK_SIZE *
sizeof(kmp_taskdata_t *));
108 task_stack->ts_entries = TASK_STACK_EMPTY;
109 first_block->sb_next = NULL;
110 first_block->sb_prev = NULL;
117 static void __kmp_free_task_stack(kmp_int32 gtid,
118 kmp_thread_data_t *thread_data) {
119 kmp_task_stack_t *task_stack = &thread_data->td.td_susp_tied_tasks;
120 kmp_stack_block_t *stack_block = &task_stack->ts_first_block;
122 KMP_DEBUG_ASSERT(task_stack->ts_entries == TASK_STACK_EMPTY);
124 while (stack_block != NULL) {
125 kmp_stack_block_t *next_block = (stack_block) ? stack_block->sb_next : NULL;
127 stack_block->sb_next = NULL;
128 stack_block->sb_prev = NULL;
129 if (stack_block != &task_stack->ts_first_block) {
130 __kmp_thread_free(thread,
133 stack_block = next_block;
136 task_stack->ts_entries = 0;
137 task_stack->ts_top = NULL;
146 static void __kmp_push_task_stack(kmp_int32 gtid, kmp_info_t *thread,
147 kmp_taskdata_t *tied_task) {
149 kmp_thread_data_t *thread_data =
150 &thread->th.th_task_team->tt.tt_threads_data[__kmp_tid_from_gtid(gtid)];
151 kmp_task_stack_t *task_stack = &thread_data->td.td_susp_tied_tasks;
153 if (tied_task->td_flags.team_serial || tied_task->td_flags.tasking_ser) {
157 KMP_DEBUG_ASSERT(tied_task->td_flags.tasktype == TASK_TIED);
158 KMP_DEBUG_ASSERT(task_stack->ts_top != NULL);
161 (
"__kmp_push_task_stack(enter): GTID: %d; THREAD: %p; TASK: %p\n",
162 gtid, thread, tied_task));
164 *(task_stack->ts_top) = tied_task;
167 task_stack->ts_top++;
168 task_stack->ts_entries++;
170 if (task_stack->ts_entries & TASK_STACK_INDEX_MASK == 0) {
172 kmp_stack_block_t *stack_block =
173 (kmp_stack_block_t *)(task_stack->ts_top - TASK_STACK_BLOCK_SIZE);
176 if (stack_block->sb_next !=
178 task_stack->ts_top = &stack_block->sb_next->sb_block[0];
180 kmp_stack_block_t *new_block = (kmp_stack_block_t *)__kmp_thread_calloc(
181 thread,
sizeof(kmp_stack_block_t));
183 task_stack->ts_top = &new_block->sb_block[0];
184 stack_block->sb_next = new_block;
185 new_block->sb_prev = stack_block;
186 new_block->sb_next = NULL;
190 (
"__kmp_push_task_stack(): GTID: %d; TASK: %p; Alloc new block: %p\n",
191 gtid, tied_task, new_block));
194 KA_TRACE(20, (
"__kmp_push_task_stack(exit): GTID: %d; TASK: %p\n", gtid,
205 static void __kmp_pop_task_stack(kmp_int32 gtid, kmp_info_t *thread,
206 kmp_taskdata_t *ending_task) {
208 kmp_thread_data_t *thread_data =
209 &thread->th.th_task_team->tt_threads_data[__kmp_tid_from_gtid(gtid)];
210 kmp_task_stack_t *task_stack = &thread_data->td.td_susp_tied_tasks;
211 kmp_taskdata_t *tied_task;
213 if (ending_task->td_flags.team_serial || ending_task->td_flags.tasking_ser) {
218 KMP_DEBUG_ASSERT(task_stack->ts_top != NULL);
219 KMP_DEBUG_ASSERT(task_stack->ts_entries > 0);
221 KA_TRACE(20, (
"__kmp_pop_task_stack(enter): GTID: %d; THREAD: %p\n", gtid,
225 if (task_stack->ts_entries & TASK_STACK_INDEX_MASK == 0) {
226 kmp_stack_block_t *stack_block = (kmp_stack_block_t *)(task_stack->ts_top);
228 stack_block = stack_block->sb_prev;
229 task_stack->ts_top = &stack_block->sb_block[TASK_STACK_BLOCK_SIZE];
233 task_stack->ts_top--;
234 task_stack->ts_entries--;
236 tied_task = *(task_stack->ts_top);
238 KMP_DEBUG_ASSERT(tied_task != NULL);
239 KMP_DEBUG_ASSERT(tied_task->td_flags.tasktype == TASK_TIED);
240 KMP_DEBUG_ASSERT(tied_task == ending_task);
242 KA_TRACE(20, (
"__kmp_pop_task_stack(exit): GTID: %d; TASK: %p\n", gtid,
251 static bool __kmp_task_is_allowed(
int gtid,
const kmp_int32 is_constrained,
252 const kmp_taskdata_t *tasknew,
253 const kmp_taskdata_t *taskcurr) {
254 if (is_constrained && (tasknew->td_flags.tiedness == TASK_TIED)) {
258 kmp_taskdata_t *current = taskcurr->td_last_tied;
259 KMP_DEBUG_ASSERT(current != NULL);
261 if (current->td_flags.tasktype == TASK_EXPLICIT ||
262 current->td_taskwait_thread > 0) {
263 kmp_int32 level = current->td_level;
264 kmp_taskdata_t *parent = tasknew->td_parent;
265 while (parent != current && parent->td_level > level) {
267 parent = parent->td_parent;
268 KMP_DEBUG_ASSERT(parent != NULL);
270 if (parent != current)
275 kmp_depnode_t *node = tasknew->td_depnode;
276 if (UNLIKELY(node && (node->dn.mtx_num_locks > 0))) {
277 for (
int i = 0; i < node->dn.mtx_num_locks; ++i) {
278 KMP_DEBUG_ASSERT(node->dn.mtx_locks[i] != NULL);
279 if (__kmp_test_lock(node->dn.mtx_locks[i], gtid))
282 for (
int j = i - 1; j >= 0; --j)
283 __kmp_release_lock(node->dn.mtx_locks[j], gtid);
287 node->dn.mtx_num_locks = -node->dn.mtx_num_locks;
296 static void __kmp_realloc_task_deque(kmp_info_t *thread,
297 kmp_thread_data_t *thread_data) {
298 kmp_int32 size = TASK_DEQUE_SIZE(thread_data->td);
299 KMP_DEBUG_ASSERT(TCR_4(thread_data->td.td_deque_ntasks) == size);
300 kmp_int32 new_size = 2 * size;
302 KE_TRACE(10, (
"__kmp_realloc_task_deque: T#%d reallocating deque[from %d to "
303 "%d] for thread_data %p\n",
304 __kmp_gtid_from_thread(thread), size, new_size, thread_data));
306 kmp_taskdata_t **new_deque =
307 (kmp_taskdata_t **)__kmp_allocate(new_size *
sizeof(kmp_taskdata_t *));
310 for (i = thread_data->td.td_deque_head, j = 0; j < size;
311 i = (i + 1) & TASK_DEQUE_MASK(thread_data->td), j++)
312 new_deque[j] = thread_data->td.td_deque[i];
314 __kmp_free(thread_data->td.td_deque);
316 thread_data->td.td_deque_head = 0;
317 thread_data->td.td_deque_tail = size;
318 thread_data->td.td_deque = new_deque;
319 thread_data->td.td_deque_size = new_size;
323 static kmp_int32 __kmp_push_task(kmp_int32 gtid, kmp_task_t *task) {
324 kmp_info_t *thread = __kmp_threads[gtid];
325 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
328 if (taskdata->td_flags.hidden_helper && !KMP_HIDDEN_HELPER_THREAD(gtid)) {
329 gtid = KMP_GTID_TO_SHADOW_GTID(gtid);
330 thread = __kmp_threads[gtid];
333 kmp_task_team_t *task_team = thread->th.th_task_team;
334 kmp_int32 tid = __kmp_tid_from_gtid(gtid);
335 kmp_thread_data_t *thread_data;
338 (
"__kmp_push_task: T#%d trying to push task %p.\n", gtid, taskdata));
340 if (UNLIKELY(taskdata->td_flags.tiedness == TASK_UNTIED)) {
343 kmp_int32 counter = 1 + KMP_ATOMIC_INC(&taskdata->td_untied_count);
344 KMP_DEBUG_USE_VAR(counter);
347 (
"__kmp_push_task: T#%d untied_count (%d) incremented for task %p\n",
348 gtid, counter, taskdata));
352 if (UNLIKELY(taskdata->td_flags.task_serial)) {
353 KA_TRACE(20, (
"__kmp_push_task: T#%d team serialized; returning "
354 "TASK_NOT_PUSHED for task %p\n",
356 return TASK_NOT_PUSHED;
361 KMP_DEBUG_ASSERT(__kmp_tasking_mode != tskm_immediate_exec);
362 if (UNLIKELY(!KMP_TASKING_ENABLED(task_team))) {
363 __kmp_enable_tasking(task_team, thread);
365 KMP_DEBUG_ASSERT(TCR_4(task_team->tt.tt_found_tasks) == TRUE);
366 KMP_DEBUG_ASSERT(TCR_PTR(task_team->tt.tt_threads_data) != NULL);
369 thread_data = &task_team->tt.tt_threads_data[tid];
374 if (UNLIKELY(thread_data->td.td_deque == NULL)) {
375 __kmp_alloc_task_deque(thread, thread_data);
380 if (TCR_4(thread_data->td.td_deque_ntasks) >=
381 TASK_DEQUE_SIZE(thread_data->td)) {
382 if (__kmp_enable_task_throttling &&
383 __kmp_task_is_allowed(gtid, __kmp_task_stealing_constraint, taskdata,
384 thread->th.th_current_task)) {
385 KA_TRACE(20, (
"__kmp_push_task: T#%d deque is full; returning "
386 "TASK_NOT_PUSHED for task %p\n",
388 return TASK_NOT_PUSHED;
390 __kmp_acquire_bootstrap_lock(&thread_data->td.td_deque_lock);
392 if (TCR_4(thread_data->td.td_deque_ntasks) >=
393 TASK_DEQUE_SIZE(thread_data->td)) {
395 __kmp_realloc_task_deque(thread, thread_data);
401 __kmp_acquire_bootstrap_lock(&thread_data->td.td_deque_lock);
403 if (TCR_4(thread_data->td.td_deque_ntasks) >=
404 TASK_DEQUE_SIZE(thread_data->td)) {
405 if (__kmp_enable_task_throttling &&
406 __kmp_task_is_allowed(gtid, __kmp_task_stealing_constraint, taskdata,
407 thread->th.th_current_task)) {
408 __kmp_release_bootstrap_lock(&thread_data->td.td_deque_lock);
409 KA_TRACE(20, (
"__kmp_push_task: T#%d deque is full on 2nd check; "
410 "returning TASK_NOT_PUSHED for task %p\n",
412 return TASK_NOT_PUSHED;
415 __kmp_realloc_task_deque(thread, thread_data);
420 KMP_DEBUG_ASSERT(TCR_4(thread_data->td.td_deque_ntasks) <
421 TASK_DEQUE_SIZE(thread_data->td));
423 thread_data->td.td_deque[thread_data->td.td_deque_tail] =
426 thread_data->td.td_deque_tail =
427 (thread_data->td.td_deque_tail + 1) & TASK_DEQUE_MASK(thread_data->td);
428 TCW_4(thread_data->td.td_deque_ntasks,
429 TCR_4(thread_data->td.td_deque_ntasks) + 1);
430 KMP_FSYNC_RELEASING(thread->th.th_current_task);
431 KMP_FSYNC_RELEASING(taskdata);
432 KA_TRACE(20, (
"__kmp_push_task: T#%d returning TASK_SUCCESSFULLY_PUSHED: "
433 "task=%p ntasks=%d head=%u tail=%u\n",
434 gtid, taskdata, thread_data->td.td_deque_ntasks,
435 thread_data->td.td_deque_head, thread_data->td.td_deque_tail));
437 auto hidden_helper = taskdata->td_flags.hidden_helper;
439 __kmp_release_bootstrap_lock(&thread_data->td.td_deque_lock);
442 if (UNLIKELY(hidden_helper)) {
444 __kmp_hidden_helper_worker_thread_signal();
447 return TASK_SUCCESSFULLY_PUSHED;
454 void __kmp_pop_current_task_from_thread(kmp_info_t *this_thr) {
455 KF_TRACE(10, (
"__kmp_pop_current_task_from_thread(enter): T#%d "
456 "this_thread=%p, curtask=%p, "
457 "curtask_parent=%p\n",
458 0, this_thr, this_thr->th.th_current_task,
459 this_thr->th.th_current_task->td_parent));
461 this_thr->th.th_current_task = this_thr->th.th_current_task->td_parent;
463 KF_TRACE(10, (
"__kmp_pop_current_task_from_thread(exit): T#%d "
464 "this_thread=%p, curtask=%p, "
465 "curtask_parent=%p\n",
466 0, this_thr, this_thr->th.th_current_task,
467 this_thr->th.th_current_task->td_parent));
476 void __kmp_push_current_task_to_thread(kmp_info_t *this_thr, kmp_team_t *team,
480 KF_TRACE(10, (
"__kmp_push_current_task_to_thread(enter): T#%d this_thread=%p "
483 tid, this_thr, this_thr->th.th_current_task,
484 team->t.t_implicit_task_taskdata[tid].td_parent));
486 KMP_DEBUG_ASSERT(this_thr != NULL);
489 if (this_thr->th.th_current_task != &team->t.t_implicit_task_taskdata[0]) {
490 team->t.t_implicit_task_taskdata[0].td_parent =
491 this_thr->th.th_current_task;
492 this_thr->th.th_current_task = &team->t.t_implicit_task_taskdata[0];
495 team->t.t_implicit_task_taskdata[tid].td_parent =
496 team->t.t_implicit_task_taskdata[0].td_parent;
497 this_thr->th.th_current_task = &team->t.t_implicit_task_taskdata[tid];
500 KF_TRACE(10, (
"__kmp_push_current_task_to_thread(exit): T#%d this_thread=%p "
503 tid, this_thr, this_thr->th.th_current_task,
504 team->t.t_implicit_task_taskdata[tid].td_parent));
512 static void __kmp_task_start(kmp_int32 gtid, kmp_task_t *task,
513 kmp_taskdata_t *current_task) {
514 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
515 kmp_info_t *thread = __kmp_threads[gtid];
518 (
"__kmp_task_start(enter): T#%d starting task %p: current_task=%p\n",
519 gtid, taskdata, current_task));
521 KMP_DEBUG_ASSERT(taskdata->td_flags.tasktype == TASK_EXPLICIT);
526 current_task->td_flags.executing = 0;
529 #ifdef BUILD_TIED_TASK_STACK
530 if (taskdata->td_flags.tiedness == TASK_TIED) {
531 __kmp_push_task_stack(gtid, thread, taskdata);
536 thread->th.th_current_task = taskdata;
538 KMP_DEBUG_ASSERT(taskdata->td_flags.started == 0 ||
539 taskdata->td_flags.tiedness == TASK_UNTIED);
540 KMP_DEBUG_ASSERT(taskdata->td_flags.executing == 0 ||
541 taskdata->td_flags.tiedness == TASK_UNTIED);
542 taskdata->td_flags.started = 1;
543 taskdata->td_flags.executing = 1;
544 KMP_DEBUG_ASSERT(taskdata->td_flags.complete == 0);
545 KMP_DEBUG_ASSERT(taskdata->td_flags.freed == 0);
552 KA_TRACE(10, (
"__kmp_task_start(exit): T#%d task=%p\n", gtid, taskdata));
563 static inline void __ompt_task_init(kmp_taskdata_t *task,
int tid) {
565 task->ompt_task_info.task_data.value = 0;
566 task->ompt_task_info.frame.exit_frame = ompt_data_none;
567 task->ompt_task_info.frame.enter_frame = ompt_data_none;
568 task->ompt_task_info.frame.exit_frame_flags =
569 ompt_frame_runtime | ompt_frame_framepointer;
570 task->ompt_task_info.frame.enter_frame_flags =
571 ompt_frame_runtime | ompt_frame_framepointer;
576 static inline void __ompt_task_start(kmp_task_t *task,
577 kmp_taskdata_t *current_task,
579 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
580 ompt_task_status_t status = ompt_task_switch;
581 if (__kmp_threads[gtid]->th.ompt_thread_info.ompt_task_yielded) {
582 status = ompt_task_yield;
583 __kmp_threads[gtid]->th.ompt_thread_info.ompt_task_yielded = 0;
586 if (ompt_enabled.ompt_callback_task_schedule) {
587 ompt_callbacks.ompt_callback(ompt_callback_task_schedule)(
588 &(current_task->ompt_task_info.task_data), status,
589 &(taskdata->ompt_task_info.task_data));
591 taskdata->ompt_task_info.scheduling_parent = current_task;
596 static inline void __ompt_task_finish(kmp_task_t *task,
597 kmp_taskdata_t *resumed_task,
598 ompt_task_status_t status) {
599 if (ompt_enabled.ompt_callback_task_schedule) {
600 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
601 if (__kmp_omp_cancellation && taskdata->td_taskgroup &&
602 taskdata->td_taskgroup->cancel_request == cancel_taskgroup) {
603 status = ompt_task_cancel;
607 ompt_callbacks.ompt_callback(ompt_callback_task_schedule)(
608 &(taskdata->ompt_task_info.task_data), status,
609 (resumed_task ? &(resumed_task->ompt_task_info.task_data) : NULL));
615 static void __kmpc_omp_task_begin_if0_template(
ident_t *loc_ref, kmp_int32 gtid,
618 void *return_address) {
619 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
620 kmp_taskdata_t *current_task = __kmp_threads[gtid]->th.th_current_task;
622 KA_TRACE(10, (
"__kmpc_omp_task_begin_if0(enter): T#%d loc=%p task=%p "
624 gtid, loc_ref, taskdata, current_task));
626 if (UNLIKELY(taskdata->td_flags.tiedness == TASK_UNTIED)) {
629 kmp_int32 counter = 1 + KMP_ATOMIC_INC(&taskdata->td_untied_count);
630 KMP_DEBUG_USE_VAR(counter);
631 KA_TRACE(20, (
"__kmpc_omp_task_begin_if0: T#%d untied_count (%d) "
632 "incremented for task %p\n",
633 gtid, counter, taskdata));
636 taskdata->td_flags.task_serial =
638 __kmp_task_start(gtid, task, current_task);
642 if (current_task->ompt_task_info.frame.enter_frame.ptr == NULL) {
643 current_task->ompt_task_info.frame.enter_frame.ptr =
644 taskdata->ompt_task_info.frame.exit_frame.ptr = frame_address;
645 current_task->ompt_task_info.frame.enter_frame_flags =
646 taskdata->ompt_task_info.frame.exit_frame_flags =
647 ompt_frame_application | ompt_frame_framepointer;
649 if (ompt_enabled.ompt_callback_task_create) {
650 ompt_task_info_t *parent_info = &(current_task->ompt_task_info);
651 ompt_callbacks.ompt_callback(ompt_callback_task_create)(
652 &(parent_info->task_data), &(parent_info->frame),
653 &(taskdata->ompt_task_info.task_data),
654 ompt_task_explicit | TASK_TYPE_DETAILS_FORMAT(taskdata), 0,
657 __ompt_task_start(task, current_task, gtid);
661 KA_TRACE(10, (
"__kmpc_omp_task_begin_if0(exit): T#%d loc=%p task=%p,\n", gtid,
667 static void __kmpc_omp_task_begin_if0_ompt(
ident_t *loc_ref, kmp_int32 gtid,
670 void *return_address) {
671 __kmpc_omp_task_begin_if0_template<true>(loc_ref, gtid, task, frame_address,
682 void __kmpc_omp_task_begin_if0(
ident_t *loc_ref, kmp_int32 gtid,
685 if (UNLIKELY(ompt_enabled.enabled)) {
686 OMPT_STORE_RETURN_ADDRESS(gtid);
687 __kmpc_omp_task_begin_if0_ompt(loc_ref, gtid, task,
688 OMPT_GET_FRAME_ADDRESS(1),
689 OMPT_LOAD_RETURN_ADDRESS(gtid));
693 __kmpc_omp_task_begin_if0_template<false>(loc_ref, gtid, task, NULL, NULL);
699 void __kmpc_omp_task_begin(
ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *task) {
700 kmp_taskdata_t *current_task = __kmp_threads[gtid]->th.th_current_task;
704 (
"__kmpc_omp_task_begin(enter): T#%d loc=%p task=%p current_task=%p\n",
705 gtid, loc_ref, KMP_TASK_TO_TASKDATA(task), current_task));
707 __kmp_task_start(gtid, task, current_task);
709 KA_TRACE(10, (
"__kmpc_omp_task_begin(exit): T#%d loc=%p task=%p,\n", gtid,
710 loc_ref, KMP_TASK_TO_TASKDATA(task)));
720 static void __kmp_free_task(kmp_int32 gtid, kmp_taskdata_t *taskdata,
721 kmp_info_t *thread) {
722 KA_TRACE(30, (
"__kmp_free_task: T#%d freeing data from task %p\n", gtid,
726 KMP_DEBUG_ASSERT(taskdata->td_flags.tasktype == TASK_EXPLICIT);
727 KMP_DEBUG_ASSERT(taskdata->td_flags.executing == 0);
728 KMP_DEBUG_ASSERT(taskdata->td_flags.complete == 1);
729 KMP_DEBUG_ASSERT(taskdata->td_flags.freed == 0);
730 KMP_DEBUG_ASSERT(taskdata->td_allocated_child_tasks == 0 ||
731 taskdata->td_flags.task_serial == 1);
732 KMP_DEBUG_ASSERT(taskdata->td_incomplete_child_tasks == 0);
734 taskdata->td_flags.freed = 1;
737 __kmp_fast_free(thread, taskdata);
739 __kmp_thread_free(thread, taskdata);
741 KA_TRACE(20, (
"__kmp_free_task: T#%d freed task %p\n", gtid, taskdata));
750 static void __kmp_free_task_and_ancestors(kmp_int32 gtid,
751 kmp_taskdata_t *taskdata,
752 kmp_info_t *thread) {
755 kmp_int32 team_serial =
756 (taskdata->td_flags.team_serial || taskdata->td_flags.tasking_ser) &&
757 !taskdata->td_flags.proxy;
758 KMP_DEBUG_ASSERT(taskdata->td_flags.tasktype == TASK_EXPLICIT);
760 kmp_int32 children = KMP_ATOMIC_DEC(&taskdata->td_allocated_child_tasks) - 1;
761 KMP_DEBUG_ASSERT(children >= 0);
764 while (children == 0) {
765 kmp_taskdata_t *parent_taskdata = taskdata->td_parent;
767 KA_TRACE(20, (
"__kmp_free_task_and_ancestors(enter): T#%d task %p complete "
768 "and freeing itself\n",
772 __kmp_free_task(gtid, taskdata, thread);
774 taskdata = parent_taskdata;
780 if (taskdata->td_flags.tasktype == TASK_IMPLICIT) {
781 if (taskdata->td_dephash) {
782 int children = KMP_ATOMIC_LD_ACQ(&taskdata->td_incomplete_child_tasks);
783 kmp_tasking_flags_t flags_old = taskdata->td_flags;
784 if (children == 0 && flags_old.complete == 1) {
785 kmp_tasking_flags_t flags_new = flags_old;
786 flags_new.complete = 0;
787 if (KMP_COMPARE_AND_STORE_ACQ32(
788 RCAST(kmp_int32 *, &taskdata->td_flags),
789 *RCAST(kmp_int32 *, &flags_old),
790 *RCAST(kmp_int32 *, &flags_new))) {
791 KA_TRACE(100, (
"__kmp_free_task_and_ancestors: T#%d cleans "
792 "dephash of implicit task %p\n",
795 __kmp_dephash_free_entries(thread, taskdata->td_dephash);
802 children = KMP_ATOMIC_DEC(&taskdata->td_allocated_child_tasks) - 1;
803 KMP_DEBUG_ASSERT(children >= 0);
807 20, (
"__kmp_free_task_and_ancestors(exit): T#%d task %p has %d children; "
808 "not freeing it yet\n",
809 gtid, taskdata, children));
822 static void __kmp_task_finish(kmp_int32 gtid, kmp_task_t *task,
823 kmp_taskdata_t *resumed_task) {
824 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
825 kmp_info_t *thread = __kmp_threads[gtid];
826 kmp_task_team_t *task_team =
827 thread->th.th_task_team;
828 kmp_int32 children = 0;
830 KA_TRACE(10, (
"__kmp_task_finish(enter): T#%d finishing task %p and resuming "
832 gtid, taskdata, resumed_task));
834 KMP_DEBUG_ASSERT(taskdata->td_flags.tasktype == TASK_EXPLICIT);
837 #ifdef BUILD_TIED_TASK_STACK
838 if (taskdata->td_flags.tiedness == TASK_TIED) {
839 __kmp_pop_task_stack(gtid, thread, taskdata);
843 if (UNLIKELY(taskdata->td_flags.tiedness == TASK_UNTIED)) {
846 kmp_int32 counter = KMP_ATOMIC_DEC(&taskdata->td_untied_count) - 1;
849 (
"__kmp_task_finish: T#%d untied_count (%d) decremented for task %p\n",
850 gtid, counter, taskdata));
854 if (resumed_task == NULL) {
855 KMP_DEBUG_ASSERT(taskdata->td_flags.task_serial);
856 resumed_task = taskdata->td_parent;
859 thread->th.th_current_task = resumed_task;
860 resumed_task->td_flags.executing = 1;
861 KA_TRACE(10, (
"__kmp_task_finish(exit): T#%d partially done task %p, "
862 "resuming task %p\n",
863 gtid, taskdata, resumed_task));
871 (taskdata->td_flags.tasking_ser || taskdata->td_flags.task_serial) ==
872 taskdata->td_flags.task_serial);
873 if (taskdata->td_flags.task_serial) {
874 if (resumed_task == NULL) {
875 resumed_task = taskdata->td_parent;
879 KMP_DEBUG_ASSERT(resumed_task !=
889 if (UNLIKELY(taskdata->td_flags.destructors_thunk)) {
890 kmp_routine_entry_t destr_thunk = task->data1.destructors;
891 KMP_ASSERT(destr_thunk);
892 destr_thunk(gtid, task);
895 KMP_DEBUG_ASSERT(taskdata->td_flags.complete == 0);
896 KMP_DEBUG_ASSERT(taskdata->td_flags.started == 1);
897 KMP_DEBUG_ASSERT(taskdata->td_flags.freed == 0);
900 if (UNLIKELY(taskdata->td_flags.detachable == TASK_DETACHABLE)) {
901 if (taskdata->td_allow_completion_event.type ==
902 KMP_EVENT_ALLOW_COMPLETION) {
904 __kmp_acquire_tas_lock(&taskdata->td_allow_completion_event.lock, gtid);
905 if (taskdata->td_allow_completion_event.type ==
906 KMP_EVENT_ALLOW_COMPLETION) {
908 KMP_DEBUG_ASSERT(taskdata->td_flags.executing == 1);
909 taskdata->td_flags.executing = 0;
916 __ompt_task_finish(task, resumed_task, ompt_task_detach);
922 taskdata->td_flags.proxy = TASK_PROXY;
925 __kmp_release_tas_lock(&taskdata->td_allow_completion_event.lock, gtid);
930 taskdata->td_flags.complete = 1;
935 __ompt_task_finish(task, resumed_task, ompt_task_complete);
940 if (!(taskdata->td_flags.team_serial || taskdata->td_flags.tasking_ser) ||
941 taskdata->td_flags.detachable == TASK_DETACHABLE ||
942 taskdata->td_flags.hidden_helper) {
945 KMP_ATOMIC_DEC(&taskdata->td_parent->td_incomplete_child_tasks) - 1;
946 KMP_DEBUG_ASSERT(children >= 0);
947 if (taskdata->td_taskgroup)
948 KMP_ATOMIC_DEC(&taskdata->td_taskgroup->count);
949 __kmp_release_deps(gtid, taskdata);
950 }
else if (task_team && task_team->tt.tt_found_proxy_tasks) {
953 __kmp_release_deps(gtid, taskdata);
959 KMP_DEBUG_ASSERT(taskdata->td_flags.executing == 1);
960 taskdata->td_flags.executing = 0;
964 20, (
"__kmp_task_finish: T#%d finished task %p, %d incomplete children\n",
965 gtid, taskdata, children));
971 thread->th.th_current_task = resumed_task;
973 __kmp_free_task_and_ancestors(gtid, taskdata, thread);
977 resumed_task->td_flags.executing = 1;
980 10, (
"__kmp_task_finish(exit): T#%d finished task %p, resuming task %p\n",
981 gtid, taskdata, resumed_task));
987 static void __kmpc_omp_task_complete_if0_template(
ident_t *loc_ref,
990 KA_TRACE(10, (
"__kmpc_omp_task_complete_if0(enter): T#%d loc=%p task=%p\n",
991 gtid, loc_ref, KMP_TASK_TO_TASKDATA(task)));
992 KMP_DEBUG_ASSERT(gtid >= 0);
994 __kmp_task_finish<ompt>(gtid, task, NULL);
996 KA_TRACE(10, (
"__kmpc_omp_task_complete_if0(exit): T#%d loc=%p task=%p\n",
997 gtid, loc_ref, KMP_TASK_TO_TASKDATA(task)));
1001 ompt_frame_t *ompt_frame;
1002 __ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
1003 ompt_frame->enter_frame = ompt_data_none;
1004 ompt_frame->enter_frame_flags =
1005 ompt_frame_runtime | ompt_frame_framepointer;
1014 void __kmpc_omp_task_complete_if0_ompt(
ident_t *loc_ref, kmp_int32 gtid,
1016 __kmpc_omp_task_complete_if0_template<true>(loc_ref, gtid, task);
1025 void __kmpc_omp_task_complete_if0(
ident_t *loc_ref, kmp_int32 gtid,
1028 if (UNLIKELY(ompt_enabled.enabled)) {
1029 __kmpc_omp_task_complete_if0_ompt(loc_ref, gtid, task);
1033 __kmpc_omp_task_complete_if0_template<false>(loc_ref, gtid, task);
1039 void __kmpc_omp_task_complete(
ident_t *loc_ref, kmp_int32 gtid,
1041 KA_TRACE(10, (
"__kmpc_omp_task_complete(enter): T#%d loc=%p task=%p\n", gtid,
1042 loc_ref, KMP_TASK_TO_TASKDATA(task)));
1044 __kmp_task_finish<false>(gtid, task,
1047 KA_TRACE(10, (
"__kmpc_omp_task_complete(exit): T#%d loc=%p task=%p\n", gtid,
1048 loc_ref, KMP_TASK_TO_TASKDATA(task)));
1064 void __kmp_init_implicit_task(
ident_t *loc_ref, kmp_info_t *this_thr,
1065 kmp_team_t *team,
int tid,
int set_curr_task) {
1066 kmp_taskdata_t *task = &team->t.t_implicit_task_taskdata[tid];
1070 (
"__kmp_init_implicit_task(enter): T#:%d team=%p task=%p, reinit=%s\n",
1071 tid, team, task, set_curr_task ?
"TRUE" :
"FALSE"));
1073 task->td_task_id = KMP_GEN_TASK_ID();
1074 task->td_team = team;
1077 task->td_ident = loc_ref;
1078 task->td_taskwait_ident = NULL;
1079 task->td_taskwait_counter = 0;
1080 task->td_taskwait_thread = 0;
1082 task->td_flags.tiedness = TASK_TIED;
1083 task->td_flags.tasktype = TASK_IMPLICIT;
1084 task->td_flags.proxy = TASK_FULL;
1087 task->td_flags.task_serial = 1;
1088 task->td_flags.tasking_ser = (__kmp_tasking_mode == tskm_immediate_exec);
1089 task->td_flags.team_serial = (team->t.t_serialized) ? 1 : 0;
1091 task->td_flags.started = 1;
1092 task->td_flags.executing = 1;
1093 task->td_flags.complete = 0;
1094 task->td_flags.freed = 0;
1096 task->td_depnode = NULL;
1097 task->td_last_tied = task;
1098 task->td_allow_completion_event.type = KMP_EVENT_UNINITIALIZED;
1100 if (set_curr_task) {
1101 KMP_ATOMIC_ST_REL(&task->td_incomplete_child_tasks, 0);
1103 KMP_ATOMIC_ST_REL(&task->td_allocated_child_tasks, 0);
1104 task->td_taskgroup = NULL;
1105 task->td_dephash = NULL;
1106 __kmp_push_current_task_to_thread(this_thr, team, tid);
1108 KMP_DEBUG_ASSERT(task->td_incomplete_child_tasks == 0);
1109 KMP_DEBUG_ASSERT(task->td_allocated_child_tasks == 0);
1113 if (UNLIKELY(ompt_enabled.enabled))
1114 __ompt_task_init(task, tid);
1117 KF_TRACE(10, (
"__kmp_init_implicit_task(exit): T#:%d team=%p task=%p\n", tid,
1126 void __kmp_finish_implicit_task(kmp_info_t *thread) {
1127 kmp_taskdata_t *task = thread->th.th_current_task;
1128 if (task->td_dephash) {
1130 task->td_flags.complete = 1;
1131 children = KMP_ATOMIC_LD_ACQ(&task->td_incomplete_child_tasks);
1132 kmp_tasking_flags_t flags_old = task->td_flags;
1133 if (children == 0 && flags_old.complete == 1) {
1134 kmp_tasking_flags_t flags_new = flags_old;
1135 flags_new.complete = 0;
1136 if (KMP_COMPARE_AND_STORE_ACQ32(RCAST(kmp_int32 *, &task->td_flags),
1137 *RCAST(kmp_int32 *, &flags_old),
1138 *RCAST(kmp_int32 *, &flags_new))) {
1139 KA_TRACE(100, (
"__kmp_finish_implicit_task: T#%d cleans "
1140 "dephash of implicit task %p\n",
1141 thread->th.th_info.ds.ds_gtid, task));
1142 __kmp_dephash_free_entries(thread, task->td_dephash);
1152 void __kmp_free_implicit_task(kmp_info_t *thread) {
1153 kmp_taskdata_t *task = thread->th.th_current_task;
1154 if (task && task->td_dephash) {
1155 __kmp_dephash_free(thread, task->td_dephash);
1156 task->td_dephash = NULL;
1162 static size_t __kmp_round_up_to_val(
size_t size,
size_t val) {
1163 if (size & (val - 1)) {
1165 if (size <= KMP_SIZE_T_MAX - val) {
1184 kmp_task_t *__kmp_task_alloc(
ident_t *loc_ref, kmp_int32 gtid,
1185 kmp_tasking_flags_t *flags,
1186 size_t sizeof_kmp_task_t,
size_t sizeof_shareds,
1187 kmp_routine_entry_t task_entry) {
1189 kmp_taskdata_t *taskdata;
1190 kmp_info_t *thread = __kmp_threads[gtid];
1191 kmp_info_t *encountering_thread = thread;
1192 kmp_team_t *team = thread->th.th_team;
1193 kmp_taskdata_t *parent_task = thread->th.th_current_task;
1194 size_t shareds_offset;
1196 if (UNLIKELY(!TCR_4(__kmp_init_middle)))
1197 __kmp_middle_initialize();
1199 if (flags->hidden_helper) {
1200 if (__kmp_enable_hidden_helper) {
1201 if (!TCR_4(__kmp_init_hidden_helper))
1202 __kmp_hidden_helper_initialize();
1207 if (!KMP_HIDDEN_HELPER_THREAD(gtid)) {
1208 thread = __kmp_threads[KMP_GTID_TO_SHADOW_GTID(gtid)];
1214 flags->hidden_helper = FALSE;
1218 KA_TRACE(10, (
"__kmp_task_alloc(enter): T#%d loc=%p, flags=(0x%x) "
1219 "sizeof_task=%ld sizeof_shared=%ld entry=%p\n",
1220 gtid, loc_ref, *((kmp_int32 *)flags), sizeof_kmp_task_t,
1221 sizeof_shareds, task_entry));
1223 KMP_DEBUG_ASSERT(parent_task);
1224 if (parent_task->td_flags.final) {
1225 if (flags->merged_if0) {
1230 if (flags->tiedness == TASK_UNTIED && !team->t.t_serialized) {
1235 encountering_thread->th.th_task_team->tt.tt_untied_task_encountered, 1);
1241 if (UNLIKELY(flags->proxy == TASK_PROXY ||
1242 flags->detachable == TASK_DETACHABLE || flags->hidden_helper)) {
1243 if (flags->proxy == TASK_PROXY) {
1244 flags->tiedness = TASK_UNTIED;
1245 flags->merged_if0 = 1;
1249 if ((encountering_thread->th.th_task_team) == NULL) {
1252 KMP_DEBUG_ASSERT(team->t.t_serialized);
1254 (
"T#%d creating task team in __kmp_task_alloc for proxy task\n",
1256 __kmp_task_team_setup(
1257 encountering_thread, team,
1259 encountering_thread->th.th_task_team =
1260 team->t.t_task_team[encountering_thread->th.th_task_state];
1262 kmp_task_team_t *task_team = encountering_thread->th.th_task_team;
1265 if (!KMP_TASKING_ENABLED(task_team)) {
1268 (
"T#%d enabling tasking in __kmp_task_alloc for proxy task\n", gtid));
1269 __kmp_enable_tasking(task_team, encountering_thread);
1270 kmp_int32 tid = encountering_thread->th.th_info.ds.ds_tid;
1271 kmp_thread_data_t *thread_data = &task_team->tt.tt_threads_data[tid];
1273 if (thread_data->td.td_deque == NULL) {
1274 __kmp_alloc_task_deque(encountering_thread, thread_data);
1278 if ((flags->proxy == TASK_PROXY || flags->detachable == TASK_DETACHABLE) &&
1279 task_team->tt.tt_found_proxy_tasks == FALSE)
1280 TCW_4(task_team->tt.tt_found_proxy_tasks, TRUE);
1281 if (flags->hidden_helper &&
1282 task_team->tt.tt_hidden_helper_task_encountered == FALSE)
1283 TCW_4(task_team->tt.tt_hidden_helper_task_encountered, TRUE);
1288 shareds_offset =
sizeof(kmp_taskdata_t) + sizeof_kmp_task_t;
1289 shareds_offset = __kmp_round_up_to_val(shareds_offset,
sizeof(
void *));
1292 KA_TRACE(30, (
"__kmp_task_alloc: T#%d First malloc size: %ld\n", gtid,
1294 KA_TRACE(30, (
"__kmp_task_alloc: T#%d Second malloc size: %ld\n", gtid,
1299 taskdata = (kmp_taskdata_t *)__kmp_fast_allocate(
1300 encountering_thread, shareds_offset + sizeof_shareds);
1302 taskdata = (kmp_taskdata_t *)__kmp_thread_malloc(
1303 encountering_thread, shareds_offset + sizeof_shareds);
1306 task = KMP_TASKDATA_TO_TASK(taskdata);
1309 #if KMP_ARCH_X86 || KMP_ARCH_PPC64 || !KMP_HAVE_QUAD
1310 KMP_DEBUG_ASSERT((((kmp_uintptr_t)taskdata) & (
sizeof(
double) - 1)) == 0);
1311 KMP_DEBUG_ASSERT((((kmp_uintptr_t)task) & (
sizeof(
double) - 1)) == 0);
1313 KMP_DEBUG_ASSERT((((kmp_uintptr_t)taskdata) & (
sizeof(_Quad) - 1)) == 0);
1314 KMP_DEBUG_ASSERT((((kmp_uintptr_t)task) & (
sizeof(_Quad) - 1)) == 0);
1316 if (sizeof_shareds > 0) {
1318 task->shareds = &((
char *)taskdata)[shareds_offset];
1320 KMP_DEBUG_ASSERT((((kmp_uintptr_t)task->shareds) & (
sizeof(
void *) - 1)) ==
1323 task->shareds = NULL;
1325 task->routine = task_entry;
1328 taskdata->td_task_id = KMP_GEN_TASK_ID();
1329 taskdata->td_team = thread->th.th_team;
1330 taskdata->td_alloc_thread = encountering_thread;
1331 taskdata->td_parent = parent_task;
1332 taskdata->td_level = parent_task->td_level + 1;
1333 KMP_ATOMIC_ST_RLX(&taskdata->td_untied_count, 0);
1334 taskdata->td_ident = loc_ref;
1335 taskdata->td_taskwait_ident = NULL;
1336 taskdata->td_taskwait_counter = 0;
1337 taskdata->td_taskwait_thread = 0;
1338 KMP_DEBUG_ASSERT(taskdata->td_parent != NULL);
1340 if (flags->proxy == TASK_FULL)
1341 copy_icvs(&taskdata->td_icvs, &taskdata->td_parent->td_icvs);
1343 taskdata->td_flags = *flags;
1344 taskdata->encountering_gtid = gtid;
1345 taskdata->td_task_team = thread->th.th_task_team;
1346 taskdata->td_size_alloc = shareds_offset + sizeof_shareds;
1347 taskdata->td_flags.tasktype = TASK_EXPLICIT;
1350 taskdata->td_flags.tasking_ser = (__kmp_tasking_mode == tskm_immediate_exec);
1353 taskdata->td_flags.team_serial = (team->t.t_serialized) ? 1 : 0;
1359 taskdata->td_flags.task_serial =
1360 (parent_task->td_flags.final || taskdata->td_flags.team_serial ||
1361 taskdata->td_flags.tasking_ser || flags->merged_if0);
1363 taskdata->td_flags.started = 0;
1364 taskdata->td_flags.executing = 0;
1365 taskdata->td_flags.complete = 0;
1366 taskdata->td_flags.freed = 0;
1368 KMP_ATOMIC_ST_RLX(&taskdata->td_incomplete_child_tasks, 0);
1370 KMP_ATOMIC_ST_RLX(&taskdata->td_allocated_child_tasks, 1);
1371 taskdata->td_taskgroup =
1372 parent_task->td_taskgroup;
1373 taskdata->td_dephash = NULL;
1374 taskdata->td_depnode = NULL;
1375 if (flags->tiedness == TASK_UNTIED)
1376 taskdata->td_last_tied = NULL;
1378 taskdata->td_last_tied = taskdata;
1379 taskdata->td_allow_completion_event.type = KMP_EVENT_UNINITIALIZED;
1381 if (UNLIKELY(ompt_enabled.enabled))
1382 __ompt_task_init(taskdata, gtid);
1386 if (flags->proxy == TASK_PROXY || flags->detachable == TASK_DETACHABLE ||
1387 flags->hidden_helper ||
1388 !(taskdata->td_flags.team_serial || taskdata->td_flags.tasking_ser)) {
1389 KMP_ATOMIC_INC(&parent_task->td_incomplete_child_tasks);
1390 if (parent_task->td_taskgroup)
1391 KMP_ATOMIC_INC(&parent_task->td_taskgroup->count);
1394 if (taskdata->td_parent->td_flags.tasktype == TASK_EXPLICIT) {
1395 KMP_ATOMIC_INC(&taskdata->td_parent->td_allocated_child_tasks);
1397 if (flags->hidden_helper) {
1398 taskdata->td_flags.task_serial = FALSE;
1400 KMP_ATOMIC_INC(&__kmp_unexecuted_hidden_helper_tasks);
1404 KA_TRACE(20, (
"__kmp_task_alloc(exit): T#%d created task %p parent=%p\n",
1405 gtid, taskdata, taskdata->td_parent));
1410 kmp_task_t *__kmpc_omp_task_alloc(
ident_t *loc_ref, kmp_int32 gtid,
1411 kmp_int32 flags,
size_t sizeof_kmp_task_t,
1412 size_t sizeof_shareds,
1413 kmp_routine_entry_t task_entry) {
1415 kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *)&flags;
1416 __kmp_assert_valid_gtid(gtid);
1417 input_flags->native = FALSE;
1419 KA_TRACE(10, (
"__kmpc_omp_task_alloc(enter): T#%d loc=%p, flags=(%s %s %s) "
1420 "sizeof_task=%ld sizeof_shared=%ld entry=%p\n",
1421 gtid, loc_ref, input_flags->tiedness ?
"tied " :
"untied",
1422 input_flags->proxy ?
"proxy" :
"",
1423 input_flags->detachable ?
"detachable" :
"", sizeof_kmp_task_t,
1424 sizeof_shareds, task_entry));
1426 retval = __kmp_task_alloc(loc_ref, gtid, input_flags, sizeof_kmp_task_t,
1427 sizeof_shareds, task_entry);
1429 KA_TRACE(20, (
"__kmpc_omp_task_alloc(exit): T#%d retval %p\n", gtid, retval));
1434 kmp_task_t *__kmpc_omp_target_task_alloc(
ident_t *loc_ref, kmp_int32 gtid,
1436 size_t sizeof_kmp_task_t,
1437 size_t sizeof_shareds,
1438 kmp_routine_entry_t task_entry,
1439 kmp_int64 device_id) {
1440 if (__kmp_enable_hidden_helper) {
1441 auto &input_flags =
reinterpret_cast<kmp_tasking_flags_t &
>(flags);
1442 input_flags.hidden_helper = TRUE;
1445 return __kmpc_omp_task_alloc(loc_ref, gtid, flags, sizeof_kmp_task_t,
1446 sizeof_shareds, task_entry);
1464 kmp_task_t *new_task, kmp_int32 naffins,
1465 kmp_task_affinity_info_t *affin_list) {
1474 static void __kmp_invoke_task(kmp_int32 gtid, kmp_task_t *task,
1475 kmp_taskdata_t *current_task) {
1476 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
1480 30, (
"__kmp_invoke_task(enter): T#%d invoking task %p, current_task=%p\n",
1481 gtid, taskdata, current_task));
1482 KMP_DEBUG_ASSERT(task);
1483 if (UNLIKELY(taskdata->td_flags.proxy == TASK_PROXY &&
1484 taskdata->td_flags.complete == 1)) {
1489 (
"__kmp_invoke_task: T#%d running bottom finish for proxy task %p\n",
1492 __kmp_bottom_half_finish_proxy(gtid, task);
1494 KA_TRACE(30, (
"__kmp_invoke_task(exit): T#%d completed bottom finish for "
1495 "proxy task %p, resuming task %p\n",
1496 gtid, taskdata, current_task));
1504 ompt_thread_info_t oldInfo;
1505 if (UNLIKELY(ompt_enabled.enabled)) {
1507 thread = __kmp_threads[gtid];
1508 oldInfo = thread->th.ompt_thread_info;
1509 thread->th.ompt_thread_info.wait_id = 0;
1510 thread->th.ompt_thread_info.state = (thread->th.th_team_serialized)
1511 ? ompt_state_work_serial
1512 : ompt_state_work_parallel;
1513 taskdata->ompt_task_info.frame.exit_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1518 if (taskdata->td_flags.hidden_helper) {
1520 KMP_ASSERT(KMP_HIDDEN_HELPER_THREAD(gtid));
1521 KMP_ATOMIC_DEC(&__kmp_unexecuted_hidden_helper_tasks);
1525 if (taskdata->td_flags.proxy != TASK_PROXY) {
1526 __kmp_task_start(gtid, task, current_task);
1532 if (UNLIKELY(__kmp_omp_cancellation)) {
1533 thread = __kmp_threads[gtid];
1534 kmp_team_t *this_team = thread->th.th_team;
1535 kmp_taskgroup_t *taskgroup = taskdata->td_taskgroup;
1536 if ((taskgroup && taskgroup->cancel_request) ||
1537 (this_team->t.t_cancel_request == cancel_parallel)) {
1538 #if OMPT_SUPPORT && OMPT_OPTIONAL
1539 ompt_data_t *task_data;
1540 if (UNLIKELY(ompt_enabled.ompt_callback_cancel)) {
1541 __ompt_get_task_info_internal(0, NULL, &task_data, NULL, NULL, NULL);
1542 ompt_callbacks.ompt_callback(ompt_callback_cancel)(
1544 ((taskgroup && taskgroup->cancel_request) ? ompt_cancel_taskgroup
1545 : ompt_cancel_parallel) |
1546 ompt_cancel_discarded_task,
1559 if (taskdata->td_flags.tiedness == TASK_UNTIED) {
1560 taskdata->td_last_tied = current_task->td_last_tied;
1561 KMP_DEBUG_ASSERT(taskdata->td_last_tied);
1563 #if KMP_STATS_ENABLED
1565 switch (KMP_GET_THREAD_STATE()) {
1566 case FORK_JOIN_BARRIER:
1567 KMP_PUSH_PARTITIONED_TIMER(OMP_task_join_bar);
1570 KMP_PUSH_PARTITIONED_TIMER(OMP_task_plain_bar);
1573 KMP_PUSH_PARTITIONED_TIMER(OMP_task_taskyield);
1576 KMP_PUSH_PARTITIONED_TIMER(OMP_task_taskwait);
1579 KMP_PUSH_PARTITIONED_TIMER(OMP_task_taskgroup);
1582 KMP_PUSH_PARTITIONED_TIMER(OMP_task_immediate);
1589 if (UNLIKELY(ompt_enabled.enabled))
1590 __ompt_task_start(task, current_task, gtid);
1594 if (ompd_state & OMPD_ENABLE_BP)
1595 ompd_bp_task_begin();
1598 #if USE_ITT_BUILD && USE_ITT_NOTIFY
1599 kmp_uint64 cur_time;
1600 kmp_int32 kmp_itt_count_task =
1601 __kmp_forkjoin_frames_mode == 3 && !taskdata->td_flags.task_serial &&
1602 current_task->td_flags.tasktype == TASK_IMPLICIT;
1603 if (kmp_itt_count_task) {
1604 thread = __kmp_threads[gtid];
1606 if (thread->th.th_bar_arrive_time)
1607 cur_time = __itt_get_timestamp();
1609 kmp_itt_count_task = 0;
1611 KMP_FSYNC_ACQUIRED(taskdata);
1614 #ifdef KMP_GOMP_COMPAT
1615 if (taskdata->td_flags.native) {
1616 ((void (*)(
void *))(*(task->routine)))(task->shareds);
1620 (*(task->routine))(gtid, task);
1622 KMP_POP_PARTITIONED_TIMER();
1624 #if USE_ITT_BUILD && USE_ITT_NOTIFY
1625 if (kmp_itt_count_task) {
1627 thread->th.th_bar_arrive_time += (__itt_get_timestamp() - cur_time);
1629 KMP_FSYNC_CANCEL(taskdata);
1630 KMP_FSYNC_RELEASING(taskdata->td_parent);
1635 if (ompd_state & OMPD_ENABLE_BP)
1640 if (taskdata->td_flags.proxy != TASK_PROXY) {
1642 if (UNLIKELY(ompt_enabled.enabled)) {
1643 thread->th.ompt_thread_info = oldInfo;
1644 if (taskdata->td_flags.tiedness == TASK_TIED) {
1645 taskdata->ompt_task_info.frame.exit_frame = ompt_data_none;
1647 __kmp_task_finish<true>(gtid, task, current_task);
1650 __kmp_task_finish<false>(gtid, task, current_task);
1655 (
"__kmp_invoke_task(exit): T#%d completed task %p, resuming task %p\n",
1656 gtid, taskdata, current_task));
1670 kmp_int32 __kmpc_omp_task_parts(
ident_t *loc_ref, kmp_int32 gtid,
1671 kmp_task_t *new_task) {
1672 kmp_taskdata_t *new_taskdata = KMP_TASK_TO_TASKDATA(new_task);
1674 KA_TRACE(10, (
"__kmpc_omp_task_parts(enter): T#%d loc=%p task=%p\n", gtid,
1675 loc_ref, new_taskdata));
1678 kmp_taskdata_t *parent;
1679 if (UNLIKELY(ompt_enabled.enabled)) {
1680 parent = new_taskdata->td_parent;
1681 if (ompt_enabled.ompt_callback_task_create) {
1682 ompt_callbacks.ompt_callback(ompt_callback_task_create)(
1683 &(parent->ompt_task_info.task_data), &(parent->ompt_task_info.frame),
1684 &(new_taskdata->ompt_task_info.task_data), ompt_task_explicit, 0,
1685 OMPT_GET_RETURN_ADDRESS(0));
1693 if (__kmp_push_task(gtid, new_task) == TASK_NOT_PUSHED)
1695 kmp_taskdata_t *current_task = __kmp_threads[gtid]->th.th_current_task;
1696 new_taskdata->td_flags.task_serial = 1;
1697 __kmp_invoke_task(gtid, new_task, current_task);
1702 (
"__kmpc_omp_task_parts(exit): T#%d returning TASK_CURRENT_NOT_QUEUED: "
1703 "loc=%p task=%p, return: TASK_CURRENT_NOT_QUEUED\n",
1704 gtid, loc_ref, new_taskdata));
1707 if (UNLIKELY(ompt_enabled.enabled)) {
1708 parent->ompt_task_info.frame.enter_frame = ompt_data_none;
1711 return TASK_CURRENT_NOT_QUEUED;
1725 kmp_int32 __kmp_omp_task(kmp_int32 gtid, kmp_task_t *new_task,
1726 bool serialize_immediate) {
1727 kmp_taskdata_t *new_taskdata = KMP_TASK_TO_TASKDATA(new_task);
1731 if (new_taskdata->td_flags.proxy == TASK_PROXY ||
1732 __kmp_push_task(gtid, new_task) == TASK_NOT_PUSHED)
1734 kmp_taskdata_t *current_task = __kmp_threads[gtid]->th.th_current_task;
1735 if (serialize_immediate)
1736 new_taskdata->td_flags.task_serial = 1;
1737 __kmp_invoke_task(gtid, new_task, current_task);
1740 return TASK_CURRENT_NOT_QUEUED;
1755 kmp_int32 __kmpc_omp_task(
ident_t *loc_ref, kmp_int32 gtid,
1756 kmp_task_t *new_task) {
1758 KMP_SET_THREAD_STATE_BLOCK(EXPLICIT_TASK);
1760 #if KMP_DEBUG || OMPT_SUPPORT
1761 kmp_taskdata_t *new_taskdata = KMP_TASK_TO_TASKDATA(new_task);
1763 KA_TRACE(10, (
"__kmpc_omp_task(enter): T#%d loc=%p task=%p\n", gtid, loc_ref,
1765 __kmp_assert_valid_gtid(gtid);
1768 kmp_taskdata_t *parent = NULL;
1769 if (UNLIKELY(ompt_enabled.enabled)) {
1770 if (!new_taskdata->td_flags.started) {
1771 OMPT_STORE_RETURN_ADDRESS(gtid);
1772 parent = new_taskdata->td_parent;
1773 if (!parent->ompt_task_info.frame.enter_frame.ptr) {
1774 parent->ompt_task_info.frame.enter_frame.ptr =
1775 OMPT_GET_FRAME_ADDRESS(0);
1777 if (ompt_enabled.ompt_callback_task_create) {
1778 ompt_callbacks.ompt_callback(ompt_callback_task_create)(
1779 &(parent->ompt_task_info.task_data),
1780 &(parent->ompt_task_info.frame),
1781 &(new_taskdata->ompt_task_info.task_data),
1782 ompt_task_explicit | TASK_TYPE_DETAILS_FORMAT(new_taskdata), 0,
1783 OMPT_LOAD_RETURN_ADDRESS(gtid));
1788 __ompt_task_finish(new_task,
1789 new_taskdata->ompt_task_info.scheduling_parent,
1791 new_taskdata->ompt_task_info.frame.exit_frame = ompt_data_none;
1796 res = __kmp_omp_task(gtid, new_task,
true);
1798 KA_TRACE(10, (
"__kmpc_omp_task(exit): T#%d returning "
1799 "TASK_CURRENT_NOT_QUEUED: loc=%p task=%p\n",
1800 gtid, loc_ref, new_taskdata));
1802 if (UNLIKELY(ompt_enabled.enabled && parent != NULL)) {
1803 parent->ompt_task_info.frame.enter_frame = ompt_data_none;
1822 kmp_int32 __kmp_omp_taskloop_task(
ident_t *loc_ref, kmp_int32 gtid,
1823 kmp_task_t *new_task,
void *codeptr_ra) {
1825 KMP_SET_THREAD_STATE_BLOCK(EXPLICIT_TASK);
1827 #if KMP_DEBUG || OMPT_SUPPORT
1828 kmp_taskdata_t *new_taskdata = KMP_TASK_TO_TASKDATA(new_task);
1830 KA_TRACE(10, (
"__kmpc_omp_task(enter): T#%d loc=%p task=%p\n", gtid, loc_ref,
1834 kmp_taskdata_t *parent = NULL;
1835 if (UNLIKELY(ompt_enabled.enabled && !new_taskdata->td_flags.started)) {
1836 parent = new_taskdata->td_parent;
1837 if (!parent->ompt_task_info.frame.enter_frame.ptr)
1838 parent->ompt_task_info.frame.enter_frame.ptr = OMPT_GET_FRAME_ADDRESS(0);
1839 if (ompt_enabled.ompt_callback_task_create) {
1840 ompt_callbacks.ompt_callback(ompt_callback_task_create)(
1841 &(parent->ompt_task_info.task_data), &(parent->ompt_task_info.frame),
1842 &(new_taskdata->ompt_task_info.task_data),
1843 ompt_task_explicit | TASK_TYPE_DETAILS_FORMAT(new_taskdata), 0,
1849 res = __kmp_omp_task(gtid, new_task,
true);
1851 KA_TRACE(10, (
"__kmpc_omp_task(exit): T#%d returning "
1852 "TASK_CURRENT_NOT_QUEUED: loc=%p task=%p\n",
1853 gtid, loc_ref, new_taskdata));
1855 if (UNLIKELY(ompt_enabled.enabled && parent != NULL)) {
1856 parent->ompt_task_info.frame.enter_frame = ompt_data_none;
1862 template <
bool ompt>
1863 static kmp_int32 __kmpc_omp_taskwait_template(
ident_t *loc_ref, kmp_int32 gtid,
1864 void *frame_address,
1865 void *return_address) {
1866 kmp_taskdata_t *taskdata =
nullptr;
1868 int thread_finished = FALSE;
1869 KMP_SET_THREAD_STATE_BLOCK(TASKWAIT);
1871 KA_TRACE(10, (
"__kmpc_omp_taskwait(enter): T#%d loc=%p\n", gtid, loc_ref));
1872 KMP_DEBUG_ASSERT(gtid >= 0);
1874 if (__kmp_tasking_mode != tskm_immediate_exec) {
1875 thread = __kmp_threads[gtid];
1876 taskdata = thread->th.th_current_task;
1878 #if OMPT_SUPPORT && OMPT_OPTIONAL
1879 ompt_data_t *my_task_data;
1880 ompt_data_t *my_parallel_data;
1883 my_task_data = &(taskdata->ompt_task_info.task_data);
1884 my_parallel_data = OMPT_CUR_TEAM_DATA(thread);
1886 taskdata->ompt_task_info.frame.enter_frame.ptr = frame_address;
1888 if (ompt_enabled.ompt_callback_sync_region) {
1889 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
1890 ompt_sync_region_taskwait, ompt_scope_begin, my_parallel_data,
1891 my_task_data, return_address);
1894 if (ompt_enabled.ompt_callback_sync_region_wait) {
1895 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
1896 ompt_sync_region_taskwait, ompt_scope_begin, my_parallel_data,
1897 my_task_data, return_address);
1907 taskdata->td_taskwait_counter += 1;
1908 taskdata->td_taskwait_ident = loc_ref;
1909 taskdata->td_taskwait_thread = gtid + 1;
1912 void *itt_sync_obj = NULL;
1914 KMP_ITT_TASKWAIT_STARTING(itt_sync_obj);
1919 !taskdata->td_flags.team_serial && !taskdata->td_flags.final;
1921 must_wait = must_wait || (thread->th.th_task_team != NULL &&
1922 thread->th.th_task_team->tt.tt_found_proxy_tasks);
1926 (__kmp_enable_hidden_helper && thread->th.th_task_team != NULL &&
1927 thread->th.th_task_team->tt.tt_hidden_helper_task_encountered);
1930 kmp_flag_32<false, false> flag(
1931 RCAST(std::atomic<kmp_uint32> *,
1932 &(taskdata->td_incomplete_child_tasks)),
1934 while (KMP_ATOMIC_LD_ACQ(&taskdata->td_incomplete_child_tasks) != 0) {
1935 flag.execute_tasks(thread, gtid, FALSE,
1936 &thread_finished USE_ITT_BUILD_ARG(itt_sync_obj),
1937 __kmp_task_stealing_constraint);
1941 KMP_ITT_TASKWAIT_FINISHED(itt_sync_obj);
1942 KMP_FSYNC_ACQUIRED(taskdata);
1947 taskdata->td_taskwait_thread = -taskdata->td_taskwait_thread;
1949 #if OMPT_SUPPORT && OMPT_OPTIONAL
1951 if (ompt_enabled.ompt_callback_sync_region_wait) {
1952 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
1953 ompt_sync_region_taskwait, ompt_scope_end, my_parallel_data,
1954 my_task_data, return_address);
1956 if (ompt_enabled.ompt_callback_sync_region) {
1957 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
1958 ompt_sync_region_taskwait, ompt_scope_end, my_parallel_data,
1959 my_task_data, return_address);
1961 taskdata->ompt_task_info.frame.enter_frame = ompt_data_none;
1967 KA_TRACE(10, (
"__kmpc_omp_taskwait(exit): T#%d task %p finished waiting, "
1968 "returning TASK_CURRENT_NOT_QUEUED\n",
1971 return TASK_CURRENT_NOT_QUEUED;
1974 #if OMPT_SUPPORT && OMPT_OPTIONAL
1976 static kmp_int32 __kmpc_omp_taskwait_ompt(
ident_t *loc_ref, kmp_int32 gtid,
1977 void *frame_address,
1978 void *return_address) {
1979 return __kmpc_omp_taskwait_template<true>(loc_ref, gtid, frame_address,
1986 kmp_int32 __kmpc_omp_taskwait(
ident_t *loc_ref, kmp_int32 gtid) {
1987 #if OMPT_SUPPORT && OMPT_OPTIONAL
1988 if (UNLIKELY(ompt_enabled.enabled)) {
1989 OMPT_STORE_RETURN_ADDRESS(gtid);
1990 return __kmpc_omp_taskwait_ompt(loc_ref, gtid, OMPT_GET_FRAME_ADDRESS(0),
1991 OMPT_LOAD_RETURN_ADDRESS(gtid));
1994 return __kmpc_omp_taskwait_template<false>(loc_ref, gtid, NULL, NULL);
1998 kmp_int32 __kmpc_omp_taskyield(
ident_t *loc_ref, kmp_int32 gtid,
int end_part) {
1999 kmp_taskdata_t *taskdata = NULL;
2001 int thread_finished = FALSE;
2004 KMP_SET_THREAD_STATE_BLOCK(TASKYIELD);
2006 KA_TRACE(10, (
"__kmpc_omp_taskyield(enter): T#%d loc=%p end_part = %d\n",
2007 gtid, loc_ref, end_part));
2008 __kmp_assert_valid_gtid(gtid);
2010 if (__kmp_tasking_mode != tskm_immediate_exec && __kmp_init_parallel) {
2011 thread = __kmp_threads[gtid];
2012 taskdata = thread->th.th_current_task;
2019 taskdata->td_taskwait_counter += 1;
2020 taskdata->td_taskwait_ident = loc_ref;
2021 taskdata->td_taskwait_thread = gtid + 1;
2024 void *itt_sync_obj = NULL;
2026 KMP_ITT_TASKWAIT_STARTING(itt_sync_obj);
2029 if (!taskdata->td_flags.team_serial) {
2030 kmp_task_team_t *task_team = thread->th.th_task_team;
2031 if (task_team != NULL) {
2032 if (KMP_TASKING_ENABLED(task_team)) {
2034 if (UNLIKELY(ompt_enabled.enabled))
2035 thread->th.ompt_thread_info.ompt_task_yielded = 1;
2037 __kmp_execute_tasks_32(
2038 thread, gtid, (kmp_flag_32<> *)NULL, FALSE,
2039 &thread_finished USE_ITT_BUILD_ARG(itt_sync_obj),
2040 __kmp_task_stealing_constraint);
2042 if (UNLIKELY(ompt_enabled.enabled))
2043 thread->th.ompt_thread_info.ompt_task_yielded = 0;
2049 KMP_ITT_TASKWAIT_FINISHED(itt_sync_obj);
2054 taskdata->td_taskwait_thread = -taskdata->td_taskwait_thread;
2057 KA_TRACE(10, (
"__kmpc_omp_taskyield(exit): T#%d task %p resuming, "
2058 "returning TASK_CURRENT_NOT_QUEUED\n",
2061 return TASK_CURRENT_NOT_QUEUED;
2082 unsigned reserved31 : 31;
2162 template <
typename T>
2163 void *__kmp_task_reduction_init(
int gtid,
int num, T *data) {
2164 __kmp_assert_valid_gtid(gtid);
2165 kmp_info_t *thread = __kmp_threads[gtid];
2166 kmp_taskgroup_t *tg = thread->th.th_current_task->td_taskgroup;
2167 kmp_uint32 nth = thread->th.th_team_nproc;
2171 KMP_ASSERT(tg != NULL);
2172 KMP_ASSERT(data != NULL);
2173 KMP_ASSERT(num > 0);
2175 KA_TRACE(10, (
"__kmpc_task_reduction_init: T#%d, tg %p, exiting nth=1\n",
2179 KA_TRACE(10, (
"__kmpc_task_reduction_init: T#%d, taskgroup %p, #items %d\n",
2183 for (
int i = 0; i < num; ++i) {
2184 size_t size = data[i].reduce_size - 1;
2186 size += CACHE_LINE - size % CACHE_LINE;
2187 KMP_ASSERT(data[i].reduce_comb != NULL);
2190 arr[i].
flags = data[i].flags;
2194 __kmp_assign_orig<T>(arr[i], data[i]);
2195 if (!arr[i].flags.lazy_priv) {
2198 arr[i].
reduce_pend = (
char *)(arr[i].reduce_priv) + nth * size;
2199 if (arr[i].reduce_init != NULL) {
2201 for (
size_t j = 0; j < nth; ++j) {
2202 __kmp_call_init<T>(arr[i], j * size);
2209 arr[i].
reduce_priv = __kmp_allocate(nth *
sizeof(
void *));
2212 tg->reduce_data = (
void *)arr;
2213 tg->reduce_num_data = num;
2252 template <
typename T>
2253 void __kmp_task_reduction_init_copy(kmp_info_t *thr,
int num, T *data,
2254 kmp_taskgroup_t *tg,
void *reduce_data) {
2256 KA_TRACE(20, (
"__kmp_task_reduction_init_copy: Th %p, init taskgroup %p,"
2258 thr, tg, reduce_data));
2263 for (
int i = 0; i < num; ++i) {
2266 tg->reduce_data = (
void *)arr;
2267 tg->reduce_num_data = num;
2280 __kmp_assert_valid_gtid(gtid);
2281 kmp_info_t *thread = __kmp_threads[gtid];
2282 kmp_int32 nth = thread->th.th_team_nproc;
2286 kmp_taskgroup_t *tg = (kmp_taskgroup_t *)tskgrp;
2288 tg = thread->th.th_current_task->td_taskgroup;
2289 KMP_ASSERT(tg != NULL);
2291 kmp_int32 num = tg->reduce_num_data;
2292 kmp_int32 tid = thread->th.th_info.ds.ds_tid;
2294 KMP_ASSERT(data != NULL);
2295 while (tg != NULL) {
2296 for (
int i = 0; i < num; ++i) {
2297 if (!arr[i].flags.lazy_priv) {
2298 if (data == arr[i].reduce_shar ||
2299 (data >= arr[i].reduce_priv && data < arr[i].reduce_pend))
2300 return (
char *)(arr[i].
reduce_priv) + tid * arr[i].reduce_size;
2303 void **p_priv = (
void **)(arr[i].reduce_priv);
2304 if (data == arr[i].reduce_shar)
2307 for (
int j = 0; j < nth; ++j)
2308 if (data == p_priv[j])
2312 if (p_priv[tid] == NULL) {
2314 p_priv[tid] = __kmp_allocate(arr[i].reduce_size);
2315 if (arr[i].reduce_init != NULL) {
2316 if (arr[i].reduce_orig != NULL) {
2318 p_priv[tid], arr[i].reduce_orig);
2320 ((void (*)(
void *))arr[i].
reduce_init)(p_priv[tid]);
2329 num = tg->reduce_num_data;
2331 KMP_ASSERT2(0,
"Unknown task reduction item");
2337 static void __kmp_task_reduction_fini(kmp_info_t *th, kmp_taskgroup_t *tg) {
2338 kmp_int32 nth = th->th.th_team_nproc;
2339 KMP_DEBUG_ASSERT(nth > 1);
2341 kmp_int32 num = tg->reduce_num_data;
2342 for (
int i = 0; i < num; ++i) {
2344 void (*f_fini)(
void *) = (
void (*)(
void *))(arr[i].
reduce_fini);
2345 void (*f_comb)(
void *,
void *) =
2347 if (!arr[i].flags.lazy_priv) {
2350 for (
int j = 0; j < nth; ++j) {
2351 void *priv_data = (
char *)pr_data + j * size;
2352 f_comb(sh_data, priv_data);
2357 void **pr_data = (
void **)(arr[i].reduce_priv);
2358 for (
int j = 0; j < nth; ++j) {
2359 if (pr_data[j] != NULL) {
2360 f_comb(sh_data, pr_data[j]);
2363 __kmp_free(pr_data[j]);
2367 __kmp_free(arr[i].reduce_priv);
2369 __kmp_thread_free(th, arr);
2370 tg->reduce_data = NULL;
2371 tg->reduce_num_data = 0;
2377 static void __kmp_task_reduction_clean(kmp_info_t *th, kmp_taskgroup_t *tg) {
2378 __kmp_thread_free(th, tg->reduce_data);
2379 tg->reduce_data = NULL;
2380 tg->reduce_num_data = 0;
2383 template <
typename T>
2384 void *__kmp_task_reduction_modifier_init(
ident_t *loc,
int gtid,
int is_ws,
2386 __kmp_assert_valid_gtid(gtid);
2387 kmp_info_t *thr = __kmp_threads[gtid];
2388 kmp_int32 nth = thr->th.th_team_nproc;
2389 __kmpc_taskgroup(loc, gtid);
2392 (
"__kmpc_reduction_modifier_init: T#%d, tg %p, exiting nth=1\n",
2393 gtid, thr->th.th_current_task->td_taskgroup));
2394 return (
void *)thr->th.th_current_task->td_taskgroup;
2396 kmp_team_t *team = thr->th.th_team;
2398 kmp_taskgroup_t *tg;
2399 reduce_data = KMP_ATOMIC_LD_RLX(&team->t.t_tg_reduce_data[is_ws]);
2400 if (reduce_data == NULL &&
2401 __kmp_atomic_compare_store(&team->t.t_tg_reduce_data[is_ws], reduce_data,
2404 KMP_DEBUG_ASSERT(reduce_data == NULL);
2406 tg = (kmp_taskgroup_t *)__kmp_task_reduction_init<T>(gtid, num, data);
2410 KMP_DEBUG_ASSERT(KMP_ATOMIC_LD_RLX(&team->t.t_tg_fini_counter[0]) == 0);
2411 KMP_DEBUG_ASSERT(KMP_ATOMIC_LD_RLX(&team->t.t_tg_fini_counter[1]) == 0);
2412 KMP_ATOMIC_ST_REL(&team->t.t_tg_reduce_data[is_ws], reduce_data);
2415 (reduce_data = KMP_ATOMIC_LD_ACQ(&team->t.t_tg_reduce_data[is_ws])) ==
2419 KMP_DEBUG_ASSERT(reduce_data > (
void *)1);
2420 tg = thr->th.th_current_task->td_taskgroup;
2421 __kmp_task_reduction_init_copy<T>(thr, num, data, tg, reduce_data);
2443 int num,
void *data) {
2444 return __kmp_task_reduction_modifier_init(loc, gtid, is_ws, num,
2464 return __kmp_task_reduction_modifier_init(loc, gtid, is_ws, num,
2477 __kmpc_end_taskgroup(loc, gtid);
2481 void __kmpc_taskgroup(
ident_t *loc,
int gtid) {
2482 __kmp_assert_valid_gtid(gtid);
2483 kmp_info_t *thread = __kmp_threads[gtid];
2484 kmp_taskdata_t *taskdata = thread->th.th_current_task;
2485 kmp_taskgroup_t *tg_new =
2486 (kmp_taskgroup_t *)__kmp_thread_malloc(thread,
sizeof(kmp_taskgroup_t));
2487 KA_TRACE(10, (
"__kmpc_taskgroup: T#%d loc=%p group=%p\n", gtid, loc, tg_new));
2488 KMP_ATOMIC_ST_RLX(&tg_new->count, 0);
2489 KMP_ATOMIC_ST_RLX(&tg_new->cancel_request, cancel_noreq);
2490 tg_new->parent = taskdata->td_taskgroup;
2491 tg_new->reduce_data = NULL;
2492 tg_new->reduce_num_data = 0;
2493 tg_new->gomp_data = NULL;
2494 taskdata->td_taskgroup = tg_new;
2496 #if OMPT_SUPPORT && OMPT_OPTIONAL
2497 if (UNLIKELY(ompt_enabled.ompt_callback_sync_region)) {
2498 void *codeptr = OMPT_LOAD_RETURN_ADDRESS(gtid);
2500 codeptr = OMPT_GET_RETURN_ADDRESS(0);
2501 kmp_team_t *team = thread->th.th_team;
2502 ompt_data_t my_task_data = taskdata->ompt_task_info.task_data;
2504 ompt_data_t my_parallel_data = team->t.ompt_team_info.parallel_data;
2506 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2507 ompt_sync_region_taskgroup, ompt_scope_begin, &(my_parallel_data),
2508 &(my_task_data), codeptr);
2515 void __kmpc_end_taskgroup(
ident_t *loc,
int gtid) {
2516 __kmp_assert_valid_gtid(gtid);
2517 kmp_info_t *thread = __kmp_threads[gtid];
2518 kmp_taskdata_t *taskdata = thread->th.th_current_task;
2519 kmp_taskgroup_t *taskgroup = taskdata->td_taskgroup;
2520 int thread_finished = FALSE;
2522 #if OMPT_SUPPORT && OMPT_OPTIONAL
2524 ompt_data_t my_task_data;
2525 ompt_data_t my_parallel_data;
2526 void *codeptr =
nullptr;
2527 if (UNLIKELY(ompt_enabled.enabled)) {
2528 team = thread->th.th_team;
2529 my_task_data = taskdata->ompt_task_info.task_data;
2531 my_parallel_data = team->t.ompt_team_info.parallel_data;
2532 codeptr = OMPT_LOAD_RETURN_ADDRESS(gtid);
2534 codeptr = OMPT_GET_RETURN_ADDRESS(0);
2538 KA_TRACE(10, (
"__kmpc_end_taskgroup(enter): T#%d loc=%p\n", gtid, loc));
2539 KMP_DEBUG_ASSERT(taskgroup != NULL);
2540 KMP_SET_THREAD_STATE_BLOCK(TASKGROUP);
2542 if (__kmp_tasking_mode != tskm_immediate_exec) {
2544 taskdata->td_taskwait_counter += 1;
2545 taskdata->td_taskwait_ident = loc;
2546 taskdata->td_taskwait_thread = gtid + 1;
2550 void *itt_sync_obj = NULL;
2552 KMP_ITT_TASKWAIT_STARTING(itt_sync_obj);
2556 #if OMPT_SUPPORT && OMPT_OPTIONAL
2557 if (UNLIKELY(ompt_enabled.ompt_callback_sync_region_wait)) {
2558 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2559 ompt_sync_region_taskgroup, ompt_scope_begin, &(my_parallel_data),
2560 &(my_task_data), codeptr);
2564 if (!taskdata->td_flags.team_serial ||
2565 (thread->th.th_task_team != NULL &&
2566 thread->th.th_task_team->tt.tt_found_proxy_tasks)) {
2567 kmp_flag_32<false, false> flag(
2568 RCAST(std::atomic<kmp_uint32> *, &(taskgroup->count)), 0U);
2569 while (KMP_ATOMIC_LD_ACQ(&taskgroup->count) != 0) {
2570 flag.execute_tasks(thread, gtid, FALSE,
2571 &thread_finished USE_ITT_BUILD_ARG(itt_sync_obj),
2572 __kmp_task_stealing_constraint);
2575 taskdata->td_taskwait_thread = -taskdata->td_taskwait_thread;
2577 #if OMPT_SUPPORT && OMPT_OPTIONAL
2578 if (UNLIKELY(ompt_enabled.ompt_callback_sync_region_wait)) {
2579 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
2580 ompt_sync_region_taskgroup, ompt_scope_end, &(my_parallel_data),
2581 &(my_task_data), codeptr);
2586 KMP_ITT_TASKWAIT_FINISHED(itt_sync_obj);
2587 KMP_FSYNC_ACQUIRED(taskdata);
2590 KMP_DEBUG_ASSERT(taskgroup->count == 0);
2592 if (taskgroup->reduce_data != NULL &&
2593 !taskgroup->gomp_data) {
2596 kmp_team_t *t = thread->th.th_team;
2600 if ((reduce_data = KMP_ATOMIC_LD_ACQ(&t->t.t_tg_reduce_data[0])) != NULL &&
2603 cnt = KMP_ATOMIC_INC(&t->t.t_tg_fini_counter[0]);
2604 if (cnt == thread->th.th_team_nproc - 1) {
2607 __kmp_task_reduction_fini(thread, taskgroup);
2610 __kmp_thread_free(thread, reduce_data);
2611 KMP_ATOMIC_ST_REL(&t->t.t_tg_reduce_data[0], NULL);
2612 KMP_ATOMIC_ST_REL(&t->t.t_tg_fini_counter[0], 0);
2616 __kmp_task_reduction_clean(thread, taskgroup);
2618 }
else if ((reduce_data = KMP_ATOMIC_LD_ACQ(&t->t.t_tg_reduce_data[1])) !=
2622 cnt = KMP_ATOMIC_INC(&t->t.t_tg_fini_counter[1]);
2623 if (cnt == thread->th.th_team_nproc - 1) {
2625 __kmp_task_reduction_fini(thread, taskgroup);
2628 __kmp_thread_free(thread, reduce_data);
2629 KMP_ATOMIC_ST_REL(&t->t.t_tg_reduce_data[1], NULL);
2630 KMP_ATOMIC_ST_REL(&t->t.t_tg_fini_counter[1], 0);
2634 __kmp_task_reduction_clean(thread, taskgroup);
2638 __kmp_task_reduction_fini(thread, taskgroup);
2642 taskdata->td_taskgroup = taskgroup->parent;
2643 __kmp_thread_free(thread, taskgroup);
2645 KA_TRACE(10, (
"__kmpc_end_taskgroup(exit): T#%d task %p finished waiting\n",
2648 #if OMPT_SUPPORT && OMPT_OPTIONAL
2649 if (UNLIKELY(ompt_enabled.ompt_callback_sync_region)) {
2650 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
2651 ompt_sync_region_taskgroup, ompt_scope_end, &(my_parallel_data),
2652 &(my_task_data), codeptr);
2658 static kmp_task_t *__kmp_remove_my_task(kmp_info_t *thread, kmp_int32 gtid,
2659 kmp_task_team_t *task_team,
2660 kmp_int32 is_constrained) {
2662 kmp_taskdata_t *taskdata;
2663 kmp_thread_data_t *thread_data;
2666 KMP_DEBUG_ASSERT(__kmp_tasking_mode != tskm_immediate_exec);
2667 KMP_DEBUG_ASSERT(task_team->tt.tt_threads_data !=
2670 thread_data = &task_team->tt.tt_threads_data[__kmp_tid_from_gtid(gtid)];
2672 KA_TRACE(10, (
"__kmp_remove_my_task(enter): T#%d ntasks=%d head=%u tail=%u\n",
2673 gtid, thread_data->td.td_deque_ntasks,
2674 thread_data->td.td_deque_head, thread_data->td.td_deque_tail));
2676 if (TCR_4(thread_data->td.td_deque_ntasks) == 0) {
2678 (
"__kmp_remove_my_task(exit #1): T#%d No tasks to remove: "
2679 "ntasks=%d head=%u tail=%u\n",
2680 gtid, thread_data->td.td_deque_ntasks,
2681 thread_data->td.td_deque_head, thread_data->td.td_deque_tail));
2685 __kmp_acquire_bootstrap_lock(&thread_data->td.td_deque_lock);
2687 if (TCR_4(thread_data->td.td_deque_ntasks) == 0) {
2688 __kmp_release_bootstrap_lock(&thread_data->td.td_deque_lock);
2690 (
"__kmp_remove_my_task(exit #2): T#%d No tasks to remove: "
2691 "ntasks=%d head=%u tail=%u\n",
2692 gtid, thread_data->td.td_deque_ntasks,
2693 thread_data->td.td_deque_head, thread_data->td.td_deque_tail));
2697 tail = (thread_data->td.td_deque_tail - 1) &
2698 TASK_DEQUE_MASK(thread_data->td);
2699 taskdata = thread_data->td.td_deque[tail];
2701 if (!__kmp_task_is_allowed(gtid, is_constrained, taskdata,
2702 thread->th.th_current_task)) {
2704 __kmp_release_bootstrap_lock(&thread_data->td.td_deque_lock);
2706 (
"__kmp_remove_my_task(exit #3): T#%d TSC blocks tail task: "
2707 "ntasks=%d head=%u tail=%u\n",
2708 gtid, thread_data->td.td_deque_ntasks,
2709 thread_data->td.td_deque_head, thread_data->td.td_deque_tail));
2713 thread_data->td.td_deque_tail = tail;
2714 TCW_4(thread_data->td.td_deque_ntasks, thread_data->td.td_deque_ntasks - 1);
2716 __kmp_release_bootstrap_lock(&thread_data->td.td_deque_lock);
2718 KA_TRACE(10, (
"__kmp_remove_my_task(exit #4): T#%d task %p removed: "
2719 "ntasks=%d head=%u tail=%u\n",
2720 gtid, taskdata, thread_data->td.td_deque_ntasks,
2721 thread_data->td.td_deque_head, thread_data->td.td_deque_tail));
2723 task = KMP_TASKDATA_TO_TASK(taskdata);
2730 static kmp_task_t *__kmp_steal_task(kmp_info_t *victim_thr, kmp_int32 gtid,
2731 kmp_task_team_t *task_team,
2732 std::atomic<kmp_int32> *unfinished_threads,
2733 int *thread_finished,
2734 kmp_int32 is_constrained) {
2736 kmp_taskdata_t *taskdata;
2737 kmp_taskdata_t *current;
2738 kmp_thread_data_t *victim_td, *threads_data;
2740 kmp_int32 victim_tid;
2742 KMP_DEBUG_ASSERT(__kmp_tasking_mode != tskm_immediate_exec);
2744 threads_data = task_team->tt.tt_threads_data;
2745 KMP_DEBUG_ASSERT(threads_data != NULL);
2747 victim_tid = victim_thr->th.th_info.ds.ds_tid;
2748 victim_td = &threads_data[victim_tid];
2750 KA_TRACE(10, (
"__kmp_steal_task(enter): T#%d try to steal from T#%d: "
2751 "task_team=%p ntasks=%d head=%u tail=%u\n",
2752 gtid, __kmp_gtid_from_thread(victim_thr), task_team,
2753 victim_td->td.td_deque_ntasks, victim_td->td.td_deque_head,
2754 victim_td->td.td_deque_tail));
2756 if (TCR_4(victim_td->td.td_deque_ntasks) == 0) {
2757 KA_TRACE(10, (
"__kmp_steal_task(exit #1): T#%d could not steal from T#%d: "
2758 "task_team=%p ntasks=%d head=%u tail=%u\n",
2759 gtid, __kmp_gtid_from_thread(victim_thr), task_team,
2760 victim_td->td.td_deque_ntasks, victim_td->td.td_deque_head,
2761 victim_td->td.td_deque_tail));
2765 __kmp_acquire_bootstrap_lock(&victim_td->td.td_deque_lock);
2767 int ntasks = TCR_4(victim_td->td.td_deque_ntasks);
2770 __kmp_release_bootstrap_lock(&victim_td->td.td_deque_lock);
2771 KA_TRACE(10, (
"__kmp_steal_task(exit #2): T#%d could not steal from T#%d: "
2772 "task_team=%p ntasks=%d head=%u tail=%u\n",
2773 gtid, __kmp_gtid_from_thread(victim_thr), task_team, ntasks,
2774 victim_td->td.td_deque_head, victim_td->td.td_deque_tail));
2778 KMP_DEBUG_ASSERT(victim_td->td.td_deque != NULL);
2779 current = __kmp_threads[gtid]->th.th_current_task;
2780 taskdata = victim_td->td.td_deque[victim_td->td.td_deque_head];
2781 if (__kmp_task_is_allowed(gtid, is_constrained, taskdata, current)) {
2783 victim_td->td.td_deque_head =
2784 (victim_td->td.td_deque_head + 1) & TASK_DEQUE_MASK(victim_td->td);
2786 if (!task_team->tt.tt_untied_task_encountered) {
2788 __kmp_release_bootstrap_lock(&victim_td->td.td_deque_lock);
2789 KA_TRACE(10, (
"__kmp_steal_task(exit #3): T#%d could not steal from "
2790 "T#%d: task_team=%p ntasks=%d head=%u tail=%u\n",
2791 gtid, __kmp_gtid_from_thread(victim_thr), task_team, ntasks,
2792 victim_td->td.td_deque_head, victim_td->td.td_deque_tail));
2797 target = victim_td->td.td_deque_head;
2799 for (i = 1; i < ntasks; ++i) {
2800 target = (target + 1) & TASK_DEQUE_MASK(victim_td->td);
2801 taskdata = victim_td->td.td_deque[target];
2802 if (__kmp_task_is_allowed(gtid, is_constrained, taskdata, current)) {
2808 if (taskdata == NULL) {
2810 __kmp_release_bootstrap_lock(&victim_td->td.td_deque_lock);
2811 KA_TRACE(10, (
"__kmp_steal_task(exit #4): T#%d could not steal from "
2812 "T#%d: task_team=%p ntasks=%d head=%u tail=%u\n",
2813 gtid, __kmp_gtid_from_thread(victim_thr), task_team, ntasks,
2814 victim_td->td.td_deque_head, victim_td->td.td_deque_tail));
2818 for (i = i + 1; i < ntasks; ++i) {
2820 target = (target + 1) & TASK_DEQUE_MASK(victim_td->td);
2821 victim_td->td.td_deque[prev] = victim_td->td.td_deque[target];
2825 victim_td->td.td_deque_tail ==
2826 (kmp_uint32)((target + 1) & TASK_DEQUE_MASK(victim_td->td)));
2827 victim_td->td.td_deque_tail = target;
2829 if (*thread_finished) {
2835 count = KMP_ATOMIC_INC(unfinished_threads);
2839 (
"__kmp_steal_task: T#%d inc unfinished_threads to %d: task_team=%p\n",
2840 gtid, count + 1, task_team));
2842 *thread_finished = FALSE;
2844 TCW_4(victim_td->td.td_deque_ntasks, ntasks - 1);
2846 __kmp_release_bootstrap_lock(&victim_td->td.td_deque_lock);
2850 (
"__kmp_steal_task(exit #5): T#%d stole task %p from T#%d: "
2851 "task_team=%p ntasks=%d head=%u tail=%u\n",
2852 gtid, taskdata, __kmp_gtid_from_thread(victim_thr), task_team,
2853 ntasks, victim_td->td.td_deque_head, victim_td->td.td_deque_tail));
2855 task = KMP_TASKDATA_TO_TASK(taskdata);
2869 static inline int __kmp_execute_tasks_template(
2870 kmp_info_t *thread, kmp_int32 gtid, C *flag,
int final_spin,
2871 int *thread_finished USE_ITT_BUILD_ARG(
void *itt_sync_obj),
2872 kmp_int32 is_constrained) {
2873 kmp_task_team_t *task_team = thread->th.th_task_team;
2874 kmp_thread_data_t *threads_data;
2876 kmp_info_t *other_thread;
2877 kmp_taskdata_t *current_task = thread->th.th_current_task;
2878 std::atomic<kmp_int32> *unfinished_threads;
2879 kmp_int32 nthreads, victim_tid = -2, use_own_tasks = 1, new_victim = 0,
2880 tid = thread->th.th_info.ds.ds_tid;
2882 KMP_DEBUG_ASSERT(__kmp_tasking_mode != tskm_immediate_exec);
2883 KMP_DEBUG_ASSERT(thread == __kmp_threads[gtid]);
2885 if (task_team == NULL || current_task == NULL)
2888 KA_TRACE(15, (
"__kmp_execute_tasks_template(enter): T#%d final_spin=%d "
2889 "*thread_finished=%d\n",
2890 gtid, final_spin, *thread_finished));
2892 thread->th.th_reap_state = KMP_NOT_SAFE_TO_REAP;
2893 threads_data = (kmp_thread_data_t *)TCR_PTR(task_team->tt.tt_threads_data);
2895 KMP_DEBUG_ASSERT(threads_data != NULL);
2897 nthreads = task_team->tt.tt_nproc;
2898 unfinished_threads = &(task_team->tt.tt_unfinished_threads);
2899 KMP_DEBUG_ASSERT(nthreads > 1 || task_team->tt.tt_found_proxy_tasks ||
2900 task_team->tt.tt_hidden_helper_task_encountered);
2901 KMP_DEBUG_ASSERT(*unfinished_threads >= 0);
2907 if (use_own_tasks) {
2908 task = __kmp_remove_my_task(thread, gtid, task_team, is_constrained);
2910 if ((task == NULL) && (nthreads > 1)) {
2914 if (victim_tid == -2) {
2915 victim_tid = threads_data[tid].td.td_deque_last_stolen;
2918 other_thread = threads_data[victim_tid].td.td_thr;
2920 if (victim_tid != -1) {
2922 }
else if (!new_victim) {
2928 victim_tid = __kmp_get_random(thread) % (nthreads - 1);
2929 if (victim_tid >= tid) {
2933 other_thread = threads_data[victim_tid].td.td_thr;
2943 if ((__kmp_tasking_mode == tskm_task_teams) &&
2944 (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) &&
2945 (TCR_PTR(CCAST(
void *, other_thread->th.th_sleep_loc)) !=
2948 __kmp_null_resume_wrapper(__kmp_gtid_from_thread(other_thread),
2949 other_thread->th.th_sleep_loc);
2962 task = __kmp_steal_task(other_thread, gtid, task_team,
2963 unfinished_threads, thread_finished,
2967 if (threads_data[tid].td.td_deque_last_stolen != victim_tid) {
2968 threads_data[tid].td.td_deque_last_stolen = victim_tid;
2975 KMP_CHECK_UPDATE(threads_data[tid].td.td_deque_last_stolen, -1);
2984 #if USE_ITT_BUILD && USE_ITT_NOTIFY
2985 if (__itt_sync_create_ptr || KMP_ITT_DEBUG) {
2986 if (itt_sync_obj == NULL) {
2988 itt_sync_obj = __kmp_itt_barrier_object(gtid, bs_forkjoin_barrier);
2990 __kmp_itt_task_starting(itt_sync_obj);
2993 __kmp_invoke_task(gtid, task, current_task);
2995 if (itt_sync_obj != NULL)
2996 __kmp_itt_task_finished(itt_sync_obj);
3003 if (flag == NULL || (!final_spin && flag->done_check())) {
3006 (
"__kmp_execute_tasks_template: T#%d spin condition satisfied\n",
3010 if (thread->th.th_task_team == NULL) {
3013 KMP_YIELD(__kmp_library == library_throughput);
3016 if (!use_own_tasks && TCR_4(threads_data[tid].td.td_deque_ntasks) != 0) {
3017 KA_TRACE(20, (
"__kmp_execute_tasks_template: T#%d stolen task spawned "
3018 "other tasks, restart\n",
3029 KMP_ATOMIC_LD_ACQ(¤t_task->td_incomplete_child_tasks) == 0) {
3033 if (!*thread_finished) {
3036 count = KMP_ATOMIC_DEC(unfinished_threads) - 1;
3037 KA_TRACE(20, (
"__kmp_execute_tasks_template: T#%d dec "
3038 "unfinished_threads to %d task_team=%p\n",
3039 gtid, count, task_team));
3040 *thread_finished = TRUE;
3048 if (flag != NULL && flag->done_check()) {
3051 (
"__kmp_execute_tasks_template: T#%d spin condition satisfied\n",
3059 if (thread->th.th_task_team == NULL) {
3061 (
"__kmp_execute_tasks_template: T#%d no more tasks\n", gtid));
3067 if (nthreads == 1 &&
3068 KMP_ATOMIC_LD_ACQ(¤t_task->td_incomplete_child_tasks))
3072 (
"__kmp_execute_tasks_template: T#%d can't find work\n", gtid));
3078 template <
bool C,
bool S>
3079 int __kmp_execute_tasks_32(
3080 kmp_info_t *thread, kmp_int32 gtid, kmp_flag_32<C, S> *flag,
int final_spin,
3081 int *thread_finished USE_ITT_BUILD_ARG(
void *itt_sync_obj),
3082 kmp_int32 is_constrained) {
3083 return __kmp_execute_tasks_template(
3084 thread, gtid, flag, final_spin,
3085 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
3088 template <
bool C,
bool S>
3089 int __kmp_execute_tasks_64(
3090 kmp_info_t *thread, kmp_int32 gtid, kmp_flag_64<C, S> *flag,
int final_spin,
3091 int *thread_finished USE_ITT_BUILD_ARG(
void *itt_sync_obj),
3092 kmp_int32 is_constrained) {
3093 return __kmp_execute_tasks_template(
3094 thread, gtid, flag, final_spin,
3095 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
3098 int __kmp_execute_tasks_oncore(
3099 kmp_info_t *thread, kmp_int32 gtid, kmp_flag_oncore *flag,
int final_spin,
3100 int *thread_finished USE_ITT_BUILD_ARG(
void *itt_sync_obj),
3101 kmp_int32 is_constrained) {
3102 return __kmp_execute_tasks_template(
3103 thread, gtid, flag, final_spin,
3104 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
3108 __kmp_execute_tasks_32<false, false>(kmp_info_t *, kmp_int32,
3109 kmp_flag_32<false, false> *,
int,
3110 int *USE_ITT_BUILD_ARG(
void *), kmp_int32);
3112 template int __kmp_execute_tasks_64<false, true>(kmp_info_t *, kmp_int32,
3113 kmp_flag_64<false, true> *,
3115 int *USE_ITT_BUILD_ARG(
void *),
3118 template int __kmp_execute_tasks_64<true, false>(kmp_info_t *, kmp_int32,
3119 kmp_flag_64<true, false> *,
3121 int *USE_ITT_BUILD_ARG(
void *),
3127 static void __kmp_enable_tasking(kmp_task_team_t *task_team,
3128 kmp_info_t *this_thr) {
3129 kmp_thread_data_t *threads_data;
3130 int nthreads, i, is_init_thread;
3132 KA_TRACE(10, (
"__kmp_enable_tasking(enter): T#%d\n",
3133 __kmp_gtid_from_thread(this_thr)));
3135 KMP_DEBUG_ASSERT(task_team != NULL);
3136 KMP_DEBUG_ASSERT(this_thr->th.th_team != NULL);
3138 nthreads = task_team->tt.tt_nproc;
3139 KMP_DEBUG_ASSERT(nthreads > 0);
3140 KMP_DEBUG_ASSERT(nthreads == this_thr->th.th_team->t.t_nproc);
3143 is_init_thread = __kmp_realloc_task_threads_data(this_thr, task_team);
3145 if (!is_init_thread) {
3149 (
"__kmp_enable_tasking(exit): T#%d: threads array already set up.\n",
3150 __kmp_gtid_from_thread(this_thr)));
3153 threads_data = (kmp_thread_data_t *)TCR_PTR(task_team->tt.tt_threads_data);
3154 KMP_DEBUG_ASSERT(threads_data != NULL);
3156 if (__kmp_tasking_mode == tskm_task_teams &&
3157 (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME)) {
3161 for (i = 0; i < nthreads; i++) {
3162 volatile void *sleep_loc;
3163 kmp_info_t *thread = threads_data[i].td.td_thr;
3165 if (i == this_thr->th.th_info.ds.ds_tid) {
3174 if ((sleep_loc = TCR_PTR(CCAST(
void *, thread->th.th_sleep_loc))) !=
3176 KF_TRACE(50, (
"__kmp_enable_tasking: T#%d waking up thread T#%d\n",
3177 __kmp_gtid_from_thread(this_thr),
3178 __kmp_gtid_from_thread(thread)));
3179 __kmp_null_resume_wrapper(__kmp_gtid_from_thread(thread), sleep_loc);
3181 KF_TRACE(50, (
"__kmp_enable_tasking: T#%d don't wake up thread T#%d\n",
3182 __kmp_gtid_from_thread(this_thr),
3183 __kmp_gtid_from_thread(thread)));
3188 KA_TRACE(10, (
"__kmp_enable_tasking(exit): T#%d\n",
3189 __kmp_gtid_from_thread(this_thr)));
3222 static kmp_task_team_t *__kmp_free_task_teams =
3225 kmp_bootstrap_lock_t __kmp_task_team_lock =
3226 KMP_BOOTSTRAP_LOCK_INITIALIZER(__kmp_task_team_lock);
3233 static void __kmp_alloc_task_deque(kmp_info_t *thread,
3234 kmp_thread_data_t *thread_data) {
3235 __kmp_init_bootstrap_lock(&thread_data->td.td_deque_lock);
3236 KMP_DEBUG_ASSERT(thread_data->td.td_deque == NULL);
3239 thread_data->td.td_deque_last_stolen = -1;
3241 KMP_DEBUG_ASSERT(TCR_4(thread_data->td.td_deque_ntasks) == 0);
3242 KMP_DEBUG_ASSERT(thread_data->td.td_deque_head == 0);
3243 KMP_DEBUG_ASSERT(thread_data->td.td_deque_tail == 0);
3247 (
"__kmp_alloc_task_deque: T#%d allocating deque[%d] for thread_data %p\n",
3248 __kmp_gtid_from_thread(thread), INITIAL_TASK_DEQUE_SIZE, thread_data));
3252 thread_data->td.td_deque = (kmp_taskdata_t **)__kmp_allocate(
3253 INITIAL_TASK_DEQUE_SIZE *
sizeof(kmp_taskdata_t *));
3254 thread_data->td.td_deque_size = INITIAL_TASK_DEQUE_SIZE;
3260 static void __kmp_free_task_deque(kmp_thread_data_t *thread_data) {
3261 if (thread_data->td.td_deque != NULL) {
3262 __kmp_acquire_bootstrap_lock(&thread_data->td.td_deque_lock);
3263 TCW_4(thread_data->td.td_deque_ntasks, 0);
3264 __kmp_free(thread_data->td.td_deque);
3265 thread_data->td.td_deque = NULL;
3266 __kmp_release_bootstrap_lock(&thread_data->td.td_deque_lock);
3269 #ifdef BUILD_TIED_TASK_STACK
3271 if (thread_data->td.td_susp_tied_tasks.ts_entries != TASK_STACK_EMPTY) {
3272 __kmp_free_task_stack(__kmp_thread_from_gtid(gtid), thread_data);
3284 static int __kmp_realloc_task_threads_data(kmp_info_t *thread,
3285 kmp_task_team_t *task_team) {
3286 kmp_thread_data_t **threads_data_p;
3287 kmp_int32 nthreads, maxthreads;
3288 int is_init_thread = FALSE;
3290 if (TCR_4(task_team->tt.tt_found_tasks)) {
3295 threads_data_p = &task_team->tt.tt_threads_data;
3296 nthreads = task_team->tt.tt_nproc;
3297 maxthreads = task_team->tt.tt_max_threads;
3302 __kmp_acquire_bootstrap_lock(&task_team->tt.tt_threads_lock);
3304 if (!TCR_4(task_team->tt.tt_found_tasks)) {
3306 kmp_team_t *team = thread->th.th_team;
3309 is_init_thread = TRUE;
3310 if (maxthreads < nthreads) {
3312 if (*threads_data_p != NULL) {
3313 kmp_thread_data_t *old_data = *threads_data_p;
3314 kmp_thread_data_t *new_data = NULL;
3318 (
"__kmp_realloc_task_threads_data: T#%d reallocating "
3319 "threads data for task_team %p, new_size = %d, old_size = %d\n",
3320 __kmp_gtid_from_thread(thread), task_team, nthreads, maxthreads));
3325 new_data = (kmp_thread_data_t *)__kmp_allocate(
3326 nthreads *
sizeof(kmp_thread_data_t));
3328 KMP_MEMCPY_S((
void *)new_data, nthreads *
sizeof(kmp_thread_data_t),
3329 (
void *)old_data, maxthreads *
sizeof(kmp_thread_data_t));
3331 #ifdef BUILD_TIED_TASK_STACK
3333 for (i = maxthreads; i < nthreads; i++) {
3334 kmp_thread_data_t *thread_data = &(*threads_data_p)[i];
3335 __kmp_init_task_stack(__kmp_gtid_from_thread(thread), thread_data);
3339 (*threads_data_p) = new_data;
3340 __kmp_free(old_data);
3342 KE_TRACE(10, (
"__kmp_realloc_task_threads_data: T#%d allocating "
3343 "threads data for task_team %p, size = %d\n",
3344 __kmp_gtid_from_thread(thread), task_team, nthreads));
3348 *threads_data_p = (kmp_thread_data_t *)__kmp_allocate(
3349 nthreads *
sizeof(kmp_thread_data_t));
3350 #ifdef BUILD_TIED_TASK_STACK
3352 for (i = 0; i < nthreads; i++) {
3353 kmp_thread_data_t *thread_data = &(*threads_data_p)[i];
3354 __kmp_init_task_stack(__kmp_gtid_from_thread(thread), thread_data);
3358 task_team->tt.tt_max_threads = nthreads;
3361 KMP_DEBUG_ASSERT(*threads_data_p != NULL);
3365 for (i = 0; i < nthreads; i++) {
3366 kmp_thread_data_t *thread_data = &(*threads_data_p)[i];
3367 thread_data->td.td_thr = team->t.t_threads[i];
3369 if (thread_data->td.td_deque_last_stolen >= nthreads) {
3373 thread_data->td.td_deque_last_stolen = -1;
3378 TCW_SYNC_4(task_team->tt.tt_found_tasks, TRUE);
3381 __kmp_release_bootstrap_lock(&task_team->tt.tt_threads_lock);
3382 return is_init_thread;
3388 static void __kmp_free_task_threads_data(kmp_task_team_t *task_team) {
3389 __kmp_acquire_bootstrap_lock(&task_team->tt.tt_threads_lock);
3390 if (task_team->tt.tt_threads_data != NULL) {
3392 for (i = 0; i < task_team->tt.tt_max_threads; i++) {
3393 __kmp_free_task_deque(&task_team->tt.tt_threads_data[i]);
3395 __kmp_free(task_team->tt.tt_threads_data);
3396 task_team->tt.tt_threads_data = NULL;
3398 __kmp_release_bootstrap_lock(&task_team->tt.tt_threads_lock);
3405 static kmp_task_team_t *__kmp_allocate_task_team(kmp_info_t *thread,
3407 kmp_task_team_t *task_team = NULL;
3410 KA_TRACE(20, (
"__kmp_allocate_task_team: T#%d entering; team = %p\n",
3411 (thread ? __kmp_gtid_from_thread(thread) : -1), team));
3413 if (TCR_PTR(__kmp_free_task_teams) != NULL) {
3415 __kmp_acquire_bootstrap_lock(&__kmp_task_team_lock);
3416 if (__kmp_free_task_teams != NULL) {
3417 task_team = __kmp_free_task_teams;
3418 TCW_PTR(__kmp_free_task_teams, task_team->tt.tt_next);
3419 task_team->tt.tt_next = NULL;
3421 __kmp_release_bootstrap_lock(&__kmp_task_team_lock);
3424 if (task_team == NULL) {
3425 KE_TRACE(10, (
"__kmp_allocate_task_team: T#%d allocating "
3426 "task team for team %p\n",
3427 __kmp_gtid_from_thread(thread), team));
3430 task_team = (kmp_task_team_t *)__kmp_allocate(
sizeof(kmp_task_team_t));
3431 __kmp_init_bootstrap_lock(&task_team->tt.tt_threads_lock);
3432 #if USE_ITT_BUILD && USE_ITT_NOTIFY && KMP_DEBUG
3435 __itt_suppress_mark_range(
3436 __itt_suppress_range, __itt_suppress_threading_errors,
3437 &task_team->tt.tt_found_tasks,
sizeof(task_team->tt.tt_found_tasks));
3438 __itt_suppress_mark_range(__itt_suppress_range,
3439 __itt_suppress_threading_errors,
3440 CCAST(kmp_uint32 *, &task_team->tt.tt_active),
3441 sizeof(task_team->tt.tt_active));
3449 TCW_4(task_team->tt.tt_found_tasks, FALSE);
3450 TCW_4(task_team->tt.tt_found_proxy_tasks, FALSE);
3451 task_team->tt.tt_nproc = nthreads = team->t.t_nproc;
3453 KMP_ATOMIC_ST_REL(&task_team->tt.tt_unfinished_threads, nthreads);
3454 TCW_4(task_team->tt.tt_hidden_helper_task_encountered, FALSE);
3455 TCW_4(task_team->tt.tt_active, TRUE);
3457 KA_TRACE(20, (
"__kmp_allocate_task_team: T#%d exiting; task_team = %p "
3458 "unfinished_threads init'd to %d\n",
3459 (thread ? __kmp_gtid_from_thread(thread) : -1), task_team,
3460 KMP_ATOMIC_LD_RLX(&task_team->tt.tt_unfinished_threads)));
3467 void __kmp_free_task_team(kmp_info_t *thread, kmp_task_team_t *task_team) {
3468 KA_TRACE(20, (
"__kmp_free_task_team: T#%d task_team = %p\n",
3469 thread ? __kmp_gtid_from_thread(thread) : -1, task_team));
3472 __kmp_acquire_bootstrap_lock(&__kmp_task_team_lock);
3474 KMP_DEBUG_ASSERT(task_team->tt.tt_next == NULL);
3475 task_team->tt.tt_next = __kmp_free_task_teams;
3476 TCW_PTR(__kmp_free_task_teams, task_team);
3478 __kmp_release_bootstrap_lock(&__kmp_task_team_lock);
3486 void __kmp_reap_task_teams(
void) {
3487 kmp_task_team_t *task_team;
3489 if (TCR_PTR(__kmp_free_task_teams) != NULL) {
3491 __kmp_acquire_bootstrap_lock(&__kmp_task_team_lock);
3492 while ((task_team = __kmp_free_task_teams) != NULL) {
3493 __kmp_free_task_teams = task_team->tt.tt_next;
3494 task_team->tt.tt_next = NULL;
3497 if (task_team->tt.tt_threads_data != NULL) {
3498 __kmp_free_task_threads_data(task_team);
3500 __kmp_free(task_team);
3502 __kmp_release_bootstrap_lock(&__kmp_task_team_lock);
3509 void __kmp_wait_to_unref_task_teams(
void) {
3514 KMP_INIT_YIELD(spins);
3522 for (thread = CCAST(kmp_info_t *, __kmp_thread_pool); thread != NULL;
3523 thread = thread->th.th_next_pool) {
3527 if (TCR_PTR(thread->th.th_task_team) == NULL) {
3528 KA_TRACE(10, (
"__kmp_wait_to_unref_task_team: T#%d task_team == NULL\n",
3529 __kmp_gtid_from_thread(thread)));
3534 if (!__kmp_is_thread_alive(thread, &exit_val)) {
3535 thread->th.th_task_team = NULL;
3542 KA_TRACE(10, (
"__kmp_wait_to_unref_task_team: Waiting for T#%d to "
3543 "unreference task_team\n",
3544 __kmp_gtid_from_thread(thread)));
3546 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
3547 volatile void *sleep_loc;
3549 if ((sleep_loc = TCR_PTR(CCAST(
void *, thread->th.th_sleep_loc))) !=
3553 (
"__kmp_wait_to_unref_task_team: T#%d waking up thread T#%d\n",
3554 __kmp_gtid_from_thread(thread), __kmp_gtid_from_thread(thread)));
3555 __kmp_null_resume_wrapper(__kmp_gtid_from_thread(thread), sleep_loc);
3564 KMP_YIELD_OVERSUB_ELSE_SPIN(spins);
3570 void __kmp_task_team_setup(kmp_info_t *this_thr, kmp_team_t *team,
int always) {
3571 KMP_DEBUG_ASSERT(__kmp_tasking_mode != tskm_immediate_exec);
3577 if (team->t.t_task_team[this_thr->th.th_task_state] == NULL &&
3578 (always || team->t.t_nproc > 1)) {
3579 team->t.t_task_team[this_thr->th.th_task_state] =
3580 __kmp_allocate_task_team(this_thr, team);
3581 KA_TRACE(20, (
"__kmp_task_team_setup: Primary T#%d created new task_team %p"
3582 " for team %d at parity=%d\n",
3583 __kmp_gtid_from_thread(this_thr),
3584 team->t.t_task_team[this_thr->th.th_task_state], team->t.t_id,
3585 this_thr->th.th_task_state));
3595 if (team->t.t_nproc > 1) {
3596 int other_team = 1 - this_thr->th.th_task_state;
3597 KMP_DEBUG_ASSERT(other_team >= 0 && other_team < 2);
3598 if (team->t.t_task_team[other_team] == NULL) {
3599 team->t.t_task_team[other_team] =
3600 __kmp_allocate_task_team(this_thr, team);
3601 KA_TRACE(20, (
"__kmp_task_team_setup: Primary T#%d created second new "
3602 "task_team %p for team %d at parity=%d\n",
3603 __kmp_gtid_from_thread(this_thr),
3604 team->t.t_task_team[other_team], team->t.t_id, other_team));
3607 kmp_task_team_t *task_team = team->t.t_task_team[other_team];
3608 if (!task_team->tt.tt_active ||
3609 team->t.t_nproc != task_team->tt.tt_nproc) {
3610 TCW_4(task_team->tt.tt_nproc, team->t.t_nproc);
3611 TCW_4(task_team->tt.tt_found_tasks, FALSE);
3612 TCW_4(task_team->tt.tt_found_proxy_tasks, FALSE);
3613 KMP_ATOMIC_ST_REL(&task_team->tt.tt_unfinished_threads,
3615 TCW_4(task_team->tt.tt_active, TRUE);
3619 KA_TRACE(20, (
"__kmp_task_team_setup: Primary T#%d reset next task_team "
3620 "%p for team %d at parity=%d\n",
3621 __kmp_gtid_from_thread(this_thr),
3622 team->t.t_task_team[other_team], team->t.t_id, other_team));
3630 if (this_thr == __kmp_hidden_helper_main_thread) {
3631 for (
int i = 0; i < 2; ++i) {
3632 kmp_task_team_t *task_team = team->t.t_task_team[i];
3633 if (KMP_TASKING_ENABLED(task_team)) {
3636 __kmp_enable_tasking(task_team, this_thr);
3637 for (
int j = 0; j < task_team->tt.tt_nproc; ++j) {
3638 kmp_thread_data_t *thread_data = &task_team->tt.tt_threads_data[j];
3639 if (thread_data->td.td_deque == NULL) {
3640 __kmp_alloc_task_deque(__kmp_hidden_helper_threads[j], thread_data);
3650 void __kmp_task_team_sync(kmp_info_t *this_thr, kmp_team_t *team) {
3651 KMP_DEBUG_ASSERT(__kmp_tasking_mode != tskm_immediate_exec);
3655 this_thr->th.th_task_state = (kmp_uint8)(1 - this_thr->th.th_task_state);
3659 TCW_PTR(this_thr->th.th_task_team,
3660 team->t.t_task_team[this_thr->th.th_task_state]);
3662 (
"__kmp_task_team_sync: Thread T#%d task team switched to task_team "
3663 "%p from Team #%d (parity=%d)\n",
3664 __kmp_gtid_from_thread(this_thr), this_thr->th.th_task_team,
3665 team->t.t_id, this_thr->th.th_task_state));
3675 void __kmp_task_team_wait(
3676 kmp_info_t *this_thr,
3677 kmp_team_t *team USE_ITT_BUILD_ARG(
void *itt_sync_obj),
int wait) {
3678 kmp_task_team_t *task_team = team->t.t_task_team[this_thr->th.th_task_state];
3680 KMP_DEBUG_ASSERT(__kmp_tasking_mode != tskm_immediate_exec);
3681 KMP_DEBUG_ASSERT(task_team == this_thr->th.th_task_team);
3683 if ((task_team != NULL) && KMP_TASKING_ENABLED(task_team)) {
3685 KA_TRACE(20, (
"__kmp_task_team_wait: Primary T#%d waiting for all tasks "
3686 "(for unfinished_threads to reach 0) on task_team = %p\n",
3687 __kmp_gtid_from_thread(this_thr), task_team));
3691 kmp_flag_32<false, false> flag(
3692 RCAST(std::atomic<kmp_uint32> *,
3693 &task_team->tt.tt_unfinished_threads),
3695 flag.wait(this_thr, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
3701 (
"__kmp_task_team_wait: Primary T#%d deactivating task_team %p: "
3702 "setting active to false, setting local and team's pointer to NULL\n",
3703 __kmp_gtid_from_thread(this_thr), task_team));
3704 KMP_DEBUG_ASSERT(task_team->tt.tt_nproc > 1 ||
3705 task_team->tt.tt_found_proxy_tasks == TRUE);
3706 TCW_SYNC_4(task_team->tt.tt_found_proxy_tasks, FALSE);
3707 KMP_CHECK_UPDATE(task_team->tt.tt_untied_task_encountered, 0);
3708 TCW_SYNC_4(task_team->tt.tt_active, FALSE);
3711 TCW_PTR(this_thr->th.th_task_team, NULL);
3720 void __kmp_tasking_barrier(kmp_team_t *team, kmp_info_t *thread,
int gtid) {
3721 std::atomic<kmp_uint32> *spin = RCAST(
3722 std::atomic<kmp_uint32> *,
3723 &team->t.t_task_team[thread->th.th_task_state]->tt.tt_unfinished_threads);
3725 KMP_DEBUG_ASSERT(__kmp_tasking_mode == tskm_extra_barrier);
3728 KMP_FSYNC_SPIN_INIT(spin, NULL);
3730 kmp_flag_32<false, false> spin_flag(spin, 0U);
3731 while (!spin_flag.execute_tasks(thread, gtid, TRUE,
3732 &flag USE_ITT_BUILD_ARG(NULL), 0)) {
3735 KMP_FSYNC_SPIN_PREPARE(RCAST(
void *, spin));
3738 if (TCR_4(__kmp_global.g.g_done)) {
3739 if (__kmp_global.g.g_abort)
3740 __kmp_abort_thread();
3746 KMP_FSYNC_SPIN_ACQUIRED(RCAST(
void *, spin));
3755 static bool __kmp_give_task(kmp_info_t *thread, kmp_int32 tid, kmp_task_t *task,
3757 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
3758 kmp_task_team_t *task_team = taskdata->td_task_team;
3760 KA_TRACE(20, (
"__kmp_give_task: trying to give task %p to thread %d.\n",
3764 KMP_DEBUG_ASSERT(task_team != NULL);
3766 bool result =
false;
3767 kmp_thread_data_t *thread_data = &task_team->tt.tt_threads_data[tid];
3769 if (thread_data->td.td_deque == NULL) {
3773 (
"__kmp_give_task: thread %d has no queue while giving task %p.\n",
3778 if (TCR_4(thread_data->td.td_deque_ntasks) >=
3779 TASK_DEQUE_SIZE(thread_data->td)) {
3782 (
"__kmp_give_task: queue is full while giving task %p to thread %d.\n",
3787 if (TASK_DEQUE_SIZE(thread_data->td) / INITIAL_TASK_DEQUE_SIZE >= pass)
3790 __kmp_acquire_bootstrap_lock(&thread_data->td.td_deque_lock);
3791 if (TCR_4(thread_data->td.td_deque_ntasks) >=
3792 TASK_DEQUE_SIZE(thread_data->td)) {
3794 __kmp_realloc_task_deque(thread, thread_data);
3799 __kmp_acquire_bootstrap_lock(&thread_data->td.td_deque_lock);
3801 if (TCR_4(thread_data->td.td_deque_ntasks) >=
3802 TASK_DEQUE_SIZE(thread_data->td)) {
3803 KA_TRACE(30, (
"__kmp_give_task: queue is full while giving task %p to "
3809 if (TASK_DEQUE_SIZE(thread_data->td) / INITIAL_TASK_DEQUE_SIZE >= pass)
3810 goto release_and_exit;
3812 __kmp_realloc_task_deque(thread, thread_data);
3818 thread_data->td.td_deque[thread_data->td.td_deque_tail] = taskdata;
3820 thread_data->td.td_deque_tail =
3821 (thread_data->td.td_deque_tail + 1) & TASK_DEQUE_MASK(thread_data->td);
3822 TCW_4(thread_data->td.td_deque_ntasks,
3823 TCR_4(thread_data->td.td_deque_ntasks) + 1);
3826 KA_TRACE(30, (
"__kmp_give_task: successfully gave task %p to thread %d.\n",
3830 __kmp_release_bootstrap_lock(&thread_data->td.td_deque_lock);
3851 static void __kmp_first_top_half_finish_proxy(kmp_taskdata_t *taskdata) {
3852 KMP_DEBUG_ASSERT(taskdata->td_flags.tasktype == TASK_EXPLICIT);
3853 KMP_DEBUG_ASSERT(taskdata->td_flags.proxy == TASK_PROXY);
3854 KMP_DEBUG_ASSERT(taskdata->td_flags.complete == 0);
3855 KMP_DEBUG_ASSERT(taskdata->td_flags.freed == 0);
3857 taskdata->td_flags.complete = 1;
3859 if (taskdata->td_taskgroup)
3860 KMP_ATOMIC_DEC(&taskdata->td_taskgroup->count);
3864 KMP_ATOMIC_INC(&taskdata->td_incomplete_child_tasks);
3867 static void __kmp_second_top_half_finish_proxy(kmp_taskdata_t *taskdata) {
3868 kmp_int32 children = 0;
3872 KMP_ATOMIC_DEC(&taskdata->td_parent->td_incomplete_child_tasks) - 1;
3873 KMP_DEBUG_ASSERT(children >= 0);
3876 KMP_ATOMIC_DEC(&taskdata->td_incomplete_child_tasks);
3879 static void __kmp_bottom_half_finish_proxy(kmp_int32 gtid, kmp_task_t *ptask) {
3880 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(ptask);
3881 kmp_info_t *thread = __kmp_threads[gtid];
3883 KMP_DEBUG_ASSERT(taskdata->td_flags.proxy == TASK_PROXY);
3884 KMP_DEBUG_ASSERT(taskdata->td_flags.complete ==
3889 while (KMP_ATOMIC_LD_ACQ(&taskdata->td_incomplete_child_tasks) > 0)
3892 __kmp_release_deps(gtid, taskdata);
3893 __kmp_free_task_and_ancestors(gtid, taskdata, thread);
3905 KMP_DEBUG_ASSERT(ptask != NULL);
3906 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(ptask);
3908 10, (
"__kmp_proxy_task_completed(enter): T#%d proxy task %p completing\n",
3910 __kmp_assert_valid_gtid(gtid);
3911 KMP_DEBUG_ASSERT(taskdata->td_flags.proxy == TASK_PROXY);
3913 __kmp_first_top_half_finish_proxy(taskdata);
3914 __kmp_second_top_half_finish_proxy(taskdata);
3915 __kmp_bottom_half_finish_proxy(gtid, ptask);
3918 (
"__kmp_proxy_task_completed(exit): T#%d proxy task %p completing\n",
3930 KMP_DEBUG_ASSERT(ptask != NULL);
3931 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(ptask);
3935 (
"__kmp_proxy_task_completed_ooo(enter): proxy task completing ooo %p\n",
3938 KMP_DEBUG_ASSERT(taskdata->td_flags.proxy == TASK_PROXY);
3940 __kmp_first_top_half_finish_proxy(taskdata);
3944 kmp_team_t *team = taskdata->td_team;
3945 kmp_int32 nthreads = team->t.t_nproc;
3950 kmp_int32 start_k = 0;
3952 kmp_int32 k = start_k;
3956 thread = team->t.t_threads[k];
3957 k = (k + 1) % nthreads;
3963 }
while (!__kmp_give_task(thread, k, ptask, pass));
3965 __kmp_second_top_half_finish_proxy(taskdata);
3969 (
"__kmp_proxy_task_completed_ooo(exit): proxy task completing ooo %p\n",
3973 kmp_event_t *__kmpc_task_allow_completion_event(
ident_t *loc_ref,
int gtid,
3975 kmp_taskdata_t *td = KMP_TASK_TO_TASKDATA(task);
3976 if (td->td_allow_completion_event.type == KMP_EVENT_UNINITIALIZED) {
3977 td->td_allow_completion_event.type = KMP_EVENT_ALLOW_COMPLETION;
3978 td->td_allow_completion_event.ed.task = task;
3979 __kmp_init_tas_lock(&td->td_allow_completion_event.lock);
3981 return &td->td_allow_completion_event;
3984 void __kmp_fulfill_event(kmp_event_t *event) {
3985 if (event->type == KMP_EVENT_ALLOW_COMPLETION) {
3986 kmp_task_t *ptask = event->ed.task;
3987 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(ptask);
3988 bool detached =
false;
3989 int gtid = __kmp_get_gtid();
3994 __kmp_acquire_tas_lock(&event->lock, gtid);
3995 if (taskdata->td_flags.proxy == TASK_PROXY) {
4001 if (UNLIKELY(ompt_enabled.enabled))
4002 __ompt_task_finish(ptask, NULL, ompt_task_early_fulfill);
4005 event->type = KMP_EVENT_UNINITIALIZED;
4006 __kmp_release_tas_lock(&event->lock, gtid);
4012 if (UNLIKELY(ompt_enabled.enabled))
4013 __ompt_task_finish(ptask, NULL, ompt_task_late_fulfill);
4017 kmp_team_t *team = taskdata->td_team;
4018 kmp_info_t *thread = __kmp_get_thread();
4019 if (thread->th.th_team == team) {
4037 kmp_task_t *__kmp_task_dup_alloc(kmp_info_t *thread, kmp_task_t *task_src) {
4039 kmp_taskdata_t *taskdata;
4040 kmp_taskdata_t *taskdata_src = KMP_TASK_TO_TASKDATA(task_src);
4041 kmp_taskdata_t *parent_task = taskdata_src->td_parent;
4042 size_t shareds_offset;
4045 KA_TRACE(10, (
"__kmp_task_dup_alloc(enter): Th %p, source task %p\n", thread,
4047 KMP_DEBUG_ASSERT(taskdata_src->td_flags.proxy ==
4049 KMP_DEBUG_ASSERT(taskdata_src->td_flags.tasktype == TASK_EXPLICIT);
4050 task_size = taskdata_src->td_size_alloc;
4053 KA_TRACE(30, (
"__kmp_task_dup_alloc: Th %p, malloc size %ld\n", thread,
4056 taskdata = (kmp_taskdata_t *)__kmp_fast_allocate(thread, task_size);
4058 taskdata = (kmp_taskdata_t *)__kmp_thread_malloc(thread, task_size);
4060 KMP_MEMCPY(taskdata, taskdata_src, task_size);
4062 task = KMP_TASKDATA_TO_TASK(taskdata);
4065 taskdata->td_task_id = KMP_GEN_TASK_ID();
4066 if (task->shareds != NULL) {
4067 shareds_offset = (
char *)task_src->shareds - (
char *)taskdata_src;
4068 task->shareds = &((
char *)taskdata)[shareds_offset];
4069 KMP_DEBUG_ASSERT((((kmp_uintptr_t)task->shareds) & (
sizeof(
void *) - 1)) ==
4072 taskdata->td_alloc_thread = thread;
4073 taskdata->td_parent = parent_task;
4075 taskdata->td_taskgroup = parent_task->td_taskgroup;
4078 if (taskdata->td_flags.tiedness == TASK_TIED)
4079 taskdata->td_last_tied = taskdata;
4083 if (!(taskdata->td_flags.team_serial || taskdata->td_flags.tasking_ser)) {
4084 KMP_ATOMIC_INC(&parent_task->td_incomplete_child_tasks);
4085 if (parent_task->td_taskgroup)
4086 KMP_ATOMIC_INC(&parent_task->td_taskgroup->count);
4089 if (taskdata->td_parent->td_flags.tasktype == TASK_EXPLICIT)
4090 KMP_ATOMIC_INC(&taskdata->td_parent->td_allocated_child_tasks);
4094 (
"__kmp_task_dup_alloc(exit): Th %p, created task %p, parent=%p\n",
4095 thread, taskdata, taskdata->td_parent));
4097 if (UNLIKELY(ompt_enabled.enabled))
4098 __ompt_task_init(taskdata, thread->th.th_info.ds.ds_gtid);
4107 typedef void (*p_task_dup_t)(kmp_task_t *, kmp_task_t *, kmp_int32);
4109 KMP_BUILD_ASSERT(
sizeof(
long) == 4 ||
sizeof(
long) == 8);
4114 class kmp_taskloop_bounds_t {
4116 const kmp_taskdata_t *taskdata;
4117 size_t lower_offset;
4118 size_t upper_offset;
4121 kmp_taskloop_bounds_t(kmp_task_t *_task, kmp_uint64 *lb, kmp_uint64 *ub)
4122 : task(_task), taskdata(KMP_TASK_TO_TASKDATA(task)),
4123 lower_offset((char *)lb - (char *)task),
4124 upper_offset((char *)ub - (char *)task) {
4125 KMP_DEBUG_ASSERT((
char *)lb > (
char *)_task);
4126 KMP_DEBUG_ASSERT((
char *)ub > (
char *)_task);
4128 kmp_taskloop_bounds_t(kmp_task_t *_task,
const kmp_taskloop_bounds_t &bounds)
4129 : task(_task), taskdata(KMP_TASK_TO_TASKDATA(_task)),
4130 lower_offset(bounds.lower_offset), upper_offset(bounds.upper_offset) {}
4131 size_t get_lower_offset()
const {
return lower_offset; }
4132 size_t get_upper_offset()
const {
return upper_offset; }
4133 kmp_uint64 get_lb()
const {
4135 #if defined(KMP_GOMP_COMPAT)
4137 if (!taskdata->td_flags.native) {
4138 retval = *(kmp_int64 *)((
char *)task + lower_offset);
4141 if (taskdata->td_size_loop_bounds == 4) {
4142 kmp_int32 *lb = RCAST(kmp_int32 *, task->shareds);
4143 retval = (kmp_int64)*lb;
4145 kmp_int64 *lb = RCAST(kmp_int64 *, task->shareds);
4146 retval = (kmp_int64)*lb;
4151 retval = *(kmp_int64 *)((
char *)task + lower_offset);
4155 kmp_uint64 get_ub()
const {
4157 #if defined(KMP_GOMP_COMPAT)
4159 if (!taskdata->td_flags.native) {
4160 retval = *(kmp_int64 *)((
char *)task + upper_offset);
4163 if (taskdata->td_size_loop_bounds == 4) {
4164 kmp_int32 *ub = RCAST(kmp_int32 *, task->shareds) + 1;
4165 retval = (kmp_int64)*ub;
4167 kmp_int64 *ub = RCAST(kmp_int64 *, task->shareds) + 1;
4168 retval = (kmp_int64)*ub;
4172 retval = *(kmp_int64 *)((
char *)task + upper_offset);
4176 void set_lb(kmp_uint64 lb) {
4177 #if defined(KMP_GOMP_COMPAT)
4179 if (!taskdata->td_flags.native) {
4180 *(kmp_uint64 *)((
char *)task + lower_offset) = lb;
4183 if (taskdata->td_size_loop_bounds == 4) {
4184 kmp_uint32 *lower = RCAST(kmp_uint32 *, task->shareds);
4185 *lower = (kmp_uint32)lb;
4187 kmp_uint64 *lower = RCAST(kmp_uint64 *, task->shareds);
4188 *lower = (kmp_uint64)lb;
4192 *(kmp_uint64 *)((
char *)task + lower_offset) = lb;
4195 void set_ub(kmp_uint64 ub) {
4196 #if defined(KMP_GOMP_COMPAT)
4198 if (!taskdata->td_flags.native) {
4199 *(kmp_uint64 *)((
char *)task + upper_offset) = ub;
4202 if (taskdata->td_size_loop_bounds == 4) {
4203 kmp_uint32 *upper = RCAST(kmp_uint32 *, task->shareds) + 1;
4204 *upper = (kmp_uint32)ub;
4206 kmp_uint64 *upper = RCAST(kmp_uint64 *, task->shareds) + 1;
4207 *upper = (kmp_uint64)ub;
4211 *(kmp_uint64 *)((
char *)task + upper_offset) = ub;
4232 void __kmp_taskloop_linear(
ident_t *loc,
int gtid, kmp_task_t *task,
4233 kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st,
4234 kmp_uint64 ub_glob, kmp_uint64 num_tasks,
4235 kmp_uint64 grainsize, kmp_uint64 extras,
4236 kmp_int64 last_chunk, kmp_uint64 tc,
4242 KMP_TIME_PARTITIONED_BLOCK(OMP_taskloop_scheduling);
4243 p_task_dup_t ptask_dup = (p_task_dup_t)task_dup;
4245 kmp_taskloop_bounds_t task_bounds(task, lb, ub);
4246 kmp_uint64 lower = task_bounds.get_lb();
4247 kmp_uint64 upper = task_bounds.get_ub();
4249 kmp_info_t *thread = __kmp_threads[gtid];
4250 kmp_taskdata_t *current_task = thread->th.th_current_task;
4251 kmp_task_t *next_task;
4252 kmp_int32 lastpriv = 0;
4254 KMP_DEBUG_ASSERT(tc == num_tasks * grainsize +
4255 (last_chunk < 0 ? last_chunk : extras));
4256 KMP_DEBUG_ASSERT(num_tasks > extras);
4257 KMP_DEBUG_ASSERT(num_tasks > 0);
4258 KA_TRACE(20, (
"__kmp_taskloop_linear: T#%d: %lld tasks, grainsize %lld, "
4259 "extras %lld, last_chunk %lld, i=%lld,%lld(%d)%lld, dup %p\n",
4260 gtid, num_tasks, grainsize, extras, last_chunk, lower, upper,
4261 ub_glob, st, task_dup));
4264 for (i = 0; i < num_tasks; ++i) {
4265 kmp_uint64 chunk_minus_1;
4267 chunk_minus_1 = grainsize - 1;
4269 chunk_minus_1 = grainsize;
4272 upper = lower + st * chunk_minus_1;
4276 if (i == num_tasks - 1) {
4279 KMP_DEBUG_ASSERT(upper == *ub);
4280 if (upper == ub_glob)
4282 }
else if (st > 0) {
4283 KMP_DEBUG_ASSERT((kmp_uint64)st > *ub - upper);
4284 if ((kmp_uint64)st > ub_glob - upper)
4287 KMP_DEBUG_ASSERT(upper + st < *ub);
4288 if (upper - ub_glob < (kmp_uint64)(-st))
4292 next_task = __kmp_task_dup_alloc(thread, task);
4293 kmp_taskdata_t *next_taskdata = KMP_TASK_TO_TASKDATA(next_task);
4294 kmp_taskloop_bounds_t next_task_bounds =
4295 kmp_taskloop_bounds_t(next_task, task_bounds);
4298 next_task_bounds.set_lb(lower);
4299 if (next_taskdata->td_flags.native) {
4300 next_task_bounds.set_ub(upper + (st > 0 ? 1 : -1));
4302 next_task_bounds.set_ub(upper);
4304 if (ptask_dup != NULL)
4306 ptask_dup(next_task, task, lastpriv);
4308 (
"__kmp_taskloop_linear: T#%d; task #%llu: task %p: lower %lld, "
4309 "upper %lld stride %lld, (offsets %p %p)\n",
4310 gtid, i, next_task, lower, upper, st,
4311 next_task_bounds.get_lower_offset(),
4312 next_task_bounds.get_upper_offset()));
4314 __kmp_omp_taskloop_task(NULL, gtid, next_task,
4317 __kmp_omp_task(gtid, next_task,
true);
4322 __kmp_task_start(gtid, task, current_task);
4324 __kmp_task_finish<false>(gtid, task, current_task);
4329 typedef struct __taskloop_params {
4336 kmp_uint64 num_tasks;
4337 kmp_uint64 grainsize;
4339 kmp_int64 last_chunk;
4341 kmp_uint64 num_t_min;
4345 } __taskloop_params_t;
4347 void __kmp_taskloop_recur(
ident_t *,
int, kmp_task_t *, kmp_uint64 *,
4348 kmp_uint64 *, kmp_int64, kmp_uint64, kmp_uint64,
4349 kmp_uint64, kmp_uint64, kmp_int64, kmp_uint64,
4357 int __kmp_taskloop_task(
int gtid,
void *ptask) {
4358 __taskloop_params_t *p =
4359 (__taskloop_params_t *)((kmp_task_t *)ptask)->shareds;
4360 kmp_task_t *task = p->task;
4361 kmp_uint64 *lb = p->lb;
4362 kmp_uint64 *ub = p->ub;
4363 void *task_dup = p->task_dup;
4365 kmp_int64 st = p->st;
4366 kmp_uint64 ub_glob = p->ub_glob;
4367 kmp_uint64 num_tasks = p->num_tasks;
4368 kmp_uint64 grainsize = p->grainsize;
4369 kmp_uint64 extras = p->extras;
4370 kmp_int64 last_chunk = p->last_chunk;
4371 kmp_uint64 tc = p->tc;
4372 kmp_uint64 num_t_min = p->num_t_min;
4374 void *codeptr_ra = p->codeptr_ra;
4377 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
4378 KMP_DEBUG_ASSERT(task != NULL);
4380 (
"__kmp_taskloop_task: T#%d, task %p: %lld tasks, grainsize"
4381 " %lld, extras %lld, last_chunk %lld, i=%lld,%lld(%d), dup %p\n",
4382 gtid, taskdata, num_tasks, grainsize, extras, last_chunk, *lb, *ub,
4385 KMP_DEBUG_ASSERT(num_tasks * 2 + 1 > num_t_min);
4386 if (num_tasks > num_t_min)
4387 __kmp_taskloop_recur(NULL, gtid, task, lb, ub, st, ub_glob, num_tasks,
4388 grainsize, extras, last_chunk, tc, num_t_min,
4394 __kmp_taskloop_linear(NULL, gtid, task, lb, ub, st, ub_glob, num_tasks,
4395 grainsize, extras, last_chunk, tc,
4401 KA_TRACE(40, (
"__kmp_taskloop_task(exit): T#%d\n", gtid));
4423 void __kmp_taskloop_recur(
ident_t *loc,
int gtid, kmp_task_t *task,
4424 kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st,
4425 kmp_uint64 ub_glob, kmp_uint64 num_tasks,
4426 kmp_uint64 grainsize, kmp_uint64 extras,
4427 kmp_int64 last_chunk, kmp_uint64 tc,
4428 kmp_uint64 num_t_min,
4433 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
4434 KMP_DEBUG_ASSERT(task != NULL);
4435 KMP_DEBUG_ASSERT(num_tasks > num_t_min);
4437 (
"__kmp_taskloop_recur: T#%d, task %p: %lld tasks, grainsize"
4438 " %lld, extras %lld, last_chunk %lld, i=%lld,%lld(%d), dup %p\n",
4439 gtid, taskdata, num_tasks, grainsize, extras, last_chunk, *lb, *ub,
4441 p_task_dup_t ptask_dup = (p_task_dup_t)task_dup;
4442 kmp_uint64 lower = *lb;
4443 kmp_info_t *thread = __kmp_threads[gtid];
4445 kmp_task_t *next_task;
4446 size_t lower_offset =
4447 (
char *)lb - (
char *)task;
4448 size_t upper_offset =
4449 (
char *)ub - (
char *)task;
4451 KMP_DEBUG_ASSERT(tc == num_tasks * grainsize +
4452 (last_chunk < 0 ? last_chunk : extras));
4453 KMP_DEBUG_ASSERT(num_tasks > extras);
4454 KMP_DEBUG_ASSERT(num_tasks > 0);
4457 kmp_uint64 lb1, ub0, tc0, tc1, ext0, ext1;
4458 kmp_int64 last_chunk0 = 0, last_chunk1 = 0;
4459 kmp_uint64 gr_size0 = grainsize;
4460 kmp_uint64 n_tsk0 = num_tasks >> 1;
4461 kmp_uint64 n_tsk1 = num_tasks - n_tsk0;
4462 if (last_chunk < 0) {
4464 last_chunk1 = last_chunk;
4465 tc0 = grainsize * n_tsk0;
4467 }
else if (n_tsk0 <= extras) {
4470 ext1 = extras - n_tsk0;
4471 tc0 = gr_size0 * n_tsk0;
4476 tc1 = grainsize * n_tsk1;
4479 ub0 = lower + st * (tc0 - 1);
4483 next_task = __kmp_task_dup_alloc(thread, task);
4485 *(kmp_uint64 *)((
char *)next_task + lower_offset) = lb1;
4486 if (ptask_dup != NULL)
4487 ptask_dup(next_task, task, 0);
4492 kmp_taskdata_t *current_task = thread->th.th_current_task;
4493 thread->th.th_current_task = taskdata->td_parent;
4494 kmp_task_t *new_task =
4495 __kmpc_omp_task_alloc(loc, gtid, 1, 3 *
sizeof(
void *),
4496 sizeof(__taskloop_params_t), &__kmp_taskloop_task);
4498 thread->th.th_current_task = current_task;
4499 __taskloop_params_t *p = (__taskloop_params_t *)new_task->shareds;
4500 p->task = next_task;
4501 p->lb = (kmp_uint64 *)((
char *)next_task + lower_offset);
4502 p->ub = (kmp_uint64 *)((
char *)next_task + upper_offset);
4503 p->task_dup = task_dup;
4505 p->ub_glob = ub_glob;
4506 p->num_tasks = n_tsk1;
4507 p->grainsize = grainsize;
4509 p->last_chunk = last_chunk1;
4511 p->num_t_min = num_t_min;
4513 p->codeptr_ra = codeptr_ra;
4518 __kmp_omp_taskloop_task(NULL, gtid, new_task, codeptr_ra);
4520 __kmp_omp_task(gtid, new_task,
true);
4524 if (n_tsk0 > num_t_min)
4525 __kmp_taskloop_recur(loc, gtid, task, lb, ub, st, ub_glob, n_tsk0, gr_size0,
4526 ext0, last_chunk0, tc0, num_t_min,
4532 __kmp_taskloop_linear(loc, gtid, task, lb, ub, st, ub_glob, n_tsk0,
4533 gr_size0, ext0, last_chunk0, tc0,
4539 KA_TRACE(40, (
"__kmp_taskloop_recur(exit): T#%d\n", gtid));
4542 static void __kmp_taskloop(
ident_t *loc,
int gtid, kmp_task_t *task,
int if_val,
4543 kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st,
4544 int nogroup,
int sched, kmp_uint64 grainsize,
4545 int modifier,
void *task_dup) {
4546 kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task);
4547 KMP_DEBUG_ASSERT(task != NULL);
4549 #if OMPT_SUPPORT && OMPT_OPTIONAL
4550 OMPT_STORE_RETURN_ADDRESS(gtid);
4552 __kmpc_taskgroup(loc, gtid);
4557 kmp_taskloop_bounds_t task_bounds(task, lb, ub);
4560 kmp_uint64 lower = task_bounds.get_lb();
4561 kmp_uint64 upper = task_bounds.get_ub();
4562 kmp_uint64 ub_glob = upper;
4563 kmp_uint64 num_tasks = 0, extras = 0;
4564 kmp_int64 last_chunk =
4566 kmp_uint64 num_tasks_min = __kmp_taskloop_min_tasks;
4567 kmp_info_t *thread = __kmp_threads[gtid];
4568 kmp_taskdata_t *current_task = thread->th.th_current_task;
4570 KA_TRACE(20, (
"__kmp_taskloop: T#%d, task %p, lb %lld, ub %lld, st %lld, "
4571 "grain %llu(%d, %d), dup %p\n",
4572 gtid, taskdata, lower, upper, st, grainsize, sched, modifier,
4577 tc = upper - lower + 1;
4578 }
else if (st < 0) {
4579 tc = (lower - upper) / (-st) + 1;
4581 tc = (upper - lower) / st + 1;
4584 KA_TRACE(20, (
"__kmp_taskloop(exit): T#%d zero-trip loop\n", gtid));
4586 __kmp_task_start(gtid, task, current_task);
4588 __kmp_task_finish<false>(gtid, task, current_task);
4592 #if OMPT_SUPPORT && OMPT_OPTIONAL
4593 ompt_team_info_t *team_info = __ompt_get_teaminfo(0, NULL);
4594 ompt_task_info_t *task_info = __ompt_get_task_info_object(0);
4595 if (ompt_enabled.ompt_callback_work) {
4596 ompt_callbacks.ompt_callback(ompt_callback_work)(
4597 ompt_work_taskloop, ompt_scope_begin, &(team_info->parallel_data),
4598 &(task_info->task_data), tc, OMPT_GET_RETURN_ADDRESS(0));
4602 if (num_tasks_min == 0)
4605 KMP_MIN(thread->th.th_team_nproc * 10, INITIAL_TASK_DEQUE_SIZE);
4611 grainsize = thread->th.th_team_nproc * 10;
4614 if (grainsize > tc) {
4619 num_tasks = grainsize;
4620 grainsize = tc / num_tasks;
4621 extras = tc % num_tasks;
4625 if (grainsize > tc) {
4631 num_tasks = (tc + grainsize - 1) / grainsize;
4632 last_chunk = tc - (num_tasks * grainsize);
4635 num_tasks = tc / grainsize;
4637 grainsize = tc / num_tasks;
4638 extras = tc % num_tasks;
4643 KMP_ASSERT2(0,
"unknown scheduling of taskloop");
4646 KMP_DEBUG_ASSERT(tc == num_tasks * grainsize +
4647 (last_chunk < 0 ? last_chunk : extras));
4648 KMP_DEBUG_ASSERT(num_tasks > extras);
4649 KMP_DEBUG_ASSERT(num_tasks > 0);
4655 taskdata->td_flags.task_serial = 1;
4656 taskdata->td_flags.tiedness = TASK_TIED;
4658 __kmp_taskloop_linear(loc, gtid, task, lb, ub, st, ub_glob, num_tasks,
4659 grainsize, extras, last_chunk, tc,
4661 OMPT_GET_RETURN_ADDRESS(0),
4666 }
else if (num_tasks > num_tasks_min && !taskdata->td_flags.native) {
4667 KA_TRACE(20, (
"__kmp_taskloop: T#%d, go recursive: tc %llu, #tasks %llu"
4668 "(%lld), grain %llu, extras %llu, last_chunk %lld\n",
4669 gtid, tc, num_tasks, num_tasks_min, grainsize, extras,
4671 __kmp_taskloop_recur(loc, gtid, task, lb, ub, st, ub_glob, num_tasks,
4672 grainsize, extras, last_chunk, tc, num_tasks_min,
4674 OMPT_GET_RETURN_ADDRESS(0),
4678 KA_TRACE(20, (
"__kmp_taskloop: T#%d, go linear: tc %llu, #tasks %llu"
4679 "(%lld), grain %llu, extras %llu, last_chunk %lld\n",
4680 gtid, tc, num_tasks, num_tasks_min, grainsize, extras,
4682 __kmp_taskloop_linear(loc, gtid, task, lb, ub, st, ub_glob, num_tasks,
4683 grainsize, extras, last_chunk, tc,
4685 OMPT_GET_RETURN_ADDRESS(0),
4690 #if OMPT_SUPPORT && OMPT_OPTIONAL
4691 if (ompt_enabled.ompt_callback_work) {
4692 ompt_callbacks.ompt_callback(ompt_callback_work)(
4693 ompt_work_taskloop, ompt_scope_end, &(team_info->parallel_data),
4694 &(task_info->task_data), tc, OMPT_GET_RETURN_ADDRESS(0));
4699 #if OMPT_SUPPORT && OMPT_OPTIONAL
4700 OMPT_STORE_RETURN_ADDRESS(gtid);
4702 __kmpc_end_taskgroup(loc, gtid);
4704 KA_TRACE(20, (
"__kmp_taskloop(exit): T#%d\n", gtid));
4724 kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st,
int nogroup,
4725 int sched, kmp_uint64 grainsize,
void *task_dup) {
4726 __kmp_assert_valid_gtid(gtid);
4727 KA_TRACE(20, (
"__kmpc_taskloop(enter): T#%d\n", gtid));
4728 __kmp_taskloop(loc, gtid, task, if_val, lb, ub, st, nogroup, sched, grainsize,
4730 KA_TRACE(20, (
"__kmpc_taskloop(exit): T#%d\n", gtid));
4751 kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st,
4752 int nogroup,
int sched, kmp_uint64 grainsize,
4753 int modifier,
void *task_dup) {
4754 __kmp_assert_valid_gtid(gtid);
4755 KA_TRACE(20, (
"__kmpc_taskloop_5(enter): T#%d\n", gtid));
4756 __kmp_taskloop(loc, gtid, task, if_val, lb, ub, st, nogroup, sched, grainsize,
4757 modifier, task_dup);
4758 KA_TRACE(20, (
"__kmpc_taskloop_5(exit): T#%d\n", gtid));
struct kmp_taskred_data kmp_taskred_data_t
struct kmp_task_red_input kmp_task_red_input_t
struct kmp_taskred_flags kmp_taskred_flags_t
struct kmp_taskred_input kmp_taskred_input_t
#define KMP_COUNT_BLOCK(name)
Increments specified counter (name).
void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int nogroup, int sched, kmp_uint64 grainsize, void *task_dup)
void * __kmpc_taskred_modifier_init(ident_t *loc, int gtid, int is_ws, int num, void *data)
void * __kmpc_taskred_init(int gtid, int num, void *data)
void * __kmpc_task_reduction_init(int gtid, int num, void *data)
void __kmpc_proxy_task_completed_ooo(kmp_task_t *ptask)
void __kmpc_task_reduction_modifier_fini(ident_t *loc, int gtid, int is_ws)
kmp_int32 __kmpc_omp_reg_task_with_affinity(ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *new_task, kmp_int32 naffins, kmp_task_affinity_info_t *affin_list)
void * __kmpc_task_reduction_modifier_init(ident_t *loc, int gtid, int is_ws, int num, void *data)
void __kmpc_taskloop_5(ident_t *loc, int gtid, kmp_task_t *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int nogroup, int sched, kmp_uint64 grainsize, int modifier, void *task_dup)
void __kmpc_proxy_task_completed(kmp_int32 gtid, kmp_task_t *ptask)
void * __kmpc_task_reduction_get_th_data(int gtid, void *tskgrp, void *data)
kmp_taskred_flags_t flags