1! { dg-do run }
2!$ use omp_lib
3
4  logical :: l, la (4), m, ma (4), v
5  integer :: n, cnt
6
7  l = .true.
8  la = (/.true., .false., .true., .true./)
9  m = .false.
10  ma = (/.false., .false., .false., .true./)
11  v = .false.
12  cnt = -1
13
14!$omp parallel num_threads (3) private (n) reduction (.or.:v) &
15!$omp & reduction (.and.:l, la) reduction (.or.:m, ma)
16!$ if (.not. l .or. any (.not. la)) v = .true.
17!$ if (m .or. any (ma)) v = .true.
18  n = omp_get_thread_num ()
19  if (n .eq. 0) then
20    cnt = omp_get_num_threads ()
21    l = .false.
22    la(3) = .false.
23    ma(2) = .true.
24  else if (n .eq. 1) then
25    l = .false.
26    la(4) = .false.
27    ma(1) = .true.
28  else
29    la(3) = .false.
30    m = .true.
31    ma(1) = .true.
32  end if
33!$omp end parallel
34  if (v) call abort
35  if (cnt .eq. 3) then
36    if (l .or. any (la .neqv. (/.true., .false., .false., .false./))) call abort
37    if (.not. m .or. any (ma .neqv. (/.true., .true., .false., .true./))) call abort
38  end if
39
40  l = .true.
41  la = (/.true., .false., .true., .true./)
42  m = .false.
43  ma = (/.false., .false., .false., .true./)
44  v = .false.
45  cnt = -1
46
47!$omp parallel num_threads (3) private (n) reduction (.or.:v) &
48!$omp & reduction (.eqv.:l, la) reduction (.neqv.:m, ma)
49!$ if (.not. l .or. any (.not. la)) v = .true.
50!$ if (m .or. any (ma)) v = .true.
51  n = omp_get_thread_num ()
52  if (n .eq. 0) then
53    cnt = omp_get_num_threads ()
54    l = .false.
55    la(3) = .false.
56    ma(2) = .true.
57  else if (n .eq. 1) then
58    l = .false.
59    la(4) = .false.
60    ma(1) = .true.
61  else
62    la(3) = .false.
63    m = .true.
64    ma(1) = .true.
65  end if
66!$omp end parallel
67  if (v) call abort
68  if (cnt .eq. 3) then
69    if (.not. l .or. any (la .neqv. (/.true., .false., .true., .false./))) call abort
70    if (.not. m .or. any (ma .neqv. (/.false., .true., .false., .true./))) call abort
71  end if
72
73end
74