Re: Array descriptors
- From: robert.corbett@xxxxxxx
- Date: Fri, 10 Oct 2008 22:08:17 -0700 (PDT)
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
.
- Follow-Ups:
- Re: Array descriptors
- From: paul . richard . thomas
- Re: Array descriptors
- References:
- Array descriptors
- From: Tobias Burnus
- Re: Array descriptors
- From: robert . corbett
- Re: Array descriptors
- From: paul . richard . thomas
- Array descriptors
- Prev by Date: Re: Regarding FIles in Fortran
- Next by Date: Re: help with array syntax for a loop
- Previous by thread: Re: Array descriptors
- Next by thread: Re: Array descriptors
- Index(es):
Relevant Pages
|