aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/examples-4/e.53.4.f90
blob: 41d251aae37b7e4ec40c0534109c72cd6d6df81a (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
63
64
65
66
67
68
! { dg-do run }

module e_53_4_mod
  !$omp declare target (N, Q)
  integer, parameter :: N = 10
  real :: Q(N,N)
contains
  real function Pfun (i, k)
    !$omp declare target
    integer, intent(in) :: i, k
    Pfun = (Q(i,k) * Q(k,i))
  end function
end module

real function accum (k) result (tmp)
  use e_53_4_mod
  integer :: i, k
  tmp = 0.0e0
  !$omp target
    !$omp parallel do reduction(+:tmp)
    do i = 1, N
      tmp = tmp + Pfun (k, i)
    end do
  !$omp end target
end function

real function accum_ref (k) result (tmp)
  use e_53_4_mod
  integer :: i, k
  tmp = 0.0e0
  do i = 1, N
    tmp = tmp + Pfun (k, i)
  end do
end function

subroutine init ()
  use e_53_4_mod
  integer :: i, j
  do i = 1, N
    do j = 1, N
      Q(i,j) = 0.001 * i * j
    end do
  end do
end subroutine

subroutine check (a, b)
  real :: a, b, err
  real, parameter :: EPS = 0.00001
  if (b == 0.0) then
    err = a
  else if (a == 0.0) then
    err = b
  else
    err = (a - b) / b
  end if
  if (err > EPS .or. err < -EPS) call abort
end subroutine

program e_53_4
  use e_53_4_mod
  integer :: i
  real :: accum, accum_ref
  call init ()
  !$omp target update to(Q)
  do i = 1, N
    call check (accum (i), accum_ref (i))
  end do
end program