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

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

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