aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/scan-1.f90
blob: a6f8ef7ea76350ea09bd8077d914c2cbca0e24ce (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
! { dg-require-effective-target size32plus }

module m
  implicit none
  integer r, a(1024), b(1024)
contains
subroutine foo (a, b)
  integer, contiguous :: a(:), b(:)
  integer :: i
  !$omp do reduction (inscan, +:r)
  do i = 1, 1024
    r = r + a(i)
    !$omp scan inclusive(r)
    b(i) = r
  end do
end

integer function bar ()
  integer s, i
  s = 0
  !$omp parallel
  !$omp do reduction (inscan, +:s)
  do i = 1, 1024
    s = s + 2 * a(i)
    !$omp scan inclusive(s)
    b(i) = s
  end do
  !$omp end parallel
  bar = s
end

subroutine baz (a, b)
  integer, contiguous :: a(:), b(:)
  integer :: i
  !$omp parallel do reduction (inscan, +:r)
  do i = 1, 1024
    r = r + a(i)
    !$omp scan inclusive(r)
    b(i) = r
  end do
end

integer function qux ()
  integer s, i
  s = 0
  !$omp parallel do reduction (inscan, +:s)
  do i = 1, 1024
    s = s + 2 * a(i)
    !$omp scan inclusive(s)
    b(i) = s
  end do
  qux = s
end
end module m

program main
  use m
  implicit none

  integer s, i
  s = 0
  do i = 1, 1024
    a(i) = i-1
    b(i) = -1
  end do

  !$omp parallel
  call foo (a, b)
  !$omp end parallel
  if (r /= 1024 * 1023 / 2) &
    stop 1
  do i = 1, 1024
    s = s + i-1
    if (b(i) /= s) then
      stop 2
    else
      b(i) = 25
    endif
  end do

  if (bar () /= 1024 * 1023) &
    stop 3
  s = 0
  do i = 1, 1024
    s = s + 2 * (i-1)
    if (b(i) /= s) then
      stop 4
    else
      b(i) = -1
    end if
  end do

  r = 0
  call baz (a, b)
  if (r /= 1024 * 1023 / 2) &
    stop 5
  s = 0
  do i = 1, 1024
    s = s + i-1
    if (b(i) /= s) then
      stop 6
    else
      b(i) = -25
    endif
  end do

  if (qux () /= 1024 * 1023) &
    stop 6
  s = 0
  do i = 1, 1024
    s = s + 2 * (i-1)
    if (b(i) /= s) &
      stop 7
  end do
end program