summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/for-2.C
blob: 98ffa1ae6f00163bf821c1cda2fd377f827e2484 (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
182
// { dg-do run }

extern "C" void abort ();

template <typename T>
class J
{
public:
  J(T x, T y) : b (x), e (y) {}
  T begin ();
  T end ();
private:
  T b, e;
};

template <typename T> T J<T>::begin () { return b; }
template <typename T> T J<T>::end () { return e; }

int results[2000];

void
baz (int i)
{
  if (i < 0 || i >= 2000)
    abort ();
  results[i]++;
}

void
f1 (int x, int y)
{
#pragma omp parallel for
  for (int i = x; i <= y; i += 6)
    baz (i);
}

void
f2 (int x, int y)
{
  int i;
#pragma omp parallel for private(i)
  for (i = x; i < y - 1; i = 1 - 6 + 7 + i)
    baz (i);
}

template <typename T>
void
f3 (int x, int y)
{
#pragma omp parallel for
  for (int i = x; i <= y; i = i + 9 - 8)
    baz (i);
}

template <typename T>
void
f4 (int x, int y)
{
  int i;
#pragma omp parallel for lastprivate(i)
  for (i = x + 2000 - 64; i > y + 10; --i)
    baz (i);
}

void
f5 (int x, int y)
{
#pragma omp parallel for
  for (int i = x + 2000 - 64; i > y + 10L; i -= 10L)
    baz (i);
}

template <int N>
void
f6 (int x, int y)
{
#pragma omp parallel for
  for (int i = x + 2000 - 64; i > y + 10L; i = i - 12 + 2L)
    baz (i + N);
}

template <long N>
void
f7 (int i, int x, int y)
{
#pragma omp parallel for
  for (i = x - 10; i <= y + 10; i += N)
    baz (i);
}

template <long N>
void
f8 (J<int> j)
{
  int i;
#pragma omp parallel for
  for (i = j.begin (); i <= j.end () + N; i += 2)
    baz (i);
}

template <typename T, long N>
void
f9 (T x, T y)
{
#pragma omp parallel for
  for (T i = x; i <= y; i = i + N)
    baz (i);
}

template <typename T, long N>
void
f10 (T x, T y)
{
  T i;
#pragma omp parallel for
  for (i = x; i > y; i = i + N)
    baz (i);
}

template <typename T>
void
f11 (T x, long y)
{
#pragma omp parallel
  {
#pragma omp for nowait
    for (T i = x; i <= y; i += 3L)
      baz (i);
#pragma omp single
    baz (y + 3);
  }
}

template <typename T>
void
f12 (T x, T y)
{
  T i;
#pragma omp parallel for
  for (i = x; i > y; --i)
    baz (i);
}

#define check(expr) \
  for (int i = 0; i < 2000; i++)			\
    if (expr)						\
      {							\
	if (results[i] != 1)				\
	  abort ();					\
	results[i] = 0;					\
      }							\
    else if (results[i])				\
      abort ()

int
main ()
{
  f1 (10, 1990);
  check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0);
  f2 (0, 1999);
  check (i < 1998 && (i & 1) == 0);
  f3<char> (20, 1837);
  check (i >= 20 && i <= 1837);
  f4<int> (0, 30);
  check (i > 40 && i <= 2000 - 64);
  f5 (0, 100);
  check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
  f6<-10> (10, 110);
  check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
  f7<6> (0, 12, 1800);
  check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0);
  f8<121> (J<int> (14, 1803));
  check (i >= 14 && i <= 1924 && (i & 1) == 0);
  f9<int, 7> (33, 1967);
  check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0);
  f10<int, -7> (1939, 17);
  check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0);
  f11<int> (16, 1981);
  check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0);
  f12<int> (1761, 37);
  check (i > 37 && i <= 1761);
}