lastprivate-conditional-4.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include <stdlib.h>
  2. int x;
  3. long long y;
  4. int r, s, t;
  5. void
  6. foo (const char *a)
  7. {
  8. #pragma omp sections lastprivate (conditional: x, y)
  9. {
  10. if (a[0])
  11. x = a[0];
  12. #pragma omp section
  13. {
  14. if (a[1])
  15. x = a[1];
  16. if (a[2])
  17. y = a[2];
  18. }
  19. #pragma omp section
  20. if (a[3])
  21. y = a[3];
  22. #pragma omp section
  23. if (a[4])
  24. x = a[4];
  25. #pragma omp section
  26. {
  27. if (a[5])
  28. x = a[5];
  29. if (a[6])
  30. y = a[6];
  31. }
  32. }
  33. }
  34. void
  35. bar (const char *a)
  36. {
  37. #pragma omp sections lastprivate (conditional: x, y) reduction (task, +: t)
  38. {
  39. if (a[0])
  40. x = a[0];
  41. #pragma omp section
  42. {
  43. if (a[1])
  44. x = a[1];
  45. if (a[2])
  46. y = a[2];
  47. #pragma omp task in_reduction (+: t)
  48. t++;
  49. }
  50. #pragma omp section
  51. if (a[3])
  52. y = a[3];
  53. #pragma omp section
  54. if (a[4])
  55. x = a[4];
  56. #pragma omp section
  57. {
  58. #pragma omp task in_reduction (+: t)
  59. ++t;
  60. if (a[5])
  61. x = a[5];
  62. if (a[6])
  63. y = a[6];
  64. }
  65. }
  66. }
  67. void
  68. baz (const char *a)
  69. {
  70. #pragma omp sections lastprivate (conditional: x, y) reduction (+: r, s)
  71. {
  72. if (a[0])
  73. x = a[0];
  74. #pragma omp section
  75. {
  76. if (a[1])
  77. x = a[1];
  78. ++r;
  79. ++s;
  80. if (a[2])
  81. y = a[2];
  82. }
  83. #pragma omp section
  84. if (a[3])
  85. y = a[3];
  86. #pragma omp section
  87. {
  88. ++s;
  89. if (a[4])
  90. x = a[4];
  91. }
  92. #pragma omp section
  93. {
  94. if (a[5])
  95. x = a[5];
  96. if (a[6])
  97. y = a[6];
  98. ++s;
  99. }
  100. }
  101. }
  102. int
  103. main ()
  104. {
  105. #pragma omp parallel
  106. {
  107. foo ("\0\1\2\3\0\5");
  108. if (x != 5 || y != 3)
  109. abort ();
  110. #pragma omp barrier
  111. foo ("\6\0\0\0\0\0\7");
  112. if (x != 6 || y != 7)
  113. abort ();
  114. #pragma omp barrier
  115. foo ("\7\6\5\4\3\2\1");
  116. if (x != 2 || y != 1)
  117. abort ();
  118. #pragma omp barrier
  119. foo ("\0\0\4\3\0\7");
  120. if (x != 7 || y != 3)
  121. abort ();
  122. #pragma omp barrier
  123. bar ("\0\1\2\4\0\5");
  124. if (x != 5 || y != 4 || t != 2)
  125. abort ();
  126. #pragma omp barrier
  127. bar ("\6\0\0\0\0\0\7");
  128. if (x != 6 || y != 7 || t != 4)
  129. abort ();
  130. #pragma omp barrier
  131. bar ("\7\6\5\4\3\2\1");
  132. if (x != 2 || y != 1 || t != 6)
  133. abort ();
  134. #pragma omp barrier
  135. bar ("\0\0\4\3\0\7");
  136. if (x != 7 || y != 3 || t != 8)
  137. abort ();
  138. #pragma omp barrier
  139. baz ("\0\1\2\4\0\5");
  140. if (x != 5 || y != 4 || r != 1 || s != 3)
  141. abort ();
  142. #pragma omp barrier
  143. baz ("\6\0\0\0\0\0\7");
  144. if (x != 6 || y != 7 || r != 2 || s != 6)
  145. abort ();
  146. #pragma omp barrier
  147. baz ("\7\6\5\4\3\2\1");
  148. if (x != 2 || y != 1 || r != 3 || s != 9)
  149. abort ();
  150. #pragma omp barrier
  151. baz ("\0\0\4\3\0\7");
  152. if (x != 7 || y != 3 || r != 4 || s != 12)
  153. abort ();
  154. }
  155. return 0;
  156. }