[Flang][OpenMP] Common Blocks in reduction Clause
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Flang currently rejects common blocks in `reduction` clause with the error:
Program -
```fortran
module omp_red
implicit none
integer, parameter :: n=100
real (kind=4), dimension(n) :: a_4=10
end module omp_red
program omp_red
use omp_red
implicit none
integer i
real a,b
common /blk/ a,b
a = 2222.0
b = 1111.0
!$omp parallel do reduction(+:a,b)
do i=1,n
a = a + (sin(a_4(i))**2 + cos(a_4(i))**2)
enddo
!$omp end parallel do
print *, a
a = 2222.0
b = 1111.0
!$omp parallel do reduction(+:/blk/)
do i=1,n
a = a + (sin(a_4(i))**2 + cos(a_4(i))**2)
enddo
!$omp end parallel do
print *, a
print *, "The 2 results should be the same"
end program omp_red
```
Error -
```
error: Semantic errors in
:27:34: error: Common block names are not allowed in REDUCTION clause
!$omp parallel do reduction(+:/blk/)
^^^
Compiler returned: 1
```
Godbolt link - https://godbolt.org/
The `reduction` clause spec (Section 7.6.10) does **not explicitly mention** common block names being allowed or disallowed. The allowance is **implicit** — it comes from:
1. The `list` argument being of `variable list item type`
2. Section 5.2.1 defining common block names as valid variable list items
3. The expansion rule making `/blk/` equivalent to listing all members
Should `reduction(+:/blk/)` be treated as equivalent to `reduction(+:a,b)`?
References - https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-6-0.pdf
| OpenMP 6.0 | Section 5.2.1 | Common block name is a valid variable list item; expansion rule |
| OpenMP 6.0 | Section 7.6.10 | reduction clause list is of variable list item type |
Contributor guide
Research direction
Start by reproducing the supplied Fortran program in Flang and compare the accepted reduction(+:a,b) form with the rejected reduction(+:/blk/) form. Check Flang's OpenMP reduction semantic handling against the cited OpenMP 6.0 Sections 5.2.1 and 7.6.10; done when the common-block form follows the specification and has coverage for the equivalent cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100