Hello!
I have a problem with using pointer to arrays. I have created the following example just to demonstrate the nature of the problem.
program test
implicit none
real, TARGET :: a
real, POINTER :: pa
real, allocatable,TARGET:: x(:),y(:)
real, POINTER :: px(:),py(:)
a=1
pa=>a
allocate(x(1))
x(1)=3
px=>x
allocate(y(1))
y(1)=4
py=>y
!$acc enter data create(a,pa,x,px,y,py)
!$acc kernels present(a,pa,x,px,y,py) default(none)
x(1)=3
y(1)=4
px(:)=py(:)
a=px(1)
!$acc end kernels
!$acc update self(a)
!$acc exit data delete(a,pa,x,y,px,py)
write (,) a
end program test
when I compile the code, it creates the following error:
$ pgfortran test.f90 -acc -o test.out
PGF90-S-0155-Data clause required with default(none): px$f (test.f90: 21)
PGF90-S-0155-Data clause required with default(none): px$f(:) (test.f90: 21)
Although px is already in “Present” clause, the compile still complains!
I removed the “default” clause, and the compilation succeeds but the runtime generates a segmentation fault:
!$acc enter data create(a,pa,x,px,y,py)
!$acc kernels present(a,pa,x,px,y,py)
x(1)=3
y(1)=4
px(:)=py(:)
a=px(1)
!$acc end kernels
!$acc update self(a)
!$acc exit data delete(a,pa,x,y,px,py)
$>./test.out
Segmentation fault
I even assign pointers inside the kernels code region, but it still generates a segmentation fault:
!$acc enter data create(a,pa,x,px,y,py)
!$acc kernels present(a,pa,x,px,y,py)
x(1)=5
y(1)=6
px=>x
py=>y
px(:)=py(:)
a=px(1)
!$acc end kernels
!$acc update self(a)
!$acc exit data delete(a,pa,x,y,px,py)
\
./test.out
Segmentation fault
I finally removed the pointers and everything worked:
!$acc enter data create(a,pa,x,px,y,py)
!$acc kernels present(a,pa,x,px,y,py)
x(1)=5
y(1)=6
x(:)=y(:)
a=x(1)
!$acc end kernels
!$acc update self(a)
!$acc exit data delete(a,pa,x,y,px,py)
$>./test.out
6.000000
I would appreciate it if anybody can advise.
My best regards
Reza