Re: Array descriptors



On Oct 10, 4:17 am, paul.richard.tho...@xxxxxxxxx wrote:
Dear All,

The offset (or virtual origin) is unnecessary, it is merely
an artifice to gain a bit of efficiency.

I guess that one reason to have the base address, which necessitates
the offset or virtual origin, is the need to be able to free or to
reallocate the memory for pointers and allocatable arrays in scopes
other than the parent scope of the array.

Just as the virtual origin can be computed from the actual
origin (base address), the strides, and the lower bounds,
the actual origin can be computed from the virtual origin,
the strides and the lower bounds.

A related question is that of the representation of the 'dimension'
structure:

gfortran and g95 use; stride, lower_bound and upper_bound, largely
because the data is represented as an array of the element type and
referencing is done modulo the number of bytes for the alignment of
the type. If I have understood correctly, this takes maximum
advantage of the information held in the backend about the
architecture of the target.

Other compilers and the proposed TR use; lower_bound, extent (number
of elements along the dimension) and sm (distance between elements
in bytes along the dimension.)

One of our motives for changing the gfortran descriptor was to
progress from the first representation to the second. However, it is
not not evident to me that it matters. Constant folding in the
backend of the compiler should result in the same arithmetic being
done at runtime.

Thus, other than the not-inconsiderable work being good for our
immortal souls, does any body know of a benefit that would be gained
from changing the representation?

Yes. array operations can be coded more efficiently
using extents rather than lower and upper bounds.
When extents are used, array operations scalarize into
nested loops from the extent down to zero or, for some
machines, from the negation of the extent up to zero.
For such loops, it is usually better to use the actual
origin than the virtual origin. The virtual origin
tends to be better when explicit subscripts are involved.
For array operations, where array indexing is implicit,
the actual origin tends to be better.

BTW, Sun Fortran almost never references the lower bounds
that are contained in an array pointer. The lower bounds
are not needed for either explicit subscripting or array
operations. The lower bounds are needed to implement
LBOUND and UBOUND, and that is about it. For that reason,
Sun Fortran puts the lower bounds at the end of the array
pointer.

Some people argued against including the virtual origin as
part of an array pointer. They argued that the time spent
computing the virtual origin was unlikely to be recouped
by the savings in time for array indexing. The argument is
particularly string for rank 1 array pointers.

Bob Corbett
.



Relevant Pages

  • Re: Array descriptors
    ... There seem to be two ways of implementing the array descriptors ("dope ... where the base_address plus the offset defines the first memory ... Sun Fortran uses a third option. ... origin, your base address, and a virtual origin, the address ...
    (comp.lang.fortran)
  • Re: Question about smp_read_barrier_depends() in kernel/marker.c
    ... so put the explicit barrier here. ... sure the array data is written before the array pointer. ... Update the function or multi probe array pointer before setting the ...
    (Linux-Kernel)
  • Re: Intrinsic functions and non-trivial lower bounds
    ... Assumed-shape arrays sacrifice clarity to ... Consider a trivial routine to, say, add two arrays and output the result ... If lower bounds were passed, then this code, which assumes the lower ... callee have to agree on the array subscript values. ...
    (comp.lang.fortran)
  • Re: Intrinsic functions and non-trivial lower bounds
    ... Consider a trivial routine to, say, add two arrays and output the result ... If lower bounds were passed, then this code, which assumes the lower ... callee have to agree on the array subscript values. ... Yukk, yukk, yukk! ...
    (comp.lang.fortran)
  • Re: Intrinsic functions and non-trivial lower bounds
    ... Consider a trivial routine to, say, add two arrays and output the result ... If lower bounds were passed, then this code, which assumes the lower ... callee have to agree on the array subscript values. ... Yukk, yukk, yukk! ...
    (comp.lang.fortran)