mirror of
https://github.com/OpenMP/Examples.git
synced 2025-04-14 02:11:25 +01:00
37 lines
1.0 KiB
C
37 lines
1.0 KiB
C
/*
|
|
* @@name: metadirective.3
|
|
* @@type: C
|
|
* @@operation: run
|
|
* @@expect: success
|
|
* @@version: omp_5.2
|
|
*/
|
|
#include <stdio.h>
|
|
#include <math.h>
|
|
#define N 1000
|
|
|
|
#pragma omp begin declare target
|
|
void exp_pi_diff(double *d, double my_pi){
|
|
#pragma omp metadirective \
|
|
when( construct={target}: distribute parallel for ) \
|
|
otherwise( parallel for simd )
|
|
for(int i = 0; i<N; i++) d[i] = exp( (M_PI-my_pi)*i );
|
|
}
|
|
#pragma omp end declare target
|
|
|
|
int main()
|
|
{
|
|
//Calculates sequence of exponentials: (M_PI-my_pi) * index
|
|
//M_PI is from math.h, and my_pi is user provided.
|
|
|
|
double d[N];
|
|
double my_pi=3.14159265358979e0;
|
|
|
|
#pragma omp target teams map(tofrom: d[0:N])
|
|
exp_pi_diff(d,my_pi);
|
|
// value should be near 1
|
|
printf("d[N-1] = %20.14f\n",d[N-1]); // ...= 1.00000000000311
|
|
|
|
exp_pi_diff(d,my_pi); // value should be near 1
|
|
printf("d[N-1] = %20.14f\n",d[N-1]); // ...= 1.00000000000311
|
|
}
|