Print

Print


Ted Stern wrote:

> Naomi was specifically asking how to avoid slowdowns due to use of
> pointers.
>   

On 06/25/2010 12:44 AM, Van Snyder wrote:
> Here's how I solve it, rather than trying to outwit the compiler's
> memory allocator.
>   
[...]

> When the CONTIGUOUS attribute is available in all the compilers I use,
> I'll add it to the dummy argument declarations.
>   

Regarding POINTER: Pointers have two disadvantages. (a) They have to
regarded as noncontiguous by the compiler (unless they have the
CONTIGUOUS attribute) and (b) a pointer might alias with another pointer
or with a variable with TARGET attribute. Both the aliasing and
noncontiguity forces the compiler to generate much slower code. For
instance, the compiler might unnecessarily use temporary arrays, do
copy-in/copy-out, assume strides, not optimizing away useless
assignments etc. Thus, you should try to avoid POINTERS.

Regarding Van's assumed-shaped dummies: As a work around, you could
declare the dummy arguments as ALLOCATABLE. In this case, the compiler
knows (or should know ;-) that the memory is contiguous.

And instead of waiting until all compilers have the CONTIGUOUS
attribute, you could use a preprocessor and conditionally define:
   #define CONTIGUOUS  ,contiguous
At least one of the latest Cray compilers and the gfortran (4.6
developer trunk) support the CONTIGUOUS attribute; I wouldn't be
surprised if the next release of other vendors would have it as well.

Tobias