aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/examples-4/simd-7.f90
blob: 7560657050391f358d1af790b8bc873901458500 (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
! { dg-do run { target vect_simd_clones } }
! { dg-additional-options "-msse2" { target sse2_runtime } }
! { dg-additional-options "-mavx" { target avx_runtime } }

program fibonacci
   implicit none
   integer,parameter :: N=30
   integer           :: a(0:N-1), b(0:N-1)
   integer           :: a_ref(0:N-1)
   integer           :: i
   integer, external :: fib

   !$omp simd
   do i = 0,N-1
      b(i) = i
   end do

   !$omp simd
   do i=0,N-1
      a(i) = fib(b(i))
   end do

   call fib_ref (a_ref, N)

   do i = 0, N-1
     if (a(i) .ne. a_ref(i)) call abort ()
   end do

end program

recursive function fib(n) result(r)
!$omp declare simd(fib) inbranch
   integer  :: n, r

   if (n <= 1) then
       r = n
   else
      r = fib(n-1) + fib(n-2)
   endif

end function fib

subroutine fib_ref(a_ref, n)
   integer  :: n, a_ref(0:n-1)

   a_ref(0) = 0
   a_ref(1) = 1

   do i = 2, n-1
     a_ref(i) = a_ref(i-1) + a_ref(i-2)
   end do

end subroutine fib_ref