target-34.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. extern void abort (void);
  2. int
  3. main ()
  4. {
  5. int a = 1, b = 2, c = 4, d[7];
  6. #pragma omp parallel
  7. {
  8. #pragma omp single
  9. {
  10. #pragma omp taskgroup
  11. {
  12. #pragma omp target enter data nowait map (to: a, b, c) depend(out: d[0])
  13. #pragma omp target nowait map (alloc: a, b) depend(in: d[0]) depend(out: d[1])
  14. {
  15. #pragma omp atomic update
  16. a |= 4;
  17. #pragma omp atomic update
  18. b |= 8;
  19. }
  20. #pragma omp target nowait map (alloc: a, c) depend(in: d[0]) depend(out: d[2])
  21. {
  22. #pragma omp atomic update
  23. a |= 16;
  24. #pragma omp atomic update
  25. c |= 32;
  26. }
  27. #pragma omp target exit data nowait map (from: a, b, c) depend(in: d[1], d[2])
  28. }
  29. if (a != 21 || b != 10 || c != 36)
  30. abort ();
  31. #pragma omp target map (tofrom: a, b) nowait
  32. {
  33. a &= ~16;
  34. b &= ~2;
  35. }
  36. #pragma omp target map (tofrom: c) nowait
  37. {
  38. c |= 8;
  39. }
  40. } /* Implicit barrier here. */
  41. #pragma omp single
  42. {
  43. if (a != 5 || b != 8 || c != 44)
  44. abort ();
  45. #pragma omp target map (tofrom: a, b) nowait
  46. {
  47. a |= 32;
  48. b |= 4;
  49. }
  50. #pragma omp target map (tofrom: c) nowait
  51. c &= ~4;
  52. #pragma omp taskwait
  53. if (a != 37 || b != 12 || c != 40)
  54. abort ();
  55. #pragma omp target nowait map (tofrom: a, b) depend(out: d[3])
  56. {
  57. #pragma omp atomic update
  58. a = a + 9;
  59. b -= 8;
  60. }
  61. #pragma omp target nowait map (tofrom: a, c) depend(out: d[4])
  62. {
  63. #pragma omp atomic update
  64. a = a + 4;
  65. c >>= 1;
  66. }
  67. #pragma omp task if (0) depend (in: d[3], d[4]) shared (a, b, c)
  68. if (a != 50 || b != 4 || c != 20)
  69. abort ();
  70. #pragma omp task shared (a)
  71. a += 50;
  72. #pragma omp target nowait map (tofrom: b)
  73. b++;
  74. #pragma omp target map (tofrom: c) nowait
  75. c--;
  76. #pragma omp taskwait
  77. if (a != 100 || b != 5 || c != 19)
  78. abort ();
  79. #pragma omp target map (tofrom: a) nowait depend(out: d[5])
  80. a++;
  81. #pragma omp target map (tofrom: b) nowait depend(out: d[6])
  82. b++;
  83. #pragma omp target map (tofrom: a, b) depend(in: d[5], d[6])
  84. {
  85. if (a != 101 || b != 6)
  86. a = -9;
  87. else
  88. {
  89. a = 24;
  90. b = 38;
  91. }
  92. }
  93. if (a != 24 || b != 38)
  94. abort ();
  95. } /* Implicit barrier here. */
  96. #pragma omp master
  97. {
  98. #pragma omp target nowait map (tofrom: a, b)
  99. {
  100. a *= 2;
  101. b++;
  102. }
  103. #pragma omp target map (tofrom: c) nowait
  104. c--;
  105. }
  106. #pragma omp barrier
  107. if (a != 48 || b != 39 || c != 18)
  108. abort ();
  109. }
  110. return 0;
  111. }