summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/examples-4/simd-3.f90
blob: 2c02945de87408ab2a2452bb83bcacda99d7bb24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
! { dg-do run }
! { dg-additional-options "-msse2" { target sse2_runtime } }
! { dg-additional-options "-mavx" { target avx_runtime } }

module SIMD3_mod
contains
  subroutine work( a, b, n, sum )
     implicit none
     integer :: i, n
     double precision :: a(n), b(n), sum, tmp

     sum = 0.0d0
     call init(a, b, n)
     !$omp simd private(tmp) reduction(+:sum)
     do i = 1,n
        tmp = a(i) + b(i)
        sum = sum + tmp
     end do

  end subroutine work

  subroutine work_ref( a, b, n, sum )
     implicit none
     integer :: i, n
     double precision :: a(n), b(n), sum, tmp

     sum = 0.0d0
     call init(a, b, n)
     do i = 1,n
        tmp = a(i) + b(i)
        sum = sum + tmp
     end do

  end subroutine work_ref

  subroutine init (a, b, n)
    double precision :: a(*), b(*)
    integer          :: n, i, s

    s = -1
    do i = 1, n
      a(i) = i * i * s
      b(i) = i + i
      s = -s
    end do

  end subroutine
end module

program SIMD3
  use SIMD3_mod
  double precision :: a(128), b(128), sum, sum_ref, diff
  double precision, parameter :: EPS = 0.0000000000000001

  call  work(a, b, 128, sum)
  call  work_ref(a, b, 128, sum_ref)

  diff = sum - sum_ref

  if (diff > EPS .or. -diff > EPS) call abort

end program