Skip to content
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

[flang][OpenMP] reduction(min) gives an inexact negative value close to zero #73101

Closed
NimishMishra opened this issue Nov 22, 2023 · 0 comments · Fixed by #73102
Closed

[flang][OpenMP] reduction(min) gives an inexact negative value close to zero #73101

NimishMishra opened this issue Nov 22, 2023 · 0 comments · Fixed by #73102
Assignees

Comments

@NimishMishra
Copy link
Contributor

For the following program, logically, the variable x should give 0. However, LLVM flang gives an inexact negative value -1.E-45. In contrast, gfortran gives an exact 0.

program sample
   real :: x, y(100)
   x = 0
   do i = 1, 100
      y(i) = i
   end do

   !$omp parallel do reduction(min:x)
      do i = 1, 100
          x = min(y(i), x)
      end do
   !$omp end parallel do
end program sample
@NimishMishra NimishMishra added flang Flang issues not falling into any other category flang:openmp labels Nov 22, 2023
@NimishMishra NimishMishra self-assigned this Nov 22, 2023
NimishMishra added a commit that referenced this issue Nov 22, 2023
Initialization of reduction variable for min-reduction is set to largest
negative value. As such, in presence of non-negative operands, min
reduction gives incorrect output. This patch initialises min-reduction
to use the maximum positive value instead, so that it can produce
correct output for the entire range of real valued operands.

Fixes #73101
@EugeneZelenko EugeneZelenko removed the flang Flang issues not falling into any other category label Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants