OpenMP-Examples/sources/Example_declare_target.4.c

28 lines
645 B
C

/*
* @@name: declare_target.4c
* @@type: C
* @@compilable: yes
* @@linkable: no
* @@expect: success
*/
#define N 10000
#pragma omp declare target
float Q[N][N];
float Pfun(const int i, const int k)
{ return Q[i][k] * Q[k][i]; }
#pragma omp end declare target
float accum(int k)
{
float tmp = 0.0;
#pragma omp target update to(Q)
#pragma omp target map(tofrom: tmp)
#pragma omp parallel for reduction(+:tmp)
for(int i=0; i < N; i++)
tmp += Pfun(i,k);
return tmp;
}
/* Note: The variable tmp is now mapped with tofrom, for correct
execution with 4.5 (and pre-4.5) compliant compilers. See Devices Intro.
*/