diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h --- a/openmp/runtime/src/kmp.h +++ b/openmp/runtime/src/kmp.h @@ -2421,13 +2421,6 @@ kmp_depnode_t *td_depnode; // Pointer to graph node if this task has dependencies kmp_task_team_t *td_task_team; - // The global thread id of the encountering thread. We need it because when a - // regular task depends on a hidden helper task, and the hidden helper task - // is finished on a hidden helper thread, it will call __kmp_release_deps to - // release all dependences. If now the task is a regular task, we need to pass - // the encountering gtid such that the task will be picked up and executed by - // its encountering team instead of hidden helper team. - kmp_int32 encountering_gtid; size_t td_size_alloc; // Size of task structure, including shareds etc. #if defined(KMP_GOMP_COMPAT) // 4 or 8 byte integers for the loop bounds in GOMP_taskloop diff --git a/openmp/runtime/src/kmp_taskdeps.h b/openmp/runtime/src/kmp_taskdeps.h --- a/openmp/runtime/src/kmp_taskdeps.h +++ b/openmp/runtime/src/kmp_taskdeps.h @@ -144,9 +144,10 @@ // encountering thread's queue; otherwise, it can be pushed to its own // queue. if (!next_taskdata->td_flags.hidden_helper) { - __kmpc_give_task( - successor->dn.task, - __kmp_tid_from_gtid(next_taskdata->encountering_gtid)); + kmp_int32 encountering_gtid = + next_taskdata->td_alloc_thread->th.th_info.ds.ds_gtid; + kmp_int32 encountering_tid = __kmp_tid_from_gtid(encountering_gtid); + __kmpc_give_task(successor->dn.task, encountering_tid); } else { __kmp_omp_task(gtid, successor->dn.task, false); } diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp --- a/openmp/runtime/src/kmp_tasking.cpp +++ b/openmp/runtime/src/kmp_tasking.cpp @@ -1192,7 +1192,6 @@ kmp_task_t *task; kmp_taskdata_t *taskdata; kmp_info_t *thread = __kmp_threads[gtid]; - kmp_info_t *encountering_thread = thread; kmp_team_t *team = thread->th.th_team; kmp_taskdata_t *parent_task = thread->th.th_current_task; size_t shareds_offset; @@ -1204,15 +1203,6 @@ if (__kmp_enable_hidden_helper) { if (!TCR_4(__kmp_init_hidden_helper)) __kmp_hidden_helper_initialize(); - - // For a hidden helper task encountered by a regular thread, we will push - // the task to the (gtid%__kmp_hidden_helper_threads_num)-th hidden helper - // thread. - if (!KMP_HIDDEN_HELPER_THREAD(gtid)) { - thread = __kmp_threads[KMP_GTID_TO_SHADOW_GTID(gtid)]; - // We don't change the parent-child relation for hidden helper task as - // we need that to do per-task-region synchronization. - } } else { // If the hidden helper task is not enabled, reset the flag to FALSE. flags->hidden_helper = FALSE; @@ -1235,8 +1225,7 @@ // Untied task encountered causes the TSC algorithm to check entire deque of // the victim thread. If no untied task encountered, then checking the head // of the deque should be enough. - KMP_CHECK_UPDATE( - encountering_thread->th.th_task_team->tt.tt_untied_task_encountered, 1); + KMP_CHECK_UPDATE(thread->th.th_task_team->tt.tt_untied_task_encountered, 1); } // Detachable tasks are not proxy tasks yet but could be in the future. Doing @@ -1250,32 +1239,30 @@ } /* are we running in a sequential parallel or tskm_immediate_exec... we need tasking support enabled */ - if ((encountering_thread->th.th_task_team) == NULL) { + if ((thread->th.th_task_team) == NULL) { /* This should only happen if the team is serialized setup a task team and propagate it to the thread */ KMP_DEBUG_ASSERT(team->t.t_serialized); KA_TRACE(30, ("T#%d creating task team in __kmp_task_alloc for proxy task\n", gtid)); - __kmp_task_team_setup( - encountering_thread, team, - 1); // 1 indicates setup the current team regardless of nthreads - encountering_thread->th.th_task_team = - team->t.t_task_team[encountering_thread->th.th_task_state]; + // 1 indicates setup the current team regardless of nthreads + __kmp_task_team_setup(thread, team, 1); + thread->th.th_task_team = team->t.t_task_team[thread->th.th_task_state]; } - kmp_task_team_t *task_team = encountering_thread->th.th_task_team; + kmp_task_team_t *task_team = thread->th.th_task_team; /* tasking must be enabled now as the task might not be pushed */ if (!KMP_TASKING_ENABLED(task_team)) { KA_TRACE( 30, ("T#%d enabling tasking in __kmp_task_alloc for proxy task\n", gtid)); - __kmp_enable_tasking(task_team, encountering_thread); - kmp_int32 tid = encountering_thread->th.th_info.ds.ds_tid; + __kmp_enable_tasking(task_team, thread); + kmp_int32 tid = thread->th.th_info.ds.ds_tid; kmp_thread_data_t *thread_data = &task_team->tt.tt_threads_data[tid]; // No lock needed since only owner can allocate if (thread_data->td.td_deque == NULL) { - __kmp_alloc_task_deque(encountering_thread, thread_data); + __kmp_alloc_task_deque(thread, thread_data); } } @@ -1300,11 +1287,11 @@ // Avoid double allocation here by combining shareds with taskdata #if USE_FAST_MEMORY - taskdata = (kmp_taskdata_t *)__kmp_fast_allocate( - encountering_thread, shareds_offset + sizeof_shareds); + taskdata = (kmp_taskdata_t *)__kmp_fast_allocate(thread, shareds_offset + + sizeof_shareds); #else /* ! USE_FAST_MEMORY */ - taskdata = (kmp_taskdata_t *)__kmp_thread_malloc( - encountering_thread, shareds_offset + sizeof_shareds); + taskdata = (kmp_taskdata_t *)__kmp_thread_malloc(thread, shareds_offset + + sizeof_shareds); #endif /* USE_FAST_MEMORY */ task = KMP_TASKDATA_TO_TASK(taskdata); @@ -1331,7 +1318,7 @@ taskdata->td_task_id = KMP_GEN_TASK_ID(); taskdata->td_team = thread->th.th_team; - taskdata->td_alloc_thread = encountering_thread; + taskdata->td_alloc_thread = thread; taskdata->td_parent = parent_task; taskdata->td_level = parent_task->td_level + 1; // increment nesting level KMP_ATOMIC_ST_RLX(&taskdata->td_untied_count, 0); @@ -1345,10 +1332,16 @@ copy_icvs(&taskdata->td_icvs, &taskdata->td_parent->td_icvs); taskdata->td_flags = *flags; - taskdata->encountering_gtid = gtid; taskdata->td_task_team = thread->th.th_task_team; taskdata->td_size_alloc = shareds_offset + sizeof_shareds; taskdata->td_flags.tasktype = TASK_EXPLICIT; + // If it is hidden helper task, we need to set the team and task team + // correspondingly. + if (flags->hidden_helper) { + kmp_info_t *shadow_thread = __kmp_threads[KMP_GTID_TO_SHADOW_GTID(gtid)]; + taskdata->td_team = shadow_thread->th.th_team; + taskdata->td_task_team = shadow_thread->th.th_task_team; + } // GEH - TODO: fix this to copy parent task's value of tasking_ser flag taskdata->td_flags.tasking_ser = (__kmp_tasking_mode == tskm_immediate_exec); @@ -3957,7 +3950,7 @@ // This should be similar to start_k = __kmp_get_random( thread ) % nthreads // but we cannot use __kmp_get_random here - kmp_int32 start_k = start; + kmp_int32 start_k = start % nthreads; kmp_int32 pass = 1; kmp_int32 k = start_k;