[flang-commits] [flang] [llvm] [mlir] [flang][mlir][OpenMP] Add support for COPYPRIVATE (PR #73128)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Fri Dec 22 05:55:12 PST 2023


luporl wrote:

> > * There is one thing that I've noticed a bit late. The `__kmpc_copyprivate` function uses 2 barriers, which may impact the performance of COPYPRIVATE with multiple variables. Combining the updates of all variables to use a single `__kmpc_copyprivate` call is not straightforward.
> 
> Looking at the code, if the OpenMPIRBuilder provides an interface that can combine the individual variables and copy function into a struct of variables and a single-combined copy function then this issue will go away since it will be 2 barriers for all the copyprivates. I am guessing this is an additional implementation effort and not a fundamental issue. 2 barriers and runtime call per variable in copy-private is high but I guess we can improve this in another patch.
> 
It seems this is what clang does. For a simple test program with 2 copyprivates
```
#pragma omp single copyprivate(i, j)
```
LLVM IR contains
```
  %.omp.copyprivate.cpr_list = alloca [2 x ptr], align 8
  ...
  %4 = getelementptr inbounds [2 x ptr], ptr %.omp.copyprivate.cpr_list, i64 0, i64 0
  store ptr %i, ptr %4, align 8
  %5 = getelementptr inbounds [2 x ptr], ptr %.omp.copyprivate.cpr_list, i64 0, i64 1
  store ptr %j, ptr %5, align 8
  %6 = load i32, ptr %.omp.copyprivate.did_it, align 4
  call void @__kmpc_copyprivate(ptr @1, i32 %1, i64 16, ptr %.omp.copyprivate.cpr_list, ptr @.omp.copyprivate.copy_func, i32 %6)
```

I would also prefer this improvement to be done in another patch.

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


More information about the flang-commits mailing list