1 /* { dg-do run } */ 2 3 #include <omp.h> 4 #include <stdlib.h> 5 6 #define N 2000 7 8 #pragma omp declare target foo()9int foo () 10 { 11 int A[N]; 12 int i, nthreads; 13 int res = 0; 14 15 #pragma omp parallel shared (A, nthreads) 16 { 17 #pragma omp master 18 nthreads = omp_get_num_threads (); 19 20 #pragma omp for 21 for (i = 0; i < N; i++) 22 A[i] = 0; 23 24 #pragma omp critical (crit1) 25 for (i = 0; i < N; i++) 26 A[i]++; 27 } 28 29 for (i = 0; i < N; i++) 30 if (A[i] != nthreads) 31 res = 1; 32 33 return res; 34 } 35 #pragma omp end declare target 36 main()37int main () 38 { 39 int res1, res2; 40 41 #pragma omp target map (from: res1, res2) 42 { 43 int B[N]; 44 int i, nthreads; 45 46 res1 = foo (); 47 48 #pragma omp parallel shared (B, nthreads) 49 { 50 #pragma omp master 51 nthreads = omp_get_num_threads (); 52 53 #pragma omp for 54 for (i = 0; i < N; i++) 55 B[i] = 0; 56 57 #pragma omp critical (crit2) 58 for (i = 0; i < N; i++) 59 B[i]++; 60 } 61 62 res2 = 0; 63 for (i = 0; i < N; i++) 64 if (B[i] != nthreads) 65 res2 = 1; 66 } 67 68 if (res1 || res2) 69 abort (); 70 71 return 0; 72 } 73