pr33880.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* PR middle-end/33880 */
  2. /* { dg-do run } */
  3. extern void abort (void);
  4. void
  5. test1 (void)
  6. {
  7. int i = 0, j = 0;
  8. void bar (void)
  9. {
  10. i++;
  11. j++;
  12. }
  13. bar ();
  14. #pragma omp parallel for num_threads(4)
  15. for (i = 0; i < 100; i++)
  16. #pragma omp atomic
  17. j += 1;
  18. if (j != 101)
  19. abort ();
  20. #pragma omp parallel for lastprivate(i) num_threads(2)
  21. for (i = 0; i < 100; i++)
  22. #pragma omp atomic
  23. j += 1;
  24. if (i != 100)
  25. abort ();
  26. i = 3;
  27. bar ();
  28. if (j != 202)
  29. abort ();
  30. if (i != 4)
  31. abort ();
  32. }
  33. void
  34. test2 (void)
  35. {
  36. int i = -1, j = 99, k, l = 9, m = 0;
  37. void bar (void)
  38. {
  39. i++;
  40. j++;
  41. l++;
  42. m++;
  43. }
  44. bar ();
  45. #pragma omp parallel for num_threads(4)
  46. for (k = i; k < j; k += l)
  47. #pragma omp atomic
  48. m += 1;
  49. bar ();
  50. if (i != 1 || j != 101 || l != 11 || m != 12)
  51. abort ();
  52. }
  53. void
  54. test3 (void)
  55. {
  56. int i, j, k, l, m;
  57. void bar (void)
  58. {
  59. #pragma omp parallel for num_threads(4)
  60. for (i = j; i < k; i += l)
  61. #pragma omp atomic
  62. m += 1;
  63. }
  64. void baz (void)
  65. {
  66. #pragma omp parallel for num_threads(2) lastprivate(i)
  67. for (i = j; i < k * 2; i += l / 2)
  68. #pragma omp atomic
  69. m += 1;
  70. }
  71. i = 7;
  72. j = 0;
  73. k = 100;
  74. l = 2;
  75. m = 0;
  76. bar ();
  77. if (j != 0 || k != 100 || l != 2 || m != 50)
  78. abort ();
  79. baz ();
  80. if (i != 200 || j != 0 || k != 100 || l != 2 || m != 250)
  81. abort ();
  82. }
  83. void
  84. test4 (void)
  85. {
  86. int i, j, k, l, m = 0;
  87. int foo (void)
  88. {
  89. return j;
  90. }
  91. int bar (void)
  92. {
  93. return k;
  94. }
  95. int baz (void)
  96. {
  97. return l;
  98. }
  99. j = 0;
  100. k = 1000;
  101. l = 2;
  102. #pragma omp parallel for num_threads(8) lastprivate(i)
  103. for (i = foo (); i < bar (); i += baz ())
  104. #pragma omp atomic
  105. m += 1;
  106. if (i != 1000 || m != 500 || j != 0 || k != 1000 || l != 2)
  107. abort ();
  108. }
  109. int
  110. main (void)
  111. {
  112. test1 ();
  113. test2 ();
  114. test3 ();
  115. test4 ();
  116. return 0;
  117. }