dynamic-pointer-1.f90 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ! Verify that a 'enter data'ed 'pointer' object creates a persistent, visible device copy
  2. ! { dg-do run }
  3. ! { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } }
  4. module m
  5. implicit none
  6. contains
  7. subroutine verify_a (a_ref, a)
  8. implicit none
  9. integer, dimension (:, :, :), allocatable :: a_ref
  10. integer, dimension (:, :, :), pointer :: a
  11. !$acc routine seq
  12. if (any (lbound (a) /= lbound (a_ref))) stop 101
  13. if (any (ubound (a) /= ubound (a_ref))) stop 102
  14. if (size (a) /= size (a_ref)) stop 103
  15. end subroutine verify_a
  16. end module m
  17. program main
  18. use m
  19. use openacc
  20. implicit none
  21. integer, parameter :: n = 30
  22. integer, dimension (:, :, :), allocatable, target :: a1, a2
  23. integer, dimension (:, :, :), pointer :: p
  24. allocate (a1(1:n, 0:n-1, 10:n/2))
  25. !$acc enter data create(a1)
  26. allocate (a2(3:n/3, 10:n, n-10:n+10))
  27. !$acc enter data create(a2)
  28. p => a1
  29. call verify_a(a1, p)
  30. ! 'p' object isn't present on the device.
  31. !$acc parallel ! Implicit 'copy(p)'; creates 'p' object...
  32. call verify_a(a1, p)
  33. !$acc end parallel ! ..., and deletes it again.
  34. p => a2
  35. call verify_a(a2, p)
  36. ! 'p' object isn't present on the device.
  37. !$acc parallel ! Implicit 'copy(p)'; creates 'p' object...
  38. call verify_a(a2, p)
  39. !$acc end parallel ! ..., and deletes it again.
  40. p => a1
  41. !$acc enter data create(p)
  42. ! 'p' object is now present on the device (visible device copy).
  43. !TODO PR96080 if (.not. acc_is_present (p)) stop 1
  44. !$acc parallel
  45. ! On the device, got created as 'p => a1'.
  46. call verify_a(a1, p)
  47. !$acc end parallel
  48. call verify_a(a1, p)
  49. !$acc parallel
  50. p => a2
  51. ! On the device, 'p => a2' is now set.
  52. call verify_a(a2, p)
  53. !$acc end parallel
  54. ! On the host, 'p => a1' persists.
  55. call verify_a(a1, p)
  56. !$acc parallel
  57. ! On the device, 'p => a2' persists.
  58. call verify_a(a2, p)
  59. !$acc end parallel
  60. ! On the host, 'p => a1' still persists.
  61. call verify_a(a1, p)
  62. p => a2
  63. !$acc parallel
  64. p => a1
  65. ! On the device, 'p => a1' is now set.
  66. call verify_a(a1, p)
  67. !$acc end parallel
  68. ! On the host, 'p => a2' persists.
  69. call verify_a(a2, p)
  70. !$acc parallel
  71. ! On the device, 'p => a1' persists.
  72. call verify_a(a1, p)
  73. !$acc end parallel
  74. ! On the host, 'p => a2' still persists.
  75. call verify_a(a2, p)
  76. end program main