[flang-commits] [flang] [Flang][OpenMP] Heap-allocate GPU dynamic private arrays in distribute parallel do (PR #200841)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Tue Jun 2 05:34:02 PDT 2026


skatrak wrote:

Thank you Akash, the implementation looks fine but I'd like to know whether the scope of the problem could actually be larger than stated. This seems to only be looking to address the SPMD case but I'm curious about what happens here:
```f90
integer, intent(in) :: n
real, dimension(:,n), intent(inout) :: b
real, dimension(size(b, 1)) :: tmp
real :: x, y
x = 0.0
y = 0.0

!$omp target private(tmp) map(tofrom:x, y) map(to:b)
  tmp(size(b, 1)) = 1.0

  !$omp teams distribute private(tmp) reduction(+:y)
  do i = 1, n
    !$omp parallel do
    do j = 1, size(n, 1)
      tmp(j) = b(j, i)
    end do

    do j = 1, size(n, 1)
      y = y + tmp(j)
    end do
  end do

  x = tmp(size(b, 1))
!$omp end target teams

print *, x, y
! Should print: 1.0 sum(all values of b)
```

I made this on the spot, so let me know if I'm violating any OpenMP rules / improperly accessing array elements. This is mainly to try to illustrate some other ways to access these privatized dynamic size arrays in target regions.

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


More information about the flang-commits mailing list