| 1 |
! { dg-do run { target vect_simd_clones } } |
| 2 |
! { dg-additional-options "-msse2" { target sse2_runtime } } |
| 3 |
! { dg-additional-options "-mavx" { target avx_runtime } } |
| 4 |
|
| 5 |
program fibonacci |
| 6 |
implicit none |
| 7 |
integer,parameter :: N=30 |
| 8 |
integer :: a(0:N-1), b(0:N-1) |
| 9 |
integer :: a_ref(0:N-1) |
| 10 |
integer :: i |
| 11 |
integer, external :: fib |
| 12 |
|
| 13 |
!$omp simd |
| 14 |
do i = 0,N-1 |
| 15 |
b(i) = i |
| 16 |
end do |
| 17 |
|
| 18 |
!$omp simd |
| 19 |
do i=0,N-1 |
| 20 |
a(i) = fib(b(i)) |
| 21 |
end do |
| 22 |
|
| 23 |
call fib_ref (a_ref, N) |
| 24 |
|
| 25 |
do i = 0, N-1 |
| 26 |
if (a(i) .ne. a_ref(i)) stop 1 |
| 27 |
end do |
| 28 |
|
| 29 |
end program |
| 30 |
|
| 31 |
recursive function fib(n) result(r) |
| 32 |
!$omp declare simd(fib) inbranch |
| 33 |
integer :: n, r |
| 34 |
|
| 35 |
if (n <= 1) then |
| 36 |
r = n |
| 37 |
else |
| 38 |
r = fib(n-1) + fib(n-2) |
| 39 |
endif |
| 40 |
|
| 41 |
end function fib |
| 42 |
|
| 43 |
subroutine fib_ref(a_ref, n) |
| 44 |
integer :: n, a_ref(0:n-1) |
| 45 |
|
| 46 |
a_ref(0) = 0 |
| 47 |
a_ref(1) = 1 |
| 48 |
|
| 49 |
do i = 2, n-1 |
| 50 |
a_ref(i) = a_ref(i-1) + a_ref(i-2) |
| 51 |
end do |
| 52 |
|
| 53 |
end subroutine fib_ref |