| 1 |
! { dg-do run } |
| 2 |
! { dg-additional-options "-msse2" { target sse2_runtime } } |
| 3 |
! { dg-additional-options "-mavx" { target avx_runtime } } |
| 4 |
|
| 5 |
module SIMD3_mod |
| 6 |
contains |
| 7 |
subroutine work( a, b, n, sum ) |
| 8 |
implicit none |
| 9 |
integer :: i, n |
| 10 |
double precision :: a(n), b(n), sum, tmp |
| 11 |
|
| 12 |
sum = 0.0d0 |
| 13 |
call init(a, b, n) |
| 14 |
!$omp simd private(tmp) reduction(+:sum) |
| 15 |
do i = 1,n |
| 16 |
tmp = a(i) + b(i) |
| 17 |
sum = sum + tmp |
| 18 |
end do |
| 19 |
|
| 20 |
end subroutine work |
| 21 |
|
| 22 |
subroutine work_ref( a, b, n, sum ) |
| 23 |
implicit none |
| 24 |
integer :: i, n |
| 25 |
double precision :: a(n), b(n), sum, tmp |
| 26 |
|
| 27 |
sum = 0.0d0 |
| 28 |
call init(a, b, n) |
| 29 |
do i = 1,n |
| 30 |
tmp = a(i) + b(i) |
| 31 |
sum = sum + tmp |
| 32 |
end do |
| 33 |
|
| 34 |
end subroutine work_ref |
| 35 |
|
| 36 |
subroutine init (a, b, n) |
| 37 |
double precision :: a(*), b(*) |
| 38 |
integer :: n, i, s |
| 39 |
|
| 40 |
s = -1 |
| 41 |
do i = 1, n |
| 42 |
a(i) = i * i * s |
| 43 |
b(i) = i + i |
| 44 |
s = -s |
| 45 |
end do |
| 46 |
|
| 47 |
end subroutine |
| 48 |
end module |
| 49 |
|
| 50 |
program SIMD3 |
| 51 |
use SIMD3_mod |
| 52 |
double precision :: a(128), b(128), sum, sum_ref, diff |
| 53 |
double precision, parameter :: EPS = 0.0000000000000001 |
| 54 |
|
| 55 |
call work(a, b, 128, sum) |
| 56 |
call work_ref(a, b, 128, sum_ref) |
| 57 |
|
| 58 |
diff = sum - sum_ref |
| 59 |
|
| 60 |
if (diff > EPS .or. -diff > EPS) stop 1 |
| 61 |
|
| 62 |
end program |