[log in to unmask] wrote:
>
[snip]
> >New topic
> >
> >One thing I haven't seen discussed is the effect of array dimensions
> >on vector syntax. In physics problems there tend to be lots of
> >arrays, but very few actual dimension sets. Most arrays have the
> >same shape or are sub-shapes of other arrays. But given a
> >Subroutine like
> >
> > Subroutine add_em_up(a,b,c,d,e,f)
> > real a(:,:), b(:,:), c(:,:), d(:,:), e(:,:), f(:,:)
> > a = b+c
> > d = e+f
> > end
> >
> >a compiler won't know that. It will almost for sure translate
> >that into 2 DO loop nests when almost for sure one nest would
> >be good enough. Also, it's likely to have to compute an index
> >function ("I-1 + d1*(J-1))" for each of the 6 arrays, rather than
> >one function for all 6. This isn't much of a problem for smallish
> >codes, it's only 3 integer adds in the inner loop and that shouldn't
> >be a major time hit. But in bigger codes it adds to register
> >pressure and potentially adds a couple of cycles.
>
> O.K., do compilers know what a(:,:) size is? I guessed it was like a(*) where
> it was assumed a 1,n loop was valid for n without being able to check bounds.
>
> I would have assumed that with that declaration, I must say a(:n,:m) = etc.,
> where n and m are declared in common or as arguments. If that is not the case,
> and standard, such that all compilers must support it, this is my new knowledge
> for today -- even geriatrics are supposed to learn something new daily :-)
>
The answer is Yes and No. The compilers don't know at compile time what
the array size, they have to pass enough information at run time to let
things work. Using these arrays, called assumed SHAPE, requires an
explicit
interface. Either the called routine must be in a module or you need an
interface block. (The A(*) notation is assumed SIZE and it is YOUR
responsibility to do the right thing.) You can write explicit DO loops
to run over assumed shape arrays and you should expect bounds checking
to work for them. You can also use normal array notation and the
compiler
will use the passed in information, often called a dope vector, to do
the right thing. It's standard and all F90/95 compilers support it.
One advantage is that it allows compiler to efficiently pass array
sections without the need to do storage compaction. Something like
real a(100000000,100000000000)
call sub (a(I:J:K,L:M:N))
allows a sufficiently clever compiler to build a magic dope vector
and pass things efficiently. If SUB did not have an explicit interface
(eg, an old F77 routine) the compiler would probably have to build a
set of pack-copy-in/unpack-copy-out loops around the call.
There are some examples of assumed size arrays in the F examples.
Try www.fortran.com and follow the links to F and its examples.
Dick Hendrickson
> Regards, Paddy
>
> Paddy O'Brien,
> Transmission Development,
> TransGrid,
> PO Box A1000, Sydney South,
> NSW 2000, Australia
> (Street address, 201 Elizabeth Street)
>
> Tel: +61 2 9284-3063
> Fax: +61 2 9284-3050
> Email: [log in to unmask]
>
> Either "\'" or "\s" (to escape the apostrophe) seems to work for most people,
> but that little whizz-bang apostrophe gives me little spam.
|