00001
00002
00003 #include <omp.h>
00004 typedef __PTRDIFF_TYPE__ ptrdiff_t;
00005 extern "C" void abort ();
00006
00007 template <typename T>
00008 class I
00009 {
00010 public:
00011 typedef ptrdiff_t difference_type;
00012 I ();
00013 ~I ();
00014 I (T *);
00015 I (const I &);
00016 T &operator * ();
00017 T *operator -> ();
00018 T &operator [] (const difference_type &) const;
00019 I &operator = (const I &);
00020 I &operator ++ ();
00021 I operator ++ (int);
00022 I &operator -- ();
00023 I operator -- (int);
00024 I &operator += (const difference_type &);
00025 I &operator -= (const difference_type &);
00026 I operator + (const difference_type &) const;
00027 I operator - (const difference_type &) const;
00028 template <typename S> friend bool operator == (I<S> &, I<S> &);
00029 template <typename S> friend bool operator == (const I<S> &, const I<S> &);
00030 template <typename S> friend bool operator < (I<S> &, I<S> &);
00031 template <typename S> friend bool operator < (const I<S> &, const I<S> &);
00032 template <typename S> friend bool operator <= (I<S> &, I<S> &);
00033 template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
00034 template <typename S> friend bool operator > (I<S> &, I<S> &);
00035 template <typename S> friend bool operator > (const I<S> &, const I<S> &);
00036 template <typename S> friend bool operator >= (I<S> &, I<S> &);
00037 template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
00038 template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
00039 template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
00040 template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
00041 private:
00042 T *p;
00043 };
00044 template <typename T> I<T>::I () : p (0) {}
00045 template <typename T> I<T>::~I () { p = (T *) 0; }
00046 template <typename T> I<T>::I (T *x) : p (x) {}
00047 template <typename T> I<T>::I (const I &x) : p (x.p) {}
00048 template <typename T> T &I<T>::operator * () { return *p; }
00049 template <typename T> T *I<T>::operator -> () { return p; }
00050 template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
00051 template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
00052 template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
00053 template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
00054 template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
00055 template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
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) { p -= x; return *this; }
00058 template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
00059 template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
00060 template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
00061 template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
00062 template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
00063 template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
00064 template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
00065 template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
00066 template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
00067 template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
00068 template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
00069 template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
00070 template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
00071 template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
00072 template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
00073 template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
00074 template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
00075
00076 template <typename T>
00077 class J
00078 {
00079 public:
00080 J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
00081 const I<T> &begin ();
00082 const I<T> &end ();
00083 private:
00084 I<T> b, e;
00085 };
00086
00087 template <typename T> const I<T> &J<T>::begin () { return b; }
00088 template <typename T> const I<T> &J<T>::end () { return e; }
00089
00090 int results[2000];
00091
00092 void
00093 f1 (J<int> x, J<int> y, J<int> z)
00094 {
00095 I<int> i, j, k;
00096 int l, f = 0, n = 0, m = 0;
00097 #pragma omp parallel shared (i, j, k, l) firstprivate (f) \
00098 reduction (+:n, m) num_threads (8)
00099 {
00100 #pragma omp for lastprivate (i, j, k, l) schedule (static, 9) \
00101 collapse (4)
00102 for (i = x.begin (); i < x.end (); ++i)
00103 for (j = y.begin (); j <= y.end (); j += 1)
00104 for (l = 0; l < 1; l++)
00105 for (k = z.begin () + 3; k < z.end () - 3; k++)
00106 if (omp_get_num_threads () == 8
00107 && ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13)
00108 != (omp_get_thread_num () * 9 + f++)))
00109 n++;
00110 else
00111 m++;
00112 }
00113 if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3
00114 || m != 72 || l != 1)
00115 abort ();
00116 }
00117
00118 void
00119 f2 (J<int> x, J<int> y, J<int> z)
00120 {
00121 int f = 0, n = 0, m = 0;
00122 #pragma omp parallel for firstprivate (f) reduction (+:n, m) \
00123 num_threads (8) schedule (static, 9) \
00124 collapse (6 - 2)
00125 for (I<int> i = x.end () - 1; i >= x.begin (); --i)
00126 for (int l = -131; l >= -131; l--)
00127 for (I<int> j = y.end (); j > y.begin () - 1; j -= 1)
00128 {
00129 for (I<int> k = z.end () - 4; k >= z.begin () + 3; k--)
00130 if (omp_get_num_threads () == 8
00131 && ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k)
00132 != (omp_get_thread_num () * 9 + f++)))
00133 n++;
00134 else
00135 m++;
00136 }
00137 if (n || m != 72)
00138 abort ();
00139 }
00140
00141 template <typename T>
00142 void
00143 f3 (J<int> x, J<int> y, J<int> z)
00144 {
00145 I<int> i, j, k;
00146 int l, f = 0, n = 0, m = 0;
00147 #pragma omp parallel shared (i, j, k, l) firstprivate (f) \
00148 reduction (+:n, m) num_threads (8)
00149 {
00150 #pragma omp for lastprivate (i, j, k, l) schedule (static, 9) \
00151 collapse (4)
00152 for (i = x.begin (); i < x.end (); ++i)
00153 for (j = y.begin (); j <= y.end (); j += 1)
00154 for (k = z.begin () + 3; k < z.end () - 3; k++)
00155 for (l = 7; l <= 7; l++)
00156 if (omp_get_num_threads () == 8
00157 && ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13)
00158 != (omp_get_thread_num () * 9 + f++)))
00159 n++;
00160 else
00161 m++;
00162 }
00163 if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3
00164 || m != 72 || l != 8)
00165 abort ();
00166 }
00167
00168 template <typename T>
00169 void
00170 f4 (J<int> x, J<int> y, J<int> z)
00171 {
00172 int f = 0, n = 0, m = 0;
00173 #pragma omp parallel for firstprivate (f) reduction (+:n, m) \
00174 num_threads (8) schedule (static, 9) \
00175 collapse (5 - 2)
00176 for (I<int> i = x.end () - 1; i >= x.begin (); --i)
00177 {
00178 for (I<int> j = y.end (); j > y.begin () - 1; j -= 1)
00179 {
00180 for (I<int> k = z.end () - 4; k >= z.begin () + 3; k--)
00181 if (omp_get_num_threads () == 8
00182 && ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k)
00183 != (omp_get_thread_num () * 9 + f++)))
00184 n++;
00185 else
00186 m++;
00187 }
00188 }
00189 if (n || m != 72)
00190 abort ();
00191 }
00192
00193 template <typename T>
00194 void
00195 f5 (J<int> x, J<int> y, J<int> z)
00196 {
00197 I<int> i, j, k;
00198 int f = 0, n = 0, m = 0;
00199 #pragma omp parallel shared (i, j, k) firstprivate (f) \
00200 reduction (+:n, m) num_threads (8)
00201 {
00202 #pragma omp for lastprivate (i, j, k) schedule (static, 9) \
00203 collapse (3)
00204 for (i = x.begin (); i < x.end (); ++i)
00205 for (j = y.begin (); j <= y.end (); j += (T) 1)
00206 {
00207 for (k = z.begin () + 3; k < z.end () - 3; k++)
00208 if (omp_get_num_threads () == 8
00209 && ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13)
00210 != (omp_get_thread_num () * 9 + f++)))
00211 n++;
00212 else
00213 m++;
00214 }
00215 }
00216 if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3
00217 || m != 72)
00218 abort ();
00219 }
00220
00221 template <typename T>
00222 void
00223 f6 (J<int> x, J<int> y, J<int> z)
00224 {
00225 int f = 0, n = 0, m = 0;
00226 #pragma omp parallel for firstprivate (f) reduction (+:n, m) \
00227 num_threads (8) schedule (static, 9) \
00228 collapse (5 - 2)
00229 for (I<int> i = x.end () - 1; i >= x.begin (); --i)
00230 {
00231 for (I<int> j = y.end (); j > y.begin () - 1; j -= 1)
00232 {
00233 for (I<int> k = z.end () - 4; k >= z.begin () + (T) 3; k--)
00234 if (omp_get_num_threads () == 8
00235 && ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k)
00236 != (omp_get_thread_num () * 9 + f++)))
00237 n++;
00238 else
00239 m++;
00240 }
00241 }
00242 if (n || m != 72)
00243 abort ();
00244 }
00245
00246 template <typename T>
00247 void
00248 f7 (J<T> x, J<T> y, J<T> z)
00249 {
00250 I<T> i, j, k, o = y.begin ();
00251 T l, f = 0, n = 0, m = 0;
00252 #pragma omp parallel shared (i, j, k, l) firstprivate (f) \
00253 reduction (+:n, m) num_threads (8)
00254 {
00255 #pragma omp for lastprivate (i, j, k, l) schedule (static, 9) \
00256 collapse (4)
00257 for (i = x.begin (); i < x.end (); ++i)
00258 for (j = y.begin (); j <= y.end (); j += 1)
00259 for (l = *o; l <= *o; l = 1 + l)
00260 for (k = z.begin () + 3; k < z.end () - 3; k++)
00261 if (omp_get_num_threads () == 8
00262 && ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13)
00263 != (omp_get_thread_num () * 9 + f++)))
00264 n++;
00265 else
00266 m++;
00267 }
00268 if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3
00269 || m != 72 || l != *o + 1)
00270 abort ();
00271 }
00272
00273 template <typename T>
00274 void
00275 f8 (J<T> x, J<T> y, J<T> z)
00276 {
00277 T f = 0, n = 0, m = 0;
00278 #pragma omp parallel for firstprivate (f) reduction (+:n, m) \
00279 num_threads (8) schedule (static, 9) \
00280 collapse (6 - 2)
00281 for (I<T> i = x.end () - 1; i >= x.begin (); --i)
00282 for (T l = 0; l < 1; l++)
00283 for (I<T> j = y.end (); j > y.begin () - 1; j -= 1)
00284 {
00285 for (I<T> k = z.end () - 4; k >= z.begin () + 3; k--)
00286 if (omp_get_num_threads () == 8
00287 && ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k)
00288 != (omp_get_thread_num () * 9 + f++)))
00289 n++;
00290 else
00291 m++;
00292 }
00293 if (n || m != 72)
00294 abort ();
00295 }
00296
00297 template <typename S, typename T>
00298 void
00299 f9 (J<T> x, J<T> y, J<T> z)
00300 {
00301 S i, j, k, o = y.begin ();
00302 T l, f = 0, n = 0, m = 0;
00303 #pragma omp parallel shared (i, j, k, l) firstprivate (f) \
00304 reduction (+:n, m) num_threads (8)
00305 {
00306 #pragma omp for lastprivate (i, j, k, l) schedule (static, 9) \
00307 collapse (4)
00308 for (i = x.begin (); i < x.end (); ++i)
00309 for (j = y.begin (); j <= y.end (); j += 1)
00310 for (l = *o; l <= *o; l = 1 + l)
00311 for (k = z.begin () + 3; k < z.end () - 3; k++)
00312 if (omp_get_num_threads () == 8
00313 && ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13)
00314 != (omp_get_thread_num () * 9 + f++)))
00315 n++;
00316 else
00317 m++;
00318 }
00319 if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3
00320 || m != 72 || l != *o + 1)
00321 abort ();
00322 }
00323
00324 template <typename S, typename T>
00325 void
00326 f10 (J<T> x, J<T> y, J<T> z)
00327 {
00328 T f = 0, n = 0, m = 0;
00329 #pragma omp parallel for firstprivate (f) reduction (+:n, m) \
00330 num_threads (8) schedule (static, 9) \
00331 collapse (6 - 2)
00332 for (S i = x.end () - 1; i >= x.begin (); --i)
00333 for (T l = 0; l < 1; l++)
00334 for (S j = y.end (); j > y.begin () - 1; j -= 1)
00335 {
00336 for (S k = z.end () - 4; k >= z.begin () + 3; k--)
00337 if (omp_get_num_threads () == 8
00338 && ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k)
00339 != (omp_get_thread_num () * 9 + f++)))
00340 n++;
00341 else
00342 m++;
00343 }
00344 if (n || m != 72)
00345 abort ();
00346 }
00347
00348 int
00349 main ()
00350 {
00351 int a[2000];
00352 long b[2000];
00353 for (int i = 0; i < 2000; i++)
00354 {
00355 a[i] = i - 1000;
00356 b[i] = i - 1000;
00357 }
00358 J<int> x (&a[998], &a[1004]);
00359 J<int> y (&a[995], &a[997]);
00360 J<int> z (&a[1010], &a[1020]);
00361 f1 (x, y, z);
00362 f2 (x, y, z);
00363 f3 <int> (x, y, z);
00364 f4 <int> (x, y, z);
00365 f5 <int> (x, y, z);
00366 f6 <int> (x, y, z);
00367 f7 <int> (x, y, z);
00368 f8 <int> (x, y, z);
00369 f9 <I<int>, int> (x, y, z);
00370 f10 <I<int>, int> (x, y, z);
00371 }