llvm / llvm/llvm-project

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

Open
#172,935 0 comments 0 reactions 0 assignees View on GitHub
flang:openmp
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```
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.

``` fortran
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

```

``` text
$ 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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.