]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add test cases for atomic subroutines, remove atomics from TODO.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 17 Jan 2021 13:14:12 +0000 (14:14 +0100)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 17 Jan 2021 14:11:20 +0000 (15:11 +0100)
libgfortran/ChangeLog:

* caf_shared/README.native_coarrays: Remove atomics from list
of unsupported features.

gcc/testsuite/gfortran.dg/caf-shared/atomic_add_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/caf-shared/atomic_cas_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/caf-shared/atomic_define_1.f90 [new file with mode: 0644]
libgfortran/caf_shared/README.native_coarrays

diff --git a/gcc/testsuite/gfortran.dg/caf-shared/atomic_add_1.f90 b/gcc/testsuite/gfortran.dg/caf-shared/atomic_add_1.f90
new file mode 100644 (file)
index 0000000..837baef
--- /dev/null
@@ -0,0 +1,29 @@
+! { dg-do run }
+! { dg-set-target-env-var GFORTRAN_NUM_IMAGES "4" }
+! { dg-options "-fdump-tree-original" }
+! Hand-crafted spin lock to make sure that atomic_add works.
+
+program main
+  use iso_fortran_env, only : atomic_int_kind
+  implicit none
+  integer (atomic_int_kind) :: x[*]
+  integer (atomic_int_kind) :: val
+  integer :: n, me
+  character (len=20) :: line
+  integer :: i
+  n = num_images()
+  me = this_image()
+  x = 0
+  sync all
+  ! Burn some CPU time to provoke race conditions.
+  do i=1,1000
+     write (unit=line,fmt='(F12.5)') sin(i*1.d0)
+  end do
+  call atomic_add (x[1], 1)
+  wait: do
+     call atomic_ref (val, x[1])
+     if (val == n) exit wait
+  end do wait
+  sync memory
+end program main
+! { dg-final { scan-tree-dump-times "__atomic_fetch_add_4" 1 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/caf-shared/atomic_cas_1.f90 b/gcc/testsuite/gfortran.dg/caf-shared/atomic_cas_1.f90
new file mode 100644 (file)
index 0000000..0558e51
--- /dev/null
@@ -0,0 +1,28 @@
+! { dg-do run }
+! { dg-set-target-env-var GFORTRAN_NUM_IMAGES "4" }
+! { dg-options "-fdump-tree-original" }
+! { dg-output "1234" }
+! Ordering of images through a spin lock using atomic_cas.
+
+program main
+  use iso_fortran_env, only : atomic_int_kind
+  implicit none
+  integer (atomic_int_kind) :: atom[*]
+  integer (atomic_int_kind) :: old, compare, new
+  integer :: me, n
+  atom = 0
+  me = this_image ()
+  n = num_images()
+  sync all
+  compare = me - 1
+  new = -1
+  wait: do
+     call atomic_cas (atom[1], old, compare, new)
+     if (old == compare) exit wait
+  end do wait
+  sync memory
+  write (*,'(I0)',advance="no") this_image()
+  call atomic_define (atom[1], this_image())
+  sync memory
+end program main
+! { dg-final { scan-tree-dump-times "__atomic_compare_exchange" 1 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/caf-shared/atomic_define_1.f90 b/gcc/testsuite/gfortran.dg/caf-shared/atomic_define_1.f90
new file mode 100644 (file)
index 0000000..ecb18eb
--- /dev/null
@@ -0,0 +1,32 @@
+! { dg-do run }
+! { dg-set-target-env-var GFORTRAN_NUM_IMAGES "4" }
+! { dg-options "-fdump-tree-original" }
+program atomic
+  use iso_fortran_env
+  implicit none
+  integer(atomic_int_kind) :: atom[*]
+  integer :: to_set[*]
+  integer :: val, i
+  if (this_image() == 1) then
+     call atomic_define (atom[1], 0)
+  end if
+  sync all
+  ! Spin loop on image 2 setting atom[1]
+  if (this_image () == 2) then
+     do i=1,num_images()
+        to_set[i] = 42
+     end do
+     call atomic_define (atom[1], 1)
+     sync memory
+  else
+     wait: do
+        call atomic_ref (val, atom[1])
+        if (val == 1) exit wait
+     end do wait
+     sync memory
+     if (to_set /= 42) stop 42
+  end if
+end program atomic
+! { dg-final { scan-tree-dump-times "__atomic_load_4" 1 "original" } }
+! { dg-final { scan-tree-dump-times "__atomic_store_4" 2 "original" } }
+! { dg-final { scan-tree-dump-times "__atomic_thread_fence" 3 "original" } }
index 3a85ac77cc8811644c43eb12f84dd4795e9b61d6..6fe821f2a8107e3af81d3d18785fa5021f831a0e 100644 (file)
@@ -32,7 +32,6 @@ TODO (the list is probably incomplete):
 - make STAT and ERRMSG work for ALLOCATE, DEALLOCATE, SYNC and locks
 - Teams
 - Types containing allocatable components in coarrays
-- Atomics
 - Events
 - MOVE_ALLOC
 - automatic linking of relevant libraries with -fcoarray=shared