This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pr32512 - efficiency of RESHAPE and SPREAD


On 8/13/07, Paul Thomas <paulthomas2@wanadoo.fr> wrote:
> Dear All,
>
> In contemplating this excellent suggestion from Jaroslav Hajek, I have
> run into an interesting puzzle.
>
> trans-array.c (gfc_conv_array_transpose) implements a transpose in which
> the operation is entirely performed inline and only acts on the
> descriptor.  Jaroslav suggests that we do the same for reshape and spread.
>
> In investigating this, I found the rather wierd and wonderful property
> of gfortran; gfc_conv_array_transpose only works when it is the actual
> argument of something.  If I lift this constraint, it still works fine.


I suspected that, partly from gfortran source which I still don't
understand very well,
and from measuring speed of transpose in expressions.

I think that the benefits are worth consideration even in the case of
array arithmetics - it can elegantly eliminate temporaries (which can
otherwise be eliminated by loop fusion and data flow analysis), and
that's usually faster for "level 1-2" operations (i.e. operations
with one or several passes over the largest array involved).

The same holds for RESHAPE and SPREAD.

these two are somewhat more tricky than TRANSPOSE. RESHAPE can only use
descriptor manipulation if the original data was contiguous (actually,
it can sometimes be done even for discontiguous data, but that would
be even trickier)
SPREAD can be implemented by using zero strides in the
descriptor_dimension struct,
but it is necessary to make sure that library functions are OK with
zero strides.

So far, it seems no other compiler uses this descriptor trick for
SPREAD, so that would make gfortran best in this regard.

cheers to gfortran,

-- 
Jaroslav Hajek
research engineer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]