data-4-2.f90 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. ! Copy of data-4.f90 with self exchanged with host for !acc update.
  2. ! { dg-do run }
  3. program asyncwait
  4. real, allocatable :: a(:), b(:), c(:), d(:), e(:)
  5. integer i, N
  6. N = 64
  7. allocate (a(N))
  8. allocate (b(N))
  9. allocate (c(N))
  10. allocate (d(N))
  11. allocate (e(N))
  12. a(:) = 3.0
  13. b(:) = 0.0
  14. !$acc enter data copyin (a(1:N)) copyin (b(1:N)) copyin (N) async
  15. !$acc parallel async wait
  16. !$acc loop
  17. do i = 1, N
  18. b(i) = a(i)
  19. end do
  20. !$acc end parallel
  21. !$acc update self (a(1:N), b(1:N)) async wait
  22. !$acc wait
  23. do i = 1, N
  24. if (a(i) .ne. 3.0) call abort
  25. if (b(i) .ne. 3.0) call abort
  26. end do
  27. a(:) = 2.0
  28. b(:) = 0.0
  29. !$acc update device (a(1:N), b(1:N)) async (1)
  30. !$acc parallel async (1) wait (1)
  31. !$acc loop
  32. do i = 1, N
  33. b(i) = a(i)
  34. end do
  35. !$acc end parallel
  36. !$acc update host (a(1:N), b(1:N)) async (1) wait (1)
  37. !$acc wait (1)
  38. do i = 1, N
  39. if (a(i) .ne. 2.0) call abort
  40. if (b(i) .ne. 2.0) call abort
  41. end do
  42. a(:) = 3.0
  43. b(:) = 0.0
  44. c(:) = 0.0
  45. d(:) = 0.0
  46. !$acc enter data copyin (c(1:N), d(1:N)) async (1)
  47. !$acc update device (a(1:N), b(1:N)) async (1)
  48. !$acc parallel async (1)
  49. do i = 1, N
  50. b(i) = (a(i) * a(i) * a(i)) / a(i)
  51. end do
  52. !$acc end parallel
  53. !$acc parallel async (1)
  54. do i = 1, N
  55. c(i) = (a(i) * 4) / a(i)
  56. end do
  57. !$acc end parallel
  58. !$acc parallel async (1)
  59. do i = 1, N
  60. d(i) = ((a(i) * a(i) + a(i)) / a(i)) - a(i)
  61. end do
  62. !$acc end parallel
  63. !$acc update self (a(1:N), b(1:N), c(1:N), d(1:N)) async (1) wait (1)
  64. !$acc wait (1)
  65. do i = 1, N
  66. if (a(i) .ne. 3.0) call abort
  67. if (b(i) .ne. 9.0) call abort
  68. if (c(i) .ne. 4.0) call abort
  69. if (d(i) .ne. 1.0) call abort
  70. end do
  71. a(:) = 2.0
  72. b(:) = 0.0
  73. c(:) = 0.0
  74. d(:) = 0.0
  75. e(:) = 0.0
  76. !$acc enter data copyin (e(1:N)) async (1)
  77. !$acc update device (a(1:N), b(1:N), c(1:N), d(1:N)) async (1)
  78. !$acc parallel async (1)
  79. do i = 1, N
  80. b(i) = (a(i) * a(i) * a(i)) / a(i)
  81. end do
  82. !$acc end parallel
  83. !$acc parallel async (1)
  84. do i = 1, N
  85. c(i) = (a(i) * 4) / a(i)
  86. end do
  87. !$acc end parallel
  88. !$acc parallel async (1)
  89. do i = 1, N
  90. d(i) = ((a(i) * a(i) + a(i)) / a(i)) - a(i)
  91. end do
  92. !$acc end parallel
  93. !$acc parallel wait (1) async (1)
  94. do i = 1, N
  95. e(i) = a(i) + b(i) + c(i) + d(i)
  96. end do
  97. !$acc end parallel
  98. !$acc update self (a(1:N), b(1:N), c(1:N), d(1:N), e(1:N)) async (1) wait (1)
  99. !$acc wait (1)
  100. !$acc exit data delete (N, a(1:N), b(1:N), c(1:N), d(1:N), e(1:N))
  101. do i = 1, N
  102. if (a(i) .ne. 2.0) call abort
  103. if (b(i) .ne. 4.0) call abort
  104. if (c(i) .ne. 4.0) call abort
  105. if (d(i) .ne. 1.0) call abort
  106. if (e(i) .ne. 11.0) call abort
  107. end do
  108. end program asyncwait