1 #define size 8 2 3 #pragma omp declare target 4 int identity(int x)5identity (int x) 6 { 7 return x; 8 } 9 10 int expx(int x,int n)11expx (int x, int n) 12 { 13 for (int i = 0; i < n - 1; i++) 14 x *= x; 15 16 return x; 17 } 18 19 float init(int x,int y)20init (int x, int y) 21 { 22 int x1 = identity (identity (identity (identity (x)))); 23 int y1 = identity (identity (identity (identity (y)))); 24 25 int x2 = expx (x1, 2); 26 int y2 = expx (y1, 2); 27 28 return (x2 + y2); 29 } 30 #pragma omp end declare target 31 32 int main()33main () 34 { 35 int i, j; 36 int a[size][size]; 37 38 #pragma omp target teams map(to:a[:size][:size]) 39 #pragma omp distribute parallel for default(none) private(i, j) shared(a) 40 for (i = 0; i < size; ++i) 41 for (j = 0; j < size; ++j) 42 a[i][j] = init (i, j); 43 44 for (i = 0; i < size; ++i) 45 for (j = 0; j < size; ++j) 46 if (i * i + j * j != a[i][j]) 47 __builtin_abort (); 48 49 return 0; 50 } 51