Fortran User's Guide

Cray Pointers

A Cray pointer is a variable whose value is the address of another entity, which is called the pointee.

f90 supports Cray pointers; Standard Fortran 90 does not.

Syntax

The Cray POINTER statement has the following format:


POINTER  ( pointer_name, pointee_name [array_spec] ), ...

Where pointer_name, pointee_name, and array_spec are as follows:

pointer_name

Pointer to the corresponding pointee_name.

pointer_name contains the address of pointee_name.

Must be: a scalar variable name (but not a structure) 

Cannot be: a constant, a name of a structure, an array, or a 

function 

pointee_name

Pointee of the corresponding pointer_name

Must be: a variable name, array declarator, or array name 

array_spec

If array_spec is present, it must be explicit shape, (constant or nonconstant bounds), or assumed-size.

Example: Declare Cray pointers to two pointees.


	POINTER ( p, b ),  ( q, c )

The above example declares Cray pointer p and its pointee b, and Cray pointer q and its pointee c.

Example: Declare a Cray pointer to an array.


	 POINTER ( ix, x(n, 0:m) )

The above example declares Cray pointer ix and its pointee x; and declares x to be an array of dimensions n by m-1.

Purpose of Cray Pointers

You can use pointers to access user-managed storage by dynamically associating variables to particular locations in a block of storage.

Cray pointers allow accessing absolute memory locations.

Cray pointers do not provide convenient manipulation of linked lists because (for optimization purposes) it is assumed that no two pointers have the same value.

Cray Pointers and Fortran Pointers

Cray pointers are declared as follows:

POINTER ( pointer_name, pointee_name [array_spec] )

Fortran pointers are declared as follows:

POINTER object_name

The two kinds of pointers cannot be mixed.

Features of Cray Pointers

Restrictions on Cray Pointers

Restrictions on Cray Pointees

Usage of Cray Pointers

Cray pointers can be assigned values as follows:

Example: Use Cray pointers as described above.


	SUBROUTINE  sub ( n )
	COMMON pool(100000)
	INTEGER blk(128), word64
	REAL a(1000), b(n), c(100000-n-1000)
	POINTER ( pblk, blk ), (ia, a ), ( ib, b ), &
			( ic, c ), ( address, word64 )
	DATA address / 64 /
	pblk = 0
	ia = LOC( pool )
	ib = ia + 1000
	ic = ib + n
	...

Remarks about the above example:

Optimization and Cray Pointers

For purposes of optimization, f90 assumes the storage of a pointee is never overlaid on the storage of another variable--it assumes that a pointee is not associated with another variable.

Such association could occur in either of two ways:

These kinds of association are sometimes done deliberately, such as for equivalencing arrays, but then results can differ depending on whether optimization is turned on or off.

Example: b and c have the same pointer.


	POINTER ( p, b ),  ( p, c )
	REAL x, b, c
	p = LOC( x )
	b = 1.0
	c = 2.0
	PRINT *, b
	...

Above, because b and c have the same pointer, assigning 2.0 to c gives the same value to b. Therefore b prints out as 2.0, even though it was assigned 1.0.