pr26943-4.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* PR c++/26943 */
  2. /* { dg-do run } */
  3. extern int omp_set_dynamic (int);
  4. extern void omp_set_nested (int);
  5. extern int omp_get_thread_num (void);
  6. extern void abort (void);
  7. extern void GOMP_barrier (void);
  8. int a = 8, b = 12, c = 16, d = 20, j = 0, l = 0;
  9. char e[10] = "a", f[10] = "b", g[10] = "c", h[10] = "d";
  10. volatile int k;
  11. int
  12. main (void)
  13. {
  14. int i;
  15. omp_set_dynamic (0);
  16. omp_set_nested (1);
  17. #pragma omp parallel num_threads (2) reduction (+:l) \
  18. firstprivate (a, b, c, d, e, f, g, h, j)
  19. if (k == omp_get_thread_num ())
  20. {
  21. #pragma omp parallel for shared (a, e) firstprivate (b, f) \
  22. lastprivate (c, g) private (d, h) \
  23. schedule (static, 1) num_threads (4) \
  24. reduction (+:j)
  25. for (i = 0; i < 4; i++)
  26. {
  27. if (a != 8 || b != 12 || e[0] != 'a' || f[0] != 'b')
  28. j++;
  29. GOMP_barrier ();
  30. #pragma omp atomic
  31. a += i;
  32. b += i;
  33. c = i;
  34. d = i;
  35. #pragma omp atomic
  36. e[0] += i;
  37. f[0] += i;
  38. g[0] = 'g' + i;
  39. h[0] = 'h' + i;
  40. GOMP_barrier ();
  41. if (a != 8 + 6 || b != 12 + i || c != i || d != i)
  42. j += 8;
  43. if (e[0] != 'a' + 6 || f[0] != 'b' + i || g[0] != 'g' + i)
  44. j += 64;
  45. if (h[0] != 'h' + i)
  46. j += 512;
  47. }
  48. if (j || a != 8 + 6 || b != 12 || c != 3 || d != 20)
  49. ++l;
  50. if (e[0] != 'a' + 6 || f[0] != 'b' || g[0] != 'g' + 3 || h[0] != 'd')
  51. l += 8;
  52. }
  53. if (l)
  54. abort ();
  55. if (a != 8 || b != 12 || c != 16 || d != 20)
  56. abort ();
  57. if (e[0] != 'a' || f[0] != 'b' || g[0] != 'c' || h[0] != 'd')
  58. abort ();
  59. return 0;
  60. }