summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/reduction1.f90
blob: d6ceb081443a8b75ac51566101beb136cc7188a9 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
! { dg-do run }
!$ use omp_lib

  integer :: i, ia (6), n, cnt
  real :: r, ra (4)
  double precision :: d, da (5)
  complex :: c, ca (3)
  logical :: v

  i = 1
  ia = 2
  r = 3
  ra = 4
  d = 5.5
  da = 6.5
  c = cmplx (7.5, 1.5)
  ca = cmplx (8.5, -3.0)
  v = .false.
  cnt = -1

!$omp parallel num_threads (3) private (n) reduction (.or.:v) &
!$omp & reduction (+:i, ia, r, ra, d, da, c, ca)
!$ if (i .ne. 0 .or. any (ia .ne. 0)) v = .true.
!$ if (r .ne. 0 .or. any (ra .ne. 0)) v = .true.
!$ if (d .ne. 0 .or. any (da .ne. 0)) v = .true.
!$ if (c .ne. cmplx (0) .or. any (ca .ne. cmplx (0))) v = .true.
  n = omp_get_thread_num ()
  if (n .eq. 0) then
    cnt = omp_get_num_threads ()
    i = 4
    ia(3:5) = -2
    r = 5
    ra(1:2) = 6.5
    d = -2.5
    da(2:4) = 8.5
    c = cmplx (2.5, -3.5)
    ca(1) = cmplx (4.5, 5)
  else if (n .eq. 1) then
    i = 2
    ia(4:6) = 5
    r = 1
    ra(2:4) = -1.5
    d = 8.5
    da(1:3) = 2.5
    c = cmplx (0.5, -3)
    ca(2:3) = cmplx (-1, 6)
  else
    i = 1
    ia = 1
    r = -1
    ra = -1
    d = 1
    da = -1
    c = 1
    ca = cmplx (-1, 0)
  end if
!$omp end parallel
  if (v) call abort
  if (cnt .eq. 3) then
    if (i .ne. 8 .or. any (ia .ne. (/3, 3, 1, 6, 6, 8/))) call abort
    if (r .ne. 8 .or. any (ra .ne. (/9.5, 8.0, 1.5, 1.5/))) call abort
    if (d .ne. 12.5 .or. any (da .ne. (/8.0, 16.5, 16.5, 14.0, 5.5/))) call abort
    if (c .ne. cmplx (11.5, -5)) call abort
    if (ca(1) .ne. cmplx (12, 2)) call abort
    if (ca(2) .ne. cmplx (6.5, 3) .or. ca(2) .ne. ca(3)) call abort
  end if

  i = 1
  ia = 2
  r = 3
  ra = 4
  d = 5.5
  da = 6.5
  c = cmplx (7.5, 1.5)
  ca = cmplx (8.5, -3.0)
  v = .false.
  cnt = -1

!$omp parallel num_threads (3) private (n) reduction (.or.:v) &
!$omp & reduction (-:i, ia, r, ra, d, da, c, ca)
!$ if (i .ne. 0 .or. any (ia .ne. 0)) v = .true.
!$ if (r .ne. 0 .or. any (ra .ne. 0)) v = .true.
!$ if (d .ne. 0 .or. any (da .ne. 0)) v = .true.
!$ if (c .ne. cmplx (0) .or. any (ca .ne. cmplx (0))) v = .true.
  n = omp_get_thread_num ()
  if (n .eq. 0) then
    cnt = omp_get_num_threads ()
    i = 4
    ia(3:5) = -2
    r = 5
    ra(1:2) = 6.5
    d = -2.5
    da(2:4) = 8.5
    c = cmplx (2.5, -3.5)
    ca(1) = cmplx (4.5, 5)
  else if (n .eq. 1) then
    i = 2
    ia(4:6) = 5
    r = 1
    ra(2:4) = -1.5
    d = 8.5
    da(1:3) = 2.5
    c = cmplx (0.5, -3)
    ca(2:3) = cmplx (-1, 6)
  else
    i = 1
    ia = 1
    r = -1
    ra = -1
    d = 1
    da = -1
    c = 1
    ca = cmplx (-1, 0)
  end if
!$omp end parallel
  if (v) call abort
  if (cnt .eq. 3) then
    if (i .ne. 8 .or. any (ia .ne. (/3, 3, 1, 6, 6, 8/))) call abort
    if (r .ne. 8 .or. any (ra .ne. (/9.5, 8.0, 1.5, 1.5/))) call abort
    if (d .ne. 12.5 .or. any (da .ne. (/8.0, 16.5, 16.5, 14.0, 5.5/))) call abort
    if (c .ne. cmplx (11.5, -5)) call abort
    if (ca(1) .ne. cmplx (12, 2)) call abort
    if (ca(2) .ne. cmplx (6.5, 3) .or. ca(2) .ne. ca(3)) call abort
  end if

  i = 1
  ia = 2
  r = 4
  ra = 8
  d = 16
  da = 32
  c = 2
  ca = cmplx (0, 2)
  v = .false.
  cnt = -1

!$omp parallel num_threads (3) private (n) reduction (.or.:v) &
!$omp & reduction (*:i, ia, r, ra, d, da, c, ca)
!$ if (i .ne. 1 .or. any (ia .ne. 1)) v = .true.
!$ if (r .ne. 1 .or. any (ra .ne. 1)) v = .true.
!$ if (d .ne. 1 .or. any (da .ne. 1)) v = .true.
!$ if (c .ne. cmplx (1) .or. any (ca .ne. cmplx (1))) v = .true.
  n = omp_get_thread_num ()
  if (n .eq. 0) then
    cnt = omp_get_num_threads ()
    i = 3
    ia(3:5) = 2
    r = 0.5
    ra(1:2) = 2
    d = -1
    da(2:4) = -2
    c = 2.5
    ca(1) = cmplx (-5, 0)
  else if (n .eq. 1) then
    i = 2
    ia(4:6) = -2
    r = 8
    ra(2:4) = -0.5
    da(1:3) = -1
    c = -3
    ca(2:3) = cmplx (0, -1)
  else
    ia = 2
    r = 0.5
    ra = 0.25
    d = 2.5
    da = -1
    c = cmplx (0, -1)
    ca = cmplx (-1, 0)
  end if
!$omp end parallel
  if (v) call abort
  if (cnt .eq. 3) then
    if (i .ne. 6 .or. any (ia .ne. (/4, 4, 8, -16, -16, -8/))) call abort
    if (r .ne. 8 .or. any (ra .ne. (/4., -2., -1., -1./))) call abort
    if (d .ne. -40 .or. any (da .ne. (/32., -64., -64., 64., -32./))) call abort
    if (c .ne. cmplx (0, 15)) call abort
    if (ca(1) .ne. cmplx (0, 10)) call abort
    if (ca(2) .ne. cmplx (-2, 0) .or. ca(2) .ne. ca(3)) call abort
  end if
end