Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Make Arrays Equivalent

When you make an element of one array equivalent to an element of another array, the EQUIVALENCE statement also sets equivalences between the other elements of the two arrays. Thus, if the first elements of two equal-sized arrays are made equivalent, both arrays share the same storage. If the third element of a 7-element array is made equivalent to the first element of another array, the last five elements of the first array overlap the first five elements of the second array.

Two or more elements of the same array should not be associated with each other in one or more EQUIVALENCE statements. For example, you cannot use an EQUIVALENCE statement to associate the first element of one array with the first element of another array, and then attempt to associate the fourth element of the first array with the seventh element of the other array.

Consider the following example:

  DIMENSION TABLE (2,2), TRIPLE (2,2,2)
  EQUIVALENCE(TABLE(2,2), TRIPLE(1,2,2))

These statements cause the entire array TABLE to share part of the storage allocated to TRIPLE. The following table shows how these statements align the arrays:

Equivalence of Array Storage

Array TRIPLE

Array TABLE

Array Element

Element Number

Array Element

Element Number

TRIPLE(1,1,1)

1

   

TRIPLE(2,1,1)

2

   

TRIPLE(1,2,1)

3

   

TRIPLE(2,2,1)

4

TABLE(1,1)

1

TRIPLE(1,1,2)

5

TABLE(2,1)

2

TRIPLE(2,1,2)

6

TABLE(1,2)

3

TRIPLE(1,2,2)

7

TABLE(2,2)

4

TRIPLE(2,2,2)

8

   

Each of the following statements also aligns the two arrays as shown in the above table:

  EQUIVALENCE(TABLE, TRIPLE(2,2,1))
  EQUIVALENCE(TRIPLE(1,1,2), TABLE(2,1))

You can also make arrays equivalent with nonunity lower bounds. For example, an array defined as A(2:3,4) is a sequence of eight values. A reference to A(2,2) refers to the third element in the sequence. To make array A(2:3,4) share storage with array B(2:4,4), you can use the following statement:

  EQUIVALENCE(A(3,4), B(2,4))

The entire array A shares part of the storage allocated to array B. The following table shows how these statements align the arrays. The arrays can also be aligned by the following statements:

EQUIVALENCE(A, B(4,1))
EQUIVALENCE(B(3,2), A(2,2))
Equivalence of Arrays with Nonunity Lower Bounds

Array B

Array A

Array Element

Element Number

Array Element

Element Number

B(2,1)

1

   

B(3,1)

2

   

B(4,1)

3

A(2,1)

1

B(2,2)

4

A(3,1)

2

B(3,2)

5

A(2,2)

3

B(4,2)

6

A(3,2)

4

B(2,3)

7

A(2,3)

5

B(3,3)

8

A(3,3)

6

B(4,3)

9

A(2,4)

7

B(2,4)

10

A(3,4)

8

B(3,4)

11

   

B(4,4)

12

   

Only in the EQUIVALENCE statement can you identify an array element with a single subscript (the linear element number), even though the array was defined as multidimensional. For example, the following statements align the two arrays as shown in the above table:

  DIMENSION B(2:4,1:4), A(2:3,1:4)
  EQUIVALENCE(B(6), A(4))