Re: Allocatable arrays in derived types
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Tue, 29 Apr 2008 09:06:51 -0700
relaxmike <michael.baudin@xxxxxxxxx> wrote:
On 29 avr, 14:08, "Jugoslav Dujic" <jdu...@xxxxxxxxx> wrote:
"Stride" is the last thingo in the array triplet, i.e. index
difference between subsequent array elements:
Now I understand that this is not english, it is fortran...
That term in Fortran at least has recognizable analogy with the English.
The analogy might be a little easier to recognize if stated in a
different way. Jugoslav gave a definition in terms of syntax, which
doesnt capture the analogy well. It also doesn't catch all the cases
because it isn't actually the definition; it is just an example of the
syntax of one way to get an array with a specified stride. I'll try in
other terms that make the analogy explicit.
For the moment, I'll stick to arrays of rank 1. For higher ranks, the
same concept applies to each rank.
The stride is the distance (in memory) that you go in one step (between
aray elements). That definition shows the analogy.
It is common to measure stride in units of the size of an individual
element (because that unit of measurement gives the most direct
relationship of the stride to the Fortran syntax). In the simplest and
most common case, the stride is 1. That means that the distance between
two consecutive elements of the aray is the size of an element; the
elements are contiguous in memory.
Consider starting with a contiguous array x and using a slice such as
x(1:n:2). Recall that this notation means to use every 2nd element of
the array. Then the "used" elements are spaced 2 element sizes apart.
Then do something to associate an array y with x(1:n:2); this could
either be pointer association with y a pointer to x(1:n:2) as the
target, or argument association with x(1:n:2) as the actual argument for
a dummy argument y. In either of these cases, y will have stride 2. Y(1)
will correspond to x(1) and y(2) will correspond to x(3). There is a
distance of 2 element sizes from the location of y(1) to that of y(2).
Note that y itself has stride 2. Yugoslav's description doesn't quite
catch this concept. Although array triplet notation was used in the
process of defining y from x, you don't directly see that notation when
using y. That indeed is why the compiler has to store the stride
information. In the case, for example, where y is a dummy argument, you
can't see the stride of y anywhere in the current scope (and the
compiler can't see it either); so it has to be stored somewhere in
memory (which will turn out to be in the array descriptor).
Another way to get an array of stride other than 1 is to start with a
rank 2 array and take a slice that is a row. For example, if xx is an n
by n array and you take the slice x(i,:) for some particular value of i,
that slice will have stride n-1. Note that this is a case that
Yugoslav's description doesn't catch.
There are cases where the stride of an array is evident at compile time
and might not need to be stored, but it is usually simplest to make all
array descriptors of the same rank have the same structure anyway, even
if some parts of the descriptor might be unneeded. In fact, in the case
in point, an allocatable array always has a stride of 1, but the
descriptor for an allocatable array usually is just like that of other
arrays and stores the stride anyway.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- Follow-Ups:
- Re: Allocatable arrays in derived types
- From: glen herrmannsfeldt
- Re: Allocatable arrays in derived types
- References:
- Allocatable arrays in derived types
- From: Gib Bogle
- Re: Allocatable arrays in derived types
- From: Arjen Markus
- Re: Allocatable arrays in derived types
- From: relaxmike
- Re: Allocatable arrays in derived types
- From: Richard Maine
- Re: Allocatable arrays in derived types
- From: relaxmike
- Re: Allocatable arrays in derived types
- From: Jugoslav Dujic
- Re: Allocatable arrays in derived types
- From: relaxmike
- Allocatable arrays in derived types
- Prev by Date: Re: gfortran produces huge executables
- Next by Date: Re: variable length of integer
- Previous by thread: Re: Allocatable arrays in derived types
- Next by thread: Re: Allocatable arrays in derived types
- Index(es):
Relevant Pages
|