Skip to content

[Flang][OpenMP] Incorrect execution result of a do-variable in critical construct which exists in parallel construct with default(none) clause #78936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ohno-fj opened this issue Jan 22, 2024 · 3 comments · Fixed by #90671

Comments

@ohno-fj
Copy link

ohno-fj commented Jan 22, 2024

Version of flang-new : 18.0.0(0fe86f9c518fb1296bba8d66ce495f9dfff2c435)

If critical construct exists in parallel construct with default(none) clause, a do-variable has an incorrect value after executing parallel construct.
A do-variable is private according to the specification in Section (2.15.1.1) of OpenMP 4.5, so the values of k1 and k2 are expected to be 1.
Changing critical construct to sections construct has the same result.

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

snfm_omp_array_do_011.f90:

program main
  integer::k1,k2
  k1=1; k2=1
!$omp parallel default(none)
!$omp critical
  do k2=1,10
     do k1=1,10
     end do
  end do
!$omp end critical
!$omp endparallel
  write(6,*) "k1 = ", k1, " k2 = ", k2
end program main
$ export OMP_NUM_THREADS=2; flang-new -fopenmp snfm_omp_shared_13_011.f90; ./a.out
 k1 =  11  k2 =  11
$
$ export OMP_NUM_THREADS=2; gfortran -fopenmp snfm_omp_array_do_011.f90; ./a.out
 k1 =            1  k2 =            1
$
$ export OMP_NUM_THREADS=2; ifort -qopenmp snfm_omp_array_do_011.f90; ./a.out
 k1 =            1  k2 =            1
$
@github-actions github-actions bot added the flang Flang issues not falling into any other category label Jan 22, 2024
@ohno-fj ohno-fj added the openmp label Jan 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 22, 2024

@llvm/issue-subscribers-openmp

Author: None (ohno-fj)

``` Version of flang-new : 18.0.0(0fe86f9) ```

If critical construct exists in parallel construct with default(none) clause, a do-variable has an incorrect value after executing parallel construct.
A do-variable is private according to the specification in Section (2.15.1.1) of OpenMP 4.5, so the values of k1 and k2 are expected to be 1.
Changing critical construct to sections construct has the same result.

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

snfm_omp_array_do_011.f90:

program main
  integer::k1,k2
  k1=1; k2=1
!$omp parallel default(none)
!$omp critical
  do k2=1,10
     do k1=1,10
     end do
  end do
!$omp end critical
!$omp endparallel
  write(6,*) "k1 = ", k1, " k2 = ", k2
end program main
$ export OMP_NUM_THREADS=2; flang-new -fopenmp snfm_omp_shared_13_011.f90; ./a.out
 k1 =  11  k2 =  11
$
$ export OMP_NUM_THREADS=2; gfortran -fopenmp snfm_omp_array_do_011.f90; ./a.out
 k1 =            1  k2 =            1
$
$ export OMP_NUM_THREADS=2; ifort -qopenmp snfm_omp_array_do_011.f90; ./a.out
 k1 =            1  k2 =            1
$

@luporl
Copy link
Contributor

luporl commented Apr 30, 2024

This is similar to #75767.
But predetermined loop iteration variables for a sequential loop in a parallel construct are handled by OmpAttributeVisitor::Pre(const parser::DoConstruct &x) instead, that also checks for !dirContext_.empty() && GetContext().withinConstruct, which evaluates to false with the test program.

@llvmbot
Copy link
Member

llvmbot commented May 6, 2024

@llvm/issue-subscribers-flang-frontend

Author: None (ohno-fj)

``` Version of flang-new : 18.0.0(0fe86f9) ```

If critical construct exists in parallel construct with default(none) clause, a do-variable has an incorrect value after executing parallel construct.
A do-variable is private according to the specification in Section (2.15.1.1) of OpenMP 4.5, so the values of k1 and k2 are expected to be 1.
Changing critical construct to sections construct has the same result.

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

snfm_omp_array_do_011.f90:

program main
  integer::k1,k2
  k1=1; k2=1
!$omp parallel default(none)
!$omp critical
  do k2=1,10
     do k1=1,10
     end do
  end do
!$omp end critical
!$omp endparallel
  write(6,*) "k1 = ", k1, " k2 = ", k2
end program main
$ export OMP_NUM_THREADS=2; flang-new -fopenmp snfm_omp_shared_13_011.f90; ./a.out
 k1 =  11  k2 =  11
$
$ export OMP_NUM_THREADS=2; gfortran -fopenmp snfm_omp_array_do_011.f90; ./a.out
 k1 =            1  k2 =            1
$
$ export OMP_NUM_THREADS=2; ifort -qopenmp snfm_omp_array_do_011.f90; ./a.out
 k1 =            1  k2 =            1
$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants