• Aucun résultat trouvé

ASSOCIATION OF ENTITIES

Dans le document CRAY® COMPUTER SYSTEMS (Page 150-157)

DATA STRUCTURES, STORAGE,

4.5 STORAGE AND ASSOCIATION

4.5.5 ASSOCIATION OF ENTITIES

Two entities are associated if their names represent the same storage location, either within a program unit or in different program units:

that is, entities are associated if they use the same storage, or if their storage sequences overlap. Character entities must not be associated with arithmetic or logical entities.

Association of entities across program units allows a subprogram to process data as needed by another program unit. This is accomplished by the use of either arguments or common blocks. Arguments allow the calling program unit to specify, in effect, an address to be accessed; this

associates entities in the called and calling program units (see 2.5).

With a common block, each program unit independently declares a group of entities that occupy a common area of storage; corresponding entities declared by different program units are then associated (see 4.6). Data that can be referenced by more than one program unit is called global in Cray parlance; see 4.5.5.2.

Within a program unit, an EQUIVALENCE statement associates entities. Such association is used to organize storage in large common blocks (see 4.6.3).

Totally associated entities have the same storage sequence. Partially associated entities share part but not all of a storage sequence. All entities using a given storage unit are affected by the unit's value or undefined status; totally associated entities of the same type have the same values and definition status.

Partial association can exist between a double-precision or complex value and a second value of type integer, real, logical, double-precision, or complex; or between two character entities. Partial association can occur through the use of COMMON, EQUIVALENCE, or ENTRY statements. (In a

function subprogram, all entry names are associated with one another and with the function name.) Partial association must not occur through argument association except for character arguments.

Partial association is illustrated in 4.5.6.

*******************************************************

CAUTION

The order in which CFT77 stores variables may differ from that used by other compilers, such as CFT.

Programs written for these compilers give invalid results when compiled with CFT77 if they use weak implicit association, described in the following subsection.

*******************************************************

4.5.5.1 Implicit association

With many Fortran compilers, including CFT, entities can be associated based on assumptions about how storage is allocated. For example:

INTEGER T(5) INTEGER A,B,C,D,E EQUIVALENCE (T(l),A)

With such compilers, you can assume that variables A through E are stored in the order declared in the above INTEGER statement; the EQUIVALENCE statement would then associate element T(2) with B, and so on. This is

weak implicit association because i t is merely a by-product of certain compiler implementations.

Under eFT77, however, you should not make assumptions about storage sequences except for those of an array or of the entities declared in a COMMON statement. Only in these cases can association be reliably based on implied positions, such as when two arrays are equivalenced. This is

strong implicit association because i t results from storage

requirements defined in the ANSI standard. See example in 4.5.6, following.

Storage order is discussed in 4.5.2; array storage sequences are

4.5.5.2 Global and local data (Cray terminology)

In Cray usage, data is considered global if i t is represented by entities in common blocks or used as arguments, because such data can be referenced and changed by more than one program unit. Local data is declared and accessed only by one program unit.

The ANSI standard does not define these terms as just described but makes the same distinction, such as in requirements for the SAVE statement. The distinction is important in Cray usage, for such techniques as vectorizing and multiprocessing. In the ANSI standard these terms apply only to the scope of symbolic names (see 2.1.5); for example, a variable name is local because the scope in which i t can be referenced is a single program unit.

In Cray usage, however, a local variable not only has a local name but also references local data; that is, i t is not used as an argument and is not contained in a common block.

4.5.6 EQUIVALENCE STATEMENT

An EQUIVALENCE statement specifies the sharing of one or more storage units by two or more entities in a single program unit, in order to use storage more efficiently. This causes the association of those entities.

EQUIVALENCE (nlist)[,(nlist)] ..•

nlist List of two or more variable names, array element names, character substring names, or array names, separated by commas. nlist cannot include names of subprogram dummy arguments, pointees, or variable names that are also function names. An array name with no subscript refers only to the array's initial address.

Examples:

EQUIVALENCE (ARRAY1,VECTOR1), (ARRAY2,VECTOR2) EQUIVALENCE (A(l),X), (A(73),Y), (A(247),Z)

An EQUIVALENCE statement specifies that the storage sequence of each entity in a list nlist shares the same first storage unit. This associates all entities in the list and can also indirectly associate other entities, such as adjacent addresses (higher or lower) when two array elements are associated. If entities are of different data types, the EQUIVALENCE statement does not cause type conversion or imply

mathematical equivalence.

Associated entities are assigned to the same kind of storage, static or stack. Stack storage is used if -a stack is in the cft77 command or ALLOC=STACK is in the CFT?? control statement (see section 1) and the entities have not been otherwise assigned to static storage (for example, with a DATA statement).

The ANSI Fortran Standard does not specify storage allocation methods.

Example:

INTEGER I REAL R(4) COMPLEX C(2)

DOUBLE PRECISION D

EQUIVALENCE (C(2), R(2), I), (R,D)

The above EQUIVALENCE statement specifies that the following storage units are the same:

The third storage unit of C (that is, the first unit of the second element of C)

The second storage unit of R

The storage unit of I

The second storage unit of D

The storage sequences can be illustrated as follows:

Complex Real Integer

Double precision

Storage Unit 1 2 I 3 I 4 I 5

C(l) C(2) I IR(1)IR(2)IR(3)IR(4)1

I

I

I

D

I

As the preceding diagram shows, R(2) and I are totally associated.

The following are partially associated: R(l) and C(l), R(2) and C(2), R(3) and C(2), I and C(2), R(l) and D, R(2) and D, I and D, C(l) and D, and C(2) and D. Although C(l) and C(2) are each

associated with D, C(l) and C(2) are not associated with each other.

Association of element C(l) is implied by the association of C(2) with R(2), even though C(l) does not appear in the EQUIVALENCE

4.5.6.1 Array names in EQUIVALENCE statements

The use of an array name in an EQUIVALENCE statement has the same effect as using the name of the array's first array element. If an array

element name appears in an EQUIVALENCE statement, the number of subscript expressions must be less than or equal to the number of dimensions in the array declarator for the array. When the number of subscripts is less than the number of dimensions, the lower bounds are used for the

unspecified subscripts; this does not conform to the ANSI Fortran standard, and a warning is issued.

4.5.6.2 Restrictions on EQUIVALENCE statements

An EQUIVALENCE statement must not specify the same storage unit to occur more than once in a storage sequence. Example:

DIMENSION A(2)

EQUIVALENCE (A(1),B) , (A(2),B) !Illegal statement The above sequence is prohibited because it specifies the same storage unit for A(1) and A(2).

An EQUIVALENCE statement must not specify consecutive storage units to be nonconsecutive. For example, the following is prohibited:

REAL A(2)

DOUBLE PRECISION D(2)

EQUIVALENCE (A(1),D(1»,(A(2),D(2» !Illegal statement

An EQUIVALENCE statement must not associate the storage sequences of two different common blocks in the same program unit. For example, the following is prohibited:

COMMON/A/X COMMON/B/Y

EQUIVALENCE (X,Y) !Illegal statement

An EQUIVALENCE statement must not extend a common block storage sequence by adding storage units preceding the first storage unit in the block.

(This unit is the first entity specified in a COMMON statement for the common block.) Example:

COMMON IX/A

REAL B(2)

EQUIVALENCE (A,B(2» !Illegal statement

The above sequence is not permitted because it would associate an array element B(1) with a storage unit preceding A in common block X.

An entity tif type character can be equivalenced only with other entities of type character. Lengths are not required to be the same. Partial overlapping between character entities can occur through equivalance association.

Example:

CHARACTER A*4,B*4,C(2)*3 EQUIVALENCE (A,C(l»,(B,C(2»

The above sequence partially associates A with C(2) as shown in the following illustration.

Character number:

4.6 COMMON BLOCKS

1011021031041051061071

1----

A

----I

1----

B

----I

1--C(l)--I--C(2)--1

A common block is an area of memory that can be referenced by any

program unit in a program, allowing a subprogram to process data as needed by another program unit. A common block can be referenced by any program unit that declares the common block.

The COMMON statement declares a common block's name (if any) along with the names of variables and arrays contained in the block. The order in which these names appear within each COMMON statement determines how the entities are associated across program units. TASK COMMON and LOCAL

COMMON work the same way for common blocks used in multitasking (see 4.6.6 and 4.6.7).

Example:

PROGRAM EXBLOK

COMMON ITIMEI ARRAYA(10),ARRAYB(20),FACTOR CALL SWING

SUBROUTINE SWING

COMMON ITIMEI VECTORA(10),VECTORB(20),AMULT

The two COMMON statements above declare a common block named TIME and associate VECTORA with ARRAYA, VECTORB with ARRAYB, and AMULT with FACTOR. This allows subroutine SWING to process the current values

Because character and noncharacter data use different kinds of storage units (see 4.5.1 and G.5), a common block must include either no

characters or all characters.

A named common block has a name specified in a COMMON, TASK COMMON, or LOCAL COMMON statement, along with the names of variables or arrays stored in the block. A blank common block, often called simply "blank common," is declared in the same way but with no name shown. Blank common cannot be initialized before run time, such as with a DATA statement. You can use blank common to manage memory for your own requirements, as described in appendix D.

4.6.1 FEATURES AND UTILITIES FOR USING COMMON BLOCKS

This subsection describes compiler features for managing common blocks, and the FTREF utility.

If all program units in a program declare the same common block in the same way, entities in the common block are effectively global, as in Pascal usage. However, this global property is lost unless every change in the declaration is made in all program units. You can make global changes easily if the declaration is contained only in a separate file and inserted in each program unit by an INCLUDE statement (see 1.5).

The optional Symbol Cross-reference Table in your program listing

indicates the storage type for each symbol; this includes the name of any common block containing a symbol. To get this table, include -e sx on the cft77 command or ON=SX on the CFT7? control statement.

To obtain a list of all references to entities in common blocks, use the FTREF utility; this is described in the Performance Utilities Reference Manual for either UNICOS or COS, respectively pUblications SR-2040 and SR-0146. You can invoke FTREF as follows; the loader is not invoked because FTREF performs only a static analysis of source code.

Under UNICOS:

cft77 -e sx hello.f

ftref -c full - t full hello.l > hello. ref

Under COS (JCL statements in $IN, following JOB and ACCOUNT statements):

CFT??,ON=SX,L=LISTX.

FTREF,I=LISTX,CB=FULL,TREE=FULL.

IEOF

As specified above, the two full options for FTREF give the information most frequently needed: common block references and a calling tree.

Under COS, you must specify a nondefault listing dataset (here LISTX) in the invocations of both CFT?? and FTREF.

Dans le document CRAY® COMPUTER SYSTEMS (Page 150-157)