Re: automatic arrays versus saved, allocated arrays
- From: Ron Shepard <ron-shepard@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 12 Oct 2006 10:07:52 -0500
In article <1160639410.683498.154900@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
robert.corbett@xxxxxxx wrote:
Bil Kleb wrote:
Can someone explain what is going on behind the curtain
that would explain this difference, e.g., stack, heap,
CPU cache misses, TLB misses? Is this a general result,
or will it vary with work array size and work flow memory
utilization?
There could be many reasons for the performance advantage
of automatic arrays over pointer arrays, but usually the biggest
advantage is that the automatic array is known to be contiguous.
Consider the translation of a simple array assignment such as
A = 0.0
where A is a rank 2 array. Given the pointer array, the compiler
is likely to generate code similar to a doubly nested DO-loop.
For an automatic array, the compiler can interate over the entire
array with a single loop. Furthermore, the address calculations,
even after optimization, are simpler and on some machines are
hardware assisted.
I'm not sure this is causing the problem. I would guess that both
the automatic array and the allocated pointer array are contiguous.
However, I think this is probably close to the problem, which
involves aliasing. The compiler knows that an automatic array
cannot be aliased to any other variable in scope, so it is free to
perform various optimizations (e.g. storing the value of some
elements in registers). However, the pointer array can also be the
target of a pointer assignment, so the compiler may be conservative
about what kind of optimizations it attempts. That is, using
pointer arrays in fortran causes the compiler to behave more like a
C compiler as far as optimizations, and this may be particularly
true for fortran compilers (such as g95 and gfortran) that share
some of the same code as a C compiler.
Changing the pointer array to an allocatable array would eliminate
the aliasing possibilities too. That is, it is probably not the
difference between using allocate() and the automatic array, it is
that pointer arrays can be targets of pointer assignments, even
though they do not have the target attribute in their declaration,
whereas other types of arrays cannot.
$.02 -Ron Shepard
.
- Follow-Ups:
- Re: automatic arrays versus saved, allocated arrays
- From: Richard E Maine
- Re: automatic arrays versus saved, allocated arrays
- References:
- automatic arrays versus saved, allocated arrays
- From: Bil Kleb
- Re: automatic arrays versus saved, allocated arrays
- From: robert . corbett
- automatic arrays versus saved, allocated arrays
- Prev by Date: Re: Logical expressions with integer operands
- Next by Date: Re: Standard query: Bounds of allocatable components from derived-type constructors?
- Previous by thread: Re: automatic arrays versus saved, allocated arrays
- Next by thread: Re: automatic arrays versus saved, allocated arrays
- Index(es):
Relevant Pages
|