diff options
Diffstat (limited to 'libgomp/testsuite/libgomp.c++')
39 files changed, 5179 insertions, 2 deletions
diff --git a/libgomp/testsuite/libgomp.c++/ctor-13.C b/libgomp/testsuite/libgomp.c++/ctor-13.C new file mode 100644 index 0000000..8c7a09f --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/ctor-13.C @@ -0,0 +1,242 @@ +// { dg-do run } + +#include <omp.h> +#include <assert.h> + +struct B +{ + static int ic, dc, xc, ac, cc; + + B(); + B(const B &); + ~B(); + B& operator=(const B &); + void doit(); + static void clear(); +}; + +int B::ic; +int B::dc; +int B::xc; +int B::cc; +int B::ac; + +B::B() +{ + #pragma omp atomic + ic++; +} + +B::~B() +{ + #pragma omp atomic + dc++; +} + +B::B(const B &) +{ + #pragma omp atomic + cc++; +} + +B& B::operator=(const B &) +{ + #pragma omp atomic + ac++; + return *this; +} + +void B::doit() +{ + #pragma omp atomic + xc++; +} + +void B::clear() +{ + ic = 0; + dc = 0; + cc = 0; + ac = 0; + xc = 0; +} + +static int n; + +void f1(B &a) +{ + B b; + B &c = b; + #pragma omp parallel default(none) private(a, c) shared (n) + { + #pragma omp master + n = omp_get_num_threads (); + a.doit(); + c.doit(); + } +} + +void f2(B &a) +{ + B b; + B &c = b; + #pragma omp parallel default(none) firstprivate(a, c) shared(n) + { + #pragma omp master + n = omp_get_num_threads (); + a.doit(); + c.doit(); + } +} + +void f3(B &a) +{ + B b; + B &c = b; + #pragma omp parallel default(none) shared(n, a, c) + { + #pragma omp master + n = omp_get_num_threads (); + #pragma omp for lastprivate (a, c) + for (int i = 0; i < omp_get_num_threads (); i++) + { + a.doit(); + c.doit(); + } + } +} + +void f4() +{ + B b; + B &c = b; + #pragma omp parallel default(none) private (c) shared (n) + { + B d; + B &e = d; + #pragma omp single copyprivate (c, e) + { + c.doit(); + e.doit(); + } + c.doit(); + e.doit(); + } +} + +void f5(B (&a)[2]) +{ + B b[2]; + B (&c)[2] = b; + #pragma omp parallel default(none) private(a, c) shared (n) + { + #pragma omp master + n = omp_get_num_threads (); + a[0].doit(); + a[1].doit(); + c[0].doit(); + c[1].doit(); + } +} + +void f6(B (&a)[2]) +{ + B b[2]; + B (&c)[2] = b; + #pragma omp parallel default(none) firstprivate(a, c) shared (n) + { + #pragma omp master + n = omp_get_num_threads (); + a[0].doit(); + a[1].doit(); + c[0].doit(); + c[1].doit(); + } +} + +void f7(B (&a)[2]) +{ + B b[2]; + B (&c)[2] = b; + #pragma omp parallel default(none) shared(n, a, c) + { + #pragma omp master + n = omp_get_num_threads (); + #pragma omp for lastprivate (a, c) + for (int i = 0; i < omp_get_num_threads (); i++) + { + a[0].doit(); + a[1].doit(); + c[0].doit(); + c[1].doit(); + } + } +} + +void f8() +{ + B b[2]; + B (&c)[2] = b; + #pragma omp parallel default(none) private (c) shared (n) + { + B d[2]; + B (&e)[2] = d; + #pragma omp single copyprivate (c, e) + { + c[0].doit(); + c[1].doit(); + e[0].doit(); + e[1].doit(); + } + c[0].doit(); + c[1].doit(); + e[0].doit(); + e[1].doit(); + } +} + +int main() +{ + { + B a; + f1(a); + } + assert (B::xc == 2*n && B::ic == 2*n+2 && B::dc == 2*n+2 && B::ac == 0 && B::cc == 0); + B::clear(); + { + B a; + f2(a); + } + assert (B::xc == 2*n && B::ic == 2 && B::dc == 2*n+2 && B::ac == 0 && B::cc == 2*n); + B::clear(); + { + B a; + f3(a); + } + assert (B::xc == 2*n && B::ic == 2*n+2 && B::dc == 2*n+2 && B::ac == 2 && B::cc == 0); + B::clear(); + f4(); + assert (B::xc == 2*n+2 && B::ic == 2*n+1 && B::dc == 2*n+1 && B::ac == 2*n-2 && B::cc == 0); + B::clear(); + { + B a[2]; + f5(a); + } + assert (B::xc == 4*n && B::ic == 4*n+4 && B::dc == 4*n+4 && B::ac == 0 && B::cc == 0); + B::clear(); + { + B a[2]; + f6(a); + } + assert (B::xc == 4*n && B::ic == 4 && B::dc == 4*n+4 && B::ac == 0 && B::cc == 4*n); + B::clear(); + { + B a[2]; + f7(a); + } + assert (B::xc == 4*n && B::ic == 4*n+4 && B::dc == 4*n+4 && B::ac == 4 && B::cc == 0); + B::clear(); + f8(); + assert (B::xc == 4*n+4 && B::ic == 4*n+2 && B::dc == 4*n+2 && B::ac == 4*n-4 && B::cc == 0); + return 0; +} diff --git a/libgomp/testsuite/libgomp.c++/doacross-1.C b/libgomp/testsuite/libgomp.c++/doacross-1.C new file mode 100644 index 0000000..bc53ee6 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/doacross-1.C @@ -0,0 +1,294 @@ +// { dg-do run } + +typedef __PTRDIFF_TYPE__ ptrdiff_t; +extern "C" void abort (); + +template <typename T> +class I +{ +public: + typedef ptrdiff_t difference_type; + I (); + ~I (); + I (T *); + I (const I &); + T &operator * (); + T *operator -> (); + T &operator [] (const difference_type &) const; + I &operator = (const I &); + I &operator ++ (); + I operator ++ (int); + I &operator -- (); + I operator -- (int); + I &operator += (const difference_type &); + I &operator -= (const difference_type &); + I operator + (const difference_type &) const; + I operator - (const difference_type &) const; + template <typename S> friend bool operator == (I<S> &, I<S> &); + template <typename S> friend bool operator == (const I<S> &, const I<S> &); + template <typename S> friend bool operator < (I<S> &, I<S> &); + template <typename S> friend bool operator < (const I<S> &, const I<S> &); + template <typename S> friend bool operator <= (I<S> &, I<S> &); + template <typename S> friend bool operator <= (const I<S> &, const I<S> &); + template <typename S> friend bool operator > (I<S> &, I<S> &); + template <typename S> friend bool operator > (const I<S> &, const I<S> &); + template <typename S> friend bool operator >= (I<S> &, I<S> &); + template <typename S> friend bool operator >= (const I<S> &, const I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &); + template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &); +private: + T *p; +}; +template <typename T> I<T>::I () : p (0) {} +template <typename T> I<T>::~I () {} +template <typename T> I<T>::I (T *x) : p (x) {} +template <typename T> I<T>::I (const I &x) : p (x.p) {} +template <typename T> T &I<T>::operator * () { return *p; } +template <typename T> T *I<T>::operator -> () { return p; } +template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; } +template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; } +template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; } +template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); } +template <typename T> I<T> &I<T>::operator -- () { --p; return *this; } +template <typename T> I<T> I<T>::operator -- (int) { return I (p--); } +template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; } +template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; } +template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); } +template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); } +template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; } +template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; } +template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); } +template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); } +template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; } +template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; } +template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; } +template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; } +template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; } +template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; } +template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; } +template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; } +template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); } + +int results[2048]; + +template <typename T> +void +baz (I<T> &i, I<T> &j, I<T> &k, T &l) +{ + if (*i < 0 || *i >= 16) + abort (); + if (*j < 0 || *j >= 16) + abort (); + if (*k < 0 || *k >= 16) + abort (); + if (l < 0 || l >= 16) + abort (); + #pragma omp atomic + results[512 * *i + 64 * *j + 8 * *k + l]++; +} + +template <typename T> +void +baz (T &i, T &j, T &k, T &l) +{ + if (i < 0 || i >= 16) + abort (); + if (j < 0 || j >= 16) + abort (); + if (k < 0 || k >= 16) + abort (); + if (l < 0 || l >= 16) + abort (); + #pragma omp atomic + results[512 * i + 64 * j + 8 * k + l]++; +} + +void +f1 (const I<int> &a, const I<int> &b, const I<int> &c, const I<int> &d, + const I<int> &e, const I<int> &f, int g, int h, + I<int> &r1, I<int> &r2, I<int> &r3) +{ + I<int> i, j, k; + int l; +#pragma omp parallel for ordered(4) lastprivate (i, j, k) schedule(static, 1) + for (i = a; i <= b; i++) + for (j = c; j < d; j++) + for (k = e; k < f; k++) + for (l = g; l < h; l++) + { + #pragma omp ordered depend(sink: i - 1, j, k + 1, l - 2) + baz (i, j, k, l); + if (i > a && k < f - 1 && l > g + 1) + { + int m; + #pragma omp atomic read + m = results[512 * *(i - 1) + 64 * *j + 8 * *(k + 1) + l - 2]; + if (m == 0) + abort (); + } + #pragma omp ordered depend(source) + } + r1 = i; + r2 = j; + r3 = k; +} + +void +f2 (int a, int b, int c, int d, int e, int f, int g, int h, int &r1, int &r2, int &r3) +{ + int i, j, k, l; +#pragma omp parallel for collapse (1) ordered(4) lastprivate (i, j, k) schedule(static, 2) + for (i = a; i <= b; i++) + for (j = c; j < d; j++) + for (k = e; k < f; k++) + for (l = g; l < h; l++) + { + #pragma omp ordered depend(sink: i - 1, j, k + 1, l - 2) + baz (i, j, k, l); + if (i > a && k < f - 1 && l > g + 1) + { + int m; + #pragma omp atomic read + m = results[512 * (i - 1) + 64 * j + 8 * (k + 1) + l - 2]; + if (m == 0) + abort (); + } + #pragma omp ordered depend(source) + } + r1 = i; + r2 = j; + r3 = k; +} + +void +f3 (const I<int> &a, const I<int> &b, const I<int> &c, const I<int> &d, + const I<int> &e, const I<int> &f, int g, int h, + I<int> &r1, I<int> &r2, I<int> &r3) +{ + I<int> i, j, k; + int l; +#pragma omp parallel for collapse (2) ordered(4) lastprivate (i, j, k) schedule(static, 1) + for (i = a; i <= b; i++) + for (j = c; j < d; j++) + for (k = e; k < f; k++) + for (l = g; l < h; l++) + { + #pragma omp ordered depend(sink: i - 1, j, k + 1, l - 2) + baz (i, j, k, l); + if (i > a && k < f - 1 && l > g + 1) + { + int m; + #pragma omp atomic read + m = results[512 * *(i - 1) + 64 * *j + 8 * *(k + 1) + l - 2]; + if (m == 0) + abort (); + } + #pragma omp ordered depend(source) + } + r1 = i; + r2 = j; + r3 = k; +} + +void +f4 (int a, int b, int c, int d, int e, int f, int g, int h, int &r1, int &r2, int &r3) +{ + int i, j, k, l; +#pragma omp parallel for collapse (2) ordered(4) lastprivate (i, j, k) schedule(static, 2) + for (i = a; i <= b; i++) + for (j = c; j < d; j++) + for (k = e; k < f; k++) + for (l = g; l < h; l++) + { + #pragma omp ordered depend(sink: i - 1, j, k + 1, l - 2) + baz (i, j, k, l); + if (i > a && k < f - 1 && l > g + 1) + { + int m; + #pragma omp atomic read + m = results[512 * (i - 1) + 64 * j + 8 * (k + 1) + l - 2]; + if (m == 0) + abort (); + } + #pragma omp ordered depend(source) + } + r1 = i; + r2 = j; + r3 = k; +} + +#define check(expr) \ + for (int i = 0; i < 2048; i++) \ + if (expr) \ + { \ + if (results[i] != 1) \ + abort (); \ + results[i] = 0; \ + } \ + else if (results[i]) \ + abort () + +int +main () +{ + int a[16], s1, s2, s3; + I<int> r1, r2, r3; + for (int i = 0; i < 16; i++) + a[i] = i; + r1 = &a[15]; r2 = &a[15]; r3 = &a[15]; + f1 (&a[1], &a[3], &a[2], &a[5], &a[1], &a[3], 0, 5, r1, r2, r3); + if (*r1 != 4 || *r2 != 5 || *r3 != 3) + abort (); + check ((i / 512) - 1U < 3U && ((i / 64) & 7) - 2U < 3U && ((i / 8) & 7) - 1U < 2U && (i & 7) < 5); + r1 = &a[15]; r2 = &a[15]; r3 = &a[15]; + f1 (&a[1], &a[3], &a[1], &a[4], &a[1], &a[5], 1, 0, r1, r2, r3); + if (*r1 != 4 || *r2 != 4 || *r3 != 5) + abort (); + r1 = &a[15]; r2 = &a[15]; r3 = &a[15]; + f1 (&a[1], &a[3], &a[1], &a[9], &a[7], &a[2], 0, 7, r1, r2, r3); + if (*r1 != 4 || *r2 != 9 || *r3 != 7) + abort (); + s1 = 15; s2 = 15; s3 = 15; + f2 (1, 3, 2, 5, 1, 3, 0, 5, s1, s2, s3); + if (s1 != 4 || s2 != 5 || s3 != 3) + abort (); + check ((i / 512) - 1U < 3U && ((i / 64) & 7) - 2U < 3U && ((i / 8) & 7) - 1U < 2U && (i & 7) < 5); + s1 = 15; s2 = 15; s3 = 15; + f2 (1, 3, 1, 4, 1, 5, 1, 0, s1, s2, s3); + if (s1 != 4 || s2 != 4 || s3 != 5) + abort (); + s1 = 15; s2 = 15; s3 = 15; + f2 (1, 3, 1, 9, 7, 2, 0, 7, s1, s2, s3); + if (s1 != 4 || s2 != 9 || s3 != 7) + abort (); + r1 = &a[15]; r2 = &a[15]; r3 = &a[15]; + f3 (&a[1], &a[3], &a[2], &a[5], &a[1], &a[3], 0, 5, r1, r2, r3); + if (*r1 != 4 || *r2 != 5 || *r3 != 3) + abort (); + check ((i / 512) - 1U < 3U && ((i / 64) & 7) - 2U < 3U && ((i / 8) & 7) - 1U < 2U && (i & 7) < 5); + r1 = &a[15]; r2 = &a[15]; r3 = &a[15]; + f3 (&a[1], &a[3], &a[1], &a[4], &a[1], &a[5], 1, 0, r1, r2, r3); + if (*r1 != 4 || *r2 != 4 || *r3 != 5) + abort (); + r1 = &a[15]; r2 = &a[15]; r3 = &a[15]; + f3 (&a[1], &a[3], &a[1], &a[9], &a[7], &a[2], 0, 7, r1, r2, r3); + if (*r1 != 4 || *r2 != 9 || *r3 != 7) + abort (); + s1 = 15; s2 = 15; s3 = 15; + f4 (1, 3, 2, 5, 1, 3, 0, 5, s1, s2, s3); + if (s1 != 4 || s2 != 5 || s3 != 3) + abort (); + check ((i / 512) - 1U < 3U && ((i / 64) & 7) - 2U < 3U && ((i / 8) & 7) - 1U < 2U && (i & 7) < 5); + s1 = 15; s2 = 15; s3 = 15; + f4 (1, 3, 1, 4, 1, 5, 1, 0, s1, s2, s3); + if (s1 != 4 || s2 != 4 || s3 != 5) + abort (); + s1 = 15; s2 = 15; s3 = 15; + f4 (1, 3, 1, 9, 7, 2, 0, 7, s1, s2, s3); + if (s1 != 4 || s2 != 9 || s3 != 7) + abort (); + return 0; +} diff --git a/libgomp/testsuite/libgomp.c++/examples-4/declare_target-2.C b/libgomp/testsuite/libgomp.c++/examples-4/declare_target-2.C index 75276e7..6d5b5e4 100644 --- a/libgomp/testsuite/libgomp.c++/examples-4/declare_target-2.C +++ b/libgomp/testsuite/libgomp.c++/examples-4/declare_target-2.C @@ -1,5 +1,5 @@ // { dg-do run } -// { dg-require-effective-target offload_device } +// { dg-require-effective-target offload_device_nonshared_as } #include <stdlib.h> diff --git a/libgomp/testsuite/libgomp.c++/for-12.C b/libgomp/testsuite/libgomp.c++/for-12.C new file mode 100644 index 0000000..ea32192 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/for-12.C @@ -0,0 +1,42 @@ +/* { dg-options "-fopenmp" } */ + +extern "C" void abort (void); + +#define M(x, y, z) O(x, y, z) +#define O(x, y, z) x ## _ ## y ## _ ## z + +#define F taskloop +#define G taskloop +#define S +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F taskloop simd +#define G taskloop_simd +#define S +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +int +main () +{ + int err = 0; + #pragma omp parallel reduction(|:err) + #pragma omp single + { + if (test_taskloop_normal () + || test_taskloop_simd_normal ()) + err = 1; + } + if (err) + abort (); + return 0; +} diff --git a/libgomp/testsuite/libgomp.c++/for-13.C b/libgomp/testsuite/libgomp.c++/for-13.C new file mode 100644 index 0000000..ac1601a --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/for-13.C @@ -0,0 +1,151 @@ +extern "C" void abort (); + +#define M(x, y, z) O(x, y, z) +#define O(x, y, z) x ## _ ## y ## _ ## z + +#pragma omp declare target + +#define F for +#define G f +#define S +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#pragma omp end declare target + +#undef OMPFROM +#undef OMPTO +#define DO_PRAGMA(x) _Pragma (#x) +#define OMPFROM(v) DO_PRAGMA (omp target update from(v)) +#define OMPTO(v) DO_PRAGMA (omp target update to(v)) + +#define F target parallel for +#define G tpf +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F target simd +#define G t_simd +#define S +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F target parallel for simd +#define G tpf_simd +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F target teams distribute +#define G ttd +#define S +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F target teams distribute +#define G ttd_ds128 +#define S dist_schedule(static, 128) +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F target teams distribute simd +#define G ttds +#define S +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F target teams distribute simd +#define G ttds_ds128 +#define S dist_schedule(static, 128) +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F target teams distribute parallel for +#define G ttdpf +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F target teams distribute parallel for dist_schedule(static, 128) +#define G ttdpf_ds128 +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F target teams distribute parallel for simd +#define G ttdpfs +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F target teams distribute parallel for simd dist_schedule(static, 128) +#define G ttdpfs_ds128 +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +int +main () +{ + if (test_tpf_static () + || test_tpf_static32 () + || test_tpf_auto () + || test_tpf_guided32 () + || test_tpf_runtime () + || test_t_simd_normal () + || test_tpf_simd_static () + || test_tpf_simd_static32 () + || test_tpf_simd_auto () + || test_tpf_simd_guided32 () + || test_tpf_simd_runtime () + || test_ttd_normal () + || test_ttd_ds128_normal () + || test_ttds_normal () + || test_ttds_ds128_normal () + || test_ttdpf_static () + || test_ttdpf_static32 () + || test_ttdpf_auto () + || test_ttdpf_guided32 () + || test_ttdpf_runtime () + || test_ttdpf_ds128_static () + || test_ttdpf_ds128_static32 () + || test_ttdpf_ds128_auto () + || test_ttdpf_ds128_guided32 () + || test_ttdpf_ds128_runtime () + || test_ttdpfs_static () + || test_ttdpfs_static32 () + || test_ttdpfs_auto () + || test_ttdpfs_guided32 () + || test_ttdpfs_runtime () + || test_ttdpfs_ds128_static () + || test_ttdpfs_ds128_static32 () + || test_ttdpfs_ds128_auto () + || test_ttdpfs_ds128_guided32 () + || test_ttdpfs_ds128_runtime ()) + abort (); +} diff --git a/libgomp/testsuite/libgomp.c++/for-14.C b/libgomp/testsuite/libgomp.c++/for-14.C new file mode 100644 index 0000000..7738473 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/for-14.C @@ -0,0 +1,120 @@ +extern "C" void abort (); + +#define M(x, y, z) O(x, y, z) +#define O(x, y, z) x ## _ ## y ## _ ## z + +#pragma omp declare target + +#define F for +#define G f +#define S +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#pragma omp end declare target + +#undef OMPTGT +#undef OMPFROM +#undef OMPTO +#define DO_PRAGMA(x) _Pragma (#x) +#define OMPTGT DO_PRAGMA (omp target) +#define OMPFROM(v) DO_PRAGMA (omp target update from(v)) +#define OMPTO(v) DO_PRAGMA (omp target update to(v)) + +#define F teams distribute +#define G td +#define S +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F teams distribute +#define G td_ds128 +#define S dist_schedule(static, 128) +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F teams distribute simd +#define G tds +#define S +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F teams distribute simd +#define G tds_ds128 +#define S dist_schedule(static, 128) +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F teams distribute parallel for +#define G tdpf +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F teams distribute parallel for dist_schedule(static, 128) +#define G tdpf_ds128 +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F teams distribute parallel for simd +#define G tdpfs +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F teams distribute parallel for simd dist_schedule(static, 128) +#define G tdpfs_ds128 +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +int +main () +{ + if (test_td_normal () + || test_td_ds128_normal () + || test_tds_normal () + || test_tds_ds128_normal () + || test_tdpf_static () + || test_tdpf_static32 () + || test_tdpf_auto () + || test_tdpf_guided32 () + || test_tdpf_runtime () + || test_tdpf_ds128_static () + || test_tdpf_ds128_static32 () + || test_tdpf_ds128_auto () + || test_tdpf_ds128_guided32 () + || test_tdpf_ds128_runtime () + || test_tdpfs_static () + || test_tdpfs_static32 () + || test_tdpfs_auto () + || test_tdpfs_guided32 () + || test_tdpfs_runtime () + || test_tdpfs_ds128_static () + || test_tdpfs_ds128_static32 () + || test_tdpfs_ds128_auto () + || test_tdpfs_ds128_guided32 () + || test_tdpfs_ds128_runtime ()) + abort (); +} diff --git a/libgomp/testsuite/libgomp.c++/linear-1.C b/libgomp/testsuite/libgomp.c++/linear-1.C new file mode 100644 index 0000000..1dd1ffc --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/linear-1.C @@ -0,0 +1,268 @@ +int a[256]; + +__attribute__((noinline, noclone)) int +f1 (int i) +{ + #pragma omp parallel for linear (i: 4) + for (int j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) short int & +f2 (short int &i, char k) +{ + #pragma omp parallel for linear (i: k + 1) + for (long j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +template <typename T> +__attribute__((noinline, noclone)) T +f3 (T i, T k) +{ + #pragma omp parallel for linear (i: k) + for (short j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +template <typename T> +__attribute__((noinline, noclone)) T & +f4 (T &i) +{ + #pragma omp parallel for linear (i: 4) schedule(static, 3) + for (int j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) short int +f5 (short int i, char &k) +{ + #pragma omp parallel for linear (i: k + 1) schedule(static, 5) + for (long j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +template <int N> +__attribute__((noinline, noclone)) long long int +f6 (long long int i, long long int k) +{ + #pragma omp parallel for linear (i: k) schedule(static, 7) + for (short j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) int +f7 (int &i) +{ + #pragma omp parallel for linear (i: 4) schedule(dynamic, 3) + for (int j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) short int +f8 (short int i, char k) +{ + #pragma omp parallel for linear (i: k + 1) schedule(dynamic, 5) + for (long j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) long long int +f9 (long long int i, long long int k) +{ + #pragma omp parallel for linear (i: k) schedule(dynamic, 7) + for (short j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +template <typename T> +__attribute__((noinline, noclone)) T & +f10 (T &i, long &step) +{ + #pragma omp parallel for linear (i: 4) + for (int j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) short int +f11 (short int i, char k, char step) +{ + #pragma omp parallel for linear (i: k + 1) + for (long j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) long long int +f12 (long long int i, long long int k, int step) +{ + #pragma omp parallel for linear (i: k) + for (short j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) int +f13 (int &i, long long int step) +{ + #pragma omp parallel for linear (i: 4) schedule(static, 3) + for (int j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) short int +f14 (short int &i, char &k, int &step) +{ + #pragma omp parallel for linear (i: k + 1) schedule(static, 5) + for (long j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +template <int N> +__attribute__((noinline, noclone)) long long int +f15 (long long int i, long long int k, long int step) +{ + #pragma omp parallel for linear (i: k) schedule(static, 7) + for (short j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) int +f16 (int i, long long int step) +{ + #pragma omp parallel for linear (i: 4) schedule(dynamic, 3) + for (int j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) short int +f17 (short int i, char k, int step) +{ + #pragma omp parallel for linear (i: k + 1) schedule(dynamic, 5) + for (long j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +template <typename T> +__attribute__((noinline, noclone)) T +f18 (T i, T k, long int step) +{ + #pragma omp parallel for linear (i: k) schedule(dynamic, 7) + for (short j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +int +main () +{ +#define TEST(x) \ + if (x != 8 + 48 * 4) \ + __builtin_abort (); \ + for (int i = 0; i < 256; i++) \ + if (a[i] != (((i & 3) == 0 && i >= 8 \ + && i < 8 + 48 * 4) \ + ? ((i - 8) / 4) + 16 : 0)) \ + __builtin_abort (); \ + __builtin_memset (a, 0, sizeof (a)) + TEST (f1 (8)); + short int vs = 8; + TEST (f2 (vs, 3)); + TEST (f3 (8LL, 4LL)); + int vi = 8; + TEST (f4 (vi)); + char vk = 3; + TEST (f5 (8, vk)); + TEST (f6<7> (8LL, 4LL)); + vi = 8; + TEST (f7 (vi)); + TEST (f8 (8, 3)); + TEST (f9 (8LL, 4LL)); + vi = 8; + long vl = 2; + TEST (f10 (vi, vl)); + TEST (f11 (8, 3, 2)); + TEST (f12 (8LL, 4LL, 2)); + vi = 8; + TEST (f13 (vi, 2)); + vs = 8; + vk = 3; + vi = 2; + TEST (f14 (vs, vk, vi)); + TEST (f15<9> (8LL, 4LL, 2)); + TEST (f16 (8, 2)); + TEST (f17 (8, 3, 2)); + long long int vll1 = 8LL; + long long int vll2 = 4LL; + TEST (f18<long long int &> (vll1, vll2, 2)); + return 0; +} diff --git a/libgomp/testsuite/libgomp.c++/member-1.C b/libgomp/testsuite/libgomp.c++/member-1.C new file mode 100644 index 0000000..d2d0c5b --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/member-1.C @@ -0,0 +1,206 @@ +// { dg-do run } + +#include <omp.h> + +struct R { R () {}; ~R () {}; int r; }; +struct T { T () {}; virtual ~T () {}; int t; }; +int c; +struct A : public R, virtual public T { A () : b(c) {} int a; int &b; void m1 (); }; + +void +take (int &a, int &b, int &c, int &d) +{ + asm volatile ("" : : "g" (&a), "g" (&b), "g" (&c), "g" (&d) : "memory"); +} + +void +A::m1 () +{ + #pragma omp parallel private (a, r, T::t, A::b) + { + int q = omp_get_thread_num (); + a = q; + r = 2 * q; + t = 3 * q; + b = 4 * q; + take (a, r, t, b); + #pragma omp barrier + if (A::a != q || R::r != 2 * q || T::t != 3 * q || A::b != 4 * q) + __builtin_abort (); + } + a = 7; + r = 8; + t = 9; + b = 10; + #pragma omp parallel firstprivate (A::a, R::r, t, b) + { + int q = omp_get_thread_num (); + take (A::a, R::r, T::t, A::b); + if (a != 7 || r != 8 || t != 9 || b != 10) + __builtin_abort (); + A::a = 5 * q; + R::r = 6 * q; + T::t = 7 * q; + A::b = 8 * q; + take (a, r, t, b); + #pragma omp barrier + if (a != 5 * q || r != 6 * q || t != 7 * q || b != 8 * q) + __builtin_abort (); + } + bool f = false; + a = -5; + b = -4; + r = -3; + t = -2; + int n; + #pragma omp parallel for firstprivate (a, T::t, b, f) lastprivate (A::a, r, t, n) + for (int i = 0; i < omp_get_num_threads (); i++) + { + int q = omp_get_thread_num (); + if (!f) + { + if (A::a != -5 || A::b != -4 || T::t != -2) + __builtin_abort (); + } + else if (a != q || b != 2 * q || r != 3 * q || t != 4 * q) + __builtin_abort (); + take (a, r, t, b); + A::a = q; + A::b = 2 * q; + R::r = 3 * q; + T::t = 4 * q; + n = q; + f = true; + } + if (a != n || r != 3 * n || T::t != 4 * n) + __builtin_abort (); + b = 8; + #pragma omp parallel + #pragma omp single + for (int i = 0; i < 5; i++) + #pragma omp task firstprivate (t, b, n) private (a, R::r) + { + if (t != 4 * n || b != 8) + __builtin_abort (); + a = 9; + r = 8; + t = 12; + b = 18; + take (a, r, t, b); + if (a != 9 || r != 8 || t != 12 || b != 18) + __builtin_abort (); + } + a = 1; + b = 2; + R::r = 3; + t = 4; + #pragma omp parallel private (f) + { + f = false; + #pragma omp single + #pragma omp taskloop firstprivate (r, T::t, b, f) lastprivate (a, t, b, n) + for (int i = 0; i < 30; i++) + { + int q = omp_get_thread_num (); + if (!f) + { + if (R::r != 3 || A::b != 2 || T::t != 4) + __builtin_abort (); + } + else if (a != 7 * q || b != 8 * q || r != 9 * q || t != 10 * q) + __builtin_abort (); + take (a, r, t, b); + A::a = 7 * q; + A::b = 8 * q; + R::r = 9 * q; + T::t = 10 * q; + n = q; + f = true; + } + } + if (a != 7 * n || b != 8 * n || t != 10 * n) + __builtin_abort (); + a = 1; + b = 2; + R::r = 3; + t = 4; + #pragma omp parallel private (f) + { + f = false; + #pragma omp single + #pragma omp taskloop firstprivate (r, T::t, b, A::a, f) + for (int i = 0; i < 30; i++) + { + int q = omp_get_thread_num (); + if (!f) + { + if (A::a != 1 || R::r != 3 || A::b != 2 || T::t != 4) + __builtin_abort (); + } + else if (a != 7 * q || b != 8 * q || r != 9 * q || t != 10 * q) + __builtin_abort (); + take (a, r, t, b); + A::a = 7 * q; + A::b = 8 * q; + R::r = 9 * q; + T::t = 10 * q; + f = true; + } + } + #pragma omp parallel private (f) + { + f = false; + #pragma omp single + #pragma omp taskloop lastprivate (a, t, b, n) + for (int i = 0; i < 30; i++) + { + int q = omp_get_thread_num (); + if (f && (a != 7 * q || b != 8 * q || r != 9 * q || t != 10 * q)) + __builtin_abort (); + take (a, r, t, b); + A::a = 7 * q; + A::b = 8 * q; + R::r = 9 * q; + T::t = 10 * q; + n = q; + f = true; + } + } + if (a != 7 * n || b != 8 * n || t != 10 * n) + __builtin_abort (); + #pragma omp parallel private (a, T::t, A::b, r) + { + int q = omp_get_thread_num (); + a = q; + b = 2 * q; + r = 3 * q; + t = 4 * q; + take (a, b, r, t); + #pragma omp single copyprivate (A::a, t, b, R::r) + n = q; + if (a != n || b != 2 * n || r != 3 * n || t != 4 * n) + __builtin_abort (); + } + a = 0; + b = 0; + R::r = 0; + t = 0; + #pragma omp parallel for reduction (+: A::a, t, b, R::r) + for (int i = 0; i < 30; i++) + { + a += i; + A::b += 2 * i; + r += 3 * i; + T::t += 4 * i; + take (a, b, r, t); + } + if (A::a != 435 || b != 2 * 435 || R::r != 3 * 435 || t != 4 * 435) + __builtin_abort (); +} + +int +main () +{ + A a; + a.m1 (); +} diff --git a/libgomp/testsuite/libgomp.c++/member-2.C b/libgomp/testsuite/libgomp.c++/member-2.C new file mode 100644 index 0000000..bb348d8 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/member-2.C @@ -0,0 +1,211 @@ +// { dg-do run } + +#include <omp.h> + +int c, d, e; +struct R { R () {}; ~R () {}; int r; }; +template <typename Q> +struct T { T () : t(d) {}; virtual ~T () {}; Q t; }; +template <typename Q> +struct A : public R, virtual public T<Q> { A () : b(c), a(e) {} Q a; int &b; void m1 (); }; + +void +take (int &a, int &b, int &c, int &d) +{ + asm volatile ("" : : "g" (&a), "g" (&b), "g" (&c), "g" (&d) : "memory"); +} + +template <typename Q> +void +A<Q>::m1 () +{ + #pragma omp parallel private (a, r, T<Q>::t, A::b) + { + int q = omp_get_thread_num (); + a = q; + r = 2 * q; + T<Q>::t = 3 * q; + b = 4 * q; + take (a, r, T<Q>::t, b); + #pragma omp barrier + if (A::a != q || R::r != 2 * q || T<Q>::t != 3 * q || A::b != 4 * q) + __builtin_abort (); + } + a = 7; + r = 8; + T<Q>::t = 9; + b = 10; + #pragma omp parallel firstprivate (A::a, R::r, T<Q>::t, b) + { + int q = omp_get_thread_num (); + take (A::a, R::r, T<Q>::t, A::b); + if (a != 7 || r != 8 || T<Q>::t != 9 || b != 10) + __builtin_abort (); + A::a = 5 * q; + R::r = 6 * q; + T<Q>::t = 7 * q; + A::b = 8 * q; + take (a, r, T<Q>::t, b); + #pragma omp barrier + if (a != 5 * q || r != 6 * q || T<Q>::t != 7 * q || b != 8 * q) + __builtin_abort (); + } + bool f = false; + a = -5; + b = -4; + r = -3; + T<Q>::t = -2; + int n; + #pragma omp parallel for firstprivate (a, T<Q>::t, b, f) lastprivate (A::a, r, T<Q>::t, n) + for (int i = 0; i < omp_get_num_threads (); i++) + { + int q = omp_get_thread_num (); + if (!f) + { + if (A::a != -5 || A::b != -4 || T<Q>::t != -2) + __builtin_abort (); + } + else if (a != q || b != 2 * q || r != 3 * q || T<Q>::t != 4 * q) + __builtin_abort (); + take (a, r, T<Q>::t, b); + A::a = q; + A::b = 2 * q; + R::r = 3 * q; + T<Q>::t = 4 * q; + n = q; + f = true; + } + if (a != n || r != 3 * n || T<Q>::t != 4 * n) + __builtin_abort (); + b = 8; + #pragma omp parallel + #pragma omp single + for (int i = 0; i < 5; i++) + #pragma omp task firstprivate (T<Q>::t, b, n) private (a, R::r) + { + if (T<Q>::t != 4 * n || b != 8) + __builtin_abort (); + a = 9; + r = 8; + T<Q>::t = 12; + b = 18; + take (a, r, T<Q>::t, b); + if (a != 9 || r != 8 || T<Q>::t != 12 || b != 18) + __builtin_abort (); + } + a = 1; + b = 2; + R::r = 3; + T<Q>::t = 4; + #pragma omp parallel private (f) + { + f = false; + #pragma omp single + #pragma omp taskloop firstprivate (r, T<Q>::t, b, f) lastprivate (a, T<Q>::t, b, n) + for (int i = 0; i < 30; i++) + { + int q = omp_get_thread_num (); + if (!f) + { + if (R::r != 3 || A::b != 2 || T<Q>::t != 4) + __builtin_abort (); + } + else if (a != 7 * q || b != 8 * q || r != 9 * q || T<Q>::t != 10 * q) + __builtin_abort (); + take (a, r, T<Q>::t, b); + A::a = 7 * q; + A::b = 8 * q; + R::r = 9 * q; + T<Q>::t = 10 * q; + n = q; + f = true; + } + } + if (a != 7 * n || b != 8 * n || T<Q>::t != 10 * n) + __builtin_abort (); + a = 1; + b = 2; + R::r = 3; + T<Q>::t = 4; + #pragma omp parallel private (f) + { + f = false; + #pragma omp single + #pragma omp taskloop firstprivate (r, T<Q>::t, b, A::a, f) + for (int i = 0; i < 30; i++) + { + int q = omp_get_thread_num (); + if (!f) + { + if (A::a != 1 || R::r != 3 || A::b != 2 || T<Q>::t != 4) + __builtin_abort (); + } + else if (a != 7 * q || b != 8 * q || r != 9 * q || T<Q>::t != 10 * q) + __builtin_abort (); + take (a, r, T<Q>::t, b); + A::a = 7 * q; + A::b = 8 * q; + R::r = 9 * q; + T<Q>::t = 10 * q; + f = true; + } + } + #pragma omp parallel private (f) + { + f = false; + #pragma omp single + #pragma omp taskloop lastprivate (a, T<Q>::t, b, n) + for (int i = 0; i < 30; i++) + { + int q = omp_get_thread_num (); + if (f && (a != 7 * q || b != 8 * q || r != 9 * q || T<Q>::t != 10 * q)) + __builtin_abort (); + take (a, r, T<Q>::t, b); + A::a = 7 * q; + A::b = 8 * q; + R::r = 9 * q; + T<Q>::t = 10 * q; + n = q; + f = true; + } + } + if (a != 7 * n || b != 8 * n || T<Q>::t != 10 * n) + __builtin_abort (); + #pragma omp parallel private (a, T<Q>::t, A::b, r) + { + int q = omp_get_thread_num (); + a = q; + b = 2 * q; + r = 3 * q; + T<Q>::t = 4 * q; + take (a, b, r, T<Q>::t); + #pragma omp single copyprivate (A::a, T<Q>::t, b, R::r) + n = q; + if (a != n || b != 2 * n || r != 3 * n || T<Q>::t != 4 * n) + __builtin_abort (); + } + a = 0; + b = 0; + R::r = 0; + T<Q>::t = 0; + #pragma omp parallel for reduction (+: A::a, T<Q>::t, b, R::r) + for (int i = 0; i < 30; i++) + { + a += i; + A::b += 2 * i; + r += 3 * i; + T<Q>::t += 4 * i; + take (a, b, r, T<Q>::t); + } + if (A::a != 435 || b != 2 * 435 || R::r != 3 * 435 || T<Q>::t != 4 * 435) + __builtin_abort (); +} + +int +main () +{ + A<int> a; + a.m1 (); + A<int &> b; + b.m1 (); +} diff --git a/libgomp/testsuite/libgomp.c++/member-3.C b/libgomp/testsuite/libgomp.c++/member-3.C new file mode 100644 index 0000000..50bd587 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/member-3.C @@ -0,0 +1,105 @@ +// { dg-do run } + +struct R { R () {}; ~R () {}; int r; }; +struct T { T () {}; virtual ~T () {}; int t; }; +int c; +struct A : public R, virtual public T { A () : b(c) {} int a; int &b; void m1 (); }; +int d[64]; + +void +A::m1 () +{ + r = 0; + #pragma omp parallel for private (a) reduction(|:R::r) + for (a = 0; A::a < 31; a += 2) + r |= (1 << A::a); + if (r != 0x55555555) + __builtin_abort (); + #pragma omp parallel for simd linear (R::r) + for (R::r = 0; r < 32; R::r++) + d[r + 8] |= 1; + for (int i = 0; i < 64; i++) + if (d[i] != ((i >= 8 && i < 32 + 8) ? 1 : 0)) + __builtin_abort (); + #pragma omp parallel for lastprivate (t) + for (T::t = 0; t < 32; t += 3) + d[T::t + 2] |= 2; + if (T::t != 33) + __builtin_abort (); + for (int i = 0; i < 64; i++) + if (d[i] != (((i >= 8 && i < 32 + 8) ? 1 : 0) + | ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 2 : 0))) + __builtin_abort (); + #pragma omp simd linear (t) + for (t = 0; t < 32; t++) + d[T::t + 9] |= 4; + if (t != 32) + __builtin_abort (); + for (int i = 0; i < 64; i++) + if (d[i] != (((i >= 8 && i < 32 + 8) ? 1 : 0) + | ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 2 : 0) + | ((i >= 9 && i < 32 + 9) ? 4 : 0))) + __builtin_abort (); + r = 0; + #pragma omp parallel for reduction(|:r) + for (a = 0; A::a < 31; a += 2) + r |= (1 << A::a); + if (r != 0x55555555) + __builtin_abort (); + #pragma omp parallel for simd + for (R::r = 0; r < 32; R::r += 2) + d[r + 8] |= 8; + for (int i = 0; i < 64; i++) + if (d[i] != (((i >= 8 && i < 32 + 8) ? ((i & 1) ? 1 : (8 | 1)) : 0) + | ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 2 : 0) + | ((i >= 9 && i < 32 + 9) ? 4 : 0))) + __builtin_abort (); + #pragma omp simd collapse(2) + for (T::t = 0; t < 7; t += 2) + for (a = 0; A::a < 8; a++) + d[((t << 2) | a) + 3] |= 16; + if (t != 8 || A::a != 8) + __builtin_abort (); + for (int i = 0; i < 64; i++) + if (d[i] != (((i >= 8 && i < 32 + 8) ? ((i & 1) ? 1 : (8 | 1)) : 0) + | ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 2 : 0) + | ((i >= 9 && i < 32 + 9) ? 4 : 0) + | ((i >= 3 && i < 32 + 3) ? 16 : 0))) + __builtin_abort (); + T::t = 32; + a = 16; + #pragma omp parallel + #pragma omp single + #pragma omp taskloop simd collapse(2) + for (t = 0; T::t < 7; T::t += 2) + for (A::a = 0; a < 8; A::a++) + d[((t << 2) | A::a) + 3] |= 32; + if (T::t != 8 || a != 8) + __builtin_abort (); + for (int i = 0; i < 64; i++) + if (d[i] != (((i >= 8 && i < 32 + 8) ? ((i & 1) ? 1 : (8 | 1)) : 0) + | ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 2 : 0) + | ((i >= 9 && i < 32 + 9) ? 4 : 0) + | ((i >= 3 && i < 32 + 3) ? (16 | 32) : 0))) + __builtin_abort (); + #pragma omp parallel + #pragma omp single + #pragma omp taskloop simd + for (R::r = 0; r < 31; R::r += 2) + d[r + 8] |= 64; + if (r != 32) + __builtin_abort (); + for (int i = 0; i < 64; i++) + if (d[i] != (((i >= 8 && i < 32 + 8) ? ((i & 1) ? 1 : (64 | 8 | 1)) : 0) + | ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 2 : 0) + | ((i >= 9 && i < 32 + 9) ? 4 : 0) + | ((i >= 3 && i < 32 + 3) ? (16 | 32) : 0))) + __builtin_abort (); +} + +int +main () +{ + A a; + a.m1 (); +} diff --git a/libgomp/testsuite/libgomp.c++/member-4.C b/libgomp/testsuite/libgomp.c++/member-4.C new file mode 100644 index 0000000..f76695d --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/member-4.C @@ -0,0 +1,108 @@ +// { dg-do run } + +int c, d, e; +struct R { R () {}; ~R () {}; int r; }; +template <typename Q> +struct T { T () : t(d) {}; virtual ~T () {}; Q t; }; +template <typename Q> +struct A : public R, virtual public T<Q> { A () : b(c), a(e) {} Q a; int &b; void m1 (); }; +int f[64]; + +template <typename Q> +void +A<Q>::m1 () +{ + r = 0; + #pragma omp parallel for private (a) reduction(|:R::r) + for (a = 0; A::a < 31; a += 2) + r |= (1 << A::a); + if (r != 0x55555555) + __builtin_abort (); + #pragma omp parallel for simd linear (R::r) + for (R::r = 0; r < 32; R::r++) + f[r + 8] |= 1; + for (int i = 0; i < 64; i++) + if (f[i] != ((i >= 8 && i < 32 + 8) ? 1 : 0)) + __builtin_abort (); + #pragma omp parallel for lastprivate (T<Q>::t) + for (T<Q>::t = 0; T<Q>::t < 32; T<Q>::t += 3) + f[T<Q>::t + 2] |= 2; + if (T<Q>::t != 33) + __builtin_abort (); + for (int i = 0; i < 64; i++) + if (f[i] != (((i >= 8 && i < 32 + 8) ? 1 : 0) + | ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 2 : 0))) + __builtin_abort (); + #pragma omp simd linear (T<Q>::t) + for (T<Q>::t = 0; T<Q>::t < 32; T<Q>::t++) + f[T<Q>::t + 9] |= 4; + if (T<Q>::t != 32) + __builtin_abort (); + for (int i = 0; i < 64; i++) + if (f[i] != (((i >= 8 && i < 32 + 8) ? 1 : 0) + | ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 2 : 0) + | ((i >= 9 && i < 32 + 9) ? 4 : 0))) + __builtin_abort (); + r = 0; + #pragma omp parallel for reduction(|:r) + for (a = 0; A::a < 31; a += 2) + r |= (1 << A::a); + if (r != 0x55555555) + __builtin_abort (); + #pragma omp parallel for simd + for (R::r = 0; r < 32; R::r += 2) + f[r + 8] |= 8; + for (int i = 0; i < 64; i++) + if (f[i] != (((i >= 8 && i < 32 + 8) ? ((i & 1) ? 1 : (8 | 1)) : 0) + | ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 2 : 0) + | ((i >= 9 && i < 32 + 9) ? 4 : 0))) + __builtin_abort (); + #pragma omp simd collapse(2) + for (T<Q>::t = 0; T<Q>::t < 7; T<Q>::t += 2) + for (a = 0; A::a < 8; a++) + f[((T<Q>::t << 2) | a) + 3] |= 16; + if (T<Q>::t != 8 || A::a != 8) + __builtin_abort (); + for (int i = 0; i < 64; i++) + if (f[i] != (((i >= 8 && i < 32 + 8) ? ((i & 1) ? 1 : (8 | 1)) : 0) + | ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 2 : 0) + | ((i >= 9 && i < 32 + 9) ? 4 : 0) + | ((i >= 3 && i < 32 + 3) ? 16 : 0))) + __builtin_abort (); + T<Q>::t = 32; + a = 16; + #pragma omp parallel + #pragma omp single + #pragma omp taskloop simd collapse(2) + for (T<Q>::t = 0; T<Q>::t < 7; T<Q>::t += 2) + for (A::a = 0; a < 8; A::a++) + f[((T<Q>::t << 2) | A::a) + 3] |= 32; + if (T<Q>::t != 8 || a != 8) + __builtin_abort (); + for (int i = 0; i < 64; i++) + if (f[i] != (((i >= 8 && i < 32 + 8) ? ((i & 1) ? 1 : (8 | 1)) : 0) + | ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 2 : 0) + | ((i >= 9 && i < 32 + 9) ? 4 : 0) + | ((i >= 3 && i < 32 + 3) ? (16 | 32) : 0))) + __builtin_abort (); + #pragma omp parallel + #pragma omp single + #pragma omp taskloop simd + for (R::r = 0; r < 31; R::r += 2) + f[r + 8] |= 64; + if (r != 32) + __builtin_abort (); + for (int i = 0; i < 64; i++) + if (f[i] != (((i >= 8 && i < 32 + 8) ? ((i & 1) ? 1 : (64 | 8 | 1)) : 0) + | ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 2 : 0) + | ((i >= 9 && i < 32 + 9) ? 4 : 0) + | ((i >= 3 && i < 32 + 3) ? (16 | 32) : 0))) + __builtin_abort (); +} + +int +main () +{ + A<int> a; + a.m1 (); +} diff --git a/libgomp/testsuite/libgomp.c++/member-5.C b/libgomp/testsuite/libgomp.c++/member-5.C new file mode 100644 index 0000000..d6fec7a --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/member-5.C @@ -0,0 +1,183 @@ +// { dg-do run } + +typedef __PTRDIFF_TYPE__ ptrdiff_t; + +template <typename T> +class I +{ +public: + typedef ptrdiff_t difference_type; + I (); + ~I (); + I (T *); + I (const I &); + T &operator * (); + T *operator -> (); + T &operator [] (const difference_type &) const; + I &operator = (const I &); + I &operator ++ (); + I operator ++ (int); + I &operator -- (); + I operator -- (int); + I &operator += (const difference_type &); + I &operator -= (const difference_type &); + I operator + (const difference_type &) const; + I operator - (const difference_type &) const; + template <typename S> friend bool operator == (I<S> &, I<S> &); + template <typename S> friend bool operator == (const I<S> &, const I<S> &); + template <typename S> friend bool operator < (I<S> &, I<S> &); + template <typename S> friend bool operator < (const I<S> &, const I<S> &); + template <typename S> friend bool operator <= (I<S> &, I<S> &); + template <typename S> friend bool operator <= (const I<S> &, const I<S> &); + template <typename S> friend bool operator > (I<S> &, I<S> &); + template <typename S> friend bool operator > (const I<S> &, const I<S> &); + template <typename S> friend bool operator >= (I<S> &, I<S> &); + template <typename S> friend bool operator >= (const I<S> &, const I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &); + template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &); +private: + T *p; +}; +template <typename T> I<T>::I () : p (0) {} +template <typename T> I<T>::~I () {} +template <typename T> I<T>::I (T *x) : p (x) {} +template <typename T> I<T>::I (const I &x) : p (x.p) {} +template <typename T> T &I<T>::operator * () { return *p; } +template <typename T> T *I<T>::operator -> () { return p; } +template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; } +template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; } +template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; } +template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); } +template <typename T> I<T> &I<T>::operator -- () { --p; return *this; } +template <typename T> I<T> I<T>::operator -- (int) { return I (p--); } +template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; } +template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; } +template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); } +template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); } +template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; } +template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; } +template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); } +template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); } +template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; } +template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; } +template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; } +template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; } +template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; } +template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; } +template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; } +template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; } +template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); } + +struct R { R () {}; ~R () {}; I<int> r; }; +struct T { T () {}; virtual ~T () {}; I<int> t; }; +struct A : public R, virtual public T { A () {} I<int> a; void m1 (const I<int> &, const I<int> &); }; +template <typename Q> +struct U { U () {}; virtual ~U () {}; Q t; }; +template <typename Q> +struct B : public R, virtual public U<Q> { B () {} Q a; void m2 (const Q &, const Q &, const I<int> &, const I<int> &); }; + +int d[64]; + +void +A::m1 (const I<int> &x, const I<int> &y) +{ + int w = 0; + #pragma omp parallel for private (a) reduction(|:w) + for (a = x; A::a < y - 33; a += 2) + w |= (1 << *A::a); + if (w != 0x55555555) + __builtin_abort (); + #pragma omp parallel for lastprivate (t) + for (T::t = x; t < y - 32; t += 3) + d[*T::t + 2] |= 1; + if (*T::t != 33) + __builtin_abort (); + for (int i = 0; i < 64; i++) + if (d[i] != ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 1 : 0)) + __builtin_abort (); + w = 0; + #pragma omp parallel for reduction(|:w) + for (a = x; A::a < y - 33; a += 2) + w |= (1 << *A::a); + if (w != 0x55555555) + __builtin_abort (); + #pragma omp taskloop + for (R::r = x; r < y - 32; R::r += 2) + d[*r + 8] |= 2; + for (int i = 0; i < 64; i++) + if (d[i] != (((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 1 : 0) + | ((i >= 8 && i < 32 + 8 && (i & 1) == 0) ? 2 : 0))) + __builtin_abort (); + #pragma omp taskloop collapse(2) + for (T::t = x; t < y - 57; t += 2) + for (a = x; A::a < y - 56; a++) + d[((*t << 2) | *a) + 3] |= 4; + for (int i = 0; i < 64; i++) + if (d[i] != (((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 1 : 0) + | ((i >= 8 && i < 32 + 8 && (i & 1) == 0) ? 2 : 0) + | ((i >= 3 && i < 32 + 3) ? 4 : 0))) + __builtin_abort (); +} + +template <typename Q> +void +B<Q>::m2 (const Q &u, const Q &v, const I<int> &x, const I<int> &y) +{ + int w = 0; + #pragma omp parallel for private (a) reduction(|:w) + for (a = u; B::a < v - 33; a += 2) + w |= (1 << *B::a); + if (w != 0x55555555) + __builtin_abort (); + #pragma omp parallel for lastprivate (U<Q>::t) + for (U<Q>::t = u; U<Q>::t < v - 32; U<Q>::t += 3) + d[*U<Q>::t + 2] |= 1; + if (*U<Q>::t != 33) + __builtin_abort (); + for (int i = 0; i < 64; i++) + if (d[i] != ((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 1 : 0)) + __builtin_abort (); + w = 0; + #pragma omp parallel for reduction(|:w) + for (a = u; B::a < v - 33; a += 2) + w |= (1 << *B::a); + if (w != 0x55555555) + __builtin_abort (); + #pragma omp taskloop + for (R::r = x; r < y - 32; R::r += 2) + d[*r + 8] |= 2; + for (int i = 0; i < 64; i++) + if (d[i] != (((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 1 : 0) + | ((i >= 8 && i < 32 + 8 && (i & 1) == 0) ? 2 : 0))) + __builtin_abort (); + #pragma omp taskloop collapse(2) + for (U<Q>::t = u; U<Q>::t < v - 57; U<Q>::t += 2) + for (a = u; B::a < v - 56; a++) + d[((*U<Q>::t << 2) | *a) + 3] |= 4; + for (int i = 0; i < 64; i++) + if (d[i] != (((i >= 2 && i < 32 + 2 && (i - 2) % 3 == 0) ? 1 : 0) + | ((i >= 8 && i < 32 + 8 && (i & 1) == 0) ? 2 : 0) + | ((i >= 3 && i < 32 + 3) ? 4 : 0))) + __builtin_abort (); +} + +int +main () +{ + A a; + int b[128]; + for (int i = 0; i < 128; i++) + b[i] = i - 32; + a.m1 (&b[32], &b[96]); + for (int i = 0; i < 64; i++) + d[i] = 0; + B<I<int> > c; + c.m2 (&b[32], &b[96], &b[32], &b[96]); + for (int i = 0; i < 64; i++) + d[i] = 0; + B<int *> d; + d.m2 (&b[32], &b[96], &b[32], &b[96]); +} diff --git a/libgomp/testsuite/libgomp.c++/ordered-1.C b/libgomp/testsuite/libgomp.c++/ordered-1.C new file mode 100644 index 0000000..a1bedd8 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/ordered-1.C @@ -0,0 +1 @@ +#include "../libgomp.c/ordered-4.c" diff --git a/libgomp/testsuite/libgomp.c++/reduction-10.C b/libgomp/testsuite/libgomp.c++/reduction-10.C new file mode 100644 index 0000000..2254430 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/reduction-10.C @@ -0,0 +1,201 @@ +template <typename T> +struct A +{ + A () { t = 0; } + A (T x) { t = x; } + A (const A &x) { t = x.t; } + ~A () {} + T t; +}; +template <typename T> +struct M +{ + M () { t = 1; } + M (T x) { t = x; } + M (const M &x) { t = x.t; } + ~M () {} + T t; +}; +template <typename T> +struct B +{ + B () { t = ~(T) 0; } + B (T x) { t = x; } + B (const B &x) { t = x.t; } + ~B () {} + T t; +}; +template <typename T> +void +add (T &x, T &y) +{ + x.t += y.t; +} +template <typename T> +void +zero (T &x) +{ + x.t = 0; +} +template <typename T> +void +orit (T *x, T *y) +{ + y->t |= x->t; +} +B<long> bb; +#pragma omp declare reduction(+:A<int>:omp_out.t += omp_in.t) +#pragma omp declare reduction(+:A<char>:add (omp_out, omp_in)) initializer(zero (omp_priv)) +#pragma omp declare reduction(*:M<int>:omp_out.t *= omp_in.t) initializer(omp_priv = 1) +#pragma omp declare reduction(|:A<unsigned long long>:orit (&omp_in, &omp_out)) +#pragma omp declare reduction(&:B<long>:omp_out.t = omp_out.t & omp_in.t) initializer(orit (&omp_priv, &omp_orig)) +#pragma omp declare reduction(maxb:short:omp_out = omp_in > omp_out ? omp_in : omp_out) initializer(omp_priv = -6) + +A<char> z[10]; + +template <int N> +__attribute__((noinline, noclone)) void +foo (A<int> (*&x)[3][N], M<int> *y, B<long> (&w)[1][N], int p1, long p2, long p3, int p4, + int p5, long p6, short p7) +{ + A<unsigned long long> a[p7 + 4]; + short bb[p7]; + short (&b)[p7] = bb; + for (int i = 0; i < p7; i++) + bb[i] = -6; + #pragma omp parallel for reduction(+:x[0:p1 + 1][:p2 + N - 2], z[:p3]) \ + reduction(*:y[:p4]) reduction(|:a[:p5 - N + 2]) \ + reduction(&:w[0:p6 - 3 + N][:p6]) reduction(maxb:b) + for (int i = 0; i < 128; i++) + { + x[i / 64][i % 3][(i / 4) & 1].t += i; + if ((i & 15) == 1) + y[0].t *= 3; + if ((i & 31) == N) + y[1].t *= 7; + if ((i & 63) == 3) + y[N].t *= 17; + z[i / 32].t += (i & 3); + if (i < 4) + z[i].t += i; + a[i / 32].t |= 1ULL << (i & 30); + w[0][i & 1].t &= ~(1L << (i / 17 * 3)); + if ((i % 79) > b[0]) + b[0] = i % 79; + if ((i % 13) > b[1]) + b[1] = i % 13; + if ((i % 23) > b[N]) + b[N] = i % 23; + if ((i % 85) > b[3]) + b[3] = i % 85; + if ((i % 192) > b[4]) + b[4] = i % 192; + } + for (int i = 0; i < 9; i++) + if (a[i].t != (i < 4 ? 0x55555555ULL : 0)) + __builtin_abort (); + if (bb[0] != 78 || bb[1] != 12 || bb[N] != 22 || bb[3] != 84 || bb[4] != 127) + __builtin_abort (); +} + +A<int> a3[4][3][2]; +A<int> (*p3)[3][2] = &a3[1]; +M<int> y3[5] = { 0, 1, 1, 1, 0 }; +B<long> w3[1][2]; + +template <int N> +struct S +{ + A<int> (*&x)[3][N]; + M<int> *y; + B<long> (&w)[1][N]; + A<char> z[10]; + short b[5]; + A<unsigned long long> a[9]; + S() : x(p3), y(y3+1), w(w3), z(), a(), b() {} + __attribute__((noinline, noclone)) void foo (int, long, long, int, int, long, short); +}; + +template <int N> +void +S<N>::foo (int p1, long p2, long p3, int p4, int p5, long p6, short p7) +{ + #pragma omp parallel for reduction(+:x[0:p1 + 1][:p2][0:N], z[:p3 + N - 2]) \ + reduction(*:y[:p4]) reduction(|:a[:p5]) \ + reduction(&:w[0:p6 - 3 + N][:p6]) reduction(maxb:b) + for (int i = 0; i < 128; i++) + { + x[i / 64][i % 3][(i / 4) & 1].t += i; + if ((i & 15) == 1) + y[0].t *= 3; + if ((i & 31) == N) + y[1].t *= 7; + if ((i & 63) == 3) + y[N].t *= 17; + z[i / 32].t += (i & 3); + if (i < 4) + z[i].t += i; + a[i / 32].t |= 1ULL << (i & 30); + w[0][i & 1].t &= ~(1L << (i / 17 * 3)); + if ((i % 79) > b[0]) + b[0] = i % 79; + if ((i % 13) > b[1]) + b[1] = i % 13; + if ((i % 23) > b[N]) + b[N] = i % 23; + if ((i % 85) > b[3]) + b[3] = i % 85; + if ((i % 192) > b[4]) + b[4] = i % 192; + } +} + +int +main () +{ + A<int> a[4][3][2]; + static int a2[4][3][2] = {{{ 0, 0 }, { 0, 0 }, { 0, 0 }}, + {{ 312, 381 }, { 295, 356 }, { 337, 335 }}, + {{ 1041, 975 }, { 1016, 1085 }, { 935, 1060 }}, + {{ 0, 0 }, { 0, 0 }, { 0, 0 }}}; + A<int> (*p)[3][2] = &a[1]; + M<int> y[5] = { 0, 1, 1, 1, 0 }; + int y2[5] = { 0, 6561, 2401, 289, 0 }; + char z2[10] = { 48, 49, 50, 51, 0, 0, 0, 0, 0, 0 }; + B<long> w[1][2]; + foo<2> (p, y + 1, w, 1, 3L, 4L, 3, 4, 2L, 5); + for (int i = 0; i < 4; i++) + for (int j = 0; j < 3; j++) + for (int k = 0; k < 2; k++) + if (a[i][j][k].t != a2[i][j][k]) + __builtin_abort (); + for (int i = 0; i < 5; i++) + if (y[i].t != y2[i]) + __builtin_abort (); + for (int i = 0; i < 10; i++) + if (z[i].t != z2[i]) + __builtin_abort (); + if (w[0][0].t != ~0x249249L || w[0][1].t != ~0x249249L) + __builtin_abort (); + S<2> s; + s.foo (1, 3L, 4L, 3, 4, 2L, 5); + for (int i = 0; i < 9; i++) + if (s.a[i].t != (i < 4 ? 0x55555555ULL : 0)) + __builtin_abort (); + for (int i = 0; i < 4; i++) + for (int j = 0; j < 3; j++) + for (int k = 0; k < 2; k++) + if (a3[i][j][k].t != a2[i][j][k]) + __builtin_abort (); + for (int i = 0; i < 5; i++) + if (y3[i].t != y2[i]) + __builtin_abort (); + for (int i = 0; i < 10; i++) + if (s.z[i].t != z2[i]) + __builtin_abort (); + if (w3[0][0].t != ~0x249249L || w3[0][1].t != ~0x249249L) + __builtin_abort (); + if (s.b[0] != 78 || s.b[1] != 12 || s.b[2] != 22 + || s.b[3] != 84 || s.b[4] != 127) + __builtin_abort (); +} diff --git a/libgomp/testsuite/libgomp.c++/reduction-5.C b/libgomp/testsuite/libgomp.c++/reduction-5.C new file mode 100644 index 0000000..212fd69 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/reduction-5.C @@ -0,0 +1,127 @@ +char z[10] = { 0 }; + +__attribute__((noinline, noclone)) void +foo (int (*&x)[3][2], int *y, long (&w)[1][2]) +{ + unsigned long long a[9] = {}; + short b[5] = {}; + #pragma omp parallel for reduction(+:x[0:2][:][0:2], z[:4]) \ + reduction(*:y[:3]) reduction(|:a[:4]) \ + reduction(&:w[0:][:2]) reduction(max:b) + for (int i = 0; i < 128; i++) + { + x[i / 64][i % 3][(i / 4) & 1] += i; + if ((i & 15) == 1) + y[0] *= 3; + if ((i & 31) == 2) + y[1] *= 7; + if ((i & 63) == 3) + y[2] *= 17; + z[i / 32] += (i & 3); + if (i < 4) + z[i] += i; + a[i / 32] |= 1ULL << (i & 30); + w[0][i & 1] &= ~(1L << (i / 17 * 3)); + if ((i % 79) > b[0]) + b[0] = i % 79; + if ((i % 13) > b[1]) + b[1] = i % 13; + if ((i % 23) > b[2]) + b[2] = i % 23; + if ((i % 85) > b[3]) + b[3] = i % 85; + if ((i % 192) > b[4]) + b[4] = i % 192; + } + for (int i = 0; i < 9; i++) + if (a[i] != (i < 4 ? 0x55555555ULL : 0)) + __builtin_abort (); + if (b[0] != 78 || b[1] != 12 || b[2] != 22 || b[3] != 84 || b[4] != 127) + __builtin_abort (); +} + +int a3[4][3][2]; +int (*p3)[3][2] = &a3[1]; +int y3[5] = { 0, 1, 1, 1, 0 }; +long w3[1][2] = { ~0L, ~0L }; +short bb[5]; + +struct S +{ + int (*&x)[3][2]; + int *y; + long (&w)[1][2]; + char z[10]; + short (&b)[5]; + unsigned long long a[9]; + S() : x(p3), y(y3+1), w(w3), z(), a(), b(bb) {} + __attribute__((noinline, noclone)) void foo (); +}; + +void +S::foo () +{ + #pragma omp parallel for reduction(+:x[0:2][:][0:2], z[:4]) \ + reduction(*:y[:3]) reduction(|:a[:4]) \ + reduction(&:w[0:][:2]) reduction(max:b) + for (int i = 0; i < 128; i++) + { + x[i / 64][i % 3][(i / 4) & 1] += i; + if ((i & 15) == 1) + y[0] *= 3; + if ((i & 31) == 2) + y[1] *= 7; + if ((i & 63) == 3) + y[2] *= 17; + z[i / 32] += (i & 3); + if (i < 4) + z[i] += i; + a[i / 32] |= 1ULL << (i & 30); + w[0][i & 1] &= ~(1L << (i / 17 * 3)); + if ((i % 79) > b[0]) + b[0] = i % 79; + if ((i % 13) > b[1]) + b[1] = i % 13; + if ((i % 23) > b[2]) + b[2] = i % 23; + if ((i % 85) > b[3]) + b[3] = i % 85; + if ((i % 192) > b[4]) + b[4] = i % 192; + } +} + +int +main () +{ + int a[4][3][2] = {}; + static int a2[4][3][2] = {{{ 0, 0 }, { 0, 0 }, { 0, 0 }}, + {{ 312, 381 }, { 295, 356 }, { 337, 335 }}, + {{ 1041, 975 }, { 1016, 1085 }, { 935, 1060 }}, + {{ 0, 0 }, { 0, 0 }, { 0, 0 }}}; + int (*p)[3][2] = &a[1]; + int y[5] = { 0, 1, 1, 1, 0 }; + int y2[5] = { 0, 6561, 2401, 289, 0 }; + char z2[10] = { 48, 49, 50, 51, 0, 0, 0, 0, 0, 0 }; + long w[1][2] = { ~0L, ~0L }; + foo (p, y + 1, w); + if (__builtin_memcmp (a, a2, sizeof (a)) + || __builtin_memcmp (y, y2, sizeof (y)) + || __builtin_memcmp (z, z2, sizeof (z)) + || w[0][0] != ~0x249249L + || w[0][1] != ~0x249249L) + __builtin_abort (); + S s; + s.foo (); + for (int i = 0; i < 9; i++) + if (s.a[i] != (i < 4 ? 0x55555555ULL : 0)) + __builtin_abort (); + if (__builtin_memcmp (a3, a2, sizeof (a3)) + || __builtin_memcmp (y3, y2, sizeof (y3)) + || __builtin_memcmp (s.z, z2, sizeof (s.z)) + || w3[0][0] != ~0x249249L + || w3[0][1] != ~0x249249L) + __builtin_abort (); + if (bb[0] != 78 || bb[1] != 12 || bb[2] != 22 || bb[3] != 84 || bb[4] != 127) + __builtin_abort (); +} diff --git a/libgomp/testsuite/libgomp.c++/reduction-6.C b/libgomp/testsuite/libgomp.c++/reduction-6.C new file mode 100644 index 0000000..f180ca3 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/reduction-6.C @@ -0,0 +1,195 @@ +template <typename T> +struct A +{ + A () { t = 0; } + A (T x) { t = x; } + A (const A &x) { t = x.t; } + ~A () {} + T t; +}; +template <typename T> +struct M +{ + M () { t = 1; } + M (T x) { t = x; } + M (const M &x) { t = x.t; } + ~M () {} + T t; +}; +template <typename T> +struct B +{ + B () { t = ~(T) 0; } + B (T x) { t = x; } + B (const B &x) { t = x.t; } + ~B () {} + T t; +}; +template <typename T> +void +add (T &x, T &y) +{ + x.t += y.t; +} +template <typename T> +void +zero (T &x) +{ + x.t = 0; +} +template <typename T> +void +orit (T *x, T *y) +{ + y->t |= x->t; +} +B<long> bb; +#pragma omp declare reduction(+:A<int>:omp_out.t += omp_in.t) +#pragma omp declare reduction(+:A<char>:add (omp_out, omp_in)) initializer(zero (omp_priv)) +#pragma omp declare reduction(*:M<int>:omp_out.t *= omp_in.t) initializer(omp_priv = 1) +#pragma omp declare reduction(|:A<unsigned long long>:orit (&omp_in, &omp_out)) +#pragma omp declare reduction(&:B<long>:omp_out.t = omp_out.t & omp_in.t) initializer(orit (&omp_priv, &omp_orig)) +#pragma omp declare reduction(maxb:short:omp_out = omp_in > omp_out ? omp_in : omp_out) initializer(omp_priv = -6) + +A<char> z[10]; + +__attribute__((noinline, noclone)) void +foo (A<int> (*&x)[3][2], M<int> *y, B<long> (&w)[1][2]) +{ + A<unsigned long long> a[9]; + short bb[5] = {}; + short (&b)[5] = bb; + #pragma omp parallel for reduction(+:x[0:2][:][0:2], z[:4]) \ + reduction(*:y[:3]) reduction(|:a[:4]) \ + reduction(&:w[0:][:2]) reduction(maxb:b) + for (int i = 0; i < 128; i++) + { + x[i / 64][i % 3][(i / 4) & 1].t += i; + if ((i & 15) == 1) + y[0].t *= 3; + if ((i & 31) == 2) + y[1].t *= 7; + if ((i & 63) == 3) + y[2].t *= 17; + z[i / 32].t += (i & 3); + if (i < 4) + z[i].t += i; + a[i / 32].t |= 1ULL << (i & 30); + w[0][i & 1].t &= ~(1L << (i / 17 * 3)); + if ((i % 79) > b[0]) + b[0] = i % 79; + if ((i % 13) > b[1]) + b[1] = i % 13; + if ((i % 23) > b[2]) + b[2] = i % 23; + if ((i % 85) > b[3]) + b[3] = i % 85; + if ((i % 192) > b[4]) + b[4] = i % 192; + } + for (int i = 0; i < 9; i++) + if (a[i].t != (i < 4 ? 0x55555555ULL : 0)) + __builtin_abort (); + if (bb[0] != 78 || bb[1] != 12 || bb[2] != 22 || bb[3] != 84 || bb[4] != 127) + __builtin_abort (); +} + +A<int> a3[4][3][2]; +A<int> (*p3)[3][2] = &a3[1]; +M<int> y3[5] = { 0, 1, 1, 1, 0 }; +B<long> w3[1][2]; + +struct S +{ + A<int> (*&x)[3][2]; + M<int> *y; + B<long> (&w)[1][2]; + A<char> z[10]; + short b[5]; + A<unsigned long long> a[9]; + S() : x(p3), y(y3+1), w(w3), z(), a(), b() {} + __attribute__((noinline, noclone)) void foo (); +}; + +void +S::foo () +{ + #pragma omp parallel for reduction(+:x[0:2][:][0:2], z[:4]) \ + reduction(*:y[:3]) reduction(|:a[:4]) \ + reduction(&:w[0:][:2]) reduction(maxb:b) + for (int i = 0; i < 128; i++) + { + x[i / 64][i % 3][(i / 4) & 1].t += i; + if ((i & 15) == 1) + y[0].t *= 3; + if ((i & 31) == 2) + y[1].t *= 7; + if ((i & 63) == 3) + y[2].t *= 17; + z[i / 32].t += (i & 3); + if (i < 4) + z[i].t += i; + a[i / 32].t |= 1ULL << (i & 30); + w[0][i & 1].t &= ~(1L << (i / 17 * 3)); + if ((i % 79) > b[0]) + b[0] = i % 79; + if ((i % 13) > b[1]) + b[1] = i % 13; + if ((i % 23) > b[2]) + b[2] = i % 23; + if ((i % 85) > b[3]) + b[3] = i % 85; + if ((i % 192) > b[4]) + b[4] = i % 192; + } +} + +int +main () +{ + A<int> a[4][3][2]; + static int a2[4][3][2] = {{{ 0, 0 }, { 0, 0 }, { 0, 0 }}, + {{ 312, 381 }, { 295, 356 }, { 337, 335 }}, + {{ 1041, 975 }, { 1016, 1085 }, { 935, 1060 }}, + {{ 0, 0 }, { 0, 0 }, { 0, 0 }}}; + A<int> (*p)[3][2] = &a[1]; + M<int> y[5] = { 0, 1, 1, 1, 0 }; + int y2[5] = { 0, 6561, 2401, 289, 0 }; + char z2[10] = { 48, 49, 50, 51, 0, 0, 0, 0, 0, 0 }; + B<long> w[1][2]; + foo (p, y + 1, w); + for (int i = 0; i < 4; i++) + for (int j = 0; j < 3; j++) + for (int k = 0; k < 2; k++) + if (a[i][j][k].t != a2[i][j][k]) + __builtin_abort (); + for (int i = 0; i < 5; i++) + if (y[i].t != y2[i]) + __builtin_abort (); + for (int i = 0; i < 10; i++) + if (z[i].t != z2[i]) + __builtin_abort (); + if (w[0][0].t != ~0x249249L || w[0][1].t != ~0x249249L) + __builtin_abort (); + S s; + s.foo (); + for (int i = 0; i < 9; i++) + if (s.a[i].t != (i < 4 ? 0x55555555ULL : 0)) + __builtin_abort (); + for (int i = 0; i < 4; i++) + for (int j = 0; j < 3; j++) + for (int k = 0; k < 2; k++) + if (a3[i][j][k].t != a2[i][j][k]) + __builtin_abort (); + for (int i = 0; i < 5; i++) + if (y3[i].t != y2[i]) + __builtin_abort (); + for (int i = 0; i < 10; i++) + if (s.z[i].t != z2[i]) + __builtin_abort (); + if (w3[0][0].t != ~0x249249L || w3[0][1].t != ~0x249249L) + __builtin_abort (); + if (s.b[0] != 78 || s.b[1] != 12 || s.b[2] != 22 + || s.b[3] != 84 || s.b[4] != 127) + __builtin_abort (); +} diff --git a/libgomp/testsuite/libgomp.c++/reduction-7.C b/libgomp/testsuite/libgomp.c++/reduction-7.C new file mode 100644 index 0000000..75f9d08 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/reduction-7.C @@ -0,0 +1,134 @@ +char z[10] = { 0 }; + +__attribute__((noinline, noclone)) void +foo (int (*&x)[3][2], int *y, long (&w)[1][2], int p1, long p2, long p3, int p4, + int p5, long p6, short p7) +{ + unsigned long long a[p7 + 4]; + short b[p7]; + for (int i = 0; i < p7 + 4; i++) + { + if (i < p7) + b[i] = -6; + a[i] = 0; + } + #pragma omp parallel for reduction(+:x[0:p1 + 1][:p2], z[:p3]) \ + reduction(*:y[:p4]) reduction(|:a[:p5]) \ + reduction(&:w[0:p6 - 1][:p6]) reduction(max:b) + for (int i = 0; i < 128; i++) + { + x[i / 64][i % 3][(i / 4) & 1] += i; + if ((i & 15) == 1) + y[0] *= 3; + if ((i & 31) == 2) + y[1] *= 7; + if ((i & 63) == 3) + y[2] *= 17; + z[i / 32] += (i & 3); + if (i < 4) + z[i] += i; + a[i / 32] |= 1ULL << (i & 30); + w[0][i & 1] &= ~(1L << (i / 17 * 3)); + if ((i % 79) > b[0]) + b[0] = i % 79; + if ((i % 13) > b[1]) + b[1] = i % 13; + if ((i % 23) > b[2]) + b[2] = i % 23; + if ((i % 85) > b[3]) + b[3] = i % 85; + if ((i % 192) > b[4]) + b[4] = i % 192; + } + for (int i = 0; i < 9; i++) + if (a[i] != (i < 4 ? 0x55555555ULL : 0)) + __builtin_abort (); + if (b[0] != 78 || b[1] != 12 || b[2] != 22 || b[3] != 84 || b[4] != 127) + __builtin_abort (); +} + +int a3[4][3][2]; +int (*p3)[3][2] = &a3[1]; +int y3[5] = { 0, 1, 1, 1, 0 }; +long w3[1][2] = { ~0L, ~0L }; +short bb[5]; + +struct S +{ + int (*&x)[3][2]; + int *y; + long (&w)[1][2]; + char z[10]; + short (&b)[5]; + unsigned long long a[9]; + S() : x(p3), y(y3+1), w(w3), z(), a(), b(bb) {} + __attribute__((noinline, noclone)) void foo (int, long, long, int, int, long, short); +}; + +void +S::foo (int p1, long p2, long p3, int p4, int p5, long p6, short p7) +{ + #pragma omp parallel for reduction(+:x[0:p1 + 1][:p2], z[:p3]) \ + reduction(*:y[:p4]) reduction(|:a[:p5]) \ + reduction(&:w[0:p6 - 1][:p6]) reduction(max:b[0:p7]) + for (int i = 0; i < 128; i++) + { + x[i / 64][i % 3][(i / 4) & 1] += i; + if ((i & 15) == 1) + y[0] *= 3; + if ((i & 31) == 2) + y[1] *= 7; + if ((i & 63) == 3) + y[2] *= 17; + z[i / 32] += (i & 3); + if (i < 4) + z[i] += i; + a[i / 32] |= 1ULL << (i & 30); + w[0][i & 1] &= ~(1L << (i / 17 * 3)); + if ((i % 79) > b[0]) + b[0] = i % 79; + if ((i % 13) > b[1]) + b[1] = i % 13; + if ((i % 23) > b[2]) + b[2] = i % 23; + if ((i % 85) > b[3]) + b[3] = i % 85; + if ((i % 192) > b[4]) + b[4] = i % 192; + } +} + +int +main () +{ + int a[4][3][2] = {}; + static int a2[4][3][2] = {{{ 0, 0 }, { 0, 0 }, { 0, 0 }}, + {{ 312, 381 }, { 295, 356 }, { 337, 335 }}, + {{ 1041, 975 }, { 1016, 1085 }, { 935, 1060 }}, + {{ 0, 0 }, { 0, 0 }, { 0, 0 }}}; + int (*p)[3][2] = &a[1]; + int y[5] = { 0, 1, 1, 1, 0 }; + int y2[5] = { 0, 6561, 2401, 289, 0 }; + char z2[10] = { 48, 49, 50, 51, 0, 0, 0, 0, 0, 0 }; + long w[1][2] = { ~0L, ~0L }; + foo (p, y + 1, w, 1, 3L, 4L, 3, 4, 2L, 5); + if (__builtin_memcmp (a, a2, sizeof (a)) + || __builtin_memcmp (y, y2, sizeof (y)) + || __builtin_memcmp (z, z2, sizeof (z)) + || w[0][0] != ~0x249249L + || w[0][1] != ~0x249249L) + __builtin_abort (); + S s; + s.foo (1, 3L, 4L, 3, 4, 2L, 5); + for (int i = 0; i < 9; i++) + if (s.a[i] != (i < 4 ? 0x55555555ULL : 0)) + __builtin_abort (); + if (__builtin_memcmp (a3, a2, sizeof (a3)) + || __builtin_memcmp (y3, y2, sizeof (y3)) + || __builtin_memcmp (s.z, z2, sizeof (s.z)) + || w3[0][0] != ~0x249249L + || w3[0][1] != ~0x249249L) + __builtin_abort (); + if (bb[0] != 78 || bb[1] != 12 || bb[2] != 22 || bb[3] != 84 || bb[4] != 127) + __builtin_abort (); +} diff --git a/libgomp/testsuite/libgomp.c++/reduction-8.C b/libgomp/testsuite/libgomp.c++/reduction-8.C new file mode 100644 index 0000000..cffd7cc --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/reduction-8.C @@ -0,0 +1,198 @@ +template <typename T> +struct A +{ + A () { t = 0; } + A (T x) { t = x; } + A (const A &x) { t = x.t; } + ~A () {} + T t; +}; +template <typename T> +struct M +{ + M () { t = 1; } + M (T x) { t = x; } + M (const M &x) { t = x.t; } + ~M () {} + T t; +}; +template <typename T> +struct B +{ + B () { t = ~(T) 0; } + B (T x) { t = x; } + B (const B &x) { t = x.t; } + ~B () {} + T t; +}; +template <typename T> +void +add (T &x, T &y) +{ + x.t += y.t; +} +template <typename T> +void +zero (T &x) +{ + x.t = 0; +} +template <typename T> +void +orit (T *x, T *y) +{ + y->t |= x->t; +} +B<long> bb; +#pragma omp declare reduction(+:A<int>:omp_out.t += omp_in.t) +#pragma omp declare reduction(+:A<char>:add (omp_out, omp_in)) initializer(zero (omp_priv)) +#pragma omp declare reduction(*:M<int>:omp_out.t *= omp_in.t) initializer(omp_priv = 1) +#pragma omp declare reduction(|:A<unsigned long long>:orit (&omp_in, &omp_out)) +#pragma omp declare reduction(&:B<long>:omp_out.t = omp_out.t & omp_in.t) initializer(orit (&omp_priv, &omp_orig)) +#pragma omp declare reduction(maxb:short:omp_out = omp_in > omp_out ? omp_in : omp_out) initializer(omp_priv = -6) + +A<char> z[10]; + +__attribute__((noinline, noclone)) void +foo (A<int> (*&x)[3][2], M<int> *y, B<long> (&w)[1][2], int p1, long p2, long p3, int p4, + int p5, long p6, short p7) +{ + A<unsigned long long> a[p7 + 4]; + short bb[p7]; + short (&b)[p7] = bb; + for (int i = 0; i < p7; i++) + bb[i] = -6; + #pragma omp parallel for reduction(+:x[0:p1 + 1][:p2], z[:p3]) \ + reduction(*:y[:p4]) reduction(|:a[:p5]) \ + reduction(&:w[0:p6 - 1][:p6]) reduction(maxb:b) + for (int i = 0; i < 128; i++) + { + x[i / 64][i % 3][(i / 4) & 1].t += i; + if ((i & 15) == 1) + y[0].t *= 3; + if ((i & 31) == 2) + y[1].t *= 7; + if ((i & 63) == 3) + y[2].t *= 17; + z[i / 32].t += (i & 3); + if (i < 4) + z[i].t += i; + a[i / 32].t |= 1ULL << (i & 30); + w[0][i & 1].t &= ~(1L << (i / 17 * 3)); + if ((i % 79) > b[0]) + b[0] = i % 79; + if ((i % 13) > b[1]) + b[1] = i % 13; + if ((i % 23) > b[2]) + b[2] = i % 23; + if ((i % 85) > b[3]) + b[3] = i % 85; + if ((i % 192) > b[4]) + b[4] = i % 192; + } + for (int i = 0; i < 9; i++) + if (a[i].t != (i < 4 ? 0x55555555ULL : 0)) + __builtin_abort (); + if (bb[0] != 78 || bb[1] != 12 || bb[2] != 22 || bb[3] != 84 || bb[4] != 127) + __builtin_abort (); +} + +A<int> a3[4][3][2]; +A<int> (*p3)[3][2] = &a3[1]; +M<int> y3[5] = { 0, 1, 1, 1, 0 }; +B<long> w3[1][2]; + +struct S +{ + A<int> (*&x)[3][2]; + M<int> *y; + B<long> (&w)[1][2]; + A<char> z[10]; + short b[5]; + A<unsigned long long> a[9]; + S() : x(p3), y(y3+1), w(w3), z(), a(), b() {} + __attribute__((noinline, noclone)) void foo (int, long, long, int, int, long, short); +}; + +void +S::foo (int p1, long p2, long p3, int p4, int p5, long p6, short p7) +{ + #pragma omp parallel for reduction(+:x[0:p1 + 1][:p2][0:2], z[:p3]) \ + reduction(*:y[:p4]) reduction(|:a[:p5]) \ + reduction(&:w[0:p6 - 1][:p6]) reduction(maxb:b) + for (int i = 0; i < 128; i++) + { + x[i / 64][i % 3][(i / 4) & 1].t += i; + if ((i & 15) == 1) + y[0].t *= 3; + if ((i & 31) == 2) + y[1].t *= 7; + if ((i & 63) == 3) + y[2].t *= 17; + z[i / 32].t += (i & 3); + if (i < 4) + z[i].t += i; + a[i / 32].t |= 1ULL << (i & 30); + w[0][i & 1].t &= ~(1L << (i / 17 * 3)); + if ((i % 79) > b[0]) + b[0] = i % 79; + if ((i % 13) > b[1]) + b[1] = i % 13; + if ((i % 23) > b[2]) + b[2] = i % 23; + if ((i % 85) > b[3]) + b[3] = i % 85; + if ((i % 192) > b[4]) + b[4] = i % 192; + } +} + +int +main () +{ + A<int> a[4][3][2]; + static int a2[4][3][2] = {{{ 0, 0 }, { 0, 0 }, { 0, 0 }}, + {{ 312, 381 }, { 295, 356 }, { 337, 335 }}, + {{ 1041, 975 }, { 1016, 1085 }, { 935, 1060 }}, + {{ 0, 0 }, { 0, 0 }, { 0, 0 }}}; + A<int> (*p)[3][2] = &a[1]; + M<int> y[5] = { 0, 1, 1, 1, 0 }; + int y2[5] = { 0, 6561, 2401, 289, 0 }; + char z2[10] = { 48, 49, 50, 51, 0, 0, 0, 0, 0, 0 }; + B<long> w[1][2]; + foo (p, y + 1, w, 1, 3L, 4L, 3, 4, 2L, 5); + for (int i = 0; i < 4; i++) + for (int j = 0; j < 3; j++) + for (int k = 0; k < 2; k++) + if (a[i][j][k].t != a2[i][j][k]) + __builtin_abort (); + for (int i = 0; i < 5; i++) + if (y[i].t != y2[i]) + __builtin_abort (); + for (int i = 0; i < 10; i++) + if (z[i].t != z2[i]) + __builtin_abort (); + if (w[0][0].t != ~0x249249L || w[0][1].t != ~0x249249L) + __builtin_abort (); + S s; + s.foo (1, 3L, 4L, 3, 4, 2L, 5); + for (int i = 0; i < 9; i++) + if (s.a[i].t != (i < 4 ? 0x55555555ULL : 0)) + __builtin_abort (); + for (int i = 0; i < 4; i++) + for (int j = 0; j < 3; j++) + for (int k = 0; k < 2; k++) + if (a3[i][j][k].t != a2[i][j][k]) + __builtin_abort (); + for (int i = 0; i < 5; i++) + if (y3[i].t != y2[i]) + __builtin_abort (); + for (int i = 0; i < 10; i++) + if (s.z[i].t != z2[i]) + __builtin_abort (); + if (w3[0][0].t != ~0x249249L || w3[0][1].t != ~0x249249L) + __builtin_abort (); + if (s.b[0] != 78 || s.b[1] != 12 || s.b[2] != 22 + || s.b[3] != 84 || s.b[4] != 127) + __builtin_abort (); +} diff --git a/libgomp/testsuite/libgomp.c++/reduction-9.C b/libgomp/testsuite/libgomp.c++/reduction-9.C new file mode 100644 index 0000000..117a8f6 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/reduction-9.C @@ -0,0 +1,130 @@ +char z[10] = { 0 }; + +template <int N> +__attribute__((noinline, noclone)) void +foo (int (*&x)[3][N], int *y, long (&w)[1][N]) +{ + unsigned long long a[9] = {}; + short b[5] = {}; + #pragma omp parallel for reduction(+:x[0:N][:][0:N], z[:4]) \ + reduction(*:y[:3]) reduction(|:a[:4]) \ + reduction(&:w[0:][:N]) reduction(max:b) + for (int i = 0; i < 128; i++) + { + x[i / 64][i % 3][(i / 4) & 1] += i; + if ((i & 15) == 1) + y[0] *= 3; + if ((i & 31) == N) + y[1] *= 7; + if ((i & 63) == 3) + y[N] *= 17; + z[i / 32] += (i & 3); + if (i < 4) + z[i] += i; + a[i / 32] |= 1ULL << (i & 30); + w[0][i & 1] &= ~(1L << (i / 17 * 3)); + if ((i % 79) > b[0]) + b[0] = i % 79; + if ((i % 13) > b[1]) + b[1] = i % 13; + if ((i % 23) > b[N]) + b[N] = i % 23; + if ((i % 85) > b[3]) + b[3] = i % 85; + if ((i % 192) > b[4]) + b[4] = i % 192; + } + for (int i = 0; i < 9; i++) + if (a[i] != (i < 4 ? 0x55555555ULL : 0)) + __builtin_abort (); + if (b[0] != 78 || b[1] != 12 || b[N] != 22 || b[3] != 84 || b[4] != 127) + __builtin_abort (); +} + +int a3[4][3][2]; +int (*p3)[3][2] = &a3[1]; +int y3[5] = { 0, 1, 1, 1, 0 }; +long w3[1][2] = { ~0L, ~0L }; +short bb[5]; + +template <int N> +struct S +{ + int (*&x)[3][N]; + int *y; + long (&w)[1][N]; + char z[10]; + short (&b)[5]; + unsigned long long a[9]; + S() : x(p3), y(y3+1), w(w3), z(), a(), b(bb) {} + __attribute__((noinline, noclone)) void foo (); +}; + +template <int N> +void +S<N>::foo () +{ + #pragma omp parallel for reduction(+:x[0:N][:][0:N], z[:4]) \ + reduction(*:y[:3]) reduction(|:a[:4]) \ + reduction(&:w[0:][:N]) reduction(max:b) + for (int i = 0; i < 128; i++) + { + x[i / 64][i % 3][(i / 4) & 1] += i; + if ((i & 15) == 1) + y[0] *= 3; + if ((i & 31) == N) + y[1] *= 7; + if ((i & 63) == 3) + y[N] *= 17; + z[i / 32] += (i & 3); + if (i < 4) + z[i] += i; + a[i / 32] |= 1ULL << (i & 30); + w[0][i & 1] &= ~(1L << (i / 17 * 3)); + if ((i % 79) > b[0]) + b[0] = i % 79; + if ((i % 13) > b[1]) + b[1] = i % 13; + if ((i % 23) > b[N]) + b[N] = i % 23; + if ((i % 85) > b[3]) + b[3] = i % 85; + if ((i % 192) > b[4]) + b[4] = i % 192; + } +} + +int +main () +{ + int a[4][3][2] = {}; + static int a2[4][3][2] = {{{ 0, 0 }, { 0, 0 }, { 0, 0 }}, + {{ 312, 381 }, { 295, 356 }, { 337, 335 }}, + {{ 1041, 975 }, { 1016, 1085 }, { 935, 1060 }}, + {{ 0, 0 }, { 0, 0 }, { 0, 0 }}}; + int (*p)[3][2] = &a[1]; + int y[5] = { 0, 1, 1, 1, 0 }; + int y2[5] = { 0, 6561, 2401, 289, 0 }; + char z2[10] = { 48, 49, 50, 51, 0, 0, 0, 0, 0, 0 }; + long w[1][2] = { ~0L, ~0L }; + foo<2> (p, y + 1, w); + if (__builtin_memcmp (a, a2, sizeof (a)) + || __builtin_memcmp (y, y2, sizeof (y)) + || __builtin_memcmp (z, z2, sizeof (z)) + || w[0][0] != ~0x249249L + || w[0][1] != ~0x249249L) + __builtin_abort (); + S<2> s; + s.foo (); + for (int i = 0; i < 9; i++) + if (s.a[i] != (i < 4 ? 0x55555555ULL : 0)) + __builtin_abort (); + if (__builtin_memcmp (a3, a2, sizeof (a3)) + || __builtin_memcmp (y3, y2, sizeof (y3)) + || __builtin_memcmp (s.z, z2, sizeof (s.z)) + || w3[0][0] != ~0x249249L + || w3[0][1] != ~0x249249L) + __builtin_abort (); + if (bb[0] != 78 || bb[1] != 12 || bb[2] != 22 || bb[3] != 84 || bb[4] != 127) + __builtin_abort (); +} diff --git a/libgomp/testsuite/libgomp.c++/reference-1.C b/libgomp/testsuite/libgomp.c++/reference-1.C new file mode 100644 index 0000000..f2a7861 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/reference-1.C @@ -0,0 +1,57 @@ +// { dg-do run } + +#include <omp.h> + +__attribute__((noinline, noclone)) void +foo (int &a, short &d, char &g) +{ + unsigned long b = 12; + unsigned long &c = b; + long long e = 21; + long long &f = e; + unsigned int h = 12; + unsigned int &k = h; + #pragma omp parallel default(none) private(a, c) firstprivate(d, f) shared(g, k) + { + int i = omp_get_thread_num (); + a = i; + c = 2 * i; + if (d != 27 || f != 21) + __builtin_abort (); + d = 3 * (i & 0xfff); + f = 4 * i; + #pragma omp barrier + if (a != i || c != 2 * i || d != 3 * (i & 0xfff) || f != 4 * i) + __builtin_abort (); + #pragma omp for lastprivate(g, k) + for (int j = 0; j < 32; j++) + { + g = j; + k = 3 * j; + } + } + if (g != 31 || k != 31 * 3) + __builtin_abort (); + #pragma omp parallel for firstprivate (g, k) lastprivate (g, k) + for (int j = 0; j < 32; j++) + { + if (g != 31 || k != 31 * 3) + __builtin_abort (); + if (j == 31) + { + g = 29; + k = 138; + } + } + if (g != 29 || k != 138) + __builtin_abort (); +} + +int +main () +{ + int a = 5; + short d = 27; + char g = ' '; + foo (a, d, g); +} diff --git a/libgomp/testsuite/libgomp.c++/simd14.C b/libgomp/testsuite/libgomp.c++/simd14.C new file mode 100644 index 0000000..dc18cb6 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/simd14.C @@ -0,0 +1,43 @@ +// { dg-do run } +// { dg-options "-O2" } +// { dg-additional-options "-msse2" { target sse2_runtime } } +// { dg-additional-options "-mavx" { target avx_runtime } } + +int a[1024]; +short b[2048]; + +static inline void +bar (int &x, unsigned long long &y, short *&z) +{ + a[x] = x + y + *z; + x++; + y += 17; + z += 2; +} + +__attribute__((noinline, noclone)) int +foo (unsigned long long &s, short *&t) +{ + int i, j = 0; + int &r = j; +#pragma omp parallel for simd linear(r) linear(s:17ULL) linear(t:2) + for (i = 0; i < 1024; i++) + bar (r, s, t); + return j; +} + +int +main () +{ + int i; + for (i = 0; i < 2048; i++) + b[i] = 3 * i; + unsigned long long s = 12; + short *t = b; + int j = foo (s, t); + for (i = 0; i < 1024; i++) + if (a[i] != 12 + 24 * i) + __builtin_abort (); + if (j != 1024 || s != 12 + 1024 * 17ULL || t != &b[2048]) + __builtin_abort (); +} diff --git a/libgomp/testsuite/libgomp.c++/target-10.C b/libgomp/testsuite/libgomp.c++/target-10.C new file mode 100644 index 0000000..860773e --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/target-10.C @@ -0,0 +1,154 @@ +extern "C" void abort (void); +union U { int x; long long y; }; +struct T { int a; union U b; int c; }; +struct S { int s; int u; T v; int x[10]; union U w; int y[10]; int z[10]; }; +volatile int z; + +template <typename R> +void +foo () +{ + R s; + s.template s = 0; + s.u = 1; + s.v.a = 2; + s.v.b.y = 3LL; + s.v.c = 19; + s.w.x = 4; + s.template x[0] = 7; + s.x[1] = 8; + s.y[3] = 9; + s.y[4] = 10; + s.y[5] = 11; + int err = 0; + #pragma omp target map (to:s.template v.template b, s.u, s.x[0:z + 2]) \ + map (tofrom:s.y[3:3]) \ + map (from: s.w, s.template z[z + 1:z + 3], err) + { + err = 0; + if (s.u != 1 || s.v.b.y != 3LL || s.x[0] != 7 || s.x[1] != 8 + || s.y[3] != 9 || s.y[4] != 10 || s.y[5] != 11) + err = 1; + s.w.x = 6; + s.y[3] = 12; + s.y[4] = 13; + s.y[5] = 14; + s.z[1] = 15; + s.z[2] = 16; + s.z[3] = 17; + } + if (err || s.w.x != 6 || s.y[3] != 12 || s.y[4] != 13 || s.y[5] != 14 + || s.z[1] != 15 || s.z[2] != 16 || s.z[3] != 17) + abort (); + s.u++; + s.v.a++; + s.v.b.y++; + s.w.x++; + s.x[1] = 18; + s.z[0] = 19; + #pragma omp target data map (tofrom: s) + #pragma omp target map (always to: s.template w, s.x[1], err) map (alloc:s.u, s. template v.template b, s.z[z:z + 1]) + { + err = 0; + if (s.u != 2 || s.v.b.y != 4LL || s.w.x != 7 || s.x[1] != 18 || s.z[0] != 19) + err = 1; + s.w.x = 8; + s.x[1] = 20; + s.z[0] = 21; + } + if (err || s.w.x != 8 || s.x[1] != 20 || s.z[0] != 21) + abort (); + s.u++; + s.v.a++; + s.v.b.y++; + s.w.x++; + s.x[0] = 22; + s.x[1] = 23; + #pragma omp target data map (from: s.w, s.x[0:2]) map (to: s.v.b, s.u) + #pragma omp target map (always to: s.w, s.x[0:2], err) map (alloc:s.u, s.v.b) + { + err = 0; + if (s.u != 3 || s.v.b.y != 5LL || s.w.x != 9 || s.x[0] != 22 || s.x[1] != 23) + err = 1; + s.w.x = 11; + s.x[0] = 24; + s.x[1] = 25; + } + if (err || s.w.x != 11 || s.x[0] != 24 || s.x[1] != 25) + abort (); +} + +int +main () +{ + S s; + s.s = 0; + s.u = 1; + s.v.a = 2; + s.v.b.y = 3LL; + s.v.c = 19; + s.w.x = 4; + s.x[0] = 7; + s.x[1] = 8; + s.y[3] = 9; + s.y[4] = 10; + s.y[5] = 11; + int err = 0; + #pragma omp target map (to:s.v.b, s.u, s.x[0:z + 2]) \ + map (tofrom:s.y[3:3]) \ + map (from: s.w, s.z[z + 1:z + 3], err) + { + err = 0; + if (s.u != 1 || s.v.b.y != 3LL || s.x[0] != 7 || s.x[1] != 8 + || s.y[3] != 9 || s.y[4] != 10 || s.y[5] != 11) + err = 1; + s.w.x = 6; + s.y[3] = 12; + s.y[4] = 13; + s.y[5] = 14; + s.z[1] = 15; + s.z[2] = 16; + s.z[3] = 17; + } + if (err || s.w.x != 6 || s.y[3] != 12 || s.y[4] != 13 || s.y[5] != 14 + || s.z[1] != 15 || s.z[2] != 16 || s.z[3] != 17) + abort (); + s.u++; + s.v.a++; + s.v.b.y++; + s.w.x++; + s.x[1] = 18; + s.z[0] = 19; + #pragma omp target data map (tofrom: s) + #pragma omp target map (always to: s.w, s.x[1], err) map (alloc:s.u, s.v.b, s.z[z:z + 1]) + { + err = 0; + if (s.u != 2 || s.v.b.y != 4LL || s.w.x != 7 || s.x[1] != 18 || s.z[0] != 19) + err = 1; + s.w.x = 8; + s.x[1] = 20; + s.z[0] = 21; + } + if (err || s.w.x != 8 || s.x[1] != 20 || s.z[0] != 21) + abort (); + s.u++; + s.v.a++; + s.v.b.y++; + s.w.x++; + s.x[0] = 22; + s.x[1] = 23; + #pragma omp target data map (from: s.w, s.x[0:2]) map (to: s.v.b, s.u) + #pragma omp target map (always to: s.w, s.x[0:2], err) map (alloc:s.u, s.v.b) + { + err = 0; + if (s.u != 3 || s.v.b.y != 5LL || s.w.x != 9 || s.x[0] != 22 || s.x[1] != 23) + err = 1; + s.w.x = 11; + s.x[0] = 24; + s.x[1] = 25; + } + if (err || s.w.x != 11 || s.x[0] != 24 || s.x[1] != 25) + abort (); + foo <S> (); + return 0; +} diff --git a/libgomp/testsuite/libgomp.c++/target-11.C b/libgomp/testsuite/libgomp.c++/target-11.C new file mode 100644 index 0000000..fe99603 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/target-11.C @@ -0,0 +1,121 @@ +extern "C" void abort (); +struct T { int a; int *b; int c; char (&d)[10]; }; +struct S { int *s; char *u; T v; short *w; short *&x; }; +volatile int z; + +template <typename A, typename B, typename C, typename D> +void +foo () +{ + A d[10]; + B *e; + C a[32], i; + A b[32]; + B c[32]; + for (i = 0; i < 32; i++) + { + a[i] = i; + b[i] = 32 + i; + c[i] = 64 + i; + } + for (i = 0; i < 10; i++) + d[i] = 17 + i; + e = c + 18; + D s = { a, b + 2, { 0, a + 16, 0, d }, c + 3, e }; + int err = 0; + #pragma omp target map (to:s.v.b[0:z + 7], s.template u[z + 1:z + 4]) \ + map (tofrom:s.s[3:3], s. template v. template d[z + 1:z + 3]) \ + map (from: s.w[z:4], s.x[1:3], err) private (i) + { + err = 0; + for (i = 0; i < 7; i++) + if (s.v.b[i] != 16 + i) + err = 1; + for (i = 1; i < 5; i++) + if (s.u[i] != 34 + i) + err = 1; + for (i = 3; i < 6; i++) + if (s.s[i] != i) + err = 1; + else + s.s[i] = 128 + i; + for (i = 1; i < 4; i++) + if (s.v.d[i] != 17 + i) + err = 1; + else + s.v.d[i] = 23 + i; + for (i = 0; i < 4; i++) + s.w[i] = 96 + i; + for (i = 1; i < 4; i++) + s.x[i] = 173 + i; + } + if (err) + abort (); + for (i = 0; i < 32; i++) + if (a[i] != ((i >= 3 && i < 6) ? 128 + i : i) + || b[i] != 32 + i + || c[i] != ((i >= 3 && i < 7) ? 93 + i : ((i >= 19 && i < 22) ? 155 + i : 64 + i))) + abort (); + for (i = 0; i < 10; i++) + if (d[i] != ((i >= 1 && i < 4) ? 23 + i : 17 + i)) + abort (); +} + +int +main () +{ + char d[10]; + short *e; + int a[32], i; + char b[32]; + short c[32]; + for (i = 0; i < 32; i++) + { + a[i] = i; + b[i] = 32 + i; + c[i] = 64 + i; + } + for (i = 0; i < 10; i++) + d[i] = 17 + i; + e = c + 18; + S s = { a, b + 2, { 0, a + 16, 0, d }, c + 3, e }; + int err = 0; + #pragma omp target map (to:s.v.b[0:z + 7], s.u[z + 1:z + 4]) \ + map (tofrom:s.s[3:3], s.v.d[z + 1:z + 3]) \ + map (from: s.w[z:4], s.x[1:3], err) private (i) + { + err = 0; + for (i = 0; i < 7; i++) + if (s.v.b[i] != 16 + i) + err = 1; + for (i = 1; i < 5; i++) + if (s.u[i] != 34 + i) + err = 1; + for (i = 3; i < 6; i++) + if (s.s[i] != i) + err = 1; + else + s.s[i] = 128 + i; + for (i = 1; i < 4; i++) + if (s.v.d[i] != 17 + i) + err = 1; + else + s.v.d[i] = 23 + i; + for (i = 0; i < 4; i++) + s.w[i] = 96 + i; + for (i = 1; i < 4; i++) + s.x[i] = 173 + i; + } + if (err) + abort (); + for (i = 0; i < 32; i++) + if (a[i] != ((i >= 3 && i < 6) ? 128 + i : i) + || b[i] != 32 + i + || c[i] != ((i >= 3 && i < 7) ? 93 + i : ((i >= 19 && i < 22) ? 155 + i : 64 + i))) + abort (); + for (i = 0; i < 10; i++) + if (d[i] != ((i >= 1 && i < 4) ? 23 + i : 17 + i)) + abort (); + foo <char, short, int, S> (); + return 0; +} diff --git a/libgomp/testsuite/libgomp.c++/target-12.C b/libgomp/testsuite/libgomp.c++/target-12.C new file mode 100644 index 0000000..3b4ed57 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/target-12.C @@ -0,0 +1,93 @@ +extern "C" void abort (void); +struct S { int s; int *u; int v[5]; }; +volatile int z; + +template <typename T> +void +foo () +{ + int u[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, err = 0; + T s = { 9, u + 3, { 10, 11, 12, 13, 14 } }; + int *v = u + 4; + #pragma omp target enter data map (to: s.s, s.template u[0:5]) map (alloc: s.template v[1:3]) + s.s++; + u[3]++; + s.v[1]++; + #pragma omp target update to (s.template s) to (s.u[0:2], s.v[1:3]) + #pragma omp target map (alloc: s.s, s.v[1:3]) map (from: err) + { + err = 0; + if (s.s != 10 || s.v[1] != 12 || s.v[2] != 12 || s.v[3] != 13) + err = 1; + if (v[-1] != 4 || v[0] != 4 || v[1] != 5 || v[2] != 6 || v[3] != 7) + err = 1; + s.s++; + s.v[2] += 2; + v[-1] = 5; + v[3] = 9; + } + if (err) + abort (); + #pragma omp target map (alloc: s.u[0:5]) + { + err = 0; + if (s.u[0] != 5 || s.u[1] != 4 || s.u[2] != 5 || s.u[3] != 6 || s.u[4] != 9) + err = 1; + s.u[1] = 12; + } + #pragma omp target update from (s.s, s.u[0:5]) from (s.v[1:3]) + if (err || s.s != 11 || u[0] != 0 || u[1] != 1 || u[2] != 2 || u[3] != 5 + || u[4] != 12 || u[5] != 5 || u[6] != 6 || u[7] != 9 || u[8] != 8 + || u[9] != 9 || s.v[0] != 10 || s.v[1] != 12 || s.v[2] != 14 + || s.v[3] != 13 || s.v[4] != 14) + abort (); + #pragma omp target exit data map (release: s.s) + #pragma omp target exit data map (release: s.u[0:5]) + #pragma omp target exit data map (delete: s.v[1:3]) + #pragma omp target exit data map (release: s.s) +} + +int +main () +{ + int u[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, err = 0; + S s = { 9, u + 3, { 10, 11, 12, 13, 14 } }; + int *v = u + 4; + #pragma omp target enter data map (to: s.s, s.u[0:5]) map (alloc: s.v[1:3]) + s.s++; + u[3]++; + s.v[1]++; + #pragma omp target update to (s.s) to (s.u[0:2], s.v[1:3]) + #pragma omp target map (alloc: s.s, s.v[1:3]) map (from: err) + { + err = 0; + if (s.s != 10 || s.v[1] != 12 || s.v[2] != 12 || s.v[3] != 13) + err = 1; + if (v[-1] != 4 || v[0] != 4 || v[1] != 5 || v[2] != 6 || v[3] != 7) + err = 1; + s.s++; + s.v[2] += 2; + v[-1] = 5; + v[3] = 9; + } + if (err) + abort (); + #pragma omp target map (alloc: s.u[0:5]) + { + err = 0; + if (s.u[0] != 5 || s.u[1] != 4 || s.u[2] != 5 || s.u[3] != 6 || s.u[4] != 9) + err = 1; + s.u[1] = 12; + } + #pragma omp target update from (s.s, s.u[0:5]) from (s.v[1:3]) + if (err || s.s != 11 || u[0] != 0 || u[1] != 1 || u[2] != 2 || u[3] != 5 + || u[4] != 12 || u[5] != 5 || u[6] != 6 || u[7] != 9 || u[8] != 8 + || u[9] != 9 || s.v[0] != 10 || s.v[1] != 12 || s.v[2] != 14 + || s.v[3] != 13 || s.v[4] != 14) + abort (); + #pragma omp target exit data map (release: s.s) + #pragma omp target exit data map (release: s.u[0:5]) + #pragma omp target exit data map (always, delete: s.v[1:3]) + #pragma omp target exit data map (release: s.s) + #pragma omp target exit data map (always delete : s.v[1:3]) +} diff --git a/libgomp/testsuite/libgomp.c++/target-2.C b/libgomp/testsuite/libgomp.c++/target-2.C index 35e910a..1eab7f2 100644 --- a/libgomp/testsuite/libgomp.c++/target-2.C +++ b/libgomp/testsuite/libgomp.c++/target-2.C @@ -33,7 +33,8 @@ fn2 (int x, double (&dr) [1024], double *&er) int j; fn1 (hr + 2 * x, ir + 2 * x, x); #pragma omp target map(to: br[:x], cr[0:x], dr[x:x], er[x:x]) \ - map(to: fr[0:x], gr[0:x], hr[2 * x:x], ir[2 * x:x]) + map(to: fr[0:x], gr[0:x], hr[2 * x:x], ir[2 * x:x]) \ + map(tofrom: s) #pragma omp parallel for reduction(+:s) for (j = 0; j < x; j++) s += br[j] * cr[j] + dr[x + j] + er[x + j] diff --git a/libgomp/testsuite/libgomp.c++/target-5.C b/libgomp/testsuite/libgomp.c++/target-5.C new file mode 100644 index 0000000..6639be3 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/target-5.C @@ -0,0 +1 @@ +#include "../libgomp.c/target-13.c" diff --git a/libgomp/testsuite/libgomp.c++/target-6.C b/libgomp/testsuite/libgomp.c++/target-6.C new file mode 100644 index 0000000..8dbafb0 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/target-6.C @@ -0,0 +1,64 @@ +extern "C" void abort (void); +struct S { int s, t; }; + +void +foo (int &x, int &y, S &u, S &v, double &s, double &t) +{ + int err = 0, i; + int a[y - 2], b[y - 2]; + int (&c)[y - 2] = a, (&d)[y - 2] = b; + for (i = 0; i < y - 2; i++) + { + c[i] = i; + d[i] = 3 + i; + } + #pragma omp target private (x, u, s, c, i) firstprivate (y, v, t, d) map(from:err) + { + x = y; + u = v; + s = t; + for (i = 0; i < y - 2; i++) + c[i] = d[i]; + err = (x != 6 || y != 6 + || u.s != 9 || u.t != 10 || v.s != 9 || v.t != 10 + || s != 12.5 || t != 12.5); + for (i = 0; i < y - 2; i++) + if (d[i] != 3 + i || c[i] != 3 + i) + err = 1; + else + { + c[i] += 2 * i; + d[i] += i; + } + x += 1; + y += 2; + u.s += 3; + v.t += 4; + s += 2.5; + t += 3.0; + if (x != 7 || y != 8 + || u.s != 12 || u.t != 10 || v.s != 9 || v.t != 14 + || s != 15.0 || t != 15.5) + err = 1; + for (i = 0; i < y - 4; i++) + if (d[i] != 3 + 2 * i || c[i] != 3 + 3 * i) + err = 1; + } + if (err || x != 5 || y != 6 + || u.s != 7 || u.t != 8 || v.s != 9 || v.t != 10 + || s != 11.5 || t != 12.5) + abort (); + for (i = 0; i < y - 2; i++) + if (d[i] != 3 + i || c[i] != i) + abort (); +} + +int +main () +{ + int x = 5, y = 6; + S u = { 7, 8 }, v = { 9, 10 }; + double s = 11.5, t = 12.5; + foo (x, y, u, v, s, t); + return 0; +} diff --git a/libgomp/testsuite/libgomp.c++/target-7.C b/libgomp/testsuite/libgomp.c++/target-7.C new file mode 100644 index 0000000..e13c50f --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/target-7.C @@ -0,0 +1,90 @@ +extern "C" void abort (); + +void +foo (int *x, int *&y, int (&z)[15]) +{ + int a[10], b[15], err, i; + for (i = 0; i < 10; i++) + a[i] = 7 * i; + for (i = 0; i < 15; i++) + b[i] = 8 * i; + #pragma omp target map(to:x[5:10], y[5:10], z[5:10], a[0:10], b[5:10]) map(from:err) + { + err = 0; + for (i = 0; i < 10; i++) + if (x[5 + i] != 20 + 4 * i + || y[5 + i] != 25 + 5 * i + || z[5 + i] != 30 + 6 * i + || a[i] != 7 * i + || b[5 + i] != 40 + 8 * i) + err = 1; + } + if (err) + abort (); +} + +void +bar (int n, int v) +{ + int a[n], b[n], c[n], d[n], e[n], err, i; + int (*x)[n] = &c; + int (*y2)[n] = &d; + int (*&y)[n] = y2; + int (&z)[n] = e; + for (i = 0; i < n; i++) + { + (*x)[i] = 4 * i; + (*y)[i] = 5 * i; + z[i] = 6 * i; + a[i] = 7 * i; + b[i] = 8 * i; + } + #pragma omp target map(to:x[0][5:10], y[0][5:10], z[5:10], a[0:10], b[5:10]) map(from:err) + { + err = 0; + for (i = 0; i < 10; i++) + if ((*x)[5 + i] != 20 + 4 * i + || (*y)[5 + i] != 25 + 5 * i + || z[5 + i] != 30 + 6 * i + || a[i] != 7 * i + || b[5 + i] != 40 + 8 * i) + err = 1; + } + if (err) + abort (); + for (i = 0; i < n; i++) + { + (*x)[i] = 9 * i; + (*y)[i] = 10 * i; + z[i] = 11 * i; + a[i] = 12 * i; + b[i] = 13 * i; + } + #pragma omp target map(to:x[0][v:v+5], y[0][v:v+5], z[v:v+5], a[v-5:v+5], b[v:v+5]) map(from:err) + { + err = 0; + for (i = 0; i < 10; i++) + if ((*x)[5 + i] != 45 + 9 * i + || (*y)[5 + i] != 50 + 10 * i + || z[5 + i] != 55 + 11 * i + || a[i] != 12 * i + || b[5 + i] != 65 + 13 * i) + err = 1; + } + if (err) + abort (); +} + +int +main () +{ + int x[15], y2[15], z[15], *y = y2, i; + for (i = 0; i < 15; i++) + { + x[i] = 4 * i; + y[i] = 5 * i; + z[i] = 6 * i; + } + foo (x, y, z); + bar (15, 5); +} diff --git a/libgomp/testsuite/libgomp.c++/target-8.C b/libgomp/testsuite/libgomp.c++/target-8.C new file mode 100644 index 0000000..d886b47 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/target-8.C @@ -0,0 +1,58 @@ +extern "C" void abort (); +struct S { int a; }; +#ifdef __SIZEOF_INT128__ +typedef __int128 T; +#else +typedef long long int T; +#endif + +void +foo (T a, int b, struct S c) +{ + int err; + #pragma omp target firstprivate (a, b, c) map(from:err) + { + err = 0; + if (a != 131 || b != 276 || c.a != 59) + err = 1; + a = 936; + b = 27; + c.a = 98; + if (a != 936 || b != 27 || c.a != 98) + err = 1; + } + if (err || a != 131 || b != 276 || c.a != 59) + abort (); +} + +void +bar (T &a, int &b, struct S &c) +{ + int err; + #pragma omp target firstprivate (a, b, c) map(from:err) + { + err = 0; + if (a != 131 || b != 276 || c.a != 59) + err = 1; + a = 936; + b = 27; + c.a = 98; + if (a != 936 || b != 27 || c.a != 98) + err = 1; + } + if (err || a != 131 || b != 276 || c.a != 59) + abort (); +} + +int +main () +{ + T a = 131; + int b = 276; + struct S c; + c.a = 59; + foo (a, b, c); + bar (a, b, c); + if (a != 131 || b != 276 || c.a != 59) + abort (); +} diff --git a/libgomp/testsuite/libgomp.c++/target-9.C b/libgomp/testsuite/libgomp.c++/target-9.C new file mode 100644 index 0000000..a5d171b --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/target-9.C @@ -0,0 +1,73 @@ +extern "C" void abort (void); + +void +foo (int *&p, int (&s)[5], int n) +{ + int a[4] = { 7, 8, 9, 10 }, b[n], c[3] = { 20, 21, 22 }; + int *r = a + 1, *q = p - 1, i, err; + for (i = 0; i < n; i++) + b[i] = 9 + i; + #pragma omp target data map(to:a) + #pragma omp target data use_device_ptr(r) map(from:err) + #pragma omp target is_device_ptr(r) private(i) map(from:err) + { + err = 0; + for (i = 0; i < 4; i++) + if (r[i - 1] != 7 + i) + err = 1; + } + if (err) + abort (); + #pragma omp target data map(to:q[:4]) + #pragma omp target data use_device_ptr(p) map(from:err) + #pragma omp target is_device_ptr(p) private(i) map(from:err) + { + err = 0; + for (i = 0; i < 4; i++) + if (p[i - 1] != i) + err = 1; + } + if (err) + abort (); + #pragma omp target data map(to:b) + #pragma omp target data use_device_ptr(b) map(from:err) + #pragma omp target is_device_ptr(b) private(i) map(from:err) + { + err = 0; + for (i = 0; i < n; i++) + if (b[i] != 9 + i) + err = 1; + } + if (err) + abort (); + #pragma omp target data map(to:c) + #pragma omp target data use_device_ptr(c) map(from:err) + #pragma omp target is_device_ptr(c) private(i) map(from:err) + { + err = 0; + for (i = 0; i < 3; i++) + if (c[i] != 20 + i) + err = 1; + } + if (err) + abort (); + #pragma omp target data map(to:s[:5]) + #pragma omp target data use_device_ptr(s) map(from:err) + #pragma omp target is_device_ptr(s) private(i) map(from:err) + { + err = 0; + for (i = 0; i < 5; i++) + if (s[i] != 17 + i) + err = 1; + } + if (err) + abort (); +} + +int +main () +{ + int a[4] = { 0, 1, 2, 3 }, b[5] = { 17, 18, 19, 20, 21 }; + int *p = a + 1; + foo (p, b, 9); +} diff --git a/libgomp/testsuite/libgomp.c++/taskloop-1.C b/libgomp/testsuite/libgomp.c++/taskloop-1.C new file mode 100644 index 0000000..66f8e0b --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/taskloop-1.C @@ -0,0 +1,4 @@ +// { dg-do run } +// { dg-options "-O2 -fopenmp" } + +#include "../libgomp.c/taskloop-1.c" diff --git a/libgomp/testsuite/libgomp.c++/taskloop-2.C b/libgomp/testsuite/libgomp.c++/taskloop-2.C new file mode 100644 index 0000000..67a0e92 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/taskloop-2.C @@ -0,0 +1,6 @@ +// { dg-do run } +// { dg-options "-O2" } +// { dg-additional-options "-msse2" { target sse2_runtime } } +// { dg-additional-options "-mavx" { target avx_runtime } } + +#include "../libgomp.c/taskloop-2.c" diff --git a/libgomp/testsuite/libgomp.c++/taskloop-3.C b/libgomp/testsuite/libgomp.c++/taskloop-3.C new file mode 100644 index 0000000..bfd793c --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/taskloop-3.C @@ -0,0 +1,4 @@ +// { dg-do run } +// { dg-options "-O2 -fopenmp" } + +#include "../libgomp.c/taskloop-3.c" diff --git a/libgomp/testsuite/libgomp.c++/taskloop-4.C b/libgomp/testsuite/libgomp.c++/taskloop-4.C new file mode 100644 index 0000000..937cfcc --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/taskloop-4.C @@ -0,0 +1,4 @@ +// { dg-do run } +// { dg-options "-O2 -fopenmp" } + +#include "../libgomp.c/taskloop-4.c" diff --git a/libgomp/testsuite/libgomp.c++/taskloop-5.C b/libgomp/testsuite/libgomp.c++/taskloop-5.C new file mode 100644 index 0000000..eb46446 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/taskloop-5.C @@ -0,0 +1,73 @@ +#include <omp.h> + +__attribute__((noinline, noclone)) void +foo (int &b) +{ +#pragma omp parallel +#pragma omp single + { + bool f = false; + #pragma omp taskloop firstprivate (b, f) + for (int i = 0; i < 30; i++) + { + int q = omp_get_thread_num (); + if (!f) + { + if (b != 2) + __builtin_abort (); + } + else if (b != 8 * q) + __builtin_abort (); + b = 8 * q; + f = true; + } + } + int n; +#pragma omp parallel +#pragma omp single + { + bool f = false; + #pragma omp taskloop firstprivate (f) lastprivate (b, n) + for (int i = 0; i < 30; i++) + { + int q = omp_get_thread_num (); + if (f && b != 8 * q) + __builtin_abort (); + b = 8 * q; + n = q; + f = true; + } + } + if (b != 8 * n) + __builtin_abort (); + b = 9; +#pragma omp parallel +#pragma omp single + { + bool f = false; + #pragma omp taskloop firstprivate (b, f) lastprivate (b, n) + for (int i = 0; i < 30; i++) + { + int q = omp_get_thread_num (); + if (!f) + { + if (b != 9) + __builtin_abort (); + } + else if (b != 11 * q) + __builtin_abort (); + b = 11 * q; + n = q; + f = true; + } + } + if (b != 11 * n) + __builtin_abort (); +} + +int +main () +{ + int b = 2; + foo (b); +} diff --git a/libgomp/testsuite/libgomp.c++/taskloop-6.C b/libgomp/testsuite/libgomp.c++/taskloop-6.C new file mode 100644 index 0000000..edf7f7a --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/taskloop-6.C @@ -0,0 +1,442 @@ +// { dg-do run } + +typedef __PTRDIFF_TYPE__ ptrdiff_t; +extern "C" void abort (); + +template <typename T> +class I +{ +public: + typedef ptrdiff_t difference_type; + I (); + ~I (); + I (T *); + I (const I &); + T &operator * (); + T *operator -> (); + T &operator [] (const difference_type &) const; + I &operator = (const I &); + I &operator ++ (); + I operator ++ (int); + I &operator -- (); + I operator -- (int); + I &operator += (const difference_type &); + I &operator -= (const difference_type &); + I operator + (const difference_type &) const; + I operator - (const difference_type &) const; + template <typename S> friend bool operator == (I<S> &, I<S> &); + template <typename S> friend bool operator == (const I<S> &, const I<S> &); + template <typename S> friend bool operator < (I<S> &, I<S> &); + template <typename S> friend bool operator < (const I<S> &, const I<S> &); + template <typename S> friend bool operator <= (I<S> &, I<S> &); + template <typename S> friend bool operator <= (const I<S> &, const I<S> &); + template <typename S> friend bool operator > (I<S> &, I<S> &); + template <typename S> friend bool operator > (const I<S> &, const I<S> &); + template <typename S> friend bool operator >= (I<S> &, I<S> &); + template <typename S> friend bool operator >= (const I<S> &, const I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &); + template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &); +private: + T *p; +}; +template <typename T> I<T>::I () : p (0) {} +template <typename T> I<T>::~I () {} +template <typename T> I<T>::I (T *x) : p (x) {} +template <typename T> I<T>::I (const I &x) : p (x.p) {} +template <typename T> T &I<T>::operator * () { return *p; } +template <typename T> T *I<T>::operator -> () { return p; } +template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; } +template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; } +template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; } +template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); } +template <typename T> I<T> &I<T>::operator -- () { --p; return *this; } +template <typename T> I<T> I<T>::operator -- (int) { return I (p--); } +template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; } +template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; } +template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); } +template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); } +template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; } +template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; } +template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); } +template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); } +template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; } +template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; } +template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; } +template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; } +template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; } +template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; } +template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; } +template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; } +template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); } + +template <typename T> +class J +{ +public: + J(const I<T> &x, const I<T> &y) : b (x), e (y) {} + const I<T> &begin (); + const I<T> &end (); +private: + I<T> b, e; +}; + +template <typename T> const I<T> &J<T>::begin () { return b; } +template <typename T> const I<T> &J<T>::end () { return e; } + +int results[2000]; + +template <typename T> +void +baz (I<T> &i) +{ + if (*i < 0 || *i >= 2000) + abort (); + results[*i]++; +} + +void +f1 (const I<int> &x, const I<int> &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop num_tasks(22) + for (I<int> i = x; i <= y; i += 6) + baz (i); +} + +void +f2 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop grainsize(384) private(i) + for (i = x; i < y - 1; i = 1 - 6 + 7 + i) + baz (i); +} + +template <typename T> +void +f3 (const I<int> &x, const I<int> &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop default(none) firstprivate (x, y) + for (I<int> i = x; i <= y; i = i + 9 - 8) + baz (i); +} + +template <typename T> +void +f4 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x + 2000 - 64; i > y + 10; --i) + baz (i); +} + +void +f5 (const I<int> &x, const I<int> &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (I<int> i = x + 2000 - 64; i > y + 10; i -= 10) + baz (i); +} + +template <int N> +void +f6 (const I<int> &x, const I<int> &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (I<int> i = x + 2000 - 64; i > y + 10; i = i - 12 + 2) + { + I<int> j = i + N; + baz (j); + } +} + +template <int N> +void +f7 (I<int> i, const I<int> &x, const I<int> &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop default(none) firstprivate (x, y) + for (i = x - 10; i <= y + 10; i += N) + baz (i); +} + +template <int N> +void +f8 (J<int> j) +{ + I<int> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop default(none) num_tasks(*I<int> (j.begin ())) firstprivate (j) + for (i = j.begin (); i <= j.end () + N; i += 2) + baz (i); +} + +template <typename T, int N> +void +f9 (const I<T> &x, const I<T> &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop grainsize(163) + for (I<T> i = x; i <= y; i = i + N) + baz (i); +} + +template <typename T, int N> +void +f10 (const I<T> &x, const I<T> &y) +{ + I<T> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (i = x; i > y; i = i + N) + baz (i); +} + +template <typename T> +void +f11 (const T &x, const T &y) +{ +#pragma omp parallel + { +#pragma omp single nowait +#pragma omp taskloop nogroup + for (T i = x; i <= y; i += 3) + baz (i); +#pragma omp single nowait + { + T j = y + 3; + baz (j); + } + } +} + +template <typename T> +void +f12 (const T &x, const T &y) +{ + T i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (i = x; i > y; --i) + baz (i); +} + +template <int N> +struct K +{ + template <typename T> + static void + f13 (const T &x, const T &y) + { +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (T i = x; i <= y + N; i += N) + baz (i); + } +}; + +I<int> +f14 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x; i < y - 1; i = 1 - 6 + 7 + i) + baz (i); + return i; +} + +template <typename T> +I<int> +f15 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x + 2000 - 64; i > y + 10; --i) + baz (i); + return i; +} + +template <int N> +I<int> +f16 (I<int> i, const I<int> &x, const I<int> &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x - 10; i <= y + 10; i += N) + baz (i); + return i; +} + +template <int N> +I<int> +f17 (J<int> j) +{ + static I<int> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = j.begin (); i <= j.end () + N; i += 2) + baz (i); + return i; +} + +template <typename T, int N> +I<T> +f18 (const I<T> &x, const I<T> &y) +{ + static I<T> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x; i > y; i = i + N) + baz (i); + return i; +} + +template <typename T> +T +f19 (const T &x, const T &y) +{ + T i; +#pragma omp parallel + { +#pragma omp single nowait +#pragma omp taskloop nogroup lastprivate(i) + for (i = x; i <= y; i += 3) + baz (i); +#pragma omp single nowait + { + T j = y + 3; + baz (j); + } + } + return i; +} + +template <typename T> +T +f20 (const T &x, const T &y) +{ + T i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x; i > y; --i) + baz (i); + return i; +} + +#define check(expr) \ + for (int i = 0; i < 2000; i++) \ + if (expr) \ + { \ + if (results[i] != 1) \ + abort (); \ + results[i] = 0; \ + } \ + else if (results[i]) \ + abort () + +int +main () +{ + int a[2000]; + long b[2000]; + for (int i = 0; i < 2000; i++) + { + a[i] = i; + b[i] = i; + } + f1 (&a[10], &a[1990]); + check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0); + f2 (&a[0], &a[1999]); + check (i < 1998 && (i & 1) == 0); + f3<char> (&a[20], &a[1837]); + check (i >= 20 && i <= 1837); + f4<int> (&a[0], &a[30]); + check (i > 40 && i <= 2000 - 64); + f5 (&a[0], &a[100]); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f6<-10> (&a[10], &a[110]); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f7<6> (I<int> (), &a[12], &a[1800]); + check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); + f8<121> (J<int> (&a[14], &a[1803])); + check (i >= 14 && i <= 1924 && (i & 1) == 0); + f9<int, 7> (&a[33], &a[1967]); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<int, -7> (&a[1939], &a[17]); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<I<int> > (&a[16], &a[1981]); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<I<int> > (&a[1761], &a[37]); + check (i > 37 && i <= 1761); + K<5>::f13<I<int> > (&a[1], &a[1935]); + check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); + if (f14 (&a[0], &a[1999]) != I<int>(&a[1998])) + abort (); + check (i < 1998 && (i & 1) == 0); + if (f15<int> (&a[0], &a[30]) != I<int>(&a[40])) + abort (); + check (i > 40 && i <= 2000 - 64); + if (f16<6> (I<int> (), &a[12], &a[1800]) != I<int>(&a[1814])) + abort (); + check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); + if (f17<121> (J<int> (&a[14], &a[1803])) != I<int>(&a[1926])) + abort (); + check (i >= 14 && i <= 1924 && (i & 1) == 0); + if (f18<int, -7> (&a[1939], &a[17]) != I<int>(&a[14])) + abort (); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + if (f19<I<int> > (&a[16], &a[1981]) != I<int>(&a[1984])) + abort (); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + if (f20<I<int> > (&a[1761], &a[37]) != I<int>(&a[37])) + abort (); + check (i > 37 && i <= 1761); + f9<long, 7> (&b[33], &b[1967]); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<long, -7> (&b[1939], &b[17]); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<I<long> > (&b[16], &b[1981]); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<I<long> > (&b[1761], &b[37]); + check (i > 37 && i <= 1761); + K<5>::f13<I<long> > (&b[1], &b[1935]); + check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); + if (f18<long, -7> (&b[1939], &b[17]) != I<long>(&b[14])) + abort (); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + if (f19<I<long> > (&b[16], &b[1981]) != I<long>(&b[1984])) + abort (); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + if (f20<I<long> > (&b[1761], &b[37]) != I<long>(&b[37])) + abort (); + check (i > 37 && i <= 1761); +} diff --git a/libgomp/testsuite/libgomp.c++/taskloop-7.C b/libgomp/testsuite/libgomp.c++/taskloop-7.C new file mode 100644 index 0000000..b9a3c81e --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/taskloop-7.C @@ -0,0 +1,400 @@ +// { dg-do run } + +#include <vector> +#include <cstdlib> + +template <typename T> +class J +{ +public: + typedef typename std::vector<T>::const_iterator const_iterator; + J(const const_iterator &x, const const_iterator &y) : b (x), e (y) {} + const const_iterator &begin (); + const const_iterator &end (); +private: + const_iterator b, e; +}; + +template <typename T> +const typename std::vector<T>::const_iterator &J<T>::begin () { return b; } +template <typename T> +const typename std::vector<T>::const_iterator &J<T>::end () { return e; } + +int results[2000]; + +template <typename T> +void +baz (T &i) +{ + if (*i < 0 || *i >= 2000) + std::abort (); + results[*i]++; +} + +void +f1 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (std::vector<int>::const_iterator i = x; i <= y; i += 6) + baz (i); +} + +void +f2 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ + std::vector<int>::const_iterator i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop private(i) + for (i = x; i < y - 1; i = 1 - 6 + 7 + i) + baz (i); +} + +template <typename T> +void +f3 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (std::vector<int>::const_iterator i = x; i <= y; i = i + 9 - 8) + baz (i); +} + +template <typename T> +void +f4 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ + std::vector<int>::const_iterator i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x + 2000 - 64; i > y + 10; --i) + baz (i); +} + +void +f5 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (std::vector<int>::const_iterator i = x + 2000 - 64; i > y + 10; i -= 10) + baz (i); +} + +template <int N> +void +f6 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (std::vector<int>::const_iterator i = x + 2000 - 64; + i > y + 10; i = i - 12 + 2) + { + std::vector<int>::const_iterator j = i + N; + baz (j); + } +} + +template <int N> +void +f7 (std::vector<int>::const_iterator i, + const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (i = x - 10; i <= y + 10; i += N) + baz (i); +} + +template <int N> +void +f8 (J<int> j) +{ + std::vector<int>::const_iterator i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (i = j.begin (); i <= j.end () + N; i += 2) + baz (i); +} + +template <typename T, int N> +void +f9 (const typename std::vector<T>::const_iterator &x, + const typename std::vector<T>::const_iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (typename std::vector<T>::const_iterator i = x; i <= y; i = i + N) + baz (i); +} + +template <typename T, int N> +void +f10 (const typename std::vector<T>::const_iterator &x, + const typename std::vector<T>::const_iterator &y) +{ + typename std::vector<T>::const_iterator i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (i = x; i > y; i = i + N) + baz (i); +} + +template <typename T> +void +f11 (const T &x, const T &y) +{ +#pragma omp parallel + { +#pragma omp single nowait +#pragma omp taskloop nogroup + for (T i = x; i <= y; i += 3) + baz (i); +#pragma omp single nowait + { + T j = y + 3; + baz (j); + } + } +} + +template <typename T> +void +f12 (const T &x, const T &y) +{ + T i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (i = x; i > y; --i) + baz (i); +} + +template <int N> +struct K +{ + template <typename T> + static void + f13 (const T &x, const T &y) + { +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (T i = x; i <= y + N; i += N) + baz (i); + } +}; + +std::vector<int>::const_iterator +f14 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ + std::vector<int>::const_iterator i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x; i < y - 1; i = 1 - 6 + 7 + i) + baz (i); + return i; +} + +template <typename T> +std::vector<int>::const_iterator +f15 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ + std::vector<int>::const_iterator i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x + 2000 - 64; i > y + 10; --i) + baz (i); + return i; +} + +template <int N> +std::vector<int>::const_iterator +f16 (std::vector<int>::const_iterator i, + const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x - 10; i <= y + 10; i += N) + baz (i); + return i; +} + +template <int N> +std::vector<int>::const_iterator +f17 (J<int> j) +{ + static std::vector<int>::const_iterator i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = j.begin (); i <= j.end () + N; i += 2) + baz (i); + return i; +} + +template <typename T, int N> +typename std::vector<T>::const_iterator +f18 (const typename std::vector<T>::const_iterator &x, + const typename std::vector<T>::const_iterator &y) +{ + static typename std::vector<T>::const_iterator i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x; i > y; i = i + N) + baz (i); + return i; +} + +template <typename T> +T +f19 (const T &x, const T &y) +{ + T i; +#pragma omp parallel + { +#pragma omp single nowait +#pragma omp taskloop nogroup lastprivate(i) + for (i = x; i <= y; i += 3) + baz (i); +#pragma omp single nowait + { + T j = y + 3; + baz (j); + } + } + return i; +} + +template <typename T> +T +f20 (const T &x, const T &y) +{ + T i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x; i > y; --i) + baz (i); + return i; +} + +#define check(expr) \ + for (int i = 0; i < 2000; i++) \ + if (expr) \ + { \ + if (results[i] != 1) \ + std::abort (); \ + results[i] = 0; \ + } \ + else if (results[i]) \ + std::abort () + +int +main () +{ + std::vector<int> a(2000); + std::vector<long> b(2000); + for (int i = 0; i < 2000; i++) + { + a[i] = i; + b[i] = i; + } + f1 (a.begin () + 10, a.begin () + 1990); + check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0); + f2 (a.begin () + 0, a.begin () + 1999); + check (i < 1998 && (i & 1) == 0); + f3<char> (a.begin () + 20, a.begin () + 1837); + check (i >= 20 && i <= 1837); + f4<int> (a.begin () + 0, a.begin () + 30); + check (i > 40 && i <= 2000 - 64); + f5 (a.begin () + 0, a.begin () + 100); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f6<-10> (a.begin () + 10, a.begin () + 110); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f7<6> (std::vector<int>::const_iterator (), a.begin () + 12, + a.begin () + 1800); + check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); + f8<121> (J<int> (a.begin () + 14, a.begin () + 1803)); + check (i >= 14 && i <= 1924 && (i & 1) == 0); + f9<int, 7> (a.begin () + 33, a.begin () + 1967); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<int, -7> (a.begin () + 1939, a.begin () + 17); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<std::vector<int>::const_iterator > (a.begin () + 16, a.begin () + 1981); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<std::vector<int>::const_iterator > (a.begin () + 1761, a.begin () + 37); + check (i > 37 && i <= 1761); + K<5>::f13<std::vector<int>::const_iterator > (a.begin () + 1, + a.begin () + 1935); + check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); + if (f14 (a.begin () + 0, a.begin () + 1999) != a.begin () + 1998) + std::abort (); + check (i < 1998 && (i & 1) == 0); + if (f15<int> (a.begin () + 0, a.begin () + 30) != a.begin () + 40) + std::abort (); + check (i > 40 && i <= 2000 - 64); + if (f16<6> (std::vector<int>::const_iterator (), a.begin () + 12, + a.begin () + 1800) != a.begin () + 1814) + std::abort (); + check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); + if (f17<121> (J<int> (a.begin () + 14, a.begin () + 1803)) != a.begin () + 1926) + std::abort (); + check (i >= 14 && i <= 1924 && (i & 1) == 0); + if (f18<int, -7> (a.begin () + 1939, a.begin () + 17) != a.begin () + 14) + std::abort (); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + if (f19<std::vector<int>::const_iterator > (a.begin () + 16, a.begin () + 1981) + != a.begin () + 1984) + std::abort (); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + if (f20<std::vector<int>::const_iterator > (a.begin () + 1761, a.begin () + 37) + != a.begin () + 37) + std::abort (); + check (i > 37 && i <= 1761); + f9<long, 7> (b.begin () + 33, b.begin () + 1967); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<long, -7> (b.begin () + 1939, b.begin () + 17); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<std::vector<long>::const_iterator > (b.begin () + 16, b.begin () + 1981); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<std::vector<long>::const_iterator > (b.begin () + 1761, b.begin () + 37); + check (i > 37 && i <= 1761); + K<5>::f13<std::vector<long>::const_iterator > (b.begin () + 1, + b.begin () + 1935); + check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); + if (f18<long, -7> (b.begin () + 1939, b.begin () + 17) != b.begin () + 14) + std::abort (); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + if (f19<std::vector<long>::const_iterator > (b.begin () + 16, b.begin () + 1981) + != b.begin () + 1984) + std::abort (); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + if (f20<std::vector<long>::const_iterator > (b.begin () + 1761, b.begin () + 37) + != b.begin () + 37) + std::abort (); + check (i > 37 && i <= 1761); +} diff --git a/libgomp/testsuite/libgomp.c++/taskloop-8.C b/libgomp/testsuite/libgomp.c++/taskloop-8.C new file mode 100644 index 0000000..d164907 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/taskloop-8.C @@ -0,0 +1,250 @@ +// { dg-do run } + +#include <string> +#include <cstdlib> + +template <typename T> +class J +{ +public: + typedef typename std::basic_string<T>::iterator iterator; + J(const iterator &x, const iterator &y) : b (x), e (y) {} + const iterator &begin (); + const iterator &end (); +private: + iterator b, e; +}; + +template <typename T> +const typename std::basic_string<T>::iterator &J<T>::begin () { return b; } +template <typename T> +const typename std::basic_string<T>::iterator &J<T>::end () { return e; } + +template <typename T> +void +baz (T &i) +{ + if (*i < L'a' || *i >= L'a' + 2000) + std::abort (); + (*i)++; +} + +void +f1 (const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (std::basic_string<wchar_t>::iterator i = x; i <= y; i += 6) + baz (i); +} + +void +f2 (const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ + std::basic_string<wchar_t>::iterator i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop private(i) + for (i = x; i < y - 1; i = 1 - 6 + 7 + i) + baz (i); +} + +template <typename T> +void +f3 (const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (std::basic_string<wchar_t>::iterator i = x; i <= y; i = i + 9 - 8) + baz (i); +} + +template <typename T> +void +f4 (const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ + std::basic_string<wchar_t>::iterator i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate(i) + for (i = x + 2000 - 64; i > y + 10; --i) + baz (i); +} + +void +f5 (const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (std::basic_string<wchar_t>::iterator i = x + 2000 - 64; + i > y + 10; i -= 10) + baz (i); +} + +template <int N> +void +f6 (const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (std::basic_string<wchar_t>::iterator i = x + 2000 - 64; + i > y + 10; i = i - 12 + 2) + { + std::basic_string<wchar_t>::iterator j = i + N; + baz (j); + } +} + +template <int N> +void +f7 (std::basic_string<wchar_t>::iterator i, + const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (i = x - 10; i <= y + 10; i += N) + baz (i); +} + +template <wchar_t N> +void +f8 (J<wchar_t> j) +{ + std::basic_string<wchar_t>::iterator i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (i = j.begin (); i <= j.end () + N; i += 2) + baz (i); +} + +template <typename T, int N> +void +f9 (const typename std::basic_string<T>::iterator &x, + const typename std::basic_string<T>::iterator &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (typename std::basic_string<T>::iterator i = x; i <= y; i = i + N) + baz (i); +} + +template <typename T, int N> +void +f10 (const typename std::basic_string<T>::iterator &x, + const typename std::basic_string<T>::iterator &y) +{ + typename std::basic_string<T>::iterator i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (i = x; i > y; i = i + N) + baz (i); +} + +template <typename T> +void +f11 (const T &x, const T &y) +{ +#pragma omp parallel + { +#pragma omp single nowait +#pragma omp taskloop nogroup + for (T i = x; i <= y; i += 3) + baz (i); +#pragma omp single nowait + { + T j = y + 3; + baz (j); + } + } +} + +template <typename T> +void +f12 (const T &x, const T &y) +{ + T i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop private(i) + for (i = x; i > y; --i) + baz (i); +} + +template <int N> +struct K +{ + template <typename T> + static void + f13 (const T &x, const T &y) + { +#pragma omp parallel +#pragma omp single +#pragma omp taskloop + for (T i = x; i <= y + N; i += N) + baz (i); + } +}; + +#define check(expr) \ + for (int i = 0; i < 2000; i++) \ + if (expr) \ + { \ + if (a[i] != L'a' + i + 1) \ + std::abort (); \ + a[i] = L'a' + i; \ + } \ + else if (a[i] != L'a' + i) \ + std::abort () + +int +main () +{ + std::basic_string<wchar_t> a = L""; + for (int i = 0; i < 2000; i++) + a += L'a' + i; + f1 (a.begin () + 10, a.begin () + 1990); + check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0); + f2 (a.begin () + 0, a.begin () + 1999); + check (i < 1998 && (i & 1) == 0); + f3<char> (a.begin () + 20, a.begin () + 1837); + check (i >= 20 && i <= 1837); + f4<int> (a.begin () + 0, a.begin () + 30); + check (i > 40 && i <= 2000 - 64); + f5 (a.begin () + 0, a.begin () + 100); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f6<-10> (a.begin () + 10, a.begin () + 110); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f7<6> (std::basic_string<wchar_t>::iterator (), a.begin () + 12, + a.begin () + 1800); + check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); + f8<121> (J<wchar_t> (a.begin () + 14, a.begin () + 1803)); + check (i >= 14 && i <= 1924 && (i & 1) == 0); + f9<wchar_t, 7> (a.begin () + 33, a.begin () + 1967); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<wchar_t, -7> (a.begin () + 1939, a.begin () + 17); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<std::basic_string<wchar_t>::iterator > (a.begin () + 16, + a.begin () + 1981); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<std::basic_string<wchar_t>::iterator > (a.begin () + 1761, + a.begin () + 37); + check (i > 37 && i <= 1761); + K<5>::f13<std::basic_string<wchar_t>::iterator > (a.begin () + 1, + a.begin () + 1935); + check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); +} diff --git a/libgomp/testsuite/libgomp.c++/taskloop-9.C b/libgomp/testsuite/libgomp.c++/taskloop-9.C new file mode 100644 index 0000000..65abc31 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/taskloop-9.C @@ -0,0 +1,323 @@ +// { dg-do run } + +typedef __PTRDIFF_TYPE__ ptrdiff_t; +extern "C" void abort (); + +template <typename T> +class I +{ +public: + typedef ptrdiff_t difference_type; + I (); + ~I (); + I (T *); + I (const I &); + T &operator * (); + T *operator -> (); + T &operator [] (const difference_type &) const; + I &operator = (const I &); + I &operator ++ (); + I operator ++ (int); + I &operator -- (); + I operator -- (int); + I &operator += (const difference_type &); + I &operator -= (const difference_type &); + I operator + (const difference_type &) const; + I operator - (const difference_type &) const; + template <typename S> friend bool operator == (I<S> &, I<S> &); + template <typename S> friend bool operator == (const I<S> &, const I<S> &); + template <typename S> friend bool operator < (I<S> &, I<S> &); + template <typename S> friend bool operator < (const I<S> &, const I<S> &); + template <typename S> friend bool operator <= (I<S> &, I<S> &); + template <typename S> friend bool operator <= (const I<S> &, const I<S> &); + template <typename S> friend bool operator > (I<S> &, I<S> &); + template <typename S> friend bool operator > (const I<S> &, const I<S> &); + template <typename S> friend bool operator >= (I<S> &, I<S> &); + template <typename S> friend bool operator >= (const I<S> &, const I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &); + template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &); +private: + T *p; +}; +template <typename T> I<T>::I () : p (0) {} +template <typename T> I<T>::~I () { p = (T *) 0; } +template <typename T> I<T>::I (T *x) : p (x) {} +template <typename T> I<T>::I (const I &x) : p (x.p) {} +template <typename T> T &I<T>::operator * () { return *p; } +template <typename T> T *I<T>::operator -> () { return p; } +template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; } +template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; } +template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; } +template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); } +template <typename T> I<T> &I<T>::operator -- () { --p; return *this; } +template <typename T> I<T> I<T>::operator -- (int) { return I (p--); } +template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; } +template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; } +template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); } +template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); } +template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; } +template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; } +template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); } +template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); } +template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; } +template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; } +template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; } +template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; } +template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; } +template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; } +template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; } +template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; } +template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); } + +template <typename T> +class J +{ +public: + J(const I<T> &x, const I<T> &y) : b (x), e (y) {} + const I<T> &begin (); + const I<T> &end (); +private: + I<T> b, e; +}; + +template <typename T> const I<T> &J<T>::begin () { return b; } +template <typename T> const I<T> &J<T>::end () { return e; } + +int results[2000]; + +template <typename T> +void +baz (I<T> &i) +{ + if (*i < 0 || *i >= 2000) + abort (); + results[*i]++; +} + +I<int> +f1 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel shared (i) + { + #pragma omp single + #pragma omp taskloop lastprivate (i) + for (i = x; i < y - 1; ++i) + baz (i); + #pragma omp single + i += 3; + } + return I<int> (i); +} + +I<int> +f2 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate (i) + for (i = x; i < y - 1; i = 1 - 6 + 7 + i) + baz (i); + return I<int> (i); +} + +template <typename T> +I<int> +f3 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate (i) + for (i = x + 1000 - 64; i <= y - 10; i++) + baz (i); + return i; +} + +template <typename T> +I<int> +f4 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate (i) + for (i = x + 2000 - 64; i > y + 10; --i) + baz (i); + return I<int> (i); +} + +template <typename T> +I<int> +f5 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate (i) + for (i = x; i > y + T (6); i--) + baz (i); + return i; +} + +template <typename T> +I<int> +f6 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate (i) + for (i = x - T (7); i > y; i -= T (2)) + baz (i); + return I<int> (i); +} + +template <int N> +I<int> +f7 (I<int> i, const I<int> &x, const I<int> &y) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate (i) + for (i = x - 10; i <= y + 10; i += N) + baz (i); + return I<int> (i); +} + +template <int N> +I<int> +f8 (J<int> j) +{ + I<int> i; +#pragma omp parallel shared (i) + #pragma omp single + #pragma omp taskloop lastprivate (i) + for (i = j.begin (); i <= j.end () + N; i += 2) + baz (i); + return i; +} + +I<int> i9; + +template <long N> +I<int> & +f9 (J<int> j) +{ +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate (i9) + for (i9 = j.begin () + N; i9 <= j.end () - N; i9 = i9 - N) + baz (i9); + return i9; +} + +template <typename T, int N> +I<T> +f10 (const I<T> &x, const I<T> &y) +{ + I<T> i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate (i) + for (i = x; i > y; i = i + N) + baz (i); + return i; +} + +template <typename T, typename U> +T +f11 (T i, const T &x, const T &y) +{ +#pragma omp parallel + #pragma omp single + #pragma omp taskloop lastprivate (i) + for (i = x + U (2); i <= y + U (1); i = U (2) + U (3) + i) + baz (i); + return T (i); +} + +template <typename T> +T +f12 (const T &x, const T &y) +{ + T i; +#pragma omp parallel +#pragma omp single +#pragma omp taskloop lastprivate (i) + for (i = x; i > y; --i) + baz (i); + return i; +} + +#define check(expr) \ + for (int i = 0; i < 2000; i++) \ + if (expr) \ + { \ + if (results[i] != 1) \ + abort (); \ + results[i] = 0; \ + } \ + else if (results[i]) \ + abort () + +int +main () +{ + int a[2000]; + long b[2000]; + for (int i = 0; i < 2000; i++) + { + a[i] = i; + b[i] = i; + } + if (*f1 (&a[10], &a[1873]) != 1875) + abort (); + check (i >= 10 && i < 1872); + if (*f2 (&a[0], &a[1998]) != 1998) + abort (); + check (i < 1997 && (i & 1) == 0); + if (*f3<int> (&a[10], &a[1971]) != 1962) + abort (); + check (i >= 946 && i <= 1961); + if (*f4<int> (&a[0], &a[30]) != 40) + abort (); + check (i > 40 && i <= 2000 - 64); + if (*f5<short> (&a[1931], &a[17]) != 23) + abort (); + check (i > 23 && i <= 1931); + if (*f6<long> (&a[1931], &a[17]) != 16) + abort (); + check (i > 17 && i <= 1924 && (i & 1) == 0); + if (*f7<6> (I<int> (), &a[12], &a[1800]) != 1814) + abort (); + check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); + if (*f8<121> (J<int> (&a[14], &a[1803])) != 1926) + abort (); + check (i >= 14 && i <= 1924 && (i & 1) == 0); + if (*f9<-3L> (J<int> (&a[27], &a[1761])) != 1767) + abort (); + check (i >= 24 && i <= 1764 && (i % 3) == 0); + if (*f10<int, -7> (&a[1939], &a[17]) != 14) + abort (); + check (i >= 21 && i <= 1939 && i % 7 == 0); + if (*f11<I<int>, short> (I<int> (), &a[71], &a[1941]) != 1943) + abort (); + check (i >= 73 && i <= 1938 && (i - 73) % 5 == 0); + if (*f12<I<int> > (&a[1761], &a[37]) != 37) + abort (); + check (i > 37 && i <= 1761); + if (*f10<long, -7> (&b[1939], &b[17]) != 14) + abort (); + check (i >= 21 && i <= 1939 && i % 7 == 0); + if (*f11<I<long>, short> (I<long> (), &b[71], &b[1941]) != 1943) + abort (); + check (i >= 73 && i <= 1938 && (i - 73) % 5 == 0); + if (*f12<I<long> > (&b[1761], &b[37]) != 37) + abort (); + check (i > 37 && i <= 1761); +} |