(j3.2006) a question on c_f_pointer call
Bill Long
longb
Wed Aug 25 16:31:42 EDT 2010
For this test:
> cat case4.f90
real, dimension(:), pointer :: p1, p2
allocate(p2(2:11))
call point_to(p1,p2,10)
deallocate(p1,stat=istat)
print *, istat
contains
subroutine point_to(p,t,n)
integer :: n
real, pointer :: p(:)
real, target :: t(:)
p=>t(1:n)
end subroutine point_to
end
I get output of 0 from Cray, PGI, and gfortran. Intel output is 173.
The difference here, compared to the CPTR case, is that ALL of the
pointers involved are, internally, represented by the vendor's version
of a Fortran descriptor. If the information needed is stored somewhere
in the descriptor, then it should not get lost across procedure
boundaries. [Indeed, Tobias is asking that this information also be
included in the C descriptor of the TR.]
Cheers,
Bill
Aleksandar Donev wrote:
> On 08/25/10 15:34, Jim Xia wrote:
>> From implementation point of view, how can one tell if FPTR is
>> eligible for deallocation? The CPTR is simply a C pointer, no
>> necessary information as to whether they can be deallocated.
> You have to look to your allocator, it seems to me. How do you do it now
> for this code:
>
> -----------------
> real, dimension(:), pointer :: p1, p2
>
> allocate(p2(2:11))
>
> call point_to(p1,p2,10)
>
> deallocate(p1,stat=...)
>
> where
>
> subroutine point_to(p,t,n)
> integer :: n
> real, pointer :: p(:)
> real, target :: t(:)
> p=>t(1:n)
> end subroutine
> -----------------
>
> It seems to me this is legal and does not use C pointers. How do you
> establish whether p1 can be deallocated? I am trying to understand why
> exactly c_f_pointer is special from using some library that does pointer
> assignments like above.
>
> Best,
> Aleks
>
> --
> Aleksandar Donev, Assistant Professor of Mathematics
> Courant Institute of Mathematical Sciences
> Office: 909 Warren Weaver Hall, New York University
> E-mail: donev at courant.nyu.edu
> Phone: (212) 992-7315; Fax: (212) 995-4121
> Mailing address: 251 Mercer St, New York, NY 10012
> Web: http://cims.nyu.edu/~donev
>
--
Bill Long longb at cray.com
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101
More information about the J3
mailing list