diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp index 6e584731a85fe3..a8da6146064cf4 100644 --- a/openmp/runtime/src/kmp_tasking.cpp +++ b/openmp/runtime/src/kmp_tasking.cpp @@ -3898,14 +3898,13 @@ void __kmp_fulfill_event(kmp_event_t *event) { kmp_task_t *__kmp_task_dup_alloc(kmp_info_t *thread, kmp_task_t *task_src) { kmp_task_t *task; kmp_taskdata_t *taskdata; - kmp_taskdata_t *taskdata_src; - kmp_taskdata_t *parent_task = thread->th.th_current_task; + kmp_taskdata_t *taskdata_src = KMP_TASK_TO_TASKDATA(task_src); + kmp_taskdata_t *parent_task = taskdata_src->td_parent; // same parent task size_t shareds_offset; size_t task_size; KA_TRACE(10, ("__kmp_task_dup_alloc(enter): Th %p, source task %p\n", thread, task_src)); - taskdata_src = KMP_TASK_TO_TASKDATA(task_src); KMP_DEBUG_ASSERT(taskdata_src->td_flags.proxy == TASK_FULL); // it should not be proxy task KMP_DEBUG_ASSERT(taskdata_src->td_flags.tasktype == TASK_EXPLICIT); @@ -4280,7 +4279,6 @@ void __kmp_taskloop_recur(ident_t *loc, int gtid, kmp_task_t *task, void *codeptr_ra, #endif void *task_dup) { -#if KMP_DEBUG kmp_taskdata_t *taskdata = KMP_TASK_TO_TASKDATA(task); KMP_DEBUG_ASSERT(task != NULL); KMP_DEBUG_ASSERT(num_tasks > num_t_min); @@ -4288,7 +4286,6 @@ void __kmp_taskloop_recur(ident_t *loc, int gtid, kmp_task_t *task, " %lld, extras %lld, i=%lld,%lld(%d), dup %p\n", gtid, taskdata, num_tasks, grainsize, extras, *lb, *ub, st, task_dup)); -#endif p_task_dup_t ptask_dup = (p_task_dup_t)task_dup; kmp_uint64 lower = *lb; kmp_info_t *thread = __kmp_threads[gtid]; @@ -4332,9 +4329,14 @@ void __kmp_taskloop_recur(ident_t *loc, int gtid, kmp_task_t *task, *ub = ub0; // adjust upper bound for the 1st half // create auxiliary task for 2nd half of the loop + // make sure new task has same parent task as the pattern task + kmp_taskdata_t *current_task = thread->th.th_current_task; + thread->th.th_current_task = taskdata->td_parent; kmp_task_t *new_task = __kmpc_omp_task_alloc(loc, gtid, 1, 3 * sizeof(void *), sizeof(__taskloop_params_t), &__kmp_taskloop_task); + // restore current task + thread->th.th_current_task = current_task; __taskloop_params_t *p = (__taskloop_params_t *)new_task->shareds; p->task = next_task; p->lb = (kmp_uint64 *)((char *)next_task + lower_offset); diff --git a/openmp/runtime/test/tasking/omp_taskloop_taskwait.c b/openmp/runtime/test/tasking/omp_taskloop_taskwait.c new file mode 100644 index 00000000000000..6cb226461c8ebe --- /dev/null +++ b/openmp/runtime/test/tasking/omp_taskloop_taskwait.c @@ -0,0 +1,30 @@ +// RUN: %libomp-compile-and-run +#include +#include +int main() +{ + enum {ITERS = 500}; + enum {SIZE = 5}; + int err = 0; + #pragma omp parallel num_threads(2) reduction(+:err) + { + int r = 0; + int i; + #pragma omp taskloop grainsize(SIZE) shared(r) nogroup + for(i=0; i