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
|
! { dg-do run }
interface
elemental subroutine sub1 (x, y)
integer, intent(in) :: y
integer, intent(out) :: x
end subroutine
elemental function fn2 (x)
integer, intent(in) :: x
integer :: fn2
end function
end interface
!$omp declare reduction (foo : integer : omp_out = omp_out + omp_in) initializer (omp_priv = 0)
!$omp declare reduction (bar : integer : omp_out = fn1 (omp_out, omp_in)) &
!$omp & initializer (sub1 (omp_priv, omp_orig))
!$omp declare reduction (baz : integer : sub2 (omp_out, omp_in)) &
!$omp initializer (omp_priv = fn2 (omp_orig))
interface
elemental function fn1 (x, y)
integer, intent(in) :: x, y
integer :: fn1
end function
elemental subroutine sub2 (x, y)
integer, intent(in) :: y
integer, intent(inout) :: x
end subroutine
end interface
integer :: a(10), b, r
a(:) = 0
b = 0
r = 0
!$omp parallel reduction (foo : a, b) reduction (+: r)
a = a + 2
b = b + 3
r = r + 1
!$omp end parallel
if (any (a /= 2 * r) .or. b /= 3 * r) STOP 1
a(:) = 0
b = 0
r = 0
!$omp parallel reduction (bar : a, b) reduction (+: r)
a = a + 2
b = b + 3
r = r + 1
!$omp end parallel
if (any (a /= 4 * r) .or. b /= 6 * r) STOP 2
a(:) = 0
b = 0
r = 0
!$omp parallel reduction (baz : a, b) reduction (+: r)
a = a + 2
b = b + 3
r = r + 1
!$omp end parallel
if (any (a /= 2 * r) .or. b /= 3 * r) STOP 3
end
elemental function fn1 (x, y)
integer, intent(in) :: x, y
integer :: fn1
fn1 = x + 2 * y
end function
elemental subroutine sub1 (x, y)
integer, intent(in) :: y
integer, intent(out) :: x
x = 0
end subroutine
elemental function fn2 (x)
integer, intent(in) :: x
integer :: fn2
fn2 = x
end function
elemental subroutine sub2 (x, y)
integer, intent(inout) :: x
integer, intent(in) :: y
x = x + y
end subroutine
|