testsuite/libgomp.c++/for-5.C

Go to the documentation of this file.
00001 // { dg-do run }
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 () { p = (T *) 0; }
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 I<int>
00101 f1 (const I<int> &x, const I<int> &y)
00102 {
00103   I<int> i;
00104 #pragma omp parallel shared (i)
00105   {
00106   #pragma omp for lastprivate (i) schedule(runtime)
00107     for (i = x; i < y - 1; ++i)
00108       baz (i);
00109   #pragma omp single
00110     i += 3;
00111   }
00112   return I<int> (i);
00113 }
00114 
00115 I<int>
00116 f2 (const I<int> &x, const I<int> &y)
00117 {
00118   I<int> i;
00119 #pragma omp parallel for lastprivate (i)
00120   for (i = x; i < y - 1; i = 1 - 6 + 7 + i)
00121     baz (i);
00122   return I<int> (i);
00123 }
00124 
00125 template <typename T>
00126 I<int>
00127 f3 (const I<int> &x, const I<int> &y)
00128 {
00129   I<int> i;
00130 #pragma omp parallel
00131   #pragma omp for lastprivate (i)
00132     for (i = x + 1000 - 64; i <= y - 10; i++)
00133       baz (i);
00134   return i;
00135 }
00136 
00137 template <typename T>
00138 I<int>
00139 f4 (const I<int> &x, const I<int> &y)
00140 {
00141   I<int> i;
00142 #pragma omp parallel for lastprivate (i)
00143   for (i = x + 2000 - 64; i > y + 10; --i)
00144     baz (i);
00145   return I<int> (i);
00146 }
00147 
00148 template <typename T>
00149 I<int>
00150 f5 (const I<int> &x, const I<int> &y)
00151 {
00152   I<int> i;
00153 #pragma omp parallel for lastprivate (i)
00154   for (i = x; i > y + T (6); i--)
00155     baz (i);
00156   return i;
00157 }
00158 
00159 template <typename T>
00160 I<int>
00161 f6 (const I<int> &x, const I<int> &y)
00162 {
00163   I<int> i;
00164 #pragma omp parallel for lastprivate (i)
00165   for (i = x - T (7); i > y; i -= T (2))
00166     baz (i);
00167   return I<int> (i);
00168 }
00169 
00170 template <int N>
00171 I<int>
00172 f7 (I<int> i, const I<int> &x, const I<int> &y)
00173 {
00174 #pragma omp parallel for lastprivate (i)
00175   for (i = x - 10; i <= y + 10; i += N)
00176     baz (i);
00177   return I<int> (i);
00178 }
00179 
00180 template <int N>
00181 I<int>
00182 f8 (J<int> j)
00183 {
00184   I<int> i;
00185 #pragma omp parallel shared (i)
00186   #pragma omp for lastprivate (i)
00187     for (i = j.begin (); i <= j.end () + N; i += 2)
00188       baz (i);
00189   return i;
00190 }
00191 
00192 I<int> i9;
00193 
00194 template <long N>
00195 I<int> &
00196 f9 (J<int> j)
00197 {
00198 #pragma omp parallel for lastprivate (i9)
00199   for (i9 = j.begin () + N; i9 <= j.end () - N; i9 = i9 - N)
00200     baz (i9);
00201   return i9;
00202 }
00203 
00204 template <typename T, int N>
00205 I<T>
00206 f10 (const I<T> &x, const I<T> &y)
00207 {
00208   I<T> i;
00209 #pragma omp parallel for lastprivate (i)
00210   for (i = x; i > y; i = i + N)
00211     baz (i);
00212   return i;
00213 }
00214 
00215 template <typename T, typename U>
00216 T
00217 f11 (T i, const T &x, const T &y)
00218 {
00219 #pragma omp parallel
00220   #pragma omp for lastprivate (i)
00221   for (i = x + U (2); i <= y + U (1); i = U (2) + U (3) + i)
00222     baz (i);
00223   return T (i);
00224 }
00225 
00226 template <typename T>
00227 T
00228 f12 (const T &x, const T &y)
00229 {
00230   T i;
00231 #pragma omp parallel for lastprivate (i)
00232   for (i = x; i > y; --i)
00233     baz (i);
00234   return i;
00235 }
00236 
00237 #define check(expr) \
00238   for (int i = 0; i < 2000; i++)            \
00239     if (expr)                       \
00240       {                         \
00241     if (results[i] != 1)                \
00242       abort ();                 \
00243     results[i] = 0;                 \
00244       }                         \
00245     else if (results[i])                \
00246       abort ()
00247 
00248 int
00249 main ()
00250 {
00251   int a[2000];
00252   long b[2000];
00253   for (int i = 0; i < 2000; i++)
00254     {
00255       a[i] = i;
00256       b[i] = i;
00257     }
00258   if (*f1 (&a[10], &a[1873]) != 1875)
00259     abort ();
00260   check (i >= 10 && i < 1872);
00261   if (*f2 (&a[0], &a[1998]) != 1998)
00262     abort ();
00263   check (i < 1997 && (i & 1) == 0);
00264   if (*f3<int> (&a[10], &a[1971]) != 1962)
00265     abort ();
00266   check (i >= 946 && i <= 1961);
00267   if (*f4<int> (&a[0], &a[30]) != 40)
00268     abort ();
00269   check (i > 40 && i <= 2000 - 64);
00270   if (*f5<short> (&a[1931], &a[17]) != 23)
00271     abort ();
00272   check (i > 23 && i <= 1931);
00273   if (*f6<long> (&a[1931], &a[17]) != 16)
00274     abort ();
00275   check (i > 17 && i <= 1924 && (i & 1) == 0);
00276   if (*f7<6> (I<int> (), &a[12], &a[1800]) != 1814)
00277     abort ();
00278   check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0);
00279   if (*f8<121> (J<int> (&a[14], &a[1803])) != 1926)
00280     abort ();
00281   check (i >= 14 && i <= 1924 && (i & 1) == 0);
00282   if (*f9<-3L> (J<int> (&a[27], &a[1761])) != 1767)
00283     abort ();
00284   check (i >= 24 && i <= 1764 && (i % 3) == 0);
00285   if (*f10<int, -7> (&a[1939], &a[17]) != 14)
00286     abort ();
00287   check (i >= 21 && i <= 1939 && i % 7 == 0);
00288   if (*f11<I<int>, short> (I<int> (), &a[71], &a[1941]) != 1943)
00289     abort ();
00290   check (i >= 73 && i <= 1938 && (i - 73) % 5 == 0);
00291   if (*f12<I<int> > (&a[1761], &a[37]) != 37)
00292     abort ();
00293   check (i > 37 && i <= 1761);
00294   if (*f10<long, -7> (&b[1939], &b[17]) != 14)
00295     abort ();
00296   check (i >= 21 && i <= 1939 && i % 7 == 0);
00297   if (*f11<I<long>, short> (I<long> (), &b[71], &b[1941]) != 1943)
00298     abort ();
00299   check (i >= 73 && i <= 1938 && (i - 73) % 5 == 0);
00300   if (*f12<I<long> > (&b[1761], &b[37]) != 37)
00301     abort ();
00302   check (i > 37 && i <= 1761);
00303 }

Generated on Fri Apr 5 05:38:10 2013 for Libgomp by  doxygen 1.4.7