llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[flang] OpenMP default private clause does not work as expected

Open shivaramaarao opened this issue 2 years ago • 7 comments

consider the following program

PROGRAM main INTEGER:: NEL !$OMP PARALLEL DO DEFAULT(PRIVATE) !PRIVATE(NEL) DO I=1, 4 NEL=I PRINT *, I, NEL ENDDO !$OMP END PARALLEL DO END PROGRAM

$flang-new -fopenmp test.f90 $a.out 2 4 4 4 3 4 1 4

NEL variable is expected to be private, but it is not considered so. uncommenting PRIVATE(NEL) clause makes the program work.

shivaramaarao avatar Jan 15 '24 14:01 shivaramaarao

The handling of DEFAULT isn't really fully implemented yet: https://github.com/llvm/llvm-project/blob/main/flang/lib/Lower/OpenMP.cpp#L1356-L1376

kparzysz avatar Jan 15 '24 16:01 kparzysz

Thanks for the reply. The testcase is extracted from 362.fma3d omp2012 benchmark suite.

if I comment the following line, the testcase passes. Should the function defaultPrivatize need to handle this case better?

https://github.com/llvm/llvm-project/blob/main/flang/lib/Lower/OpenMP.cpp#L517

shivaramaarao avatar Jan 15 '24 16:01 shivaramaarao

@shivaramaarao This check was added in https://github.com/llvm/llvm-project/pull/71922, to fix https://github.com/llvm/llvm-project/issues/65569. I will do some analysis and get back with more details by EOD on this, on why this check is causing the current issue.

NimishMishra avatar Jan 22 '24 09:01 NimishMishra

@llvm/issue-subscribers-flang-ir

Author: None (shivaramaarao)

consider the following program

PROGRAM main INTEGER:: NEL !$OMP PARALLEL DO DEFAULT(PRIVATE) !PRIVATE(NEL) DO I=1, 4 NEL=I PRINT *, I, NEL ENDDO !$OMP END PARALLEL DO END PROGRAM

$flang-new -fopenmp test.f90 $a.out 2 4 4 4 3 4 1 4

NEL variable is expected to be private, but it is not considered so. uncommenting PRIVATE(NEL) clause makes the program work.

llvmbot avatar Jan 22 '24 16:01 llvmbot

Hello @shivaramaarao,

I re-looked at the issue with rebased llvm flang. The issue is no longer existent with https://github.com/llvm/llvm-project/pull/72510 applied atop https://github.com/llvm/llvm-project/commit/4235e44d4c37ca738c74def05da8caf124d2464e. Could you check once? I get the following IR, which seems to be correct:

omp.parallel {
      %4 = fir.alloca i32 {adapt.valuebyref, pinned}
      %5 = fir.declare %4 {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
      %6 = fir.alloca i32 {bindc_name = "nel", pinned, uniq_name = "_QFEnel"}
      %7 = fir.declare %6 {uniq_name = "_QFEnel"} : (!fir.ref<i32>) -> !fir.ref<i32>
      omp.wsloop  for  (%arg0) : i32 = (%c1_i32) to (%c4_i32) inclusive step (%c1_i32) {
        fir.store %arg0 to %5 : !fir.ref<i32>
        %8 = fir.load %5 : !fir.ref<i32>
        fir.store %8 to %7 : !fir.ref<i32>
        omp.yield
      }
      omp.terminator
    }

NimishMishra avatar Feb 22 '24 13:02 NimishMishra

@NimishMishra if this works now, can you close the issue?

kiranchandramohan avatar May 09 '24 13:05 kiranchandramohan

Validated the application from which this reproducer arose, and it is working fine. Closing this hence.

NimishMishra avatar May 21 '24 05:05 NimishMishra