#ifndef HEADER
#define HEADER
#ifdef OMP5
#define CONDITIONAL conditional :
#else
#define CONDITIONAL
#endif
long long get_val() { extern void mayThrow(); mayThrow(); return 0; }
double *g_ptr;
struct S {
int a, b;
};
void simple(float *a, float *b, float *c, float *d) {
S s, *p;
#ifdef OMP5
#pragma omp simd if (simd: true) nontemporal(a, b, c, d, s)
#else
#pragma omp simd
#endif
for (int i = 3; i < 32; i += 5) {
a[i] = b[i] * c[i] * d[i] + s.a + p->a;
}
long long k = get_val();
#pragma omp simd linear(k : 3)
for (int i = 10; i > 1; i--) {
a[k]++;
k = k + 3;
}
int lin = 12;
#pragma omp simd linear(lin : get_val()), linear(g_ptr)
for (unsigned long long it = 2000; it >= 600; it-=400) {
*g_ptr++ = 0.0;
a[it + lin]++;
}
#pragma omp simd
for (short it = 6; it <= 20; it-=-4) {
}
#pragma omp simd
for (unsigned char it = 'z'; it >= 'a'; it+=-1) {
}
#pragma omp simd
for (unsigned i=100; i<10; i+=10) {
}
int A;
A = -1;
#pragma omp simd lastprivate(CONDITIONAL A)
for (long long i = -10; i < 10; i += 3) {
A += i;
}
int R;
R = -1;
#ifdef OMP5
#pragma omp simd reduction(*:R) if(A)
#else
#pragma omp simd reduction(*:R)
#endif
for (long long i = -10; i < 10; i += 3) {
R *= i;
}
}
template <class T, unsigned K> T tfoo(T a) { return a + K; }
template <typename T, unsigned N>
int templ1(T a, T *z) {
#pragma omp simd collapse(N)
for (int i = 0; i < N * 2; i++) {
for (long long j = 0; j < (N + N + N + N); j += 2) {
z[i + j] = a + tfoo<T, N>(i + j);
}
}
return 0;
}
void inst_templ1() {
float a;
float z[100];
templ1<float,2> (a, z);
}
typedef int MyIdx;
class IterDouble {
double *Ptr;
public:
IterDouble operator++ () const {
IterDouble n;
n.Ptr = Ptr + 1;
return n;
}
bool operator < (const IterDouble &that) const {
return Ptr < that.Ptr;
}
double & operator *() const {
return *Ptr;
}
MyIdx operator - (const IterDouble &that) const {
return (MyIdx) (Ptr - that.Ptr);
}
IterDouble operator + (int Delta) {
IterDouble re;
re.Ptr = Ptr + Delta;
return re;
}
};
void iter_simple(IterDouble ia, IterDouble ib, IterDouble ic) {
#pragma omp simd
for (IterDouble i = ia; i < ib; ++i) {
*i = *ic * 0.5;
++ic;
}
}
void collapsed(float *a, float *b, float *c, float *d) {
int i; unsigned j; short l; #pragma omp simd collapse(4)
for (i = 1; i < 3; i++) for (j = 2u; j < 5u; j++) for (int k = 3; k <= 6; k++) for (l = 4; l < 9; ++l) {
float res = b[j] * c[k];
a[i] = res * d[l];
}
}
extern char foo();
extern double globalfloat;
void widened(float *a, float *b, float *c, float *d) {
int i; short j; globalfloat = 1.0;
int localint = 1;
#pragma omp simd collapse(2) private(globalfloat, localint)
for (i = 1; i < 3; i++) for (j = 0; j < foo(); j++) {
globalfloat = (float)j/i;
float res = b[j] * c[j];
a[i] = res * d[i];
localint = (int)j;
}
localint = (int)j;
}
void linear(float *a) {
long long val = 0;
long long &k = val;
#pragma omp simd linear(k : 3)
for (int i = 10; i > 1; i--) {
a[k]++;
k = k + 3;
}
#pragma omp simd linear(val(k) : 3)
for (int i = 10; i > 1; i--) {
a[k]++;
k = k + 3;
}
#pragma omp simd linear(uval(k) : 3)
for (int i = 10; i > 1; i--) {
a[k]++;
k = k + 3;
}
}
#ifdef OMP5
void inner_simd() {
double a, b;
#pragma omp simd nontemporal(a)
for (int i = 0; i < 10; ++i) {
#pragma omp simd nontemporal(b)
for (int k = 0; k < 10; ++k) {
a = b;
}
a = b;
}
}
extern struct T t;
struct Base {
float a;
};
struct T : public Base {
void foo() {
#pragma omp simd nontemporal(Base::a)
for (int i = 0; i < 10; ++i) {
Base::a = 0;
t.a = 0;
}
}
} t;
void bartfoo() {
t.foo();
}
#endif int bar() { extern void mayThrow(); mayThrow(); return 0; };
void parallel_simd(float *a) {
#pragma omp parallel
#pragma omp simd
for (unsigned i = 131071; i <= 2147483647; i += 127)
a[i] += bar();
}
struct SS {
SS(): a(0) {}
SS(int v) : a(v) {}
int a;
typedef int type;
};
template <typename T>
class S7 : public T {
protected:
T *a;
T b[2];
S7() : a(0) {}
public:
S7(typename T::type &v) : a((T*)&v) {
#pragma omp simd aligned(a)
for (int k = 0; k < a->a; ++k)
++this->a->a;
#pragma omp simd aligned(this->b : 8)
for (int k = 0; k < a->a; ++k)
++a->a;
}
};
class S8 : private IterDouble, public S7<SS> {
S8() {}
public:
S8(int v) : S7<SS>(v){
#pragma omp parallel private(a)
#pragma omp simd aligned(S7<SS>::a)
for (int k = 0; k < a->a; ++k)
++this->a->a;
#pragma omp parallel shared(b)
#pragma omp simd aligned(this->b: 4)
for (int k = 0; k < a->a; ++k)
++a->a;
}
};
S8 s8(0);
#endif