https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100144

            Bug ID: 100144
           Summary: [OpenMP] Data race with "omp parallel master taskloop
                    ...  shared(scalar)"
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: openmp
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

That's SOLLVE_VV's
https://github.com/SOLLVE/sollve_vv/blob/master/tests/5.0/parallel_master_taskloop/test_parallel_master_taskloop.c#L31

The code uses:

  int num_threads = -1;
...
#pragma omp parallel master taskloop num_threads(OMPVV_NUM_THREADS_HOST)
shared(x, y, z, num_threads)
  for (int i = 0; i < N; i++) {
    x[i] += y[i]*z[i];
    if (omp_get_thread_num() == 0) {
      num_threads = omp_get_num_threads();
    }
  }

Here: N = 1024, OMPVV_NUM_THREADS_HOST = 8 - and, hence,
"omp_get_thread_num() == 0" → 128 times true.

For num_threads:
* Result:  -1 (initial value) or 8
* Expected: always >= 0, in particular == 8


The race also occurs when the assignment is surrounded by 'omp atomic write' or
'omp critical' surrounding the assignment (occurs quickly) or around the whole
for-block (did not see it, but TSAN reports this).

Reply via email to