Debian Codegraph @

libgomp/testsuite/libgomp.fortran/examples-4/simd-1.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-msse2" { target sse2_runtime } }
3 ! { dg-additional-options "-mavx" { target avx_runtime } }
4
5 module SIMD1_mod
6 contains
7 subroutine init (a, a_ref, b, c, n, ioff_ptr)
8 double precision :: a(*), a_ref(*), b(*), c(*)
9 integer :: n, i, s
10 integer, pointer :: ioff_ptr
11
12 s = -1
13 do i = 1, n
14 a(i) = i * i * s
15 a_ref(i) = a(i)
16 b(i) = i + i
17 end do
18
19 do i = 1, n+ioff_ptr
20 c(i) = i * 3
21 end do
22
23 end subroutine
24
25 subroutine check (a, b, n)
26 integer :: i, n
27 double precision, parameter :: EPS = 0.0000000000001
28 double precision :: diff, a(*), b(*)
29 do i = 1, n
30 diff = a(i) - b(i)
31 if (diff > EPS .or. -diff > EPS) stop 1
32 end do
33 end subroutine
34
35 subroutine star(a, a_ref, b, c, n, ioff_ptr)
36 double precision :: a(*), a_ref(*), b(*), c(*)
37 integer :: n, i
38 integer, pointer :: ioff_ptr
39
40 call init (a, a_ref, b, c, n, ioff_ptr)
41
42 !$omp simd
43 do i = 1,n
44 a(i) = a(i) * b(i) * c(i+ioff_ptr)
45 end do
46
47 do i = 1,n
48 a_ref(i) = a_ref(i) * b(i) * c(i+ioff_ptr)
49 end do
50
51 call check (a, a_ref, n)
52
53 end subroutine
54 end module
55
56 program SIMD1
57 use SIMD1_mod, only : star
58 double precision :: a(128), a_ref(128), b(128), c(144)
59 integer, pointer:: ioff_ptr
60 integer, target:: offset
61
62 offset = 16
63 ioff_ptr => offset
64
65 call star (a, a_ref, b, c, 128, ioff_ptr)
66
67 end program