Performance of assumed shape arrays in Fortran

Hi:

I’am coding a series of performance critical routines in Fortran 90
(pgf90 and mpif90), which were previously coded in Fortran 77. Basically
it is mostly loop and artimetic stuff with arrays.

In the original Fortran 77 we used only explicit shape, one dimensional
arrays like X(1:n).

In the new version we would like to use two-dimensional arrays of
basically two ‘types’ : Y(1:3,1:n) and Z(1:1,1:n).

( That is because we want Y(1,j) Y(2,j) and Y(3,j) to be
contiguous in memory instead of having three separate
arrays Y1(1:n), Y2(1:n), Y3(1:n) )

The routines we are dealing with, would need to be called with either
Y or Z arrays as actual arguments, so we were planing to use assumed shape
dummy arguments like W(:,:).

Alternatively, we can code two different sets of routines, one set for
Y arrays (which have first dimension of size 3) and another set of
routines for Z arrays (which have first dimension of size 1). As stated
above performance is critical in these routines.

A few questions about expected performance:

  1. In the best case scenario, would the performance using
    assumed shape dummy argument arrays, match the performance
    of using two sets of routines with explicit shape dummy arguments ?

  2. Will PGI shape propagation feature work OK for
    a routine which is called with two different
    shapes of the actual argument ( for example
    a million times with shape (1:3,1:n) and another
    two million times with shape (1:1,1:n) )

  3. Any sugestions … ?

Thanks, Gabriel

…Hi, one more question considering that we are also
planing to use MPI within these routines:

  1. Is there a compiler switch to prevent the pgf90 compiler from
    making copies of arguments (specially assumed-shape arrays),
    in either the calling or called procedure ? (i.e. to force it to
    pass the argument by reference ?)

Thanks again, G.

1 Like

Hi G.

  1. In the best case scenario, would the performance using
    assumed shape dummy argument arrays, match the performance
    of using two sets of routines with explicit shape dummy arguments ?

In the best case, yes (almost). The only extra overhead would be passing in an extra argument for the array descriptor. Note that the “best case” is when you pass in the full array “call foo(a)”.

  1. Will PGI shape propagation feature work OK for
    a routine which is called with two different
    shapes of the actual argument ( for example
    a million times with shape (1:3,1:n) and another
    two million times with shape (1:1,1:n) )

Sure.

  1. Is there a compiler switch to prevent the pgf90 compiler from
    making copies of arguments (specially assumed-shape arrays),
    in either the calling or called procedure ? (i.e. to force it to
    pass the argument by reference ?)

No but a copy is only made if the array section you’re passing is non-contiguous…

  1. Any sugestions … ?

Avoid passing in non-contiguous array sections and you should be fine.

Hope this helps,
Mat

1 Like