From walt@swcp.com Sat Feb 11 02:29:35 1995
Received: from kitsune.swcp.com by dkuug.dk with SMTP id AA19231
  (5.65c8/IDA-1.4.4j for <SC22WG5@dkuug.dk>); Sat, 11 Feb 1995 17:27:16 +0100
Received: (from walt@localhost) by kitsune.swcp.com (8.6.9/8.6.9) id JAA01258 for SC22WG5@dkuug.dk; Sat, 11 Feb 1995 09:29:35 -0700
Date: Sat, 11 Feb 1995 09:29:35 -0700
From: Walt Brainerd <walt@swcp.com>
Message-Id: <199502111629.JAA01258@kitsune.swcp.com>
To: SC22WG5@dkuug.dk
Subject: Allocatable arrays in derived types
X-Charset: ASCII
X-Char-Esc: 29

Regarding our proposals to have allocatable arrays in
derived types, perhaps you would be interested in this
inquiry from a user of Fortran 90.

===========================================================

I would like to ask you about a problem I've encountered
trying to use Fortran 90. I have a situation where I'm pretty
sure I ought to be able to get good performance and I'm not sure
whether the problem is a fundametal problem with the language or
a compiler inefficiency. 

The basic issue is I would like to be able to have a dynamically
allocated array within a derived type, e.g.:

type foo
   integer a, b, c
   real, allocatable :: q(:,:), r(:,:), s(:,:)
end type foo

Of course this isn't legal in F90 because the array must have
the pointer attribute, so I use:

type foo
   integer a, b, c
   real, pointer :: q(:,:), r(:,:), s(:,:), 
end type foo

This allows me to get all the semantics of allocatable arrays
(and more) but apparently at a significant price in 
performance because I have pointers rather than allocatable 
arrays. For instance, imagine I have a subroutine that takes
one of these foo types (f) and sets f.q = f.r * f.s - matrix 
multiply implemented with a triply nested do loop. The inside
of the loop will look something like:

	f%q(i,j) = f%q(i,j) + f%r(i,k) * f%s(k,j)

This type of thing ought to be able to go very fast but
because q, r and s are pointers the compiler has to assume that
there might be aliasing and has to generate lots of additional
store instructions. This is a simple example, of course, and
I have a more complicated one in mind. Needless to say, the
performance hit is enormous (more than a factor of 8 between 
allocatable arrays and pointers). 

I'm completely willing to assure the compiler that there
will be no aliasing but 1) there doesn't appear to be such
a directive on the XXX XXX and 2) I'd prefer a solution within
the language itself, so that as long as I was going by the
rules, the compiler would be able to do the right thing. 
Here the language seems to be forcing me to use pointers
which are more general than I need and confuse the compiler. 
