Re: Array descriptors



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
.



Relevant Pages

  • Re: Calendar: month problem..
    ... error in Java array design, ... Fortran 77 standard for calculating the offset into a multi-dimensional ...
    (comp.lang.java.help)
  • Re: Who uses clapack?
    ... > functions like SUM and MAXVAL and the ability to use array sections ... > drastically change the meaning of a Fortran code. ... >>Have you ever seen those bills for a Fortran compiler for an ... engineering applications in the C and C++ languages. ...
    (comp.lang.fortran)
  • Re: Who uses clapack?
    ... > functions like SUM and MAXVAL and the ability to use array sections ... > drastically change the meaning of a Fortran code. ... >>Have you ever seen those bills for a Fortran compiler for an ... engineering applications in the C and C++ languages. ...
    (sci.math.num-analysis)
  • Re: Benchmarking APL
    ... with that of FORTRAN. ... APL a 400% gain in programming efficiency could be obtained with only ... Another good-for-APL array problem, vector convolution, gave these ... Tomcatv, one of the SPEC benchmarks, is more typical of large array ...
    (comp.lang.apl)
  • Re: Mixing C++/Fortran using Two-Dimensional Array
    ... not a subset as in Fortran. ... if you really need it you can get the effect by an array of TYPE ... the lowest-level base element pointer, which is all you actually need ... macros in C, although it can be difficult to find macro names that are ...
    (comp.lang.fortran)