[flang-commits] [flang] [flang][OpenMP] Initialize allocatable members of derived types (PR #120295)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Fri Jan 10 11:37:28 PST 2025


================
@@ -165,8 +182,8 @@ bool DataSharingProcessor::needBarrier() {
   // variables.
   // Emit implicit barrier for linear clause. Maybe on somewhere else.
   for (const semantics::Symbol *sym : allPrivatizedSymbols) {
-    if (sym->test(semantics::Symbol::Flag::OmpFirstPrivate) &&
-        sym->test(semantics::Symbol::Flag::OmpLastPrivate))
+    if (sym->test(semantics::Symbol::Flag::OmpLastPrivate) &&
+        (sym->test(semantics::Symbol::Flag::OmpFirstPrivate) || callsInitClone))
----------------
luporl wrote:

The barrier there is necessary. It prevents the original `v` variable from being updated by `lastprivate` before every thread has finished initializing its private copy of `v` (using the original variable `v`).

As `v2` doesn't have an allocatable member, `InitializeClone` doesn't need to be called for it.
If it was the only symbol, as it is just written by `lastprivate` but not read by other threads, no barrier would be needed.
And if both `v` and `v2` had allocatable members, a single barrier after the initialization of both would be enough, as their original variables are not read by any threads after that, but only written by `lastprivate` later.

https://github.com/llvm/llvm-project/pull/120295


More information about the flang-commits mailing list