From: Thomas Koenig Date: Sun, 17 Jan 2021 13:14:12 +0000 (+0100) Subject: Add test cases for atomic subroutines, remove atomics from TODO. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3f20923e1d7410b6166ffd0fca36f3bd2032ab6;p=thirdparty%2Fgcc.git Add test cases for atomic subroutines, remove atomics from TODO. libgfortran/ChangeLog: * caf_shared/README.native_coarrays: Remove atomics from list of unsupported features. --- 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 index 000000000000..837baef6a15c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/caf-shared/atomic_add_1.f90 @@ -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 index 000000000000..0558e51f92f4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/caf-shared/atomic_cas_1.f90 @@ -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 index 000000000000..ecb18eb1e98d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/caf-shared/atomic_define_1.f90 @@ -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" } } diff --git a/libgfortran/caf_shared/README.native_coarrays b/libgfortran/caf_shared/README.native_coarrays index 3a85ac77cc88..6fe821f2a810 100644 --- a/libgfortran/caf_shared/README.native_coarrays +++ b/libgfortran/caf_shared/README.native_coarrays @@ -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