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

[Flang][OpenMP] ALLOCATED() Incorrectly Returns False for Shared Allocatable Component in OpenMP Parallel Construct

Open boo-aboutme opened this issue 11 months ago • 0 comments

Version of flang : 22.0.0git (bcbbe2c2bcbeee4e37ca39c8088bbc0702f7f69c)
Target: aarch64-unknown-linux-gnu

In the sample program below, v%x is defined and allocated outside of the parallel construct. Therefore, it is shared in the parallel construct according to the OpenMP standard (OpenMP API v6.0 7.1.1), and ALLOCATED(v%x) should be true for all threads. However, occasionally the IF clause on line 15 is taken and 101 is printed when the program is compiled with Flang on an AArch64 system.

module m1
  type y3
    integer,allocatable::x
    integer::x1
  end type
contains
  subroutine s4(v)
  type(y3),allocatable::v
  integer::omp_get_num_threads,tnum
  integer::s,n

  s=1
  n=10
  !$omp parallel
  if (.not. allocated(v%x)) print *,'101'
  !$omp do schedule(dynamic) lastprivate(v)
  do i=s,n
    v%x=i
    v%x1=i*10
    if( i == 1 ) then
      if (.not. allocated(v%x))  print *,'100'
    endif
  end do
  !$omp end do
  !$omp master
  tnum = omp_get_num_threads()
  !$omp end master
  !$omp end parallel

  if (v%x  /= 10 )  print *,'102',v%x,tnum
  if (v%x1 /= 100 ) print *,'102',v%x1,tnum

  end subroutine s4
end module m1

use m1
type(y3),allocatable::v
allocate(v)
allocate(v%x)
v%x=0
v%x1=0
call s4(v)
print *,'pass'
end

$ export OMP_NUM_THREADS=32
$ flang -fopenmp -O3 sample.f90
$ for i in $(seq 1 10) ; do ./a.out ; done
 pass
 101
 pass
 pass
 101
 pass
 101
 pass
 101
 101
 101
 101
 pass
 101
 pass
 101
 pass
 101
 pass
 101
 101
 pass
$ gfortran -fopenmp -O3  sample.f90
$ for i in $(seq 1 10) ; do ./a.out ; done
 pass
 pass
 pass
 pass
 pass
 pass
 pass
 pass
 pass
 pass

boo-aboutme avatar Dec 19 '25 01:12 boo-aboutme