2018-03-25 Thomas Koenig <tkoenig@gcc.gnu.org>
[official-gcc.git] / libgomp / testsuite / libgomp.fortran / examples-4 / simd-5.f90
blob561deb786c45b37640e8243d8dc655ca19629394
1 ! { dg-do run }
2 ! { dg-additional-options "-msse2" { target sse2_runtime } }
3 ! { dg-additional-options "-mavx" { target avx_runtime } }
5 module SIMD5_mod
6 contains
7 subroutine work( a, b, c, n )
8 implicit none
9 integer :: i,j,n
10 double precision :: a(n,n), b(n,n), c(n,n), tmp
12 !$omp do simd collapse(2) private(tmp)
13 do j = 1,n
14 do i = 1,n
15 tmp = a(i,j) + b(i,j)
16 c(i,j) = tmp
17 end do
18 end do
20 end subroutine work
22 subroutine work_ref( a, b, c, n )
23 implicit none
24 integer :: i,j,n
25 double precision :: a(n,n), b(n,n), c(n,n), tmp
27 do j = 1,n
28 do i = 1,n
29 tmp = a(i,j) + b(i,j)
30 c(i,j) = tmp
31 end do
32 end do
34 end subroutine work_ref
36 subroutine init (a, b, n)
37 integer :: i,j,n,s
38 double precision :: a(n,n), b(n,n)
40 s = -1
42 do j = 1,n
43 do i = 1,n
44 a(i,j) = i*j*s
45 b(i,j) = i+j
46 s = -s
47 end do
48 end do
50 end subroutine
52 subroutine check (a, b, n)
53 integer :: i, j, n
54 double precision, parameter :: EPS = 0.0000000000000001
55 double precision :: diff, a(n,n), b(n,n)
56 do j = 1, n
57 do i = 1, n
58 diff = a(i,j) - b(i,j)
59 if (diff > EPS .or. -diff > EPS) STOP 1
60 end do
61 end do
62 end subroutine
64 end module
66 program SIMD5
67 use SIMD5_mod
68 double precision, dimension(32, 32) :: a, b, c, c_ref
70 call init(a, b, 32)
72 call work(a, b, c, 32)
73 call work_ref(a, b, c_ref, 32)
75 call check(c, c_ref, 32)
76 end program