pizorn
2010-05-19 07:53:35 UTC
Does anybody know whether 'reshape' is always a copy function or is
this compiler-specific.
let's consider the following example:
program PROG
real, dimension(:,:,:,:),allocatable :: A
integer ::D
D=...
allocate( A(D,D,D,D))
A(:,:,:,:) = ...
call PROCA(reshape( A, (/D**2, D**2/)))
contains
subroutine PROCA(A)
real, dimension(:,:) :: A ! dimension(D**2, D**2)
! ...
end subroutine PROCA
end program
so the question is: will reshape allocate an array and copy the
contents of A(:,:,:,:) to Acopy(:,:) and then call PROCA or simply
call PROCA with the same A, just pretending it has a different shape?
I read that this is compiler specific (sometimes the compiler doesn't
really allocate a new array but indeed uses the old one). What is the
general rule?
this compiler-specific.
let's consider the following example:
program PROG
real, dimension(:,:,:,:),allocatable :: A
integer ::D
D=...
allocate( A(D,D,D,D))
A(:,:,:,:) = ...
call PROCA(reshape( A, (/D**2, D**2/)))
contains
subroutine PROCA(A)
real, dimension(:,:) :: A ! dimension(D**2, D**2)
! ...
end subroutine PROCA
end program
so the question is: will reshape allocate an array and copy the
contents of A(:,:,:,:) to Acopy(:,:) and then call PROCA or simply
call PROCA with the same A, just pretending it has a different shape?
I read that this is compiler specific (sometimes the compiler doesn't
really allocate a new array but indeed uses the old one). What is the
general rule?