[PATCH, gfortran] Re: Cray Pointers
Asher Langton
langton2@llnl.gov
Sat Aug 13 02:04:00 GMT 2005
At 10:04 PM +0100 8/12/05, Paul Brook wrote:
>> >But you still can't use both to access the same object, right? ie. the
>> >optimizers can assume that the two pointees don't alias.
>> >
>> >It would seem rather strange if two pointees can alias but a pointee and a
>> >real object can't.
>>
>> There's no prohibition on pointees aliasing real objects or other
>> pointees. Both are common, in fact. The trouble occurs when a
>> pointee and an object that it aliases are both used in the same part
>> of the program. The optimizer isn't aware of the aliasing and things
>> might break. It's a sid effect a user must be aware of when using
>> Cray pointers. Here's an example of some legal (but fragile) code
>> using Cray pointers, and the results of running that code:
>
>That's not what your proposed update in the manual says.
>There's no such thing as "legal but fragile code."
>Code is either legal and works all the time, or it's not.
>
>Just because a compiler accepts some code doesn't mean it is legal. In fact
>the majority of the requirements in the Fortran standard are requirements on
>the user writing the code. The compile need not, and in many cases can not
>issue and error when there rules are broken.
Okay, I'll backtrack a bit on this. Using a pointee in any way that
violates the Fortran aliasing rules or assumptions is illegal.
However, it is the user's responsibility to avoid doing this; the
compiler works under the assumption that there is no aliasing
whatsoever.
Cray pointers will work correctly when there is no aliasing (i.e.,
when they're used to access a dynamically allocated block of memory),
and also in any routine where a pointee is used, but any variable
with which it shares storage is not used. Some programmers use Cray
pointers for more than that (and they do so successfully), but we
can't guarantee more than that.
There are a few good descriptions of Cray pointers that cover this
issue. From Jeanne Martin's "Fortran 90 Pointers vs. Cray Pointers"
(http://portal.acm.org/citation.cfm?id=140947.140948): "For
optimization purposes, the compiler assumes that a pointer target
never never has storage in common with another variable. It is the
responsibility of the user to prevent this kind of storage
association or aliasing". (What Martin refers to as a pointer target
is usually called the "pointee").
However, the IBM XL Fortran for AIX Language Reference (version 3,
release 2, page 117) explictly permits both of the following examples
(copied verbatim):
POINTER (P,A),(P,B)
and
POINTER (P,A),(Q,B)
P=LOC(C)
Q=LOC(C)
Finally, from http://www.ibiblio.org/pub/languages/fortran/ch2-16.html:
" Cray pointers and automatic compiler optimizations
--------------------------------------------------
Compilers perform partial data-flow analysis as a preparation before
automatic optimization, unrestricted pointers that are free to point
to any other variable makes such an analysis almost impossible.
Cray pointers are restricted to some degree, e.g. pointer arithmetic
is not allowed, the pointer can point only to its pointee, but the
pointee can be different objects during one procedure activation.
Fortran was designed to produce highly optimized code (remember that
it had to compete with assembly language and won), the language
specification explicitly forbids anything that may lead to ALIASING
(having more than one name for the same variable) because of the
detrimental effect on automatic optimizations. In short, pointers
violate the spirit of Fortran, and defeat its purpose.
Cray pointers may even cause WRONG results when compiler optimization
is turned on, and they are used without deep understanding of the
effect on the optimizer. A probable reason for that may be that the
optimizer assumes no-aliasing."
I'm trying to get an updated patch prepared this afternoon, and I'll
include some updates to the manual to try to clarify this issue.
-Asher
More information about the Fortran
mailing list