aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/target-in-reduction-1.f90
blob: f9acb711e67073bf674ed99ecfbbd425d942f307 (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
69
70
71
72
73
74
75
76
77
78
! { dg-do run }

module mod1
  contains

    subroutine foo (x, y)
      integer :: x, y

      !$omp taskgroup task_reduction (+: x, y)

      !$omp target in_reduction (+: x, y)
      x = x + 8
      y = y + 16
      !$omp end target

      !$omp task in_reduction (+: x, y)
      x = x + 2
      y = y + 4
      !$omp end task

      !$omp end taskgroup
    end subroutine foo

    integer function bar (x)
      integer, value :: x

      !$omp taskgroup task_reduction (+: x)

      !$omp target in_reduction (+: x)
      x = x + 16
      !$omp end target

      !$omp task in_reduction (+: x)
      x = x + 32
      !$omp end task

      !$omp end taskgroup

      bar = x
    end function bar
  end module mod1

program main
  use mod1
  integer :: x, y
  real :: f;

  x = 1
  y = 1

  call foo (x, y)

  if (x .ne. 11) stop 1
  if (y .ne. 21) stop 2

  y = bar (8)
  if (y .ne. 56) stop 3

  x = 0
  f = 0.0

  !$omp taskgroup task_reduction (+: x, f)
  !$omp target in_reduction (+: x, f)
  x = x + 1
  f = f + 2.0
  !$omp end target

  !$omp task in_reduction (+: x, f)
  x = x + 2
  f = f + 3.0
  !$omp end task

  !$omp end taskgroup

  if (x .ne. 3) stop 4
  if (f .ne. 5.0) stop 5

end program main