next up previous contents
Next: Collapsing Dimensions Up: Data Distribution Previous: Practical Example of Alignment

 

Aligning Allocatable Arrays

Allocatable arrays may appear in ALIGN statements but

This means the array on the RHS, the align-target, of the WITH must be in existence before the array on the LHS is aligned to it.

 

Align (and distribution) statements containing references to allocatable arrays appear in the declarations area of the code as normal but the actual alignment (or distribution) only takes place after an object has been brought into existence. Consider the following example,

      REAL, DIMENSION(:), ALLOCATABLE :: A,B
!HPF$ ALIGN A(:) WITH B(:)

then,

      ALLOCATE (B(100),stat=ierr)
      ALLOCATE (A(100),stat=ierr)

is OK as the align-target B is allocated before the alignee A. The statement,

      ALLOCATE (B(100),A(100),stat=ierr)

is also OK as the statement is executed from left to right; this means that the align-target, B, is again allocated before A, however,

      ALLOCATE (A(100),stat=ierr)
      ALLOCATE (B(100),stat=ierr)

is not because the alignee, A, would be allocated and an attempt would be made to align it with the align-target B. Since B does not yet exist, an error would ensue. The same would happen if both allocations appear in the same statement but in the wrong order, viz:

      ALLOCATE (A(100),B(100),stat=ierr)

because here the allocations take places from left to right. B should have been allocated first.

 

There are quite reasonable guidelines on what can and cannot be done with allocatables arrays. Clearly one cannot ALIGN a regular array WITH an allocatable:

      REAL, DIMENSION(:)              :: X
      REAL, DIMENSION(:), ALLOCATABLE :: A
!HPF$ ALIGN X(:) WITH A(:)                  ! WRONG

because the colon notation implies that A must be the same size and shape as X. Since A is allocatable this may not be the case. It could also be that A is smaller that X which again would not make sense. [Note: there is a problem in aligning allocatables to TEMPLATE s (see later for templates). Templates have a fixed size, so how does one know whether the allocatable will be larger than the template in one or more dimensions?]

Another pitfall,

      REAL, DIMENSION(:), ALLOCATABLE :: A, B
!HPF$ ALIGN A(:) WITH B(:)                  
     ALLOCATE(B(100),stat=ierr)
     ALLOCATE(A(50),stat=ierr)

is due to the colon notation suggesting that A and B are conformable but the ALLOCATE statements clearly stating that they are not, however, the third example,

      REAL, DIMENSION(:), ALLOCATABLE :: A, B
!HPF$ ALIGN A(i) WITH B(i)
     ALLOCATE(B(100),stat=ierr)
     ALLOCATE(A(50),stat=ierr)

correctly states what was intended by the second example, does not use the colon notation and therefore does not imply conformance (no `: 's). Here A cannot be larger than B.

Now try this question gif

Return to corresponding overview page gif


next up previous contents
Next: Collapsing Dimensions Up: Data Distribution Previous: Practical Example of Alignment

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.