[PATCH] D92732: [Flang][OpenMP 4.5] Add semantic check for OpenMP Do Loop Constructs
Yashaswini Hegde via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 6 00:09:42 PST 2021
yhegde added inline comments.
================
Comment at: flang/lib/Semantics/resolve-directives.cpp:1039
}
+ ClearThreadPrivateSymbols();
PopContext();
----------------
kiranchandramohan wrote:
> yhegde wrote:
> > kiranchandramohan wrote:
> > > Will this work if there are two omp do loops having threadprivate iteration variables?
> > For the the following test case
> >
> > program omp_do1
> > integer, save:: i, j, k, n
> > !$omp threadprivate(i)
> > !$omp do
> > !ERROR: Loop iteration variable i is not allowed in THREADPRIVATE.
> > do i = 1, 10
> > !!$omp threadprivate(j)
> > !$omp do
> > do j = 1, 10
> > print *, "Hello"
> > end do
> > end do
> > !$omp end do
> >
> > !$omp do
> > !ERROR: Loop iteration variable i is not allowed in THREADPRIVATE.
> > do i = 1, 10
> > !!$omp threadprivate(j)
> > !$omp do
> > do j = 1, 10
> > print *, "Hello"
> > end do
> > end do
> > !$omp end do
> >
> > end program omp_do1
> >
> > the error is
> >
> > ./kcmtp3.f90:6:6: error: Loop iteration variable i is not allowed in THREADPRIVATE.
> > do i = 1, 10
> > ^
> > ./kcmtp3.f90:8:12: error: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
> > !$omp do
> > ^^
> > ./kcmtp3.f90:17:6: error: Loop iteration variable i is not allowed in THREADPRIVATE.
> > do i = 1, 10
> > ^
> > ./kcmtp3.f90:19:12: error: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
> > !$omp do
> > ^^
> >
> > and if I uncomment !$omp threadprivate(j) , I get parse errors.
> >
> > and the gfortran error is
> >
> > kcmtp3.f90:6:14:
> >
> > 6 | do i = 1, 10
> > | 1
> > Error: !$OMP DO iteration variable must not be THREADPRIVATE at (1)
> > kcmtp3.f90:17:14:
> >
> > 17 | do i = 1, 10
> > | 1
> > Error: !$OMP DO iteration variable must not be THREADPRIVATE at (1)
> >
> I got that slightly wrong. What i meant is that if we clear the symbols after visiting a block construct then we will miss the error on a following loop construct. For e.g.
>
> ```
> integer, save:: i, j, k, n
> !$omp threadprivate(i)
>
> !$omp parallel
> print *, "parallel"
> !$omp end parallel
>
> !$omp do
> do i = 1, 10
> do j = 1, 10
> print *, "Hello"
> end do
> end do
> !$omp end do
>
> end program
> ```
Probably I can call ClearThreadPrivateSymbols() in bool Pre(const parser::ModuleSubprogram &) ?
For the test case
program test
integer, save:: i, j, k, n
!$omp threadprivate(i)
!$omp parallel
print *, "parallel"
!$omp end parallel
!$omp do
do i = 1, 10
do j = 1, 10
print *, "Hello"
end do
end do
!$omp end do
end program test
the error message is -
./tp4.f90:10:4: error: Loop iteration variable i is not allowed in THREADPRIVATE.
do i = 1, 10
^
and for the test case
program omp_do2
!$omp threadprivate(k,i)
!$omp threadprivate(j)
!$omp threadprivate(i)
call compute()
contains
subroutine compute()
!$omp do ordered(2) collapse(2)
!ERROR: Loop iteration variable k is not allowed in THREADPRIVATE.
foo: do k = 1, 10
do i = 1, 10
print *, "Hello"
end do
end do foo
!$omp end do
end subroutine
end program omp_do2
program omp_do3
!$omp threadprivate(j)
!$omp parallel
print *, "parallel"
!$omp end parallel
!$omp do
!ERROR: Loop iteration variable i is not allowed in THREADPRIVATE.
do j = 1, 10
do i = 1, 10
print *, "Hello"
end do
end do
!$omp end do
end program omp_do3
the error message is
./tp5.f90:10:11: error: Loop iteration variable k is not allowed in THREADPRIVATE.
foo: do k = 1, 10
^
./tp5.f90:11:8: error: Loop iteration variable i is not allowed in THREADPRIVATE.
do i = 1, 10
^
./tp5.f90:27:6: error: Loop iteration variable j is not allowed in THREADPRIVATE.
do j = 1, 10
^
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92732/new/
https://reviews.llvm.org/D92732
More information about the llvm-commits
mailing list