target-critical-1.c 1.1 KB

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