public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/102698] New: omp atomic capture Abnormal results after running multiple times
@ 2021-10-12  3:35 han.wu@compiler-dev.com
  2021-10-12  6:31 ` [Bug fortran/102698] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: han.wu@compiler-dev.com @ 2021-10-12  3:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102698

            Bug ID: 102698
           Summary: omp atomic capture Abnormal results after running
                    multiple times
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: han.wu@compiler-dev.com
  Target Milestone: ---

test case:
program main
  interface
    subroutine aaaa_ieor(x, o, idx, idy, n)
      integer(2) :: x(8, 2), o(8, 2)
      integer :: n, idx(*), idy(*)
    end subroutine
  end interface
  integer, parameter :: n = 64, n1 = 8, n2 = 2
  integer(2) :: x(8, 2), o(8, 2), expect1(8, 2), a(64), b(64), c(64)
  integer :: idx(n), idy(n)
  logical(1) :: rst(32), res(32)
  integer :: i, j

  do i = 1, n
    idx(i) = mod(i, n1) + 1
    if (i > 32) then
      idy(i) = mod(i, n2) + 1
    else
      idy(i) = mod(i + 1, n2) + 1
    end if
  end do

  expect1 = reshape([120 ,25, 58, 27, 60, 29, 62, 31, &
    56, 57, 26, 59, 28, 61, 30, 63], (/8, 2/))
  x = 0
  call aaaa_ieor(x, o, idx, idy, n)

  res(1:16) = reshape((x .eq. expect1), (/16/))
  res(17:32) = reshape((o .eq. expect1), (/16/))
  !print *, x
  do i = 1, 32
    if (res(i) .neqv. .true.) print *,  i 
  end do

  if (any(res .neqv. .true.)) stop 1
    !print *, "PASS"

end program

function fun(i) result(c)
  integer :: i
  integer(2) :: c
  c = i
end function

subroutine aaaa_ieor(x, o, idx, idy, n)
  integer(2) :: x(8, 2), o(8, 2)
  integer :: n, idx(*), idy(*)

  interface
    function fun(i) result(c)
      integer :: i
      integer(2) :: c
    end function
  end interface
  !num_threads(4)
  !$omp parallel do shared(x, o)
  do i = 1, 64
    !$omp atomic capture
    x(idx(i), idy(i)) = ior(x(idx(i), idy(i)), fun(i))
    o(idx(i), idy(i)) = x(idx(i), idy(i))
    !$omp end atomic
  end do
end subroutine


next is the shell to exec:
#!/bin/bash
gfortran  -fopenmp    ieor1.f90
for((i=1;i<=1000;i++))
do
 ./a.out
done

Once executed 1,000 times in one shell, the result may be wrong one time
If you are lucky, run a.out 6000 times may only one result is wrong

How did the error happen? Looking forward to your help

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-12 12:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12  3:35 [Bug fortran/102698] New: omp atomic capture Abnormal results after running multiple times han.wu@compiler-dev.com
2021-10-12  6:31 ` [Bug fortran/102698] " rguenth at gcc dot gnu.org
2021-10-12  8:14 ` jakub at gcc dot gnu.org
2021-10-12  9:09 ` jakub at gcc dot gnu.org
2021-10-12 12:03 ` han.wu@compiler-dev.com
2021-10-12 12:20 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).