Re: Array descriptors
- From: robert.corbett@xxxxxxx
- Date: Fri, 10 Oct 2008 03:01:27 -0700 (PDT)
On Oct 10, 1:12 am, Tobias Burnus <bur...@xxxxxxxx> wrote:
Hello all,
this is more an implementation question than a Fortran standard
question, but it relates to the latter due to the upcoming TR 29113
(further interoperability with C).
(An old proposal, which was the starting point for the TR, can be
found at http://j3-fortran.org/doc/year/06/06-171.txtwhich is new
enough for the issue below.)
There seem to be two ways of implementing the array descriptors ("dope
vectors") internally:
a) base_address
and
b) base_address
offset
where the base_address plus the offset defines the first memory
location (start) of the array.
[Additionally there are of cause the array bounds, some flags
(allocatable, pointer), length-kind parameters etc., but they are not
relevant for my question.]
(a) is used by Pathscale [1] and in the current draft of TR 29113,
(b) is used by Intel [2], gfortran and g95
Off-hand I don't see the advantage of using an offset, but I'm
positive there are advantage. Does anyone know -- off hand or with
thinking -- the pros and cons for either solution?
Tobias
PS: My motivation is twofold: (a) I want to see an optimal TR and (b)
gfortran's array descriptors need to be modified to fix some issues
and the idea was to use the TR-format also internally and not only for
C interoperability; especially as the current draft-TR has no "offset"
while gfortran does, one needs to decide whether one keeps the offset
(and maybe even adds it in the TR) or whether one gets rid of it in
gfortran.
[1]http://www.pathscale.com/ws/docs/UserGuide.pdf
[2]http://www.intel.com/software/products/compilers/docs/flin/main_for/m...
Sun Fortran uses a third option. Sun Fortran uses an actual
origin, your base address, and a virtual origin, the address
of the possibly hypothetical array element indexed by
subscripts all of whose values are zero. The virtual origin
serves the same purpose as the offset you described, but it
saves an addition or subtraction (depending on which way the
offset goes).
The virtual origin provides a more efficient way of finding
the address of an array element given a sequence of
subscripts. For example, the canonical method for
computing the postition of an array element in a rank 3
array given in Section 6.5.3.2 of CD 1539-1 is
1 + (s1 - j1) + (s2 - j2)*d1 + (s3 - j3)*d2*d1
where s1, s2, and s3 are the subscript values, j1, j2, and
j3 are the lower bounds and d1 and d2 are the extent of the
firsrt and second dimensions. The extents are invariant as
long as the array is allocated, and the lower bounds are
usually fixed for relatively long times. Therefore,
regrouping the computation as
(1 + s1 + s2*d1 + s3*d2*d1) - (j1 + j2*d1 + j3*d2*d1)
allows the value of the second term to be cached and reused
as needed in subscript computations, which avoids the need
for three subtractions in the subscript caluculation. The
value of that term or its negation is the offset to which
you referred.
The offset (or vitual origin) is unnecessary, it is merely
an artifice to gain a bit of efficiency.
Bob Corbett
.
- Follow-Ups:
- Re: Array descriptors
- From: glen herrmannsfeldt
- Re: Array descriptors
- From: paul . richard . thomas
- Re: Array descriptors
- References:
- Array descriptors
- From: Tobias Burnus
- Array descriptors
- Prev by Date: Re: Array descriptors
- Next by Date: Re: Array descriptors
- Previous by thread: Re: Array descriptors
- Next by thread: Re: Array descriptors
- Index(es):
Relevant Pages
|