Because PGI OpenACC doesn’t yet support deep copy for allocatable and pointer elements in derived type variables, we should do more work.
For example,
TYPE DERIVEDTYPE
REAL, POINTER :: PointerElement(:)
END TYPE
TYPE(DERIVEDTYPE) :: A
ALLOCATE(A%PointerElement(100))
!$ACC ENTER_DATA COPYIN(A)
!$ACC ENTER_DATA COPYIN(A%PointerElement)
I know this actually works, but my question is that how does this work?
!$ACC ENTER_DATA COPYIN(A)
When A is copied in by this line, A%PointerElement still targets some locations in host memory, which is invalid on the device. (This is shallow copy, if I understood correctly.)
!$ACC ENTER_DATA COPYIN(A%PointerElement)
By this line, the data that is being pointed by A%PointerElement is copied in to the device. (This is deep copy).
But, A%PointerElement still targets host memory. Data has been copied in to the device, but we didn’t do anything to the pointer.
How are the pointers linked with the data on the device?
I saw a sentence from starting guide book:
If the derived type is not present on the device when the allocatable array members are copied, the accesses to the allocatable members on the device will be invalid, because the hidden pointer and descriptor values in the derived type variable will not get updated.
Can you explain to me more about ‘hidden pointer’ and ‘descriptor value’? I suppose my question is related with these.