lastprivate-conditional-2.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* { dg-do run } */
  2. /* { dg-require-effective-target tls_runtime } */
  3. /* { dg-additional-options "-std=gnu99" {target c } } */
  4. #include <omp.h>
  5. #include <stdlib.h>
  6. int r, s, u, v, r2, s2, u2, v2, r3, s3, u3, v3, t;
  7. long long w, w2, w3, p, p2, p3;
  8. int *x, *x2, *x3;
  9. short y, y2, y3;
  10. int z;
  11. int thr1, thr2;
  12. #pragma omp threadprivate (thr1, thr2)
  13. void
  14. foo (int *a, long long int b, long long int c)
  15. {
  16. int i;
  17. long long j;
  18. #pragma omp for lastprivate (conditional: u, x) reduction (task, +: t)
  19. for (i = 15; i < 64; i++)
  20. {
  21. ++t;
  22. if ((a[i] % 5) == 3)
  23. u = i;
  24. if ((a[i] % 7) == 2)
  25. x = &a[i];
  26. }
  27. #pragma omp for lastprivate (conditional: v) reduction (+:r, s) schedule (nonmonotonic: static) reduction (task, +: t)
  28. for (i = -3; i < 119; i += 2)
  29. {
  30. ++s;
  31. ++t;
  32. if ((a[i + 4] % 11) == 9)
  33. v = i;
  34. else
  35. ++r;
  36. }
  37. #pragma omp for schedule (monotonic: static) lastprivate (conditional: w) reduction (task, +: t)
  38. for (j = b; j < b + 115 * c; j += (b & 3) + 7)
  39. {
  40. if ((a[j] % 13) == 5)
  41. w = j * 2;
  42. ++t;
  43. }
  44. #pragma omp for schedule (auto) lastprivate (conditional: p) collapse(3) reduction (task, +: t)
  45. for (i = -5; i < (int) (b + 5); i += 2)
  46. for (j = b + 12 + c; j > b; --j)
  47. for (int k = 0; k < 5; k += c)
  48. {
  49. ++t;
  50. if (((((i + 5) * 13 + (13 - j)) * 5 + k) % 17) == 6)
  51. p = i * 10000 + j * 100 + k;
  52. }
  53. #pragma omp for schedule (nonmonotonic: static, 2) reduction (task, +: t) lastprivate (conditional: u2, x2)
  54. for (i = 15; i < 64; i++)
  55. {
  56. if ((a[i] % 5) == 3)
  57. u2 = i;
  58. if ((a[i] % 7) == 2)
  59. x2 = &a[i];
  60. t++;
  61. }
  62. #pragma omp for schedule (static, 3) lastprivate (conditional: v2) reduction (+:r2, s2) reduction (task, +: t)
  63. for (i = -3; i < 119; i += 2)
  64. {
  65. ++s2;
  66. if ((a[i + 4] % 11) == 9)
  67. v2 = i;
  68. else
  69. ++r2;
  70. t++;
  71. }
  72. #pragma omp for lastprivate (conditional: w2) schedule (static, 1) reduction (task, +: t)
  73. for (j = b; j < b + 115 * c; j += (b & 3) + 7)
  74. {
  75. if ((a[j] % 13) == 5)
  76. w2 = j * 2;
  77. t += 1;
  78. }
  79. #pragma omp for schedule (static, 3) collapse (3) reduction (task, +: t) lastprivate (conditional: p2)
  80. for (i = -5; i < (int) (b + 5); i += 2)
  81. for (j = b + 12 + c; j > b; --j)
  82. for (int k = 0; k < 5; k += c)
  83. {
  84. ++t;
  85. if (((((i + 5) * 13 + (13 - j)) * 5 + k) % 17) == 6)
  86. p2 = i * 10000 + j * 100 + k;
  87. }
  88. #pragma omp for lastprivate (conditional: u3, x3) reduction (task, +: t) schedule (runtime)
  89. for (i = 15; i < 64; i++)
  90. {
  91. t = t + 1;
  92. if ((a[i] % 5) == 3)
  93. u3 = i;
  94. if ((a[i] % 7) == 2)
  95. x3 = &a[i];
  96. }
  97. #pragma omp for reduction (task, +: t) lastprivate (conditional: v3) reduction (+:r3, s3) schedule (nonmonotonic: dynamic)
  98. for (i = -3; i < 119; i += 2)
  99. {
  100. ++s3;
  101. if ((a[i + 4] % 11) == 9)
  102. v3 = i;
  103. else
  104. ++r3;
  105. ++t;
  106. }
  107. #pragma omp for schedule (monotonic: guided, 3) lastprivate (conditional: w3) reduction (task, +: t)
  108. for (j = b; j < b + 115 * c; j += (b & 3) + 7)
  109. {
  110. if ((a[j] % 13) == 5)
  111. w3 = j * 2;
  112. t++;
  113. }
  114. #pragma omp for schedule (dynamic, 4) lastprivate (conditional: p3) collapse(3) reduction (task, +: t)
  115. for (i = -5; i < (int) (b + 5); i += 2)
  116. for (j = b + 12 + c; j > b; --j)
  117. for (int k = 0; k < 5; k += c)
  118. {
  119. ++t;
  120. if (((((i + 5) * 13 + (13 - j)) * 5 + k) % 17) == 6)
  121. p3 = i * 10000 + j * 100 + k;
  122. }
  123. /* Nasty testcase, verify that even a no-op assignment is accounted
  124. for in lastprivate(conditional:). */
  125. #pragma omp for schedule (monotonic: static, 2) firstprivate (z) \
  126. lastprivate (conditional: z) reduction (task, +: t)
  127. for (int k = -2000; k < 8000; ++k)
  128. {
  129. t++;
  130. if (k < 3000 && (k & 3) == 1)
  131. {
  132. z = k;
  133. thr1 = k;
  134. }
  135. else if (k == 7931)
  136. {
  137. z = z;
  138. thr2 = 1;
  139. }
  140. }
  141. if (thr2 && z != thr1)
  142. abort ();
  143. }
  144. int
  145. main ()
  146. {
  147. int a[128], i;
  148. volatile int j = 0;
  149. for (i = 0; i < 128; i++)
  150. a[i] = i;
  151. w = 1234;
  152. #pragma omp parallel
  153. foo (a, j, j + 1);
  154. if (u != 63 || v != 115 || w != 140 || x != &a[58] || r != 55 || s != 61 || p != 30104)
  155. abort ();
  156. if (u2 != 63 || v2 != 115 || w2 != 140 || x2 != &a[58] || r2 != 55 || s2 != 61 || p2 != 30104)
  157. abort ();
  158. if (u3 != 63 || v3 != 115 || w3 != 140 || x3 != &a[58] || r3 != 55 || s3 != 61 || p3 != 30104)
  159. abort ();
  160. if (t != 11356)
  161. abort ();
  162. return 0;
  163. }