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