OpenMP-Examples/devices/sources/target_data.3.c
2022-11-04 09:35:42 -07:00

37 lines
826 B
C

/*
* @@name: target_data.3
* @@type: C
* @@operation: compile
* @@expect: success
* @@version: omp_4.0
*/
#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.
*/