[all-commits] [llvm/llvm-project] aa4146: [flang][OpenMP] Handle the data race for firstpriv...

PeixinQiao via All-commits all-commits at lists.llvm.org
Sat Aug 20 08:32:43 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: aa4146031132c8007bc9b9109221036c24923d2a
      https://github.com/llvm/llvm-project/commit/aa4146031132c8007bc9b9109221036c24923d2a
  Author: Peixin Qiao <qiaopeixin at huawei.com>
  Date:   2022-08-20 (Sat, 20 Aug 2022)

  Changed paths:
    M flang/lib/Lower/OpenMP.cpp
    M flang/test/Lower/OpenMP/default-clause.f90
    M flang/test/Lower/OpenMP/omp-parallel-firstprivate-clause-scalar.f90
    M flang/test/Lower/OpenMP/omp-parallel-lastprivate-clause-scalar.f90
    M flang/test/Lower/OpenMP/omp-parallel-wsloop-firstpriv.f90
    M flang/test/Lower/OpenMP/omp-parallel-wsloop.f90

  Log Message:
  -----------
  [flang][OpenMP] Handle the data race for firstprivate and lastprivate

Remove barriers for firstprivate except if the variable is also
lastprivatized. Re-arrange code and put all last-privates inside a
single scf.if.

As OpenMP Spec 5.0, to avoid the data races, concurrent updates of the
original list item must be synchronized with the read of the original
list item that occurs as a result of the firstprivate clause. Adding
barrier(s) before and/or after the worksharing region would remove the
data races, and it is the application(user)'s job. However, when
one list item is in both firstprivate and lastprivate clauses, the
standard (https://www.openmp.org/spec-html/5.0/openmpsu105.html) states
the following:
```
If a list item appears in both firstprivate and lastprivate clauses, the
update required for the lastprivate clause occurs after all
initializations for the firstprivate clause.
```

So, the synchronization should be ensured by compiler such as emiting
one barrier since the lastprivate clause follows the reads of the
original list item performed for the initialization of each of the
firstprivate list item.

Add FIXME for two special cases, sections construct and linear clause.

The data race problem for single construct will be handled later.

This implementation is based on the discussion with OpenMP committee and
clang code (clang/lib/CodeGen/CGStmtOpenMP.cpp).

Reviewed By: kiranchandramohan, NimishMishra

Differential Revision: https://reviews.llvm.org/D131832




More information about the All-commits mailing list