https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129132
Bug ID: 129132
Summary: taskwait depend, if(0) tasks and target constructs
don't wait for a pending omp_all_memory sibling
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgomp
Assignee: unassigned at gcc dot gnu.org
Reporter: cq at smail dot nju.edu.cn
CC: jakub at gcc dot gnu.org
Target Milestone: ---
Created attachment 66326
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66326&action=edit
test
If the first sibling task with dependences has depend(inout: omp_all_memory),
gomp_task_handle_depend only records it in parent->depend_all_memory and
doesn't create parent->depend_hash. But the undeferred constructs only
wait for their dependences when the hash table exists:
if (thr->task && thr->task->depend_hash)
gomp_task_maybe_wait_for_dependencies (depend);
This check (or the same check around a bigger block) is in GOMP_task for
if(0)/final tasks, GOMP_taskwait_depend, GOMP_target_ext,
GOMP_target_update_ext and GOMP_target_enter_exit_data. So all of them go
ahead while the omp_all_memory task is still running.
#include <stdio.h>
#include <unistd.h>
int x;
volatile int done;
int
main ()
{
#pragma omp parallel num_threads (2)
#pragma omp single
{
#pragma omp task depend(inout: omp_all_memory)
{
usleep (20000);
done = 1;
}
#pragma omp taskwait depend(in: x)
printf ("done = %d\n", done);
}
return 0;
}
$ gcc -fopenmp -O2 pr.c && ./a.out
done = 0
It should print 1. Replacing the taskwait with
"#pragma omp task if (0) depend(in: x)", "#pragma omp target depend(in: x)",
or target update / target enter data / target exit data with
depend(in: x) gives the same result. If some sibling with an ordinary
dependence was created before the omp_all_memory task, the table exists
and everything waits as it should.
Same with 13.3 and with trunk (r17-6775); the code is from r13-337.
I have a patch that also checks depend_all_memory at these places and
skips the hash table lookups in gomp_task_maybe_wait_for_dependencies
when there is no table. Will send it to gcc-patches with a testcase.