subarrays-2.f90 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. program subarrays
  2. integer, parameter :: n = 20, c = 10, low = 5, high = 10
  3. integer :: i, a(n), b(n)
  4. a(:) = 0
  5. b(:) = 0
  6. ! COPY
  7. !$acc parallel copy (a(low:high))
  8. !$acc loop
  9. do i = low, high
  10. a(i) = i
  11. end do
  12. !$acc end parallel
  13. do i = low, high
  14. b(i) = i
  15. end do
  16. call check (a, b, n)
  17. ! COPYOUT
  18. a(:) = 0
  19. !$acc parallel copyout (a(low:high))
  20. !$acc loop
  21. do i = low, high
  22. a(i) = i
  23. end do
  24. !$acc end parallel
  25. do i = low, high
  26. if (a(i) .ne. b(i)) call abort
  27. end do
  28. call check (a, b, n)
  29. ! COPYIN
  30. a(:) = 0
  31. !$acc parallel copyout (a(low:high)) copyin (b(low:high))
  32. !$acc loop
  33. do i = low, high
  34. a(i) = b(i)
  35. end do
  36. !$acc end parallel
  37. call check (a, b, n)
  38. ! PRESENT_OR_COPY
  39. a(:) = 0
  40. !$acc parallel pcopy (a(low:high))
  41. !$acc loop
  42. do i = low, high
  43. a(i) = i
  44. end do
  45. !$acc end parallel
  46. call check (a, b, n)
  47. ! PRESENT_OR_COPYOUT
  48. a(:) = 0
  49. !$acc parallel pcopyout (a(low:high))
  50. !$acc loop
  51. do i = low, high
  52. a(i) = i
  53. end do
  54. !$acc end parallel
  55. call check (a, b, n)
  56. ! PRESENT_OR_COPYIN
  57. a(:) = 0
  58. !$acc parallel pcopyout (a(low:high)) &
  59. !$acc & pcopyin (b(low:high))
  60. !$acc loop
  61. do i = low, high
  62. a(i) = b(i)
  63. end do
  64. !$acc end parallel
  65. call check (a, b, n)
  66. end program subarrays
  67. subroutine check (a, b, n)
  68. integer :: n, a(n), b(n)
  69. integer :: i
  70. do i = 1, n
  71. if (a(i) .ne. b(i)) call abort
  72. end do
  73. end subroutine check