OpenMP-Examples/sources/Example_declare_target.5c.c
2015-01-13 11:38:24 -08:00

34 lines
619 B
C

/*
* @@name: declare_target.5c
* @@type: C
* @@compilable: yes
* @@linkable: no
* @@expect: success
*/
#define N 10000
#define M 1024
#pragma omp declare target
float Q[N][N];
#pragma omp declare simd uniform(i) linear(k) notinbranch
float P(const int i, const int k)
{
return Q[i][k] * Q[k][i];
}
#pragma omp end declare target
float accum(void)
{
float tmp = 0.0;
int i, k;
#pragma omp target
#pragma omp parallel for reduction(+:tmp)
for (i=0; i < N; i++) {
float tmp1 = 0.0;
#pragma omp simd reduction(+:tmp1)
for (k=0; k < M; k++) {
tmp1 += P(i,k);
}
tmp += tmp1;
}
return tmp;
}