OpenMP-Examples/sources/Example_target_data.3.c

37 lines
806 B
C

/*
* @@name: target_data.3c
* @@type: C
* @@compilable: yes
* @@linkable: no
* @@expect: success
*/
#include <math.h>
#define COLS 100
void gramSchmidt(float Q[][COLS], const int rows)
{
int cols = 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 map(tofrom: tmp)
#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;
}
}
/* Note: The variable tmp is now mapped with tofrom, for correct
execution with 4.5 (and pre-4.5) compliant compilers. See Devices Intro.
*/