00001
00002
00003 typedef __PTRDIFF_TYPE__ ptrdiff_t;
00004 extern "C" void abort ();
00005
00006 template <typename T>
00007 class I
00008 {
00009 public:
00010 typedef ptrdiff_t difference_type;
00011 I ();
00012 ~I ();
00013 I (T *);
00014 I (const I &);
00015 T &operator * ();
00016 T *operator -> ();
00017 T &operator [] (const difference_type &) const;
00018 I &operator = (const I &);
00019 I &operator ++ ();
00020 I operator ++ (int);
00021 I &operator -- ();
00022 I operator -- (int);
00023 I &operator += (const difference_type &);
00024 I &operator -= (const difference_type &);
00025 I operator + (const difference_type &) const;
00026 I operator - (const difference_type &) const;
00027 template <typename S> friend bool operator == (I<S> &, I<S> &);
00028 template <typename S> friend bool operator == (const I<S> &, const I<S> &);
00029 template <typename S> friend bool operator < (I<S> &, I<S> &);
00030 template <typename S> friend bool operator < (const I<S> &, const I<S> &);
00031 template <typename S> friend bool operator <= (I<S> &, I<S> &);
00032 template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
00033 template <typename S> friend bool operator > (I<S> &, I<S> &);
00034 template <typename S> friend bool operator > (const I<S> &, const I<S> &);
00035 template <typename S> friend bool operator >= (I<S> &, I<S> &);
00036 template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
00037 template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
00038 template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
00039 template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
00040 private:
00041 T *p;
00042 };
00043 template <typename T> I<T>::I () : p (0) {}
00044 template <typename T> I<T>::~I () {}
00045 template <typename T> I<T>::I (T *x) : p (x) {}
00046 template <typename T> I<T>::I (const I &x) : p (x.p) {}
00047 template <typename T> T &I<T>::operator * () { return *p; }
00048 template <typename T> T *I<T>::operator -> () { return p; }
00049 template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
00050 template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
00051 template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
00052 template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
00053 template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
00054 template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
00055 template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
00056 template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
00057 template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
00058 template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
00059 template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
00060 template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
00061 template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
00062 template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
00063 template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
00064 template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
00065 template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
00066 template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
00067 template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
00068 template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
00069 template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
00070 template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
00071 template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
00072 template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
00073 template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
00074
00075 template <typename T>
00076 class J
00077 {
00078 public:
00079 J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
00080 const I<T> &begin ();
00081 const I<T> &end ();
00082 private:
00083 I<T> b, e;
00084 };
00085
00086 template <typename T> const I<T> &J<T>::begin () { return b; }
00087 template <typename T> const I<T> &J<T>::end () { return e; }
00088
00089 int results[2000];
00090
00091 template <typename T>
00092 void
00093 baz (I<T> &i)
00094 {
00095 if (*i < 0 || *i >= 2000)
00096 abort ();
00097 results[*i]++;
00098 }
00099
00100 void
00101 f1 (const I<int> &x, const I<int> &y)
00102 {
00103 #pragma omp parallel for
00104 for (I<int> i = x; y >= i; i += 6)
00105 baz (i);
00106 }
00107
00108 void
00109 f2 (const I<int> &x, const I<int> &y)
00110 {
00111 I<int> i;
00112 #pragma omp parallel for private(i)
00113 for (i = x; y - 1 > i; i = 1 - 6 + 7 + i)
00114 baz (i);
00115 }
00116
00117 template <typename T>
00118 void
00119 f3 (const I<int> &x, const I<int> &y)
00120 {
00121 #pragma omp parallel for
00122 for (I<int> i = x; y >= i; i = i + 9 - 8)
00123 baz (i);
00124 }
00125
00126 template <typename T>
00127 void
00128 f4 (const I<int> &x, const I<int> &y)
00129 {
00130 I<int> i;
00131 #pragma omp parallel for lastprivate(i)
00132 for (i = x + 2000 - 64; y + 10 < i; --i)
00133 baz (i);
00134 }
00135
00136 void
00137 f5 (const I<int> &x, const I<int> &y)
00138 {
00139 #pragma omp parallel for
00140 for (I<int> i = x + 2000 - 64; y + 10 < i; i -= 10)
00141 baz (i);
00142 }
00143
00144 template <int N>
00145 void
00146 f6 (const I<int> &x, const I<int> &y)
00147 {
00148 #pragma omp parallel for
00149 for (I<int> i = x + 2000 - 64; y + 10 < i; i = i - 12 + 2)
00150 {
00151 I<int> j = i + N;
00152 baz (j);
00153 }
00154 }
00155
00156 template <int N>
00157 void
00158 f7 (I<int> i, const I<int> &x, const I<int> &y)
00159 {
00160 #pragma omp parallel for
00161 for (i = x - 10; y + 10 >= i; i += N)
00162 baz (i);
00163 }
00164
00165 template <int N>
00166 void
00167 f8 (J<int> j)
00168 {
00169 I<int> i;
00170 #pragma omp parallel for
00171 for (i = j.begin (); j.end () + N >= i; i += 2)
00172 baz (i);
00173 }
00174
00175 template <typename T, int N>
00176 void
00177 f9 (const I<T> &x, const I<T> &y)
00178 {
00179 #pragma omp parallel for
00180 for (I<T> i = x; y >= i; i = i + N)
00181 baz (i);
00182 }
00183
00184 template <typename T, int N>
00185 void
00186 f10 (const I<T> &x, const I<T> &y)
00187 {
00188 I<T> i;
00189 #pragma omp parallel for
00190 for (i = x; y < i; i = i + N)
00191 baz (i);
00192 }
00193
00194 template <typename T>
00195 void
00196 f11 (const T &x, const T &y)
00197 {
00198 #pragma omp parallel
00199 {
00200 #pragma omp for nowait
00201 for (T i = x; y >= i; i += 3)
00202 baz (i);
00203 #pragma omp single
00204 {
00205 T j = y + 3;
00206 baz (j);
00207 }
00208 }
00209 }
00210
00211 template <typename T>
00212 void
00213 f12 (const T &x, const T &y)
00214 {
00215 T i;
00216 #pragma omp parallel for
00217 for (i = x; y < i; --i)
00218 baz (i);
00219 }
00220
00221 template <int N>
00222 struct K
00223 {
00224 template <typename T>
00225 static void
00226 f13 (const T &x, const T &y)
00227 {
00228 #pragma omp parallel for
00229 for (T i = x; y + N >= i; i += N)
00230 baz (i);
00231 }
00232 };
00233
00234 #define check(expr) \
00235 for (int i = 0; i < 2000; i++) \
00236 if (expr) \
00237 { \
00238 if (results[i] != 1) \
00239 abort (); \
00240 results[i] = 0; \
00241 } \
00242 else if (results[i]) \
00243 abort ()
00244
00245 int
00246 main ()
00247 {
00248 int a[2000];
00249 long b[2000];
00250 for (int i = 0; i < 2000; i++)
00251 {
00252 a[i] = i;
00253 b[i] = i;
00254 }
00255 f1 (&a[10], &a[1990]);
00256 check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0);
00257 f2 (&a[0], &a[1999]);
00258 check (i < 1998 && (i & 1) == 0);
00259 f3<char> (&a[20], &a[1837]);
00260 check (i >= 20 && i <= 1837);
00261 f4<int> (&a[0], &a[30]);
00262 check (i > 40 && i <= 2000 - 64);
00263 f5 (&a[0], &a[100]);
00264 check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
00265 f6<-10> (&a[10], &a[110]);
00266 check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
00267 f7<6> (I<int> (), &a[12], &a[1800]);
00268 check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0);
00269 f8<121> (J<int> (&a[14], &a[1803]));
00270 check (i >= 14 && i <= 1924 && (i & 1) == 0);
00271 f9<int, 7> (&a[33], &a[1967]);
00272 check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0);
00273 f10<int, -7> (&a[1939], &a[17]);
00274 check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0);
00275 f11<I<int> > (&a[16], &a[1981]);
00276 check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0);
00277 f12<I<int> > (&a[1761], &a[37]);
00278 check (i > 37 && i <= 1761);
00279 K<5>::f13<I<int> > (&a[1], &a[1935]);
00280 check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0);
00281 f9<long, 7> (&b[33], &b[1967]);
00282 check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0);
00283 f10<long, -7> (&b[1939], &b[17]);
00284 check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0);
00285 f11<I<long> > (&b[16], &b[1981]);
00286 check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0);
00287 f12<I<long> > (&b[1761], &b[37]);
00288 check (i > 37 && i <= 1761);
00289 K<5>::f13<I<long> > (&b[1], &b[1935]);
00290 check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0);
00291 }