summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/udr13.f90
blob: 0da1da4bc65b38708e6bf388ae503d4dc20660c9 (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
! { dg-do run }

  interface
    subroutine sub1 (x, y)
      integer, intent(in) :: y(:)
      integer, intent(out) :: x(:)
    end subroutine
    function fn2 (x, m1, m2, n1, n2)
      integer, intent(in) :: x(:,:), m1, m2, n1, n2
      integer :: fn2(m1:m2,n1:n2)
    end function
    subroutine sub3 (x, y)
      integer, allocatable, intent(in) :: y(:,:)
      integer, allocatable, intent(inout) :: x(:,:)
    end subroutine
  end interface
!$omp declare reduction (foo : integer : sub3 (omp_out, omp_in)) &
!$omp initializer (omp_priv = fn3 (omp_orig))
!$omp declare reduction (bar : integer : omp_out = fn1 (omp_out, omp_in, &
!$omp & lbound (omp_out, 1), ubound (omp_out, 1))) &
!$omp & initializer (sub1 (omp_priv, omp_orig))
!$omp declare reduction (baz : integer : sub2 (omp_out, omp_in)) &
!$omp initializer (omp_priv = fn2 (omp_orig, lbound (omp_priv, 1), &
!$omp ubound (omp_priv, 1), lbound (omp_priv, 2), ubound (omp_priv, 2)))
  interface
    function fn1 (x, y, m1, m2)
      integer, intent(in) :: x(:), y(:), m1, m2
      integer :: fn1(m1:m2)
    end function
    subroutine sub2 (x, y)
      integer, intent(in) :: y(:,:)
      integer, intent(inout) :: x(:,:)
    end subroutine
    function fn3 (x)
      integer, allocatable, intent(in) :: x(:,:)
      integer, allocatable :: fn3(:,:)
    end function
  end interface
  integer :: a(10), b(3:5,7:9), r
  integer, allocatable :: c(:,:)
  a(:) = 0
  r = 0
!$omp parallel reduction (bar : a) reduction (+: r)
  if (lbound (a, 1) /= 1 .or. ubound (a, 1) /= 10) call abort
  a = a + 2
  r = r + 1
!$omp end parallel
  if (any (a /= 4 * r) ) call abort
  b(:,:) = 0
  allocate (c (4:6,8:10))
  c(:,:) = 0
  r = 0
!$omp parallel reduction (baz : b, c) reduction (+: r)
  if (lbound (b, 1) /= 3 .or. ubound (b, 1) /= 5) call abort
  if (lbound (b, 2) /= 7 .or. ubound (b, 2) /= 9) call abort
  if (.not. allocated (c)) call abort
  if (lbound (c, 1) /= 4 .or. ubound (c, 1) /= 6) call abort
  if (lbound (c, 2) /= 8 .or. ubound (c, 2) /= 10) call abort
  b = b + 3
  c = c + 4
  r = r + 1
!$omp end parallel
  if (any (b /= 3 * r) .or. any (c /= 4 * r)) call abort
  deallocate (c)
  allocate (c (0:1,7:11))
  c(:,:) = 0
  r = 0
!$omp parallel reduction (foo : c) reduction (+: r)
  if (.not. allocated (c)) call abort
  if (lbound (c, 1) /= 0 .or. ubound (c, 1) /= 1) call abort
  if (lbound (c, 2) /= 7 .or. ubound (c, 2) /= 11) call abort
  c = c + 5
  r = r + 1
!$omp end parallel
  if (any (c /= 10 * r)) call abort
end
function fn1 (x, y, m1, m2)
  integer, intent(in) :: x(:), y(:), m1, m2
  integer :: fn1(m1:m2)
  fn1 = x + 2 * y
end function
subroutine sub1 (x, y)
  integer, intent(in) :: y(:)
  integer, intent(out) :: x(:)
  x = 0
end subroutine
function fn2 (x, m1, m2, n1, n2)
  integer, intent(in) :: x(:,:), m1, m2, n1, n2
  integer :: fn2(m1:m2,n1:n2)
  fn2 = x
end function
subroutine sub2 (x, y)
  integer, intent(inout) :: x(:,:)
  integer, intent(in) :: y(:,:)
  x = x + y
end subroutine
function fn3 (x)
  integer, allocatable, intent(in) :: x(:,:)
  integer, allocatable :: fn3(:,:)
  fn3 = x
end function
subroutine sub3 (x, y)
  integer, allocatable, intent(inout) :: x(:,:)
  integer, allocatable, intent(in) :: y(:,:)
  x = x + 2 * y
end subroutine