lastprivate-conditional-1.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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;
  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) nowait
  19. for (i = 15; i < 64; i++)
  20. {
  21. if ((a[i] % 5) == 3)
  22. u = i;
  23. if ((a[i] % 7) == 2)
  24. x = &a[i];
  25. }
  26. #pragma omp for nowait lastprivate (conditional: v) reduction (+:r, s) schedule (nonmonotonic: static)
  27. for (i = -3; i < 119; i += 2)
  28. {
  29. ++s;
  30. if ((a[i + 4] % 11) == 9)
  31. v = i;
  32. else
  33. ++r;
  34. }
  35. #pragma omp for schedule (monotonic: static) lastprivate (conditional: w) nowait
  36. for (j = b; j < b + 115 * c; j += (b & 3) + 7)
  37. if ((a[j] % 13) == 5)
  38. w = j * 2;
  39. #pragma omp for schedule (auto) lastprivate (conditional: p) collapse(3)
  40. for (i = -5; i < (int) (b + 5); i += 2)
  41. for (j = b + 12 + c; j > b; --j)
  42. for (int k = 0; k < 5; k += c)
  43. if (((((i + 5) * 13 + (13 - j)) * 5 + k) % 17) == 6)
  44. p = i * 10000 + j * 100 + k;
  45. #pragma omp for schedule (nonmonotonic: static, 2) nowait lastprivate (conditional: u2, x2)
  46. for (i = 15; i < 64; i++)
  47. {
  48. if ((a[i] % 5) == 3)
  49. u2 = i;
  50. if ((a[i] % 7) == 2)
  51. x2 = &a[i];
  52. }
  53. #pragma omp for schedule (static, 3) lastprivate (conditional: v2) reduction (+:r2, s2)
  54. for (i = -3; i < 119; i += 2)
  55. {
  56. ++s2;
  57. if ((a[i + 4] % 11) == 9)
  58. v2 = i;
  59. else
  60. ++r2;
  61. }
  62. #pragma omp for lastprivate (conditional: w2) schedule (static, 1) nowait
  63. for (j = b; j < b + 115 * c; j += (b & 3) + 7)
  64. if ((a[j] % 13) == 5)
  65. w2 = j * 2;
  66. #pragma omp for schedule (static, 3) collapse (3) lastprivate (conditional: p2)
  67. for (i = -5; i < (int) (b + 5); i += 2)
  68. for (j = b + 12 + c; j > b; --j)
  69. for (int k = 0; k < 5; k += c)
  70. if (((((i + 5) * 13 + (13 - j)) * 5 + k) % 17) == 6)
  71. p2 = i * 10000 + j * 100 + k;
  72. #pragma omp for lastprivate (conditional: u3, x3) nowait schedule (runtime)
  73. for (i = 15; i < 64; i++)
  74. {
  75. if ((a[i] % 5) == 3)
  76. u3 = i;
  77. if ((a[i] % 7) == 2)
  78. x3 = &a[i];
  79. }
  80. #pragma omp for nowait lastprivate (conditional: v3) reduction (+:r3, s3) schedule (nonmonotonic: dynamic)
  81. for (i = -3; i < 119; i += 2)
  82. {
  83. ++s3;
  84. if ((a[i + 4] % 11) == 9)
  85. v3 = i;
  86. else
  87. ++r3;
  88. }
  89. #pragma omp for schedule (monotonic: guided, 3) lastprivate (conditional: w3) nowait
  90. for (j = b; j < b + 115 * c; j += (b & 3) + 7)
  91. if ((a[j] % 13) == 5)
  92. w3 = j * 2;
  93. #pragma omp for schedule (dynamic, 4) lastprivate (conditional: p3) collapse(3)
  94. for (i = -5; i < (int) (b + 5); i += 2)
  95. for (j = b + 12 + c; j > b; --j)
  96. for (int k = 0; k < 5; k += c)
  97. if (((((i + 5) * 13 + (13 - j)) * 5 + k) % 17) == 6)
  98. p3 = i * 10000 + j * 100 + k;
  99. /* Nasty testcase, verify that even a no-op assignment is accounted
  100. for in lastprivate(conditional:). */
  101. #pragma omp for schedule (monotonic: static, 2) firstprivate (z) \
  102. lastprivate (conditional: z)
  103. for (int k = -2000; k < 8000; ++k)
  104. {
  105. if (k < 3000 && (k & 3) == 1)
  106. {
  107. z = k;
  108. thr1 = k;
  109. }
  110. else if (k == 7931)
  111. {
  112. z = z;
  113. thr2 = 1;
  114. }
  115. }
  116. if (thr2 && z != thr1)
  117. abort ();
  118. }
  119. int
  120. main ()
  121. {
  122. int a[128], i;
  123. volatile int j = 0;
  124. for (i = 0; i < 128; i++)
  125. a[i] = i;
  126. w = 1234;
  127. #pragma omp parallel
  128. foo (a, j, j + 1);
  129. if (u != 63 || v != 115 || w != 140 || x != &a[58] || r != 55 || s != 61 || p != 30104)
  130. abort ();
  131. if (u2 != 63 || v2 != 115 || w2 != 140 || x2 != &a[58] || r2 != 55 || s2 != 61 || p2 != 30104)
  132. abort ();
  133. if (u3 != 63 || v3 != 115 || w3 != 140 || x3 != &a[58] || r3 != 55 || s3 != 61 || p3 != 30104)
  134. abort ();
  135. return 0;
  136. }