[J3] Polymorphic dummy arrays
Bill Long
longb at cray.com
Mon Jan 7 18:18:49 EST 2019
The original example did not have any assumed-size arrays. However, in the case of the dummy being explicit-shape (dimension(1:2)) it is still possible that copy-in/copy-out is required, since the elements of the dummy array correspond to elements of the actual that are (most likely) not contiguous in memory.
Cheers,
Bill
> On Jan 7, 2019, at 5:14 PM, Robert Corbett via J3 <j3 at mailman.j3-fortran.org> wrote:
>
> I am not aware of such a restriction. I recall that Oracle Fortran allows assumed-size polymorphic dummy arguments. At the time, they were tricky to implement. The ability to pass a polymorphic actual argument to a dummy argument that is not polymorphic requires making a copy. That meant Oracle's implementation had to pass the size of assumed-size polymorphic arrays. Later, the standard was modified via corrigenda to eliminate the need to make copies.
>
> Robert Corbett
>
> On Jan 7, 2019, at 2:07 PM, Steidel, Jon L via J3 <j3 at mailman.j3-fortran.org> wrote:
>
>> Happy New Year,
>>
>> I have a user that wants to be pointed to words in the standard that I cannot find. I would appreciate any help anyone can offer.
>>
>> Subroutine func has a dummy argument that is an array of polymorphic class T. It is called with an actual argument array of type S, which extends type T. The user wants to have the dummy array be explicit shape. But passing a simple address to func is insufficient as the dummy argument is polymorphic; the subroutine needs to at least know the size of each element as well as a base address.
>>
>> program class_type_conv
>>
>> implicit none
>>
>> type :: t
>> integer :: i = 1
>> end type
>>
>> type, extends(t) :: s
>> real :: r = 1.0
>> end type
>>
>> type(s), dimension(1:2) :: x
>>
>> call func(x)
>> print *,x(1)%i, x(1)%r
>> print *,x(2)%i, x(2)%r
>>
>> contains
>>
>> subroutine func(x)
>> ! class(t), dimension(1:2), intent(out) :: x ! original test
>> class(t), dimension(:), intent(out) :: x ! modified test
>>
>> call inc(x)
>> end subroutine
>>
>> subroutine inc(x)
>> type(t), dimension(1:2), intent(out) :: x
>> x(:)%i = x(:)%i + 1
>> end subroutine
>>
>> end
>>
>> One compiler I have access to diagnoses the declaration of the explicit shape dummy array in func (the commented out line) stating a polymorphic dummy array must be allocatable, pointer, or assumed shape. Passing a descriptor here solves the problem as there is element size or inter-element spacing information in the descriptor.
>>
>> I can a restriction that says a polymorphic object must have the POINTER or ALLOCATABLE attribute or be a dummy argument (C708). I can also find a requirement that a procedure with a polymorphic dummy argument requires an explicit interface (15.4.2.2.) But I cannot find a requirement that a dummy array of polymorphic objects must be assumed shape. Can someone point me to those words?
>>
>> Note that if the dummy polymorphic array is required to be assume shape, then passing this dummy array from as an actual argument func to the dummy argument x of inc is not legal. 15.5.2.4 Ordinary dummy variables, p2 sentence 3 states “If the actual argument is a polymorphic assumed-size array, the dummy argument shall be polymorphic.” In subroutine inc, x is not polymorphic.
>>
>>
>> Thanks,
>>
>> -jon
Bill Long longb at cray.com
Principal Engineer, Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9143
Cray Inc./ 2131 Lindau Lane/ Suite 1000/ Bloomington, MN 55425
More information about the J3
mailing list