llvm / llvm/llvm-project

[Flang][OpenMP] Program with TASKLOOP construct containing LASTPRIVATE clause do not terminate the execution

Open
#186,286 2 comments 0 reactions 1 assignee Claimed by @adit4443ya View on GitHub
flang:openmp
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```
Version of flang : 23.0.0(ae282974b8a40e20a4c55dfffba84d24db843d74)/AArch64
```

In the attached program (`sample.f90`), `TASKLOOP construct` containing `LASTPRIVATE clause` does not terminate.
As shown in the results below, the program continued running for over 10 minutes, so I forcibly terminated the execution.
The execution using Gfortran or ifx completes within one second.

In the following cases, the execution completes within one second:
- Do not specify the compilation option (`-fopenmp`)
- Set the environment variable (`OMP_NUM_THREADS`) to 1
- Delete `TASKLOOP construct`
The above is `sample1.f90`.
- Delete `LASTPRIVATE clause` specified in `TASKLOOP construct`
The above is `sample5.f90`.

The following are the test program, Flang, Gfortran and ifx compilation/execution results.

sample.f90:
```fortran
subroutine sub()
integer,allocatable::a(:)
integer::i, nt
!$ integer omp_get_thread_num
allocate(a(100))
a=-1
nt=0
print *,'start taskloop'
!$omp taskloop lastprivate(a)
do i=1,1
print *,'in taskoop'
!$ nt = omp_get_thread_num() + 1
end do
!$omp end taskloop
print *,'out taskoop'
end subroutine sub

program main
!$omp parallel
!$omp master
call sub()
!$omp end master
!$omp end parallel
print *,'pass'
end program main
```

```
$ export OMP_NUM_THREADS=2; flang -fopenmp sample.f90; time ./a.out
start taskloop
C-c C-c
real 10m3.753s
user 0m0.306s
sys 0m0.113s

$
```

```
$ flang sample.f90; time ./a.out
start taskloop
in taskoop
out taskoop
pass

real 0m0.014s
user 0m0.005s
sys 0m0.000s
$
```

```
$ export OMP_NUM_THREADS=1; flang -fopenmp sample.f90; time ./a.out
start taskloop
in taskoop
out taskoop
pass

real 0m0.028s
user 0m0.002s
sys 0m0.017s
$
```

```
$ export OMP_NUM_THREADS=2; gfortran -fopenmp sample.f90; time ./a.out
start taskloop
in taskoop
out taskoop
pass

real 0m0.051s
user 0m0.002s
sys 0m0.019s
$
```

```
$ export OMP_NUM_THREADS=2; ifx -qopenmp sample.f90; time ./a.out
start taskloop
in taskoop
out taskoop
pass

real 0m0.049s
user 0m0.606s
sys 0m0.054s
$
```

sample1.f90:
```fortran
subroutine sub()
integer,allocatable::a(:)
integer::i, nt
!$ integer omp_get_thread_num
allocate(a(100))
a=-1
nt=0
print *,'start taskloop'
! !$omp taskloop lastprivate(a)
do i=1,1
print *,'in taskoop'
!$ nt = omp_get_thread_num() + 1
end do
! !$omp end taskloop
print *,'out taskoop'
end subroutine sub

program main
!$omp parallel
!$omp master
call sub()
!$omp end master
!$omp end parallel
print *,'pass'
end program main
```

```
$ export OMP_NUM_THREADS=2; flang -fopenmp sample1.f90; time ./a.out
start taskloop
in taskoop
out taskoop
pass

real 0m0.029s
user 0m0.002s
sys 0m0.017s
$
```

sample5.f90:
```fortran
subroutine sub()
integer,allocatable::a(:)
integer::i, nt
!$ integer omp_get_thread_num
allocate(a(100))
a=-1
nt=0
print *,'start taskloop'
!$omp taskloop
do i=1,1
print *,'in taskoop'
!$ nt = omp_get_thread_num() + 1
end do
!$omp end taskloop
print *,'out taskoop'
end subroutine sub

program main
!$omp parallel
!$omp master
call sub()
!$omp end master
!$omp end parallel
print *,'pass'
end program main
```

```
$ export OMP_NUM_THREADS=2; flang -fopenmp sample5.f90; time ./a.out
start taskloop
in taskoop
out taskoop
pass

real 0m0.032s
user 0m0.006s
sys 0m0.015s
$
```

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.