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

26 lines
622 B
C

/*
* @@name: target_data.3c
* @@type: C
* @@compilable: yes
* @@linkable: no
* @@expect: success
*/
#include <math.h>
void gramSchmidt(restrict float Q[][COLS], const int rows, const int cols)
{
#pragma omp target data map(Q[0:rows][0:cols])
for(int k=0; k < cols; k++)
{
double tmp = 0.0;
#pragma omp target
#pragma omp parallel for reduction(+:tmp)
for(int i=0; i < rows; i++)
tmp += (Q[i][k] * Q[i][k]);
tmp = 1/sqrt(tmp);
#pragma omp target
#pragma omp parallel for
for(int i=0; i < rows; i++)
Q[i][k] *= tmp;
}
}