19 #include "kmp_wait_release.h" 20 #include "kmp_stats.h" 23 #include "ompt-specific.h" 31 static void __kmp_enable_tasking( kmp_task_team_t *task_team, kmp_info_t *this_thr );
32 static void __kmp_alloc_task_deque( kmp_info_t *thread, kmp_thread_data_t *thread_data );
33 static int __kmp_realloc_task_threads_data( kmp_info_t *thread, kmp_task_team_t *task_team );
36 static void __kmp_bottom_half_finish_proxy( kmp_int32 gtid, kmp_task_t * ptask );
39 #ifdef BUILD_TIED_TASK_STACK 51 __kmp_trace_task_stack( kmp_int32 gtid, kmp_thread_data_t *thread_data,
int threshold,
char *location )
53 kmp_task_stack_t *task_stack = & thread_data->td.td_susp_tied_tasks;
54 kmp_taskdata_t **stack_top = task_stack -> ts_top;
55 kmp_int32 entries = task_stack -> ts_entries;
56 kmp_taskdata_t *tied_task;
58 KA_TRACE(threshold, (
"__kmp_trace_task_stack(start): location = %s, gtid = %d, entries = %d, " 59 "first_block = %p, stack_top = %p \n",
60 location, gtid, entries, task_stack->ts_first_block, stack_top ) );
62 KMP_DEBUG_ASSERT( stack_top != NULL );
63 KMP_DEBUG_ASSERT( entries > 0 );
65 while ( entries != 0 )
67 KMP_DEBUG_ASSERT( stack_top != & task_stack->ts_first_block.sb_block[0] );
69 if ( entries & TASK_STACK_INDEX_MASK == 0 )
71 kmp_stack_block_t *stack_block = (kmp_stack_block_t *) (stack_top) ;
73 stack_block = stack_block -> sb_prev;
74 stack_top = & stack_block -> sb_block[TASK_STACK_BLOCK_SIZE];
81 tied_task = * stack_top;
83 KMP_DEBUG_ASSERT( tied_task != NULL );
84 KMP_DEBUG_ASSERT( tied_task -> td_flags.tasktype == TASK_TIED );
86 KA_TRACE(threshold, (
"__kmp_trace_task_stack(%s): gtid=%d, entry=%d, " 87 "stack_top=%p, tied_task=%p\n",
88 location, gtid, entries, stack_top, tied_task ) );
90 KMP_DEBUG_ASSERT( stack_top == & task_stack->ts_first_block.sb_block[0] );
92 KA_TRACE(threshold, (
"__kmp_trace_task_stack(exit): location = %s, gtid = %d\n",
105 __kmp_init_task_stack( kmp_int32 gtid, kmp_thread_data_t *thread_data )
107 kmp_task_stack_t *task_stack = & thread_data->td.td_susp_tied_tasks;
108 kmp_stack_block_t *first_block;
111 first_block = & task_stack -> ts_first_block;
112 task_stack -> ts_top = (kmp_taskdata_t **) first_block;
113 memset( (
void *) first_block,
'\0', TASK_STACK_BLOCK_SIZE *
sizeof(kmp_taskdata_t *));
116 task_stack -> ts_entries = TASK_STACK_EMPTY;
117 first_block -> sb_next = NULL;
118 first_block -> sb_prev = NULL;
129 __kmp_free_task_stack( kmp_int32 gtid, kmp_thread_data_t *thread_data )
131 kmp_task_stack_t *task_stack = & thread_data->td.td_susp_tied_tasks;
132 kmp_stack_block_t *stack_block = & task_stack -> ts_first_block;
134 KMP_DEBUG_ASSERT( task_stack -> ts_entries == TASK_STACK_EMPTY );
136 while ( stack_block != NULL ) {
137 kmp_stack_block_t *next_block = (stack_block) ? stack_block -> sb_next : NULL;
139 stack_block -> sb_next = NULL;
140 stack_block -> sb_prev = NULL;
141 if (stack_block != & task_stack -> ts_first_block) {
142 __kmp_thread_free( thread, stack_block );
144 stack_block = next_block;
147 task_stack -> ts_entries = 0;
148 task_stack -> ts_top = NULL;
161 __kmp_push_task_stack( kmp_int32 gtid, kmp_info_t *thread, kmp_taskdata_t * tied_task )
164 kmp_thread_data_t *thread_data = & thread -> th.th_task_team ->
165 tt.tt_threads_data[ __kmp_tid_from_gtid( gtid ) ];
166 kmp_task_stack_t *task_stack = & thread_data->td.td_susp_tied_tasks ;
168 if ( tied_task->td_flags.team_serial || tied_task->td_flags.tasking_ser ) {
172 KMP_DEBUG_ASSERT( tied_task -> td_flags.tasktype == TASK_TIED );
173 KMP_DEBUG_ASSERT( task_stack -> ts_top != NULL );
175 KA_TRACE(20, (
"__kmp_push_task_stack(enter): GTID: %d; THREAD: %p; TASK: %p\n",
176 gtid, thread, tied_task ) );
178 * (task_stack -> ts_top) = tied_task;
181 task_stack -> ts_top++;
182 task_stack -> ts_entries++;
184 if ( task_stack -> ts_entries & TASK_STACK_INDEX_MASK == 0 )
187 kmp_stack_block_t *stack_block =
188 (kmp_stack_block_t *) (task_stack -> ts_top - TASK_STACK_BLOCK_SIZE);
191 if ( stack_block -> sb_next != NULL )
193 task_stack -> ts_top = & stack_block -> sb_next -> sb_block[0];
197 kmp_stack_block_t *new_block = (kmp_stack_block_t *)
198 __kmp_thread_calloc(thread,
sizeof(kmp_stack_block_t));
200 task_stack -> ts_top = & new_block -> sb_block[0];
201 stack_block -> sb_next = new_block;
202 new_block -> sb_prev = stack_block;
203 new_block -> sb_next = NULL;
205 KA_TRACE(30, (
"__kmp_push_task_stack(): GTID: %d; TASK: %p; Alloc new block: %p\n",
206 gtid, tied_task, new_block ) );
209 KA_TRACE(20, (
"__kmp_push_task_stack(exit): GTID: %d; TASK: %p\n", gtid, tied_task ) );
222 __kmp_pop_task_stack( kmp_int32 gtid, kmp_info_t *thread, kmp_taskdata_t *ending_task )
225 kmp_thread_data_t *thread_data = & thread -> th.th_task_team -> tt_threads_data[ __kmp_tid_from_gtid( gtid ) ];
226 kmp_task_stack_t *task_stack = & thread_data->td.td_susp_tied_tasks ;
227 kmp_taskdata_t *tied_task;
229 if ( ending_task->td_flags.team_serial || ending_task->td_flags.tasking_ser ) {
233 KMP_DEBUG_ASSERT( task_stack -> ts_top != NULL );
234 KMP_DEBUG_ASSERT( task_stack -> ts_entries > 0 );
236 KA_TRACE(20, (
"__kmp_pop_task_stack(enter): GTID: %d; THREAD: %p\n", gtid, thread ) );
239 if ( task_stack -> ts_entries & TASK_STACK_INDEX_MASK == 0 )
241 kmp_stack_block_t *stack_block =
242 (kmp_stack_block_t *) (task_stack -> ts_top) ;
244 stack_block = stack_block -> sb_prev;
245 task_stack -> ts_top = & stack_block -> sb_block[TASK_STACK_BLOCK_SIZE];
249 task_stack -> ts_top--;
250 task_stack -> ts_entries--;
252 tied_task = * (task_stack -> ts_top );
254 KMP_DEBUG_ASSERT( tied_task != NULL );
255 KMP_DEBUG_ASSERT( tied_task -> td_flags.tasktype == TASK_TIED );
256 KMP_DEBUG_ASSERT( tied_task == ending_task );
258 KA_TRACE(20, (
"__kmp_pop_task_stack(exit): GTID: %d; TASK: %p\n", gtid, tied_task ) );
267 __kmp_push_task(kmp_int32 gtid, kmp_task_t * task )
269 kmp_info_t * thread = __kmp_threads[ gtid ];
270 kmp_taskdata_t * taskdata = KMP_TASK_TO_TASKDATA(task);
271 kmp_task_team_t * task_team = thread->th.th_task_team;
272 kmp_int32 tid = __kmp_tid_from_gtid( gtid );
273 kmp_thread_data_t * thread_data;
275 KA_TRACE(20, (
"__kmp_push_task: T#%d trying to push task %p.\n", gtid, taskdata ) );
277 if ( taskdata->td_flags.tiedness == TASK_UNTIED ) {
279 kmp_int32 counter = 1 + KMP_TEST_THEN_INC32(&taskdata->td_untied_count);
280 KA_TRACE(20, (
"__kmp_push_task: T#%d untied_count (%d) incremented for task %p\n",
281 gtid, counter, taskdata ) );
285 if ( taskdata->td_flags.task_serial ) {
286 KA_TRACE(20, (
"__kmp_push_task: T#%d team serialized; returning TASK_NOT_PUSHED for task %p\n",
288 return TASK_NOT_PUSHED;
292 KMP_DEBUG_ASSERT( __kmp_tasking_mode != tskm_immediate_exec );
293 if ( ! KMP_TASKING_ENABLED(task_team) ) {
294 __kmp_enable_tasking( task_team, thread );
296 KMP_DEBUG_ASSERT( TCR_4(task_team -> tt.tt_found_tasks) == TRUE );
297 KMP_DEBUG_ASSERT( TCR_PTR(task_team -> tt.tt_threads_data) != NULL );
300 thread_data = & task_team -> tt.tt_threads_data[ tid ];
303 if (thread_data -> td.td_deque == NULL ) {
304 __kmp_alloc_task_deque( thread, thread_data );
308 if ( TCR_4(thread_data -> td.td_deque_ntasks) >= TASK_DEQUE_SIZE(thread_data->td) )
310 KA_TRACE(20, (
"__kmp_push_task: T#%d deque is full; returning TASK_NOT_PUSHED for task %p\n",
312 return TASK_NOT_PUSHED;
316 __kmp_acquire_bootstrap_lock( & thread_data -> td.td_deque_lock );
320 if ( TCR_4(thread_data -> td.td_deque_ntasks) >= TASK_DEQUE_SIZE(thread_data->td) )
322 __kmp_release_bootstrap_lock( & thread_data -> td.td_deque_lock );
323 KA_TRACE(20, (
"__kmp_push_task: T#%d deque is full on 2nd check; returning TASK_NOT_PUSHED for task %p\n",
325 return TASK_NOT_PUSHED;
329 KMP_DEBUG_ASSERT( TCR_4(thread_data -> td.td_deque_ntasks) < TASK_DEQUE_SIZE(thread_data->td) );
332 thread_data -> td.td_deque[ thread_data -> td.td_deque_tail ] = taskdata;
334 thread_data -> td.td_deque_tail = ( thread_data -> td.td_deque_tail + 1 ) & TASK_DEQUE_MASK(thread_data->td);
335 TCW_4(thread_data -> td.td_deque_ntasks, TCR_4(thread_data -> td.td_deque_ntasks) + 1);
337 __kmp_release_bootstrap_lock( & thread_data -> td.td_deque_lock );
339 KA_TRACE(20, (
"__kmp_push_task: T#%d returning TASK_SUCCESSFULLY_PUSHED: " 340 "task=%p ntasks=%d head=%u tail=%u\n",
341 gtid, taskdata, thread_data->td.td_deque_ntasks,
342 thread_data->td.td_deque_tail, thread_data->td.td_deque_head) );
344 return TASK_SUCCESSFULLY_PUSHED;
353 __kmp_pop_current_task_from_thread( kmp_info_t *this_thr )
355 KF_TRACE( 10, (
"__kmp_pop_current_task_from_thread(enter): T#%d this_thread=%p, curtask=%p, " 356 "curtask_parent=%p\n",
357 0, this_thr, this_thr -> th.th_current_task,
358 this_thr -> th.th_current_task -> td_parent ) );
360 this_thr -> th.th_current_task = this_thr -> th.th_current_task -> td_parent;
362 KF_TRACE( 10, (
"__kmp_pop_current_task_from_thread(exit): T#%d this_thread=%p, curtask=%p, " 363 "curtask_parent=%p\n",
364 0, this_thr, this_thr -> th.th_current_task,
365 this_thr -> th.th_current_task -> td_parent ) );
376 __kmp_push_current_task_to_thread( kmp_info_t *this_thr, kmp_team_t *team,
int tid )
379 KF_TRACE( 10, (
"__kmp_push_current_task_to_thread(enter): T#%d this_thread=%p curtask=%p " 381 tid, this_thr, this_thr->th.th_current_task,
382 team->t.t_implicit_task_taskdata[tid].td_parent ) );
384 KMP_DEBUG_ASSERT (this_thr != NULL);
387 if( this_thr->th.th_current_task != & team -> t.t_implicit_task_taskdata[ 0 ] ) {
388 team -> t.t_implicit_task_taskdata[ 0 ].td_parent = this_thr->th.th_current_task;
389 this_thr->th.th_current_task = & team -> t.t_implicit_task_taskdata[ 0 ];
392 team -> t.t_implicit_task_taskdata[ tid ].td_parent = team -> t.t_implicit_task_taskdata[ 0 ].td_parent;
393 this_thr->th.th_current_task = & team -> t.t_implicit_task_taskdata[ tid ];
396 KF_TRACE( 10, (
"__kmp_push_current_task_to_thread(exit): T#%d this_thread=%p curtask=%p " 398 tid, this_thr, this_thr->th.th_current_task,
399 team->t.t_implicit_task_taskdata[tid].td_parent ) );
410 __kmp_task_start( kmp_int32 gtid, kmp_task_t * task, kmp_taskdata_t * current_task )
412 kmp_taskdata_t * taskdata = KMP_TASK_TO_TASKDATA(task);
413 kmp_info_t * thread = __kmp_threads[ gtid ];
415 KA_TRACE(10, (
"__kmp_task_start(enter): T#%d starting task %p: current_task=%p\n",
416 gtid, taskdata, current_task) );
418 KMP_DEBUG_ASSERT( taskdata -> td_flags.tasktype == TASK_EXPLICIT );
423 current_task -> td_flags.executing = 0;
426 #ifdef BUILD_TIED_TASK_STACK 427 if ( taskdata -> td_flags.tiedness == TASK_TIED )
429 __kmp_push_task_stack( gtid, thread, taskdata );
434 thread -> th.th_current_task = taskdata;
436 KMP_DEBUG_ASSERT( taskdata->td_flags.started == 0 || taskdata->td_flags.tiedness == TASK_UNTIED );
437 KMP_DEBUG_ASSERT( taskdata->td_flags.executing == 0 || taskdata->td_flags.tiedness == TASK_UNTIED );
438 taskdata -> td_flags.started = 1;
439 taskdata -> td_flags.executing = 1;
440 KMP_DEBUG_ASSERT( taskdata -> td_flags.complete == 0 );
441 KMP_DEBUG_ASSERT( taskdata -> td_flags.freed == 0 );
448 KA_TRACE(10, (
"__kmp_task_start(exit): T#%d task=%p\n",
453 ompt_callbacks.ompt_callback(ompt_event_task_begin)) {
454 kmp_taskdata_t *parent = taskdata->td_parent;
455 ompt_callbacks.ompt_callback(ompt_event_task_begin)(
456 parent ? parent->ompt_task_info.task_id : ompt_task_id_none,
457 parent ? &(parent->ompt_task_info.frame) : NULL,
458 taskdata->ompt_task_info.task_id,
459 taskdata->ompt_task_info.function);
462 #if OMP_40_ENABLED && OMPT_SUPPORT && OMPT_TRACE 464 if (ompt_enabled && taskdata->ompt_task_info.ndeps > 0 &&
465 ompt_callbacks.ompt_callback(ompt_event_task_dependences))
467 ompt_callbacks.ompt_callback(ompt_event_task_dependences)(
468 taskdata->ompt_task_info.task_id,
469 taskdata->ompt_task_info.deps,
470 taskdata->ompt_task_info.ndeps
473 KMP_OMPT_DEPS_FREE (thread, taskdata->ompt_task_info.deps);
474 taskdata->ompt_task_info.deps = NULL;
475 taskdata->ompt_task_info.ndeps = 0;
490 __kmpc_omp_task_begin_if0(
ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * task )
492 kmp_taskdata_t * taskdata = KMP_TASK_TO_TASKDATA(task);
493 kmp_taskdata_t * current_task = __kmp_threads[ gtid ] -> th.th_current_task;
495 KA_TRACE(10, (
"__kmpc_omp_task_begin_if0(enter): T#%d loc=%p task=%p current_task=%p\n",
496 gtid, loc_ref, taskdata, current_task ) );
498 if ( taskdata->td_flags.tiedness == TASK_UNTIED ) {
500 kmp_int32 counter = 1 + KMP_TEST_THEN_INC32(&taskdata->td_untied_count);
501 KA_TRACE(20, (
"__kmpc_omp_task_begin_if0: T#%d untied_count (%d) incremented for task %p\n",
502 gtid, counter, taskdata ) );
505 taskdata -> td_flags.task_serial = 1;
506 __kmp_task_start( gtid, task, current_task );
508 KA_TRACE(10, (
"__kmpc_omp_task_begin_if0(exit): T#%d loc=%p task=%p,\n",
509 gtid, loc_ref, taskdata ) );
520 __kmpc_omp_task_begin(
ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * task )
522 kmp_taskdata_t * current_task = __kmp_threads[ gtid ] -> th.th_current_task;
524 KA_TRACE(10, (
"__kmpc_omp_task_begin(enter): T#%d loc=%p task=%p current_task=%p\n",
525 gtid, loc_ref, KMP_TASK_TO_TASKDATA(task), current_task ) );
527 __kmp_task_start( gtid, task, current_task );
529 KA_TRACE(10, (
"__kmpc_omp_task_begin(exit): T#%d loc=%p task=%p,\n",
530 gtid, loc_ref, KMP_TASK_TO_TASKDATA(task) ) );
534 #endif // TASK_UNUSED 544 __kmp_free_task( kmp_int32 gtid, kmp_taskdata_t * taskdata, kmp_info_t * thread )
546 KA_TRACE(30, (
"__kmp_free_task: T#%d freeing data from task %p\n",
550 KMP_DEBUG_ASSERT( taskdata->td_flags.tasktype == TASK_EXPLICIT );
551 KMP_DEBUG_ASSERT( taskdata->td_flags.executing == 0 );
552 KMP_DEBUG_ASSERT( taskdata->td_flags.complete == 1 );
553 KMP_DEBUG_ASSERT( taskdata->td_flags.freed == 0 );
554 KMP_DEBUG_ASSERT( TCR_4(taskdata->td_allocated_child_tasks) == 0 || taskdata->td_flags.task_serial == 1);
555 KMP_DEBUG_ASSERT( TCR_4(taskdata->td_incomplete_child_tasks) == 0 );
557 taskdata->td_flags.freed = 1;
560 __kmp_fast_free( thread, taskdata );
562 __kmp_thread_free( thread, taskdata );
565 KA_TRACE(20, (
"__kmp_free_task: T#%d freed task %p\n",
577 __kmp_free_task_and_ancestors( kmp_int32 gtid, kmp_taskdata_t * taskdata, kmp_info_t * thread )
579 kmp_int32 children = 0;
580 kmp_int32 team_or_tasking_serialized = taskdata -> td_flags.team_serial || taskdata -> td_flags.tasking_ser;
582 KMP_DEBUG_ASSERT( taskdata -> td_flags.tasktype == TASK_EXPLICIT );
584 if ( !team_or_tasking_serialized ) {
585 children = KMP_TEST_THEN_DEC32( (kmp_int32 *)(& taskdata -> td_allocated_child_tasks) ) - 1;
586 KMP_DEBUG_ASSERT( children >= 0 );
590 while ( children == 0 )
592 kmp_taskdata_t * parent_taskdata = taskdata -> td_parent;
594 KA_TRACE(20, (
"__kmp_free_task_and_ancestors(enter): T#%d task %p complete " 595 "and freeing itself\n", gtid, taskdata) );
598 __kmp_free_task( gtid, taskdata, thread );
600 taskdata = parent_taskdata;
604 if ( team_or_tasking_serialized || taskdata -> td_flags.tasktype == TASK_IMPLICIT )
607 if ( !team_or_tasking_serialized ) {
609 children = KMP_TEST_THEN_DEC32( (kmp_int32 *)(& taskdata -> td_allocated_child_tasks) ) - 1;
610 KMP_DEBUG_ASSERT( children >= 0 );
614 KA_TRACE(20, (
"__kmp_free_task_and_ancestors(exit): T#%d task %p has %d children; " 615 "not freeing it yet\n", gtid, taskdata, children) );
625 __kmp_task_finish( kmp_int32 gtid, kmp_task_t *task, kmp_taskdata_t *resumed_task )
627 kmp_taskdata_t * taskdata = KMP_TASK_TO_TASKDATA(task);
628 kmp_info_t * thread = __kmp_threads[ gtid ];
629 kmp_int32 children = 0;
633 ompt_callbacks.ompt_callback(ompt_event_task_end)) {
634 kmp_taskdata_t *parent = taskdata->td_parent;
635 ompt_callbacks.ompt_callback(ompt_event_task_end)(
636 taskdata->ompt_task_info.task_id);
640 KA_TRACE(10, (
"__kmp_task_finish(enter): T#%d finishing task %p and resuming task %p\n",
641 gtid, taskdata, resumed_task) );
643 KMP_DEBUG_ASSERT( taskdata -> td_flags.tasktype == TASK_EXPLICIT );
646 #ifdef BUILD_TIED_TASK_STACK 647 if ( taskdata -> td_flags.tiedness == TASK_TIED )
649 __kmp_pop_task_stack( gtid, thread, taskdata );
653 if ( taskdata->td_flags.tiedness == TASK_UNTIED ) {
655 kmp_int32 counter = KMP_TEST_THEN_DEC32(&taskdata->td_untied_count) - 1;
656 KA_TRACE(20, (
"__kmp_task_finish: T#%d untied_count (%d) decremented for task %p\n",
657 gtid, counter, taskdata ) );
660 if (resumed_task == NULL) {
661 KMP_DEBUG_ASSERT( taskdata->td_flags.task_serial );
662 resumed_task = taskdata->td_parent;
664 thread->th.th_current_task = resumed_task;
665 resumed_task->td_flags.executing = 1;
666 KA_TRACE(10, (
"__kmp_task_finish(exit): T#%d partially done task %p, resuming task %p\n",
667 gtid, taskdata, resumed_task) );
672 KMP_DEBUG_ASSERT( taskdata -> td_flags.complete == 0 );
673 taskdata -> td_flags.complete = 1;
674 KMP_DEBUG_ASSERT( taskdata -> td_flags.started == 1 );
675 KMP_DEBUG_ASSERT( taskdata -> td_flags.freed == 0 );
678 if ( !( taskdata -> td_flags.team_serial || taskdata -> td_flags.tasking_ser ) ) {
680 children = KMP_TEST_THEN_DEC32( (kmp_int32 *)(& taskdata -> td_parent -> td_incomplete_child_tasks) ) - 1;
681 KMP_DEBUG_ASSERT( children >= 0 );
683 if ( taskdata->td_taskgroup )
684 KMP_TEST_THEN_DEC32( (kmp_int32 *)(& taskdata->td_taskgroup->count) );
685 __kmp_release_deps(gtid,taskdata);
692 KMP_DEBUG_ASSERT( taskdata -> td_flags.executing == 1 );
693 taskdata -> td_flags.executing = 0;
695 KA_TRACE(20, (
"__kmp_task_finish: T#%d finished task %p, %d incomplete children\n",
696 gtid, taskdata, children) );
706 if (taskdata->td_flags.destructors_thunk) {
707 kmp_routine_entry_t destr_thunk = task->data1.destructors;
708 KMP_ASSERT(destr_thunk);
709 destr_thunk(gtid, task);
711 #endif // OMP_40_ENABLED 715 KMP_DEBUG_ASSERT( (taskdata->td_flags.tasking_ser || taskdata->td_flags.task_serial) ==
716 taskdata->td_flags.task_serial);
717 if ( taskdata->td_flags.task_serial )
719 if (resumed_task == NULL) {
720 resumed_task = taskdata->td_parent;
724 KMP_DEBUG_ASSERT( resumed_task == taskdata->td_parent );
728 KMP_DEBUG_ASSERT( resumed_task != NULL );
735 thread->th.th_current_task = resumed_task;
736 __kmp_free_task_and_ancestors(gtid, taskdata, thread);
740 resumed_task->td_flags.executing = 1;
742 KA_TRACE(10, (
"__kmp_task_finish(exit): T#%d finished task %p, resuming task %p\n",
743 gtid, taskdata, resumed_task) );
755 __kmpc_omp_task_complete_if0(
ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *task )
757 KA_TRACE(10, (
"__kmpc_omp_task_complete_if0(enter): T#%d loc=%p task=%p\n",
758 gtid, loc_ref, KMP_TASK_TO_TASKDATA(task) ) );
760 __kmp_task_finish( gtid, task, NULL );
762 KA_TRACE(10, (
"__kmpc_omp_task_complete_if0(exit): T#%d loc=%p task=%p\n",
763 gtid, loc_ref, KMP_TASK_TO_TASKDATA(task) ) );
774 __kmpc_omp_task_complete(
ident_t *loc_ref, kmp_int32 gtid, kmp_task_t *task )
776 KA_TRACE(10, (
"__kmpc_omp_task_complete(enter): T#%d loc=%p task=%p\n",
777 gtid, loc_ref, KMP_TASK_TO_TASKDATA(task) ) );
779 __kmp_task_finish( gtid, task, NULL );
781 KA_TRACE(10, (
"__kmpc_omp_task_complete(exit): T#%d loc=%p task=%p\n",
782 gtid, loc_ref, KMP_TASK_TO_TASKDATA(task) ) );
785 #endif // TASK_UNUSED 795 __kmp_task_init_ompt( kmp_taskdata_t * task,
int tid,
void *
function )
798 task->ompt_task_info.task_id = __ompt_task_id_new(tid);
799 task->ompt_task_info.function =
function;
800 task->ompt_task_info.frame.exit_runtime_frame = NULL;
801 task->ompt_task_info.frame.reenter_runtime_frame = NULL;
803 task->ompt_task_info.ndeps = 0;
804 task->ompt_task_info.deps = NULL;
823 __kmp_init_implicit_task(
ident_t *loc_ref, kmp_info_t *this_thr, kmp_team_t *team,
int tid,
int set_curr_task )
825 kmp_taskdata_t * task = & team->t.t_implicit_task_taskdata[ tid ];
827 KF_TRACE(10, (
"__kmp_init_implicit_task(enter): T#:%d team=%p task=%p, reinit=%s\n",
828 tid, team, task, set_curr_task ?
"TRUE" :
"FALSE" ) );
830 task->td_task_id = KMP_GEN_TASK_ID();
831 task->td_team = team;
833 task->td_ident = loc_ref;
834 task->td_taskwait_ident = NULL;
835 task->td_taskwait_counter = 0;
836 task->td_taskwait_thread = 0;
838 task->td_flags.tiedness = TASK_TIED;
839 task->td_flags.tasktype = TASK_IMPLICIT;
841 task->td_flags.proxy = TASK_FULL;
845 task->td_flags.task_serial = 1;
846 task->td_flags.tasking_ser = ( __kmp_tasking_mode == tskm_immediate_exec );
847 task->td_flags.team_serial = ( team->t.t_serialized ) ? 1 : 0;
849 task->td_flags.started = 1;
850 task->td_flags.executing = 1;
851 task->td_flags.complete = 0;
852 task->td_flags.freed = 0;
855 task->td_depnode = NULL;
859 task->td_incomplete_child_tasks = 0;
860 task->td_allocated_child_tasks = 0;
862 task->td_taskgroup = NULL;
863 task->td_dephash = NULL;
865 __kmp_push_current_task_to_thread( this_thr, team, tid );
867 KMP_DEBUG_ASSERT(task->td_incomplete_child_tasks == 0);
868 KMP_DEBUG_ASSERT(task->td_allocated_child_tasks == 0);
872 __kmp_task_init_ompt(task, tid, NULL);
875 KF_TRACE(10, (
"__kmp_init_implicit_task(exit): T#:%d team=%p task=%p\n",
888 __kmp_finish_implicit_task(kmp_info_t *thread)
890 kmp_taskdata_t *task = thread->th.th_current_task;
891 if (task->td_dephash)
892 __kmp_dephash_free_entries(thread, task->td_dephash);
903 __kmp_free_implicit_task(kmp_info_t *thread)
905 kmp_taskdata_t *task = thread->th.th_current_task;
906 if (task->td_dephash)
907 __kmp_dephash_free(thread, task->td_dephash);
908 task->td_dephash = NULL;
915 __kmp_round_up_to_val(
size_t size,
size_t val ) {
916 if ( size & ( val - 1 ) ) {
917 size &= ~ ( val - 1 );
918 if ( size <= KMP_SIZE_T_MAX - val ) {
939 __kmp_task_alloc(
ident_t *loc_ref, kmp_int32 gtid, kmp_tasking_flags_t *flags,
940 size_t sizeof_kmp_task_t,
size_t sizeof_shareds,
941 kmp_routine_entry_t task_entry )
944 kmp_taskdata_t *taskdata;
945 kmp_info_t *thread = __kmp_threads[ gtid ];
946 kmp_team_t *team = thread->th.th_team;
947 kmp_taskdata_t *parent_task = thread->th.th_current_task;
948 size_t shareds_offset;
950 KA_TRACE(10, (
"__kmp_task_alloc(enter): T#%d loc=%p, flags=(0x%x) " 951 "sizeof_task=%ld sizeof_shared=%ld entry=%p\n",
952 gtid, loc_ref, *((kmp_int32 *)flags), sizeof_kmp_task_t,
953 sizeof_shareds, task_entry) );
955 if ( parent_task->td_flags.final ) {
956 if (flags->merged_if0) {
962 if ( flags->proxy == TASK_PROXY ) {
963 flags->tiedness = TASK_UNTIED;
964 flags->merged_if0 = 1;
967 if ( (thread->th.th_task_team) == NULL ) {
971 KMP_DEBUG_ASSERT(team->t.t_serialized);
972 KA_TRACE(30,(
"T#%d creating task team in __kmp_task_alloc for proxy task\n", gtid));
973 __kmp_task_team_setup(thread,team,1);
974 thread->th.th_task_team = team->t.t_task_team[thread->th.th_task_state];
976 kmp_task_team_t * task_team = thread->th.th_task_team;
979 if ( !KMP_TASKING_ENABLED( task_team ) ) {
980 KA_TRACE(30,(
"T#%d enabling tasking in __kmp_task_alloc for proxy task\n", gtid));
981 __kmp_enable_tasking( task_team, thread );
982 kmp_int32 tid = thread->th.th_info.ds.ds_tid;
983 kmp_thread_data_t * thread_data = & task_team -> tt.tt_threads_data[ tid ];
985 if (thread_data -> td.td_deque == NULL ) {
986 __kmp_alloc_task_deque( thread, thread_data );
990 if ( task_team->tt.tt_found_proxy_tasks == FALSE )
991 TCW_4(task_team -> tt.tt_found_proxy_tasks, TRUE);
997 shareds_offset =
sizeof( kmp_taskdata_t ) + sizeof_kmp_task_t;
998 shareds_offset = __kmp_round_up_to_val( shareds_offset,
sizeof(
void * ));
1001 KA_TRACE(30, (
"__kmp_task_alloc: T#%d First malloc size: %ld\n",
1002 gtid, shareds_offset) );
1003 KA_TRACE(30, (
"__kmp_task_alloc: T#%d Second malloc size: %ld\n",
1004 gtid, sizeof_shareds) );
1008 taskdata = (kmp_taskdata_t *) __kmp_fast_allocate( thread, shareds_offset + sizeof_shareds );
1010 taskdata = (kmp_taskdata_t *) __kmp_thread_malloc( thread, shareds_offset + sizeof_shareds );
1013 task = KMP_TASKDATA_TO_TASK(taskdata);
1016 #if KMP_ARCH_X86 || KMP_ARCH_PPC64 || !KMP_HAVE_QUAD 1017 KMP_DEBUG_ASSERT( ( ((kmp_uintptr_t)taskdata) & (
sizeof(
double)-1) ) == 0 );
1018 KMP_DEBUG_ASSERT( ( ((kmp_uintptr_t)task) & (
sizeof(
double)-1) ) == 0 );
1020 KMP_DEBUG_ASSERT( ( ((kmp_uintptr_t)taskdata) & (
sizeof(_Quad)-1) ) == 0 );
1021 KMP_DEBUG_ASSERT( ( ((kmp_uintptr_t)task) & (
sizeof(_Quad)-1) ) == 0 );
1023 if (sizeof_shareds > 0) {
1025 task->shareds = & ((
char *) taskdata)[ shareds_offset ];
1027 KMP_DEBUG_ASSERT( ( ((kmp_uintptr_t)task->shareds) & (
sizeof(
void *)-1) ) == 0 );
1029 task->shareds = NULL;
1031 task->routine = task_entry;
1034 taskdata->td_task_id = KMP_GEN_TASK_ID();
1035 taskdata->td_team = team;
1036 taskdata->td_alloc_thread = thread;
1037 taskdata->td_parent = parent_task;
1038 taskdata->td_level = parent_task->td_level + 1;
1039 taskdata->td_untied_count = 0;
1040 taskdata->td_ident = loc_ref;
1041 taskdata->td_taskwait_ident = NULL;
1042 taskdata->td_taskwait_counter = 0;
1043 taskdata->td_taskwait_thread = 0;
1044 KMP_DEBUG_ASSERT( taskdata->td_parent != NULL );
1047 if ( flags->proxy == TASK_FULL )
1049 copy_icvs( &taskdata->td_icvs, &taskdata->td_parent->td_icvs );
1051 taskdata->td_flags.tiedness = flags->tiedness;
1052 taskdata->td_flags.final = flags->final;
1053 taskdata->td_flags.merged_if0 = flags->merged_if0;
1055 taskdata->td_flags.destructors_thunk = flags->destructors_thunk;
1056 #endif // OMP_40_ENABLED 1058 taskdata->td_flags.proxy = flags->proxy;
1059 taskdata->td_task_team = thread->th.th_task_team;
1060 taskdata->td_size_alloc = shareds_offset + sizeof_shareds;
1062 taskdata->td_flags.tasktype = TASK_EXPLICIT;
1065 taskdata->td_flags.tasking_ser = ( __kmp_tasking_mode == tskm_immediate_exec );
1068 taskdata->td_flags.team_serial = ( team->t.t_serialized ) ? 1 : 0;
1073 taskdata->td_flags.task_serial = ( parent_task->td_flags.final
1074 || taskdata->td_flags.team_serial || taskdata->td_flags.tasking_ser );
1076 taskdata->td_flags.started = 0;
1077 taskdata->td_flags.executing = 0;
1078 taskdata->td_flags.complete = 0;
1079 taskdata->td_flags.freed = 0;
1081 taskdata->td_flags.native = flags->native;
1083 taskdata->td_incomplete_child_tasks = 0;
1084 taskdata->td_allocated_child_tasks = 1;
1086 taskdata->td_taskgroup = parent_task->td_taskgroup;
1087 taskdata->td_dephash = NULL;
1088 taskdata->td_depnode = NULL;
1093 if ( flags->proxy == TASK_PROXY || !( taskdata -> td_flags.team_serial || taskdata -> td_flags.tasking_ser ) )
1095 if ( !( taskdata -> td_flags.team_serial || taskdata -> td_flags.tasking_ser ) )
1098 KMP_TEST_THEN_INC32( (kmp_int32 *)(& parent_task->td_incomplete_child_tasks) );
1100 if ( parent_task->td_taskgroup )
1101 KMP_TEST_THEN_INC32( (kmp_int32 *)(& parent_task->td_taskgroup->count) );
1104 if ( taskdata->td_parent->td_flags.tasktype == TASK_EXPLICIT ) {
1105 KMP_TEST_THEN_INC32( (kmp_int32 *)(& taskdata->td_parent->td_allocated_child_tasks) );
1109 KA_TRACE(20, (
"__kmp_task_alloc(exit): T#%d created task %p parent=%p\n",
1110 gtid, taskdata, taskdata->td_parent) );
1113 __kmp_task_init_ompt(taskdata, gtid, (
void*) task_entry);
1121 __kmpc_omp_task_alloc(
ident_t *loc_ref, kmp_int32 gtid, kmp_int32 flags,
1122 size_t sizeof_kmp_task_t,
size_t sizeof_shareds,
1123 kmp_routine_entry_t task_entry )
1126 kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *) & flags;
1128 input_flags->native = FALSE;
1132 KA_TRACE(10, (
"__kmpc_omp_task_alloc(enter): T#%d loc=%p, flags=(%s %s) " 1133 "sizeof_task=%ld sizeof_shared=%ld entry=%p\n",
1134 gtid, loc_ref, input_flags->tiedness ?
"tied " :
"untied",
1135 input_flags->proxy ?
"proxy" :
"",
1136 sizeof_kmp_task_t, sizeof_shareds, task_entry) );
1138 KA_TRACE(10, (
"__kmpc_omp_task_alloc(enter): T#%d loc=%p, flags=(%s) " 1139 "sizeof_task=%ld sizeof_shared=%ld entry=%p\n",
1140 gtid, loc_ref, input_flags->tiedness ?
"tied " :
"untied",
1141 sizeof_kmp_task_t, sizeof_shareds, task_entry) );
1144 retval = __kmp_task_alloc( loc_ref, gtid, input_flags, sizeof_kmp_task_t,
1145 sizeof_shareds, task_entry );
1147 KA_TRACE(20, (
"__kmpc_omp_task_alloc(exit): T#%d retval %p\n", gtid, retval) );
1160 __kmp_invoke_task( kmp_int32 gtid, kmp_task_t *task, kmp_taskdata_t * current_task )
1162 kmp_taskdata_t * taskdata = KMP_TASK_TO_TASKDATA(task);
1163 kmp_uint64 cur_time;
1167 KA_TRACE(30, (
"__kmp_invoke_task(enter): T#%d invoking task %p, current_task=%p\n",
1168 gtid, taskdata, current_task) );
1169 KMP_DEBUG_ASSERT(task);
1171 if ( taskdata->td_flags.proxy == TASK_PROXY &&
1172 taskdata->td_flags.complete == 1)
1176 KA_TRACE(30, (
"__kmp_invoke_task: T#%d running bottom finish for proxy task %p\n",
1179 __kmp_bottom_half_finish_proxy(gtid,task);
1181 KA_TRACE(30, (
"__kmp_invoke_task(exit): T#%d completed bottom finish for proxy task %p, resuming task %p\n", gtid, taskdata, current_task) );
1187 #if USE_ITT_BUILD && USE_ITT_NOTIFY 1188 if(__kmp_forkjoin_frames_mode == 3) {
1190 cur_time = __itt_get_timestamp();
1196 if ( taskdata->td_flags.proxy != TASK_PROXY )
1198 __kmp_task_start( gtid, task, current_task );
1201 ompt_thread_info_t oldInfo;
1202 kmp_info_t * thread;
1205 thread = __kmp_threads[ gtid ];
1206 oldInfo = thread->th.ompt_thread_info;
1207 thread->th.ompt_thread_info.wait_id = 0;
1208 thread->th.ompt_thread_info.state = ompt_state_work_parallel;
1209 taskdata->ompt_task_info.frame.exit_runtime_frame = __builtin_frame_address(0);
1217 if (__kmp_omp_cancellation) {
1218 kmp_info_t *this_thr = __kmp_threads [ gtid ];
1219 kmp_team_t * this_team = this_thr->th.th_team;
1220 kmp_taskgroup_t * taskgroup = taskdata->td_taskgroup;
1221 if ((taskgroup && taskgroup->cancel_request) || (this_team->t.t_cancel_request == cancel_parallel)) {
1233 #if KMP_STATS_ENABLED 1235 switch(KMP_GET_THREAD_STATE()) {
1236 case FORK_JOIN_BARRIER: KMP_PUSH_PARTITIONED_TIMER(OMP_task_join_bar);
break;
1237 case PLAIN_BARRIER: KMP_PUSH_PARTITIONED_TIMER(OMP_task_plain_bar);
break;
1238 case TASKYIELD: KMP_PUSH_PARTITIONED_TIMER(OMP_task_taskyield);
break;
1239 case TASKWAIT: KMP_PUSH_PARTITIONED_TIMER(OMP_task_taskwait);
break;
1240 case TASKGROUP: KMP_PUSH_PARTITIONED_TIMER(OMP_task_taskgroup);
break;
1241 default: KMP_PUSH_PARTITIONED_TIMER(OMP_task_immediate);
break;
1243 #endif // KMP_STATS_ENABLED 1244 #endif // OMP_40_ENABLED 1246 #if OMPT_SUPPORT && OMPT_TRACE 1249 ompt_callbacks.ompt_callback(ompt_event_task_switch))
1251 ompt_callbacks.ompt_callback(ompt_event_task_switch)(
1252 current_task->ompt_task_info.task_id,
1253 taskdata->ompt_task_info.task_id);
1257 #ifdef KMP_GOMP_COMPAT 1258 if (taskdata->td_flags.native) {
1259 ((void (*)(
void *))(*(task->routine)))(task->shareds);
1264 (*(task->routine))(gtid, task);
1266 KMP_POP_PARTITIONED_TIMER();
1268 #if OMPT_SUPPORT && OMPT_TRACE 1271 ompt_callbacks.ompt_callback(ompt_event_task_switch))
1273 ompt_callbacks.ompt_callback(ompt_event_task_switch)(
1274 taskdata->ompt_task_info.task_id,
1275 current_task->ompt_task_info.task_id);
1281 #endif // OMP_40_ENABLED 1286 thread->th.ompt_thread_info = oldInfo;
1287 taskdata->ompt_task_info.frame.exit_runtime_frame = 0;
1293 if ( taskdata->td_flags.proxy != TASK_PROXY )
1295 __kmp_task_finish( gtid, task, current_task );
1297 #if USE_ITT_BUILD && USE_ITT_NOTIFY 1299 if(__kmp_forkjoin_frames_mode == 3) {
1300 kmp_info_t *this_thr = __kmp_threads [ gtid ];
1301 if(this_thr->th.th_bar_arrive_time) {
1302 this_thr->th.th_bar_arrive_time += (__itt_get_timestamp() - cur_time);
1306 KA_TRACE(30, (
"__kmp_invoke_task(exit): T#%d completed task %p, resuming task %p\n",
1307 gtid, taskdata, current_task) );
1322 __kmpc_omp_task_parts(
ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * new_task)
1324 kmp_taskdata_t * new_taskdata = KMP_TASK_TO_TASKDATA(new_task);
1326 KA_TRACE(10, (
"__kmpc_omp_task_parts(enter): T#%d loc=%p task=%p\n",
1327 gtid, loc_ref, new_taskdata ) );
1332 if ( __kmp_push_task( gtid, new_task ) == TASK_NOT_PUSHED )
1334 kmp_taskdata_t * current_task = __kmp_threads[ gtid ] -> th.th_current_task;
1335 new_taskdata->td_flags.task_serial = 1;
1336 __kmp_invoke_task( gtid, new_task, current_task );
1339 KA_TRACE(10, (
"__kmpc_omp_task_parts(exit): T#%d returning TASK_CURRENT_NOT_QUEUED: " 1340 "loc=%p task=%p, return: TASK_CURRENT_NOT_QUEUED\n", gtid, loc_ref,
1343 return TASK_CURRENT_NOT_QUEUED;
1356 __kmp_omp_task( kmp_int32 gtid, kmp_task_t * new_task,
bool serialize_immediate )
1358 kmp_taskdata_t * new_taskdata = KMP_TASK_TO_TASKDATA(new_task);
1362 new_taskdata->ompt_task_info.frame.reenter_runtime_frame =
1363 __builtin_frame_address(0);
1370 if ( new_taskdata->td_flags.proxy == TASK_PROXY || __kmp_push_task( gtid, new_task ) == TASK_NOT_PUSHED )
1372 if ( __kmp_push_task( gtid, new_task ) == TASK_NOT_PUSHED )
1375 kmp_taskdata_t * current_task = __kmp_threads[ gtid ] -> th.th_current_task;
1376 if ( serialize_immediate )
1377 new_taskdata -> td_flags.task_serial = 1;
1378 __kmp_invoke_task( gtid, new_task, current_task );
1383 new_taskdata->ompt_task_info.frame.reenter_runtime_frame = 0;
1387 return TASK_CURRENT_NOT_QUEUED;
1402 __kmpc_omp_task(
ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * new_task)
1405 KMP_SET_THREAD_STATE_BLOCK(EXPLICIT_TASK);
1408 kmp_taskdata_t * new_taskdata = KMP_TASK_TO_TASKDATA(new_task);
1410 KA_TRACE(10, (
"__kmpc_omp_task(enter): T#%d loc=%p task=%p\n",
1411 gtid, loc_ref, new_taskdata ) );
1413 res = __kmp_omp_task(gtid,new_task,
true);
1415 KA_TRACE(10, (
"__kmpc_omp_task(exit): T#%d returning TASK_CURRENT_NOT_QUEUED: loc=%p task=%p\n",
1416 gtid, loc_ref, new_taskdata ) );
1424 __kmpc_omp_taskwait(
ident_t *loc_ref, kmp_int32 gtid )
1426 kmp_taskdata_t * taskdata;
1427 kmp_info_t * thread;
1428 int thread_finished = FALSE;
1429 KMP_SET_THREAD_STATE_BLOCK(TASKWAIT);
1431 KA_TRACE(10, (
"__kmpc_omp_taskwait(enter): T#%d loc=%p\n", gtid, loc_ref) );
1433 if ( __kmp_tasking_mode != tskm_immediate_exec ) {
1436 thread = __kmp_threads[ gtid ];
1437 taskdata = thread -> th.th_current_task;
1439 #if OMPT_SUPPORT && OMPT_TRACE 1440 ompt_task_id_t my_task_id;
1441 ompt_parallel_id_t my_parallel_id;
1444 kmp_team_t *team = thread->th.th_team;
1445 my_task_id = taskdata->ompt_task_info.task_id;
1446 my_parallel_id = team->t.ompt_team_info.parallel_id;
1448 taskdata->ompt_task_info.frame.reenter_runtime_frame = __builtin_frame_address(0);
1449 if (ompt_callbacks.ompt_callback(ompt_event_taskwait_begin)) {
1450 ompt_callbacks.ompt_callback(ompt_event_taskwait_begin)(
1451 my_parallel_id, my_task_id);
1460 taskdata->td_taskwait_counter += 1;
1461 taskdata->td_taskwait_ident = loc_ref;
1462 taskdata->td_taskwait_thread = gtid + 1;
1465 void * itt_sync_obj = __kmp_itt_taskwait_object( gtid );
1466 if ( itt_sync_obj != NULL )
1467 __kmp_itt_taskwait_starting( gtid, itt_sync_obj );
1471 if ( ! taskdata->td_flags.team_serial || (thread->th.th_task_team != NULL && thread->th.th_task_team->tt.tt_found_proxy_tasks) )
1473 if ( ! taskdata->td_flags.team_serial )
1477 kmp_flag_32 flag(&(taskdata->td_incomplete_child_tasks), 0U);
1478 while ( TCR_4(taskdata -> td_incomplete_child_tasks) != 0 ) {
1479 flag.execute_tasks(thread, gtid, FALSE, &thread_finished
1480 USE_ITT_BUILD_ARG(itt_sync_obj), __kmp_task_stealing_constraint );
1484 if ( itt_sync_obj != NULL )
1485 __kmp_itt_taskwait_finished( gtid, itt_sync_obj );
1490 taskdata->td_taskwait_thread = - taskdata->td_taskwait_thread;
1492 #if OMPT_SUPPORT && OMPT_TRACE 1494 if (ompt_callbacks.ompt_callback(ompt_event_taskwait_end)) {
1495 ompt_callbacks.ompt_callback(ompt_event_taskwait_end)(
1496 my_parallel_id, my_task_id);
1498 taskdata->ompt_task_info.frame.reenter_runtime_frame = 0;
1503 KA_TRACE(10, (
"__kmpc_omp_taskwait(exit): T#%d task %p finished waiting, " 1504 "returning TASK_CURRENT_NOT_QUEUED\n", gtid, taskdata) );
1506 return TASK_CURRENT_NOT_QUEUED;
1514 __kmpc_omp_taskyield(
ident_t *loc_ref, kmp_int32 gtid,
int end_part )
1516 kmp_taskdata_t * taskdata;
1517 kmp_info_t * thread;
1518 int thread_finished = FALSE;
1521 KMP_SET_THREAD_STATE_BLOCK(TASKYIELD);
1523 KA_TRACE(10, (
"__kmpc_omp_taskyield(enter): T#%d loc=%p end_part = %d\n",
1524 gtid, loc_ref, end_part) );
1526 if ( __kmp_tasking_mode != tskm_immediate_exec && __kmp_init_parallel ) {
1529 thread = __kmp_threads[ gtid ];
1530 taskdata = thread -> th.th_current_task;
1536 taskdata->td_taskwait_counter += 1;
1537 taskdata->td_taskwait_ident = loc_ref;
1538 taskdata->td_taskwait_thread = gtid + 1;
1541 void * itt_sync_obj = __kmp_itt_taskwait_object( gtid );
1542 if ( itt_sync_obj != NULL )
1543 __kmp_itt_taskwait_starting( gtid, itt_sync_obj );
1545 if ( ! taskdata->td_flags.team_serial ) {
1546 kmp_task_team_t * task_team = thread->th.th_task_team;
1547 if (task_team != NULL) {
1548 if (KMP_TASKING_ENABLED(task_team)) {
1549 __kmp_execute_tasks_32( thread, gtid, NULL, FALSE, &thread_finished
1550 USE_ITT_BUILD_ARG(itt_sync_obj), __kmp_task_stealing_constraint );
1555 if ( itt_sync_obj != NULL )
1556 __kmp_itt_taskwait_finished( gtid, itt_sync_obj );
1561 taskdata->td_taskwait_thread = - taskdata->td_taskwait_thread;
1564 KA_TRACE(10, (
"__kmpc_omp_taskyield(exit): T#%d task %p resuming, " 1565 "returning TASK_CURRENT_NOT_QUEUED\n", gtid, taskdata) );
1567 return TASK_CURRENT_NOT_QUEUED;
1576 __kmpc_taskgroup(
ident_t* loc,
int gtid )
1578 kmp_info_t * thread = __kmp_threads[ gtid ];
1579 kmp_taskdata_t * taskdata = thread->th.th_current_task;
1580 kmp_taskgroup_t * tg_new =
1581 (kmp_taskgroup_t *)__kmp_thread_malloc( thread,
sizeof( kmp_taskgroup_t ) );
1582 KA_TRACE(10, (
"__kmpc_taskgroup: T#%d loc=%p group=%p\n", gtid, loc, tg_new) );
1584 tg_new->cancel_request = cancel_noreq;
1585 tg_new->parent = taskdata->td_taskgroup;
1586 taskdata->td_taskgroup = tg_new;
1595 __kmpc_end_taskgroup(
ident_t* loc,
int gtid )
1597 kmp_info_t * thread = __kmp_threads[ gtid ];
1598 kmp_taskdata_t * taskdata = thread->th.th_current_task;
1599 kmp_taskgroup_t * taskgroup = taskdata->td_taskgroup;
1600 int thread_finished = FALSE;
1602 KA_TRACE(10, (
"__kmpc_end_taskgroup(enter): T#%d loc=%p\n", gtid, loc) );
1603 KMP_DEBUG_ASSERT( taskgroup != NULL );
1604 KMP_SET_THREAD_STATE_BLOCK(TASKGROUP);
1606 if ( __kmp_tasking_mode != tskm_immediate_exec ) {
1609 void * itt_sync_obj = __kmp_itt_taskwait_object( gtid );
1610 if ( itt_sync_obj != NULL )
1611 __kmp_itt_taskwait_starting( gtid, itt_sync_obj );
1615 if ( ! taskdata->td_flags.team_serial || (thread->th.th_task_team != NULL && thread->th.th_task_team->tt.tt_found_proxy_tasks) )
1617 if ( ! taskdata->td_flags.team_serial )
1620 kmp_flag_32 flag(&(taskgroup->count), 0U);
1621 while ( TCR_4(taskgroup->count) != 0 ) {
1622 flag.execute_tasks(thread, gtid, FALSE, &thread_finished
1623 USE_ITT_BUILD_ARG(itt_sync_obj), __kmp_task_stealing_constraint );
1628 if ( itt_sync_obj != NULL )
1629 __kmp_itt_taskwait_finished( gtid, itt_sync_obj );
1632 KMP_DEBUG_ASSERT( taskgroup->count == 0 );
1635 taskdata->td_taskgroup = taskgroup->parent;
1636 __kmp_thread_free( thread, taskgroup );
1638 KA_TRACE(10, (
"__kmpc_end_taskgroup(exit): T#%d task %p finished waiting\n", gtid, taskdata) );
1647 __kmp_remove_my_task( kmp_info_t * thread, kmp_int32 gtid, kmp_task_team_t *task_team,
1648 kmp_int32 is_constrained )
1651 kmp_taskdata_t * taskdata;
1652 kmp_thread_data_t *thread_data;
1655 KMP_DEBUG_ASSERT( __kmp_tasking_mode != tskm_immediate_exec );
1656 KMP_DEBUG_ASSERT( task_team -> tt.tt_threads_data != NULL );
1658 thread_data = & task_team -> tt.tt_threads_data[ __kmp_tid_from_gtid( gtid ) ];
1660 KA_TRACE(10, (
"__kmp_remove_my_task(enter): T#%d ntasks=%d head=%u tail=%u\n",
1661 gtid, thread_data->td.td_deque_ntasks, thread_data->td.td_deque_head,
1662 thread_data->td.td_deque_tail) );
1664 if (TCR_4(thread_data -> td.td_deque_ntasks) == 0) {
1665 KA_TRACE(10, (
"__kmp_remove_my_task(exit #1): T#%d No tasks to remove: ntasks=%d head=%u tail=%u\n",
1666 gtid, thread_data->td.td_deque_ntasks, thread_data->td.td_deque_head,
1667 thread_data->td.td_deque_tail) );
1671 __kmp_acquire_bootstrap_lock( & thread_data -> td.td_deque_lock );
1673 if (TCR_4(thread_data -> td.td_deque_ntasks) == 0) {
1674 __kmp_release_bootstrap_lock( & thread_data -> td.td_deque_lock );
1675 KA_TRACE(10, (
"__kmp_remove_my_task(exit #2): T#%d No tasks to remove: ntasks=%d head=%u tail=%u\n",
1676 gtid, thread_data->td.td_deque_ntasks, thread_data->td.td_deque_head,
1677 thread_data->td.td_deque_tail) );
1681 tail = ( thread_data -> td.td_deque_tail - 1 ) & TASK_DEQUE_MASK(thread_data->td);
1682 taskdata = thread_data -> td.td_deque[ tail ];
1684 if (is_constrained && (taskdata->td_flags.tiedness == TASK_TIED)) {
1687 kmp_taskdata_t * current = thread->th.th_current_task;
1688 kmp_int32 level = current->td_level;
1689 kmp_taskdata_t * parent = taskdata->td_parent;
1690 while ( parent != current && parent->td_level > level ) {
1691 parent = parent->td_parent;
1692 KMP_DEBUG_ASSERT(parent != NULL);
1694 if ( parent != current ) {
1696 __kmp_release_bootstrap_lock( & thread_data -> td.td_deque_lock );
1697 KA_TRACE(10, (
"__kmp_remove_my_task(exit #2): T#%d No tasks to remove: ntasks=%d head=%u tail=%u\n",
1698 gtid, thread_data->td.td_deque_ntasks, thread_data->td.td_deque_head,
1699 thread_data->td.td_deque_tail) );
1704 thread_data -> td.td_deque_tail = tail;
1705 TCW_4(thread_data -> td.td_deque_ntasks, thread_data -> td.td_deque_ntasks - 1);
1707 __kmp_release_bootstrap_lock( & thread_data->td.td_deque_lock );
1709 KA_TRACE(10, (
"__kmp_remove_my_task(exit #2): T#%d task %p removed: ntasks=%d head=%u tail=%u\n",
1710 gtid, taskdata, thread_data->td.td_deque_ntasks, thread_data->td.td_deque_head,
1711 thread_data->td.td_deque_tail) );
1713 task = KMP_TASKDATA_TO_TASK( taskdata );
1724 __kmp_steal_task( kmp_info_t *victim, kmp_int32 gtid, kmp_task_team_t *task_team,
1725 volatile kmp_uint32 *unfinished_threads,
int *thread_finished,
1726 kmp_int32 is_constrained )
1729 kmp_taskdata_t * taskdata;
1730 kmp_thread_data_t *victim_td, *threads_data;
1731 kmp_int32 victim_tid;
1733 KMP_DEBUG_ASSERT( __kmp_tasking_mode != tskm_immediate_exec );
1735 threads_data = task_team -> tt.tt_threads_data;
1736 KMP_DEBUG_ASSERT( threads_data != NULL );
1738 victim_tid = victim->th.th_info.ds.ds_tid;
1739 victim_td = & threads_data[ victim_tid ];
1741 KA_TRACE(10, (
"__kmp_steal_task(enter): T#%d try to steal from T#%d: task_team=%p ntasks=%d " 1742 "head=%u tail=%u\n",
1743 gtid, __kmp_gtid_from_thread( victim ), task_team, victim_td->td.td_deque_ntasks,
1744 victim_td->td.td_deque_head, victim_td->td.td_deque_tail) );
1746 if ( (TCR_4(victim_td -> td.td_deque_ntasks) == 0) ||
1747 (TCR_PTR(victim->th.th_task_team) != task_team))
1749 KA_TRACE(10, (
"__kmp_steal_task(exit #1): T#%d could not steal from T#%d: task_team=%p " 1750 "ntasks=%d head=%u tail=%u\n",
1751 gtid, __kmp_gtid_from_thread( victim ), task_team, victim_td->td.td_deque_ntasks,
1752 victim_td->td.td_deque_head, victim_td->td.td_deque_tail) );
1756 __kmp_acquire_bootstrap_lock( & victim_td -> td.td_deque_lock );
1759 if ( (TCR_4(victim_td -> td.td_deque_ntasks) == 0) ||
1760 (TCR_PTR(victim->th.th_task_team) != task_team))
1762 __kmp_release_bootstrap_lock( & victim_td -> td.td_deque_lock );
1763 KA_TRACE(10, (
"__kmp_steal_task(exit #2): T#%d could not steal from T#%d: task_team=%p " 1764 "ntasks=%d head=%u tail=%u\n",
1765 gtid, __kmp_gtid_from_thread( victim ), task_team, victim_td->td.td_deque_ntasks,
1766 victim_td->td.td_deque_head, victim_td->td.td_deque_tail) );
1770 KMP_DEBUG_ASSERT( victim_td -> td.td_deque != NULL );
1772 if ( !is_constrained ) {
1773 taskdata = victim_td -> td.td_deque[ victim_td -> td.td_deque_head ];
1774 KMP_ASSERT(taskdata);
1776 victim_td -> td.td_deque_head = ( victim_td -> td.td_deque_head + 1 ) & TASK_DEQUE_MASK(victim_td->td);
1779 kmp_int32 tail = ( victim_td -> td.td_deque_tail - 1 ) & TASK_DEQUE_MASK(victim_td->td);
1780 taskdata = victim_td -> td.td_deque[ tail ];
1781 KMP_ASSERT(taskdata);
1784 kmp_taskdata_t * current = __kmp_threads[ gtid ]->th.th_current_task;
1785 kmp_int32 level = current->td_level;
1786 kmp_taskdata_t * parent = taskdata->td_parent;
1787 while ( parent != current && parent->td_level > level ) {
1788 parent = parent->td_parent;
1789 KMP_DEBUG_ASSERT(parent != NULL);
1791 if ( parent != current ) {
1793 __kmp_release_bootstrap_lock( & victim_td -> td.td_deque_lock );
1794 KA_TRACE(10, (
"__kmp_steal_task(exit #2): T#%d could not steal from T#%d: task_team=%p " 1795 "ntasks=%d head=%u tail=%u\n",
1796 gtid, __kmp_gtid_from_thread( threads_data[victim_tid].td.td_thr ),
1797 task_team, victim_td->td.td_deque_ntasks,
1798 victim_td->td.td_deque_head, victim_td->td.td_deque_tail) );
1801 victim_td -> td.td_deque_tail = tail;
1803 if (*thread_finished) {
1809 count = KMP_TEST_THEN_INC32( (kmp_int32 *)unfinished_threads );
1811 KA_TRACE(20, (
"__kmp_steal_task: T#%d inc unfinished_threads to %d: task_team=%p\n",
1812 gtid, count + 1, task_team) );
1814 *thread_finished = FALSE;
1816 TCW_4(victim_td -> td.td_deque_ntasks, TCR_4(victim_td -> td.td_deque_ntasks) - 1);
1818 __kmp_release_bootstrap_lock( & victim_td -> td.td_deque_lock );
1821 KA_TRACE(10, (
"__kmp_steal_task(exit #3): T#%d stole task %p from T#%d: task_team=%p " 1822 "ntasks=%d head=%u tail=%u\n",
1823 gtid, taskdata, __kmp_gtid_from_thread( victim ), task_team,
1824 victim_td->td.td_deque_ntasks, victim_td->td.td_deque_head,
1825 victim_td->td.td_deque_tail) );
1827 task = KMP_TASKDATA_TO_TASK( taskdata );
1842 static inline int __kmp_execute_tasks_template(kmp_info_t *thread, kmp_int32 gtid, C *flag,
int final_spin,
1843 int *thread_finished
1844 USE_ITT_BUILD_ARG(
void * itt_sync_obj), kmp_int32 is_constrained)
1846 kmp_task_team_t * task_team = thread->th.th_task_team;
1847 kmp_thread_data_t * threads_data;
1849 kmp_info_t * other_thread;
1850 kmp_taskdata_t * current_task = thread -> th.th_current_task;
1851 volatile kmp_uint32 * unfinished_threads;
1852 kmp_int32 nthreads, victim=-2, use_own_tasks=1, new_victim=0, tid=thread->th.th_info.ds.ds_tid;
1854 KMP_DEBUG_ASSERT( __kmp_tasking_mode != tskm_immediate_exec );
1855 KMP_DEBUG_ASSERT( thread == __kmp_threads[ gtid ] );
1857 if (task_team == NULL)
return FALSE;
1859 KA_TRACE(15, (
"__kmp_execute_tasks_template(enter): T#%d final_spin=%d *thread_finished=%d\n",
1860 gtid, final_spin, *thread_finished) );
1862 threads_data = (kmp_thread_data_t *)TCR_PTR(task_team -> tt.tt_threads_data);
1863 KMP_DEBUG_ASSERT( threads_data != NULL );
1865 nthreads = task_team -> tt.tt_nproc;
1866 unfinished_threads = &(task_team -> tt.tt_unfinished_threads);
1868 KMP_DEBUG_ASSERT( nthreads > 1 || task_team->tt.tt_found_proxy_tasks);
1870 KMP_DEBUG_ASSERT( nthreads > 1 );
1872 KMP_DEBUG_ASSERT( (
int)(TCR_4(*unfinished_threads)) >= 0 );
1877 if (use_own_tasks) {
1878 task = __kmp_remove_my_task( thread, gtid, task_team, is_constrained );
1880 if ((task == NULL) && (nthreads > 1)) {
1885 victim = threads_data[tid].td.td_deque_last_stolen;
1887 other_thread = threads_data[victim].td.td_thr;
1892 else if (!new_victim) {
1896 victim = __kmp_get_random(thread) % (nthreads - 1);
1897 if (victim >= tid) {
1901 other_thread = threads_data[victim].td.td_thr;
1908 if ( ( __kmp_tasking_mode == tskm_task_teams ) &&
1909 (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) &&
1910 (TCR_PTR(other_thread->th.th_sleep_loc) != NULL)) {
1912 __kmp_null_resume_wrapper(__kmp_gtid_from_thread(other_thread), other_thread->th.th_sleep_loc);
1923 task = __kmp_steal_task(other_thread, gtid, task_team, unfinished_threads, thread_finished, is_constrained);
1926 if (threads_data[tid].td.td_deque_last_stolen != victim) {
1927 threads_data[tid].td.td_deque_last_stolen = victim;
1934 KMP_CHECK_UPDATE(threads_data[tid].td.td_deque_last_stolen, -1);
1943 #if USE_ITT_BUILD && USE_ITT_NOTIFY 1944 if ( __itt_sync_create_ptr || KMP_ITT_DEBUG ) {
1945 if ( itt_sync_obj == NULL ) {
1946 itt_sync_obj = __kmp_itt_barrier_object( gtid, bs_forkjoin_barrier );
1948 __kmp_itt_task_starting( itt_sync_obj );
1951 __kmp_invoke_task( gtid, task, current_task );
1953 if ( itt_sync_obj != NULL ) __kmp_itt_task_finished( itt_sync_obj );
1959 if (flag == NULL || (!final_spin && flag->done_check())) {
1960 KA_TRACE(15, (
"__kmp_execute_tasks_template: T#%d spin condition satisfied\n", gtid) );
1963 if (thread->th.th_task_team == NULL) {
1966 KMP_YIELD( __kmp_library == library_throughput );
1968 if (!use_own_tasks && TCR_4(threads_data[tid].td.td_deque_ntasks) != 0) {
1969 KA_TRACE(20, (
"__kmp_execute_tasks_template: T#%d stolen task spawned other tasks, restart\n", gtid));
1978 if (final_spin && TCR_4(current_task->td_incomplete_child_tasks) == 0)
1985 if (! *thread_finished) {
1988 count = KMP_TEST_THEN_DEC32( (kmp_int32 *)unfinished_threads ) - 1;
1989 KA_TRACE(20, (
"__kmp_execute_tasks_template: T#%d dec unfinished_threads to %d task_team=%p\n",
1990 gtid, count, task_team) );
1991 *thread_finished = TRUE;
1998 if (flag != NULL && flag->done_check()) {
1999 KA_TRACE(15, (
"__kmp_execute_tasks_template: T#%d spin condition satisfied\n", gtid) );
2005 if (thread->th.th_task_team == NULL) {
2006 KA_TRACE(15, (
"__kmp_execute_tasks_template: T#%d no more tasks\n", gtid) );
2018 KA_TRACE(15, (
"__kmp_execute_tasks_template: T#%d can't find work\n", gtid) );
2024 int __kmp_execute_tasks_32(kmp_info_t *thread, kmp_int32 gtid, kmp_flag_32 *flag,
int final_spin,
2025 int *thread_finished
2026 USE_ITT_BUILD_ARG(
void * itt_sync_obj), kmp_int32 is_constrained)
2028 return __kmp_execute_tasks_template(thread, gtid, flag, final_spin, thread_finished
2029 USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
2032 int __kmp_execute_tasks_64(kmp_info_t *thread, kmp_int32 gtid, kmp_flag_64 *flag,
int final_spin,
2033 int *thread_finished
2034 USE_ITT_BUILD_ARG(
void * itt_sync_obj), kmp_int32 is_constrained)
2036 return __kmp_execute_tasks_template(thread, gtid, flag, final_spin, thread_finished
2037 USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
2040 int __kmp_execute_tasks_oncore(kmp_info_t *thread, kmp_int32 gtid, kmp_flag_oncore *flag,
int final_spin,
2041 int *thread_finished
2042 USE_ITT_BUILD_ARG(
void * itt_sync_obj), kmp_int32 is_constrained)
2044 return __kmp_execute_tasks_template(thread, gtid, flag, final_spin, thread_finished
2045 USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
2056 __kmp_enable_tasking( kmp_task_team_t *task_team, kmp_info_t *this_thr )
2058 kmp_thread_data_t *threads_data;
2059 int nthreads, i, is_init_thread;
2061 KA_TRACE( 10, (
"__kmp_enable_tasking(enter): T#%d\n",
2062 __kmp_gtid_from_thread( this_thr ) ) );
2064 KMP_DEBUG_ASSERT(task_team != NULL);
2065 KMP_DEBUG_ASSERT(this_thr->th.th_team != NULL);
2067 nthreads = task_team->tt.tt_nproc;
2068 KMP_DEBUG_ASSERT(nthreads > 0);
2069 KMP_DEBUG_ASSERT(nthreads == this_thr->th.th_team->t.t_nproc);
2072 is_init_thread = __kmp_realloc_task_threads_data( this_thr, task_team );
2074 if (!is_init_thread) {
2076 KA_TRACE( 20, (
"__kmp_enable_tasking(exit): T#%d: threads array already set up.\n",
2077 __kmp_gtid_from_thread( this_thr ) ) );
2080 threads_data = (kmp_thread_data_t *)TCR_PTR(task_team -> tt.tt_threads_data);
2081 KMP_DEBUG_ASSERT( threads_data != NULL );
2083 if ( ( __kmp_tasking_mode == tskm_task_teams ) &&
2084 ( __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME ) )
2089 for (i = 0; i < nthreads; i++) {
2090 volatile void *sleep_loc;
2091 kmp_info_t *thread = threads_data[i].td.td_thr;
2093 if (i == this_thr->th.th_info.ds.ds_tid) {
2103 if ( ( sleep_loc = TCR_PTR( thread -> th.th_sleep_loc) ) != NULL )
2105 KF_TRACE( 50, (
"__kmp_enable_tasking: T#%d waking up thread T#%d\n",
2106 __kmp_gtid_from_thread( this_thr ),
2107 __kmp_gtid_from_thread( thread ) ) );
2108 __kmp_null_resume_wrapper(__kmp_gtid_from_thread(thread), sleep_loc);
2111 KF_TRACE( 50, (
"__kmp_enable_tasking: T#%d don't wake up thread T#%d\n",
2112 __kmp_gtid_from_thread( this_thr ),
2113 __kmp_gtid_from_thread( thread ) ) );
2118 KA_TRACE( 10, (
"__kmp_enable_tasking(exit): T#%d\n",
2119 __kmp_gtid_from_thread( this_thr ) ) );
2159 static kmp_task_team_t *__kmp_free_task_teams = NULL;
2161 static kmp_bootstrap_lock_t __kmp_task_team_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER( __kmp_task_team_lock );
2173 __kmp_alloc_task_deque( kmp_info_t *thread, kmp_thread_data_t *thread_data )
2175 __kmp_init_bootstrap_lock( & thread_data -> td.td_deque_lock );
2176 KMP_DEBUG_ASSERT( thread_data -> td.td_deque == NULL );
2179 thread_data -> td.td_deque_last_stolen = -1;
2181 KMP_DEBUG_ASSERT( TCR_4(thread_data -> td.td_deque_ntasks) == 0 );
2182 KMP_DEBUG_ASSERT( thread_data -> td.td_deque_head == 0 );
2183 KMP_DEBUG_ASSERT( thread_data -> td.td_deque_tail == 0 );
2185 KE_TRACE( 10, (
"__kmp_alloc_task_deque: T#%d allocating deque[%d] for thread_data %p\n",
2186 __kmp_gtid_from_thread( thread ), INITIAL_TASK_DEQUE_SIZE, thread_data ) );
2190 thread_data -> td.td_deque = (kmp_taskdata_t **)
2191 __kmp_allocate( INITIAL_TASK_DEQUE_SIZE *
sizeof(kmp_taskdata_t *));
2192 thread_data -> td.td_deque_size = INITIAL_TASK_DEQUE_SIZE;
2201 static void __kmp_realloc_task_deque ( kmp_info_t *thread, kmp_thread_data_t *thread_data )
2203 kmp_int32 size = TASK_DEQUE_SIZE(thread_data->td);
2204 kmp_int32 new_size = 2 * size;
2206 KE_TRACE( 10, (
"__kmp_realloc_task_deque: T#%d reallocating deque[from %d to %d] for thread_data %p\n",
2207 __kmp_gtid_from_thread( thread ), size, new_size, thread_data ) );
2209 kmp_taskdata_t ** new_deque = (kmp_taskdata_t **) __kmp_allocate( new_size *
sizeof(kmp_taskdata_t *));
2212 for ( i = thread_data->td.td_deque_head, j = 0; j < size; i = (i+1) & TASK_DEQUE_MASK(thread_data->td), j++ )
2213 new_deque[j] = thread_data->td.td_deque[i];
2215 __kmp_free(thread_data->td.td_deque);
2217 thread_data -> td.td_deque_head = 0;
2218 thread_data -> td.td_deque_tail = size;
2219 thread_data -> td.td_deque = new_deque;
2220 thread_data -> td.td_deque_size = new_size;
2229 __kmp_free_task_deque( kmp_thread_data_t *thread_data )
2231 __kmp_acquire_bootstrap_lock( & thread_data -> td.td_deque_lock );
2233 if ( thread_data -> td.td_deque != NULL ) {
2234 TCW_4(thread_data -> td.td_deque_ntasks, 0);
2235 __kmp_free( thread_data -> td.td_deque );
2236 thread_data -> td.td_deque = NULL;
2238 __kmp_release_bootstrap_lock( & thread_data -> td.td_deque_lock );
2240 #ifdef BUILD_TIED_TASK_STACK 2242 if ( thread_data -> td.td_susp_tied_tasks.ts_entries != TASK_STACK_EMPTY ) {
2243 __kmp_free_task_stack( __kmp_thread_from_gtid( gtid ), thread_data );
2245 #endif // BUILD_TIED_TASK_STACK 2259 __kmp_realloc_task_threads_data( kmp_info_t *thread, kmp_task_team_t *task_team )
2261 kmp_thread_data_t ** threads_data_p;
2262 kmp_int32 nthreads, maxthreads;
2263 int is_init_thread = FALSE;
2265 if ( TCR_4(task_team -> tt.tt_found_tasks) ) {
2270 threads_data_p = & task_team -> tt.tt_threads_data;
2271 nthreads = task_team -> tt.tt_nproc;
2272 maxthreads = task_team -> tt.tt_max_threads;
2276 __kmp_acquire_bootstrap_lock( & task_team -> tt.tt_threads_lock );
2278 if ( ! TCR_4(task_team -> tt.tt_found_tasks) ) {
2280 kmp_team_t *team = thread -> th.th_team;
2283 is_init_thread = TRUE;
2284 if ( maxthreads < nthreads ) {
2286 if ( *threads_data_p != NULL ) {
2287 kmp_thread_data_t *old_data = *threads_data_p;
2288 kmp_thread_data_t *new_data = NULL;
2290 KE_TRACE( 10, (
"__kmp_realloc_task_threads_data: T#%d reallocating " 2291 "threads data for task_team %p, new_size = %d, old_size = %d\n",
2292 __kmp_gtid_from_thread( thread ), task_team,
2293 nthreads, maxthreads ) );
2298 new_data = (kmp_thread_data_t *)
2299 __kmp_allocate( nthreads *
sizeof(kmp_thread_data_t) );
2301 KMP_MEMCPY_S( (
void *) new_data, nthreads *
sizeof(kmp_thread_data_t),
2303 maxthreads *
sizeof(kmp_taskdata_t *) );
2305 #ifdef BUILD_TIED_TASK_STACK 2307 for (i = maxthreads; i < nthreads; i++) {
2308 kmp_thread_data_t *thread_data = & (*threads_data_p)[i];
2309 __kmp_init_task_stack( __kmp_gtid_from_thread( thread ), thread_data );
2311 #endif // BUILD_TIED_TASK_STACK 2313 (*threads_data_p) = new_data;
2314 __kmp_free( old_data );
2317 KE_TRACE( 10, (
"__kmp_realloc_task_threads_data: T#%d allocating " 2318 "threads data for task_team %p, size = %d\n",
2319 __kmp_gtid_from_thread( thread ), task_team, nthreads ) );
2323 *threads_data_p = (kmp_thread_data_t *)
2324 __kmp_allocate( nthreads *
sizeof(kmp_thread_data_t) );
2325 #ifdef BUILD_TIED_TASK_STACK 2327 for (i = 0; i < nthreads; i++) {
2328 kmp_thread_data_t *thread_data = & (*threads_data_p)[i];
2329 __kmp_init_task_stack( __kmp_gtid_from_thread( thread ), thread_data );
2331 #endif // BUILD_TIED_TASK_STACK 2333 task_team -> tt.tt_max_threads = nthreads;
2337 KMP_DEBUG_ASSERT( *threads_data_p != NULL );
2341 for (i = 0; i < nthreads; i++) {
2342 kmp_thread_data_t *thread_data = & (*threads_data_p)[i];
2343 thread_data -> td.td_thr = team -> t.t_threads[i];
2345 if ( thread_data -> td.td_deque_last_stolen >= nthreads) {
2349 thread_data -> td.td_deque_last_stolen = -1;
2354 TCW_SYNC_4(task_team -> tt.tt_found_tasks, TRUE);
2357 __kmp_release_bootstrap_lock( & task_team -> tt.tt_threads_lock );
2358 return is_init_thread;
2368 __kmp_free_task_threads_data( kmp_task_team_t *task_team )
2370 __kmp_acquire_bootstrap_lock( & task_team -> tt.tt_threads_lock );
2371 if ( task_team -> tt.tt_threads_data != NULL ) {
2373 for (i = 0; i < task_team->tt.tt_max_threads; i++ ) {
2374 __kmp_free_task_deque( & task_team -> tt.tt_threads_data[i] );
2376 __kmp_free( task_team -> tt.tt_threads_data );
2377 task_team -> tt.tt_threads_data = NULL;
2379 __kmp_release_bootstrap_lock( & task_team -> tt.tt_threads_lock );
2388 static kmp_task_team_t *
2389 __kmp_allocate_task_team( kmp_info_t *thread, kmp_team_t *team )
2391 kmp_task_team_t *task_team = NULL;
2394 KA_TRACE( 20, (
"__kmp_allocate_task_team: T#%d entering; team = %p\n",
2395 (thread ? __kmp_gtid_from_thread( thread ) : -1), team ) );
2397 if (TCR_PTR(__kmp_free_task_teams) != NULL) {
2399 __kmp_acquire_bootstrap_lock( &__kmp_task_team_lock );
2400 if (__kmp_free_task_teams != NULL) {
2401 task_team = __kmp_free_task_teams;
2402 TCW_PTR(__kmp_free_task_teams, task_team -> tt.tt_next);
2403 task_team -> tt.tt_next = NULL;
2405 __kmp_release_bootstrap_lock( &__kmp_task_team_lock );
2408 if (task_team == NULL) {
2409 KE_TRACE( 10, (
"__kmp_allocate_task_team: T#%d allocating " 2410 "task team for team %p\n",
2411 __kmp_gtid_from_thread( thread ), team ) );
2415 task_team = (kmp_task_team_t *) __kmp_allocate(
sizeof(kmp_task_team_t) );
2416 __kmp_init_bootstrap_lock( & task_team -> tt.tt_threads_lock );
2422 TCW_4(task_team -> tt.tt_found_tasks, FALSE);
2424 TCW_4(task_team -> tt.tt_found_proxy_tasks, FALSE);
2426 task_team -> tt.tt_nproc = nthreads = team->t.t_nproc;
2428 TCW_4( task_team -> tt.tt_unfinished_threads, nthreads );
2429 TCW_4( task_team -> tt.tt_active, TRUE );
2431 KA_TRACE( 20, (
"__kmp_allocate_task_team: T#%d exiting; task_team = %p unfinished_threads init'd to %d\n",
2432 (thread ? __kmp_gtid_from_thread( thread ) : -1), task_team, task_team -> tt.tt_unfinished_threads) );
2443 __kmp_free_task_team( kmp_info_t *thread, kmp_task_team_t *task_team )
2445 KA_TRACE( 20, (
"__kmp_free_task_team: T#%d task_team = %p\n",
2446 thread ? __kmp_gtid_from_thread( thread ) : -1, task_team ) );
2449 __kmp_acquire_bootstrap_lock( & __kmp_task_team_lock );
2451 KMP_DEBUG_ASSERT( task_team -> tt.tt_next == NULL );
2452 task_team -> tt.tt_next = __kmp_free_task_teams;
2453 TCW_PTR(__kmp_free_task_teams, task_team);
2455 __kmp_release_bootstrap_lock( & __kmp_task_team_lock );
2466 __kmp_reap_task_teams(
void )
2468 kmp_task_team_t *task_team;
2470 if ( TCR_PTR(__kmp_free_task_teams) != NULL ) {
2472 __kmp_acquire_bootstrap_lock( &__kmp_task_team_lock );
2473 while ( ( task_team = __kmp_free_task_teams ) != NULL ) {
2474 __kmp_free_task_teams = task_team -> tt.tt_next;
2475 task_team -> tt.tt_next = NULL;
2478 if ( task_team -> tt.tt_threads_data != NULL ) {
2479 __kmp_free_task_threads_data( task_team );
2481 __kmp_free( task_team );
2483 __kmp_release_bootstrap_lock( &__kmp_task_team_lock );
2493 __kmp_wait_to_unref_task_teams(
void)
2499 KMP_INIT_YIELD( spins );
2508 for (thread = (kmp_info_t *)__kmp_thread_pool;
2510 thread = thread->th.th_next_pool)
2515 if ( TCR_PTR(thread->th.th_task_team) == NULL ) {
2516 KA_TRACE( 10, (
"__kmp_wait_to_unref_task_team: T#%d task_team == NULL\n",
2517 __kmp_gtid_from_thread( thread ) ) );
2522 if (!__kmp_is_thread_alive(thread, &exit_val)) {
2523 thread->th.th_task_team = NULL;
2530 KA_TRACE( 10, (
"__kmp_wait_to_unref_task_team: Waiting for T#%d to unreference task_team\n",
2531 __kmp_gtid_from_thread( thread ) ) );
2533 if ( __kmp_dflt_blocktime != KMP_MAX_BLOCKTIME ) {
2534 volatile void *sleep_loc;
2536 if ( ( sleep_loc = TCR_PTR( thread->th.th_sleep_loc) ) != NULL ) {
2537 KA_TRACE( 10, (
"__kmp_wait_to_unref_task_team: T#%d waking up thread T#%d\n",
2538 __kmp_gtid_from_thread( thread ), __kmp_gtid_from_thread( thread ) ) );
2539 __kmp_null_resume_wrapper(__kmp_gtid_from_thread(thread), sleep_loc);
2550 KMP_YIELD( TCR_4(__kmp_nth) > __kmp_avail_proc );
2551 KMP_YIELD_SPIN( spins );
2560 __kmp_task_team_setup( kmp_info_t *this_thr, kmp_team_t *team,
int always )
2562 KMP_DEBUG_ASSERT( __kmp_tasking_mode != tskm_immediate_exec );
2566 if (team->t.t_task_team[this_thr->th.th_task_state] == NULL && (always || team->t.t_nproc > 1) ) {
2567 team->t.t_task_team[this_thr->th.th_task_state] = __kmp_allocate_task_team( this_thr, team );
2568 KA_TRACE(20, (
"__kmp_task_team_setup: Master T#%d created new task_team %p for team %d at parity=%d\n",
2569 __kmp_gtid_from_thread(this_thr), team->t.t_task_team[this_thr->th.th_task_state],
2570 ((team != NULL) ? team->t.t_id : -1), this_thr->th.th_task_state));
2578 if (team->t.t_nproc > 1) {
2579 int other_team = 1 - this_thr->th.th_task_state;
2580 if (team->t.t_task_team[other_team] == NULL) {
2581 team->t.t_task_team[other_team] = __kmp_allocate_task_team( this_thr, team );
2582 KA_TRACE(20, (
"__kmp_task_team_setup: Master T#%d created second new task_team %p for team %d at parity=%d\n",
2583 __kmp_gtid_from_thread( this_thr ), team->t.t_task_team[other_team],
2584 ((team != NULL) ? team->t.t_id : -1), other_team ));
2587 kmp_task_team_t *task_team = team->t.t_task_team[other_team];
2588 if (!task_team->tt.tt_active || team->t.t_nproc != task_team->tt.tt_nproc) {
2589 TCW_4(task_team->tt.tt_nproc, team->t.t_nproc);
2590 TCW_4(task_team->tt.tt_found_tasks, FALSE);
2592 TCW_4(task_team->tt.tt_found_proxy_tasks, FALSE);
2594 TCW_4(task_team->tt.tt_unfinished_threads, team->t.t_nproc );
2595 TCW_4(task_team->tt.tt_active, TRUE );
2598 KA_TRACE(20, (
"__kmp_task_team_setup: Master T#%d reset next task_team %p for team %d at parity=%d\n",
2599 __kmp_gtid_from_thread( this_thr ), team->t.t_task_team[other_team],
2600 ((team != NULL) ? team->t.t_id : -1), other_team ));
2612 __kmp_task_team_sync( kmp_info_t *this_thr, kmp_team_t *team )
2614 KMP_DEBUG_ASSERT( __kmp_tasking_mode != tskm_immediate_exec );
2617 this_thr->th.th_task_state = 1 - this_thr->th.th_task_state;
2619 TCW_PTR(this_thr->th.th_task_team, team->t.t_task_team[this_thr->th.th_task_state]);
2620 KA_TRACE(20, (
"__kmp_task_team_sync: Thread T#%d task team switched to task_team %p from Team #%d (parity=%d)\n",
2621 __kmp_gtid_from_thread( this_thr ), this_thr->th.th_task_team,
2622 ((team != NULL) ? team->t.t_id : -1), this_thr->th.th_task_state));
2633 __kmp_task_team_wait( kmp_info_t *this_thr, kmp_team_t *team
2634 USE_ITT_BUILD_ARG(
void * itt_sync_obj)
2637 kmp_task_team_t *task_team = team->t.t_task_team[this_thr->th.th_task_state];
2639 KMP_DEBUG_ASSERT( __kmp_tasking_mode != tskm_immediate_exec );
2640 KMP_DEBUG_ASSERT( task_team == this_thr->th.th_task_team );
2642 if ( ( task_team != NULL ) && KMP_TASKING_ENABLED(task_team) ) {
2644 KA_TRACE(20, (
"__kmp_task_team_wait: Master T#%d waiting for all tasks (for unfinished_threads to reach 0) on task_team = %p\n",
2645 __kmp_gtid_from_thread(this_thr), task_team));
2648 kmp_flag_32 flag(&task_team->tt.tt_unfinished_threads, 0U);
2649 flag.wait(this_thr, TRUE
2650 USE_ITT_BUILD_ARG(itt_sync_obj));
2653 KA_TRACE(20, (
"__kmp_task_team_wait: Master T#%d deactivating task_team %p: " 2654 "setting active to false, setting local and team's pointer to NULL\n",
2655 __kmp_gtid_from_thread(this_thr), task_team));
2657 KMP_DEBUG_ASSERT( task_team->tt.tt_nproc > 1 || task_team->tt.tt_found_proxy_tasks == TRUE );
2658 TCW_SYNC_4( task_team->tt.tt_found_proxy_tasks, FALSE );
2660 KMP_DEBUG_ASSERT( task_team->tt.tt_nproc > 1 );
2662 TCW_SYNC_4( task_team->tt.tt_active, FALSE );
2665 TCW_PTR(this_thr->th.th_task_team, NULL);
2678 __kmp_tasking_barrier( kmp_team_t *team, kmp_info_t *thread,
int gtid )
2680 volatile kmp_uint32 *spin = &team->t.t_task_team[thread->th.th_task_state]->tt.tt_unfinished_threads;
2682 KMP_DEBUG_ASSERT( __kmp_tasking_mode == tskm_extra_barrier );
2685 KMP_FSYNC_SPIN_INIT( spin, (kmp_uint32*) NULL );
2687 kmp_flag_32 spin_flag(spin, 0U);
2688 while (! spin_flag.execute_tasks(thread, gtid, TRUE, &flag
2689 USE_ITT_BUILD_ARG(NULL), 0 ) ) {
2692 KMP_FSYNC_SPIN_PREPARE( spin );
2695 if( TCR_4(__kmp_global.g.g_done) ) {
2696 if( __kmp_global.g.g_abort )
2697 __kmp_abort_thread( );
2703 KMP_FSYNC_SPIN_ACQUIRED( (
void*) spin );
2716 static bool __kmp_give_task ( kmp_info_t *thread, kmp_int32 tid, kmp_task_t * task, kmp_int32 pass )
2718 kmp_taskdata_t * taskdata = KMP_TASK_TO_TASKDATA(task);
2719 kmp_task_team_t * task_team = taskdata->td_task_team;
2721 KA_TRACE(20, (
"__kmp_give_task: trying to give task %p to thread %d.\n", taskdata, tid ) );
2724 KMP_DEBUG_ASSERT( task_team != NULL );
2726 bool result =
false;
2727 kmp_thread_data_t * thread_data = & task_team -> tt.tt_threads_data[ tid ];
2729 if (thread_data -> td.td_deque == NULL ) {
2732 KA_TRACE(30, (
"__kmp_give_task: thread %d has no queue while giving task %p.\n", tid, taskdata ) );
2736 if ( TCR_4(thread_data -> td.td_deque_ntasks) >= TASK_DEQUE_SIZE(thread_data->td) )
2738 KA_TRACE(30, (
"__kmp_give_task: queue is full while giving task %p to thread %d.\n", taskdata, tid ) );
2741 if ( TASK_DEQUE_SIZE(thread_data->td)/INITIAL_TASK_DEQUE_SIZE >= pass )
return result;
2743 __kmp_acquire_bootstrap_lock( & thread_data-> td.td_deque_lock );
2744 __kmp_realloc_task_deque(thread,thread_data);
2748 __kmp_acquire_bootstrap_lock( & thread_data-> td.td_deque_lock );
2750 if ( TCR_4(thread_data -> td.td_deque_ntasks) >= TASK_DEQUE_SIZE(thread_data->td) )
2752 KA_TRACE(30, (
"__kmp_give_task: queue is full while giving task %p to thread %d.\n", taskdata, tid ) );
2755 if ( TASK_DEQUE_SIZE(thread_data->td)/INITIAL_TASK_DEQUE_SIZE >= pass )
2756 goto release_and_exit;
2758 __kmp_realloc_task_deque(thread,thread_data);
2764 thread_data -> td.td_deque[ thread_data -> td.td_deque_tail ] = taskdata;
2766 thread_data -> td.td_deque_tail = ( thread_data -> td.td_deque_tail + 1 ) & TASK_DEQUE_MASK(thread_data->td);
2767 TCW_4(thread_data -> td.td_deque_ntasks, TCR_4(thread_data -> td.td_deque_ntasks) + 1);
2770 KA_TRACE(30, (
"__kmp_give_task: successfully gave task %p to thread %d.\n", taskdata, tid ) );
2773 __kmp_release_bootstrap_lock( & thread_data-> td.td_deque_lock );
2793 static void __kmp_first_top_half_finish_proxy( kmp_taskdata_t * taskdata )
2795 KMP_DEBUG_ASSERT( taskdata -> td_flags.tasktype == TASK_EXPLICIT );
2796 KMP_DEBUG_ASSERT( taskdata -> td_flags.proxy == TASK_PROXY );
2797 KMP_DEBUG_ASSERT( taskdata -> td_flags.complete == 0 );
2798 KMP_DEBUG_ASSERT( taskdata -> td_flags.freed == 0 );
2800 taskdata -> td_flags.complete = 1;
2802 if ( taskdata->td_taskgroup )
2803 KMP_TEST_THEN_DEC32( (kmp_int32 *)(& taskdata->td_taskgroup->count) );
2806 TCI_4(taskdata->td_incomplete_child_tasks);
2809 static void __kmp_second_top_half_finish_proxy( kmp_taskdata_t * taskdata )
2811 kmp_int32 children = 0;
2814 children = KMP_TEST_THEN_DEC32( (kmp_int32 *)(& taskdata -> td_parent -> td_incomplete_child_tasks) ) - 1;
2815 KMP_DEBUG_ASSERT( children >= 0 );
2818 TCD_4(taskdata->td_incomplete_child_tasks);
2821 static void __kmp_bottom_half_finish_proxy( kmp_int32 gtid, kmp_task_t * ptask )
2823 kmp_taskdata_t * taskdata = KMP_TASK_TO_TASKDATA(ptask);
2824 kmp_info_t * thread = __kmp_threads[ gtid ];
2826 KMP_DEBUG_ASSERT( taskdata -> td_flags.proxy == TASK_PROXY );
2827 KMP_DEBUG_ASSERT( taskdata -> td_flags.complete == 1 );
2831 while ( TCR_4(taskdata->td_incomplete_child_tasks) > 0 ) ;
2833 __kmp_release_deps(gtid,taskdata);
2834 __kmp_free_task_and_ancestors(gtid, taskdata, thread);
2844 void __kmpc_proxy_task_completed( kmp_int32 gtid, kmp_task_t *ptask )
2846 KMP_DEBUG_ASSERT( ptask != NULL );
2847 kmp_taskdata_t * taskdata = KMP_TASK_TO_TASKDATA(ptask);
2848 KA_TRACE(10, (
"__kmp_proxy_task_completed(enter): T#%d proxy task %p completing\n", gtid, taskdata ) );
2850 KMP_DEBUG_ASSERT( taskdata->td_flags.proxy == TASK_PROXY );
2852 __kmp_first_top_half_finish_proxy(taskdata);
2853 __kmp_second_top_half_finish_proxy(taskdata);
2854 __kmp_bottom_half_finish_proxy(gtid,ptask);
2856 KA_TRACE(10, (
"__kmp_proxy_task_completed(exit): T#%d proxy task %p completing\n", gtid, taskdata ) );
2865 void __kmpc_proxy_task_completed_ooo ( kmp_task_t *ptask )
2867 KMP_DEBUG_ASSERT( ptask != NULL );
2868 kmp_taskdata_t * taskdata = KMP_TASK_TO_TASKDATA(ptask);
2870 KA_TRACE(10, (
"__kmp_proxy_task_completed_ooo(enter): proxy task completing ooo %p\n", taskdata ) );
2872 KMP_DEBUG_ASSERT( taskdata->td_flags.proxy == TASK_PROXY );
2874 __kmp_first_top_half_finish_proxy(taskdata);
2877 kmp_team_t * team = taskdata->td_team;
2878 kmp_int32 nthreads = team->t.t_nproc;
2882 kmp_int32 start_k = 0;
2884 kmp_int32 k = start_k;
2888 thread = team->t.t_threads[k];
2889 k = (k+1) % nthreads;
2892 if ( k == start_k ) pass = pass << 1;
2894 }
while ( !__kmp_give_task( thread, k, ptask, pass ) );
2896 __kmp_second_top_half_finish_proxy(taskdata);
2898 KA_TRACE(10, (
"__kmp_proxy_task_completed_ooo(exit): proxy task completing ooo %p\n", taskdata ) );
2908 __kmp_task_dup_alloc( kmp_info_t *thread, kmp_task_t *task_src )
2911 kmp_taskdata_t *taskdata;
2912 kmp_taskdata_t *taskdata_src;
2913 kmp_taskdata_t *parent_task = thread->th.th_current_task;
2914 size_t shareds_offset;
2917 KA_TRACE(10, (
"__kmp_task_dup_alloc(enter): Th %p, source task %p\n", thread, task_src) );
2918 taskdata_src = KMP_TASK_TO_TASKDATA( task_src );
2919 KMP_DEBUG_ASSERT( taskdata_src->td_flags.proxy == TASK_FULL );
2920 KMP_DEBUG_ASSERT( taskdata_src->td_flags.tasktype == TASK_EXPLICIT );
2921 task_size = taskdata_src->td_size_alloc;
2924 KA_TRACE(30, (
"__kmp_task_dup_alloc: Th %p, malloc size %ld\n", thread, task_size) );
2926 taskdata = (kmp_taskdata_t *)__kmp_fast_allocate( thread, task_size );
2928 taskdata = (kmp_taskdata_t *)__kmp_thread_malloc( thread, task_size );
2930 KMP_MEMCPY(taskdata, taskdata_src, task_size);
2932 task = KMP_TASKDATA_TO_TASK(taskdata);
2935 taskdata->td_task_id = KMP_GEN_TASK_ID();
2936 if( task->shareds != NULL ) {
2937 shareds_offset = (
char*)task_src->shareds - (
char*)taskdata_src;
2938 task->shareds = &((
char*)taskdata)[shareds_offset];
2939 KMP_DEBUG_ASSERT( (((kmp_uintptr_t)task->shareds) & (
sizeof(
void*)-1)) == 0 );
2941 taskdata->td_alloc_thread = thread;
2942 taskdata->td_taskgroup = parent_task->td_taskgroup;
2945 if ( !( taskdata->td_flags.team_serial || taskdata->td_flags.tasking_ser ) ) {
2946 KMP_TEST_THEN_INC32( (kmp_int32 *)(& parent_task->td_incomplete_child_tasks) );
2947 if ( parent_task->td_taskgroup )
2948 KMP_TEST_THEN_INC32( (kmp_int32 *)(& parent_task->td_taskgroup->count) );
2950 if ( taskdata->td_parent->td_flags.tasktype == TASK_EXPLICIT )
2951 KMP_TEST_THEN_INC32( (kmp_int32 *)(& taskdata->td_parent->td_allocated_child_tasks) );
2954 KA_TRACE(20, (
"__kmp_task_dup_alloc(exit): Th %p, created task %p, parent=%p\n",
2955 thread, taskdata, taskdata->td_parent) );
2957 __kmp_task_init_ompt(taskdata, thread->th.th_info.ds.ds_gtid, (
void*)task->routine);
2965 typedef void(*p_task_dup_t)(kmp_task_t *, kmp_task_t *, kmp_int32);
2980 __kmp_taskloop_linear(
ident_t *loc,
int gtid, kmp_task_t *task,
2981 kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st,
2982 int sched, kmp_uint64 grainsize,
void *task_dup )
2985 KMP_TIME_PARTITIONED_BLOCK(OMP_taskloop_scheduling);
2986 p_task_dup_t ptask_dup = (p_task_dup_t)task_dup;
2988 kmp_uint64 lower = *lb;
2989 kmp_uint64 upper = *ub;
2990 kmp_uint64 i, num_tasks = 0, extras = 0;
2991 kmp_info_t *thread = __kmp_threads[gtid];
2992 kmp_taskdata_t *current_task = thread->th.th_current_task;
2993 kmp_task_t *next_task;
2994 kmp_int32 lastpriv = 0;
2995 size_t lower_offset = (
char*)lb - (
char*)task;
2996 size_t upper_offset = (
char*)ub - (
char*)task;
3000 tc = upper - lower + 1;
3001 }
else if ( st < 0 ) {
3002 tc = (lower - upper) / (-st) + 1;
3004 tc = (upper - lower) / st + 1;
3007 KA_TRACE(20, (
"__kmpc_taskloop(exit): T#%d zero-trip loop\n", gtid));
3009 __kmp_task_start( gtid, task, current_task );
3011 __kmp_task_finish( gtid, task, current_task );
3019 grainsize = thread->th.th_team_nproc * 10;
3021 if( grainsize > tc ) {
3026 num_tasks = grainsize;
3027 grainsize = tc / num_tasks;
3028 extras = tc % num_tasks;
3032 if( grainsize > tc ) {
3037 num_tasks = tc / grainsize;
3038 grainsize = tc / num_tasks;
3039 extras = tc % num_tasks;
3043 KMP_ASSERT2(0,
"unknown scheduling of taskloop");
3045 KMP_DEBUG_ASSERT(tc == num_tasks * grainsize + extras);
3046 KMP_DEBUG_ASSERT(num_tasks > extras);
3047 KMP_DEBUG_ASSERT(num_tasks > 0);
3048 KA_TRACE(20, (
"__kmpc_taskloop: T#%d will launch: num_tasks %lld, grainsize %lld, extras %lld\n",
3049 gtid, num_tasks, grainsize, extras));
3052 for( i = 0; i < num_tasks; ++i ) {
3053 kmp_uint64 chunk_minus_1;
3055 chunk_minus_1 = grainsize - 1;
3057 chunk_minus_1 = grainsize;
3060 upper = lower + st * chunk_minus_1;
3061 if( i == num_tasks - 1 ) {
3066 KMP_DEBUG_ASSERT(upper == *ub);
3068 KMP_DEBUG_ASSERT(upper+st > *ub);
3070 KMP_DEBUG_ASSERT(upper+st < *ub);
3073 next_task = __kmp_task_dup_alloc(thread, task);
3074 *(kmp_uint64*)((
char*)next_task + lower_offset) = lower;
3075 *(kmp_uint64*)((
char*)next_task + upper_offset) = upper;
3076 if( ptask_dup != NULL )
3077 ptask_dup(next_task, task, lastpriv);
3078 KA_TRACE(20, (
"__kmpc_taskloop: T#%d schedule task %p: lower %lld, upper %lld (offsets %p %p)\n",
3079 gtid, next_task, lower, upper, lower_offset, upper_offset));
3080 __kmp_omp_task(gtid, next_task,
true);
3084 __kmp_task_start( gtid, task, current_task );
3086 __kmp_task_finish( gtid, task, current_task );
3106 __kmpc_taskloop(
ident_t *loc,
int gtid, kmp_task_t *task,
int if_val,
3107 kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st,
3108 int nogroup,
int sched, kmp_uint64 grainsize,
void *task_dup )
3110 kmp_taskdata_t * taskdata = KMP_TASK_TO_TASKDATA(task);
3111 KMP_DEBUG_ASSERT( task != NULL );
3113 KA_TRACE(10, (
"__kmpc_taskloop(enter): T#%d, pattern task %p, lb %lld ub %lld st %lld, grain %llu(%d)\n",
3114 gtid, taskdata, *lb, *ub, st, grainsize, sched));
3118 taskdata->td_flags.task_serial = 1;
3119 taskdata->td_flags.tiedness = TASK_TIED;
3121 if( nogroup == 0 ) {
3122 __kmpc_taskgroup( loc, gtid );
3126 __kmp_taskloop_linear( loc, gtid, task, lb, ub, st, sched, grainsize, task_dup );
3129 if( nogroup == 0 ) {
3130 __kmpc_end_taskgroup( loc, gtid );
3132 KA_TRACE(10, (
"__kmpc_taskloop(exit): T#%d\n", gtid));
#define KMP_COUNT_BLOCK(name)
Increments specified counter (name).