fdvmLDe (1158336), страница 4
Текст из файла (страница 4)
CDVM$ DISTRIBUTE (BLOCK,BLOCK) :: PA, PB
C arrays of size N* N and M* M are required in the program
READ (6 , *) N, M
C shape of the first array
DESCA(1) = N
DESCA(2) = N
C allocation and distribution of the first array
PA = ALLOCATE(DESCA,1)
C shape of the second array
DESCB(1) = M
DESCB(2) = M
C allocation and distribution of the second array
PB = ALLOCATE(DESCB, N*N+1)
CALL SUB1(HEAP(PA), N, HEAP(PB), M)
END
SUBROUTINE SUB1(A, N, B, M)
DIMENSION A(N,N), B(M,M)
CDVM$ DISTRIBUTE (BLOCK,BLOCK) :: A, B
. . .
END
FUNCTION ALLOCATE(DESC, P)
INTEGER DESC(2), P
ALLOCATE = P
END
Other examples of dynamic array distribution see in section 7.7.
4.3Distributing by aligning
Aligning array A with distributed array B brings in accordance to each element of array A an element or a section of array B. When array B is distributed array A will be distributed simultaneously. If element of B is mapped on the processor, the element of A, corresponding to element B via alignment, will be also mapped on the same processor.
Method of mapping via alignment performs the following two functions.
The same distribution of the arrays of the same shape on one processor arrangement does not always guarantee allocation of corresponding elements on the same processor. It forces to specify remote access (see section 6) where it is possible not exist. Only alignment of corresponding elements of the arrays guarantees their allocation on the same processor.
Several arrays can be aligned with the same array. Redistribution of one array by REDISTRIBUTE directive will cause corresponding redistribution of the array group.
4.3.1ALIGN and REALIGN directives
The following directives describe array aligning:
align-directive | is align-action alignee align-directive-stuff | |
or align-action [ align-directive-stuff ] :: alignee‑list | ||
align-action | is ALIGN | |
or REALIGN | ||
align-directive-stuff | is ( align-source-list ) align-with-clause | |
alignee | is array-name | |
align-source | is * | |
or align-dummy | ||
align-dummy | is scalar-int-variable | |
align-with-clause | is WITH align-spec | |
align-spec | is align-target ( align-subscript-list ) | |
align-target | is array-name | |
or template-name | ||
align-subscript | is int-expr | |
or align-dummy-use | ||
or * | ||
align-dummy-use | is [ primary-expr * ] align‑dummy | |
primary-expr | is int-constant | |
or int-variable | ||
or ( int-expr ) | ||
add-op | is + | |
or - | ||
Constraints:
-
A length of align-source-list must be equal to the rank of aligned array.
-
A length of align-subscript-list must be equal to the rank of align‑target.
-
Each align-dummy may appear at most once in an align-subscript-list.
-
An array-name mentioned as an alignee may not appear as a distributee.
-
REALIGN directive may be applied only to the arrays specified in DYNAMIC directives.
-
align-directive-stuff can be omitted only in ALIGN directive. In such a case the distributed array can be used only after execution of REALIGN directive.
Let the alignment of two arrays is specified by the directive
CDVM$ ALIGN A(d1,…,dn) WITH B(ard1,…,ardm)
where di is specification of i-th dimension of aligned array A,
ardj is specification of j-th dimension of base array B.
If di is specified by integer variable I, then there must be at most one dimension of array B, specified by linear function ardj = a*I + b.
Let i-th dimension of array A has bounds LAi : HAi , and j-th dimension of array B, specified by linear function a*I + b , has the bounds LBj : HBj. Since the parameter I is defined on the value set LAi : HAi, then the following conditions must be satisfied:
a*LAi + b LBj , a* HAi + b HBj
If di is * , the i-th dimension of array A will be local on each processor independently from array B distribution (it is analogue of local dimension in DISTRIBUTE directive).
If ardi is * , then the array A will be replicated along j-th dimension of the array B.
If ardi is int-expr, then array A is aligned with the section of the array B.
Example 4.8. Aligning arrays
REAL A(10),B(10,10),C(22,22),D(20),E(20),F(10),G(20),H(10,10)
CDVM$ DISTRIBUTE B (BLOCK,BLOCK)
CDVM$ DISTRIBUTE D (BLOCK)
C aligning with the array section
C (the vector is aligned with the first line of A)
CDVM$ ALIGN A( I ) WITH B(1,I)
C replication of the vector aligning it with each line
CDVM$ ALIGN F( I ) WITH B(*,I)
C the matrix is collapsed;
C each matrix column corresponds to the vector element
CDVM$ ALIGN C(*,I) WITH D( I )
C alignment of vector with vector using stretching
CDVM$ ALIGN E( I ) WITH D(2*I)
C alignment vector with vector using reverse ordering
CDVM$ ALIGN G( I ) WITH D(-I+21)
C alignment matrix with matrix using rotation and stretching
CDVM$ ALIGN H(I,J) WITH C(2*J,2*I)
Several arrays (A1, A2,…) can be aligned with one B array in the same manner by the directive of the form:
CDVM$ ALIGN (d1,…,dn) WITH B(ard1,…,ardm) :: A1, A2, …
At that A1, A2… arrays must have the same rank (n), but can have different sizes of dimensions.
Let the sequence of alignments A f1 B f2 C, be specified; f2 is alignment of the array B with the array C, and f1 is alignment of the array A with the array B. The arrays A and B are considered as aligned with array C by definition. The array B is aligned by function f2 directly and array A is aligned by composite function f1(f2) indirectly. Therefore applying REALIGN directive to the array B doesn't cause redistribution of array A.
Generally a set of ALIGN specifications is a set of trees. At that every tree root must be distributed by DISTRIBUTE or REDISTRIBUTE directives. When REDISTRIBUTE directive is executed, the whole alignment tree is redistributed.
4.3.2TEMPLATE directive
If values of linear function a*I + b are beyond base array dimension, it is necessary to define a dummy array - referred to as an alignment template – using the following directive.
template-directive | is TEMPLATE template-decl-list |
template-decl | is template-name [ ( explicit-shape-spec-list ) ] |
Then it is necessary to align both arrays with the template. The template is distributed by DISTRIBUTE and REDISTRIBUTE directives. The template elements are mapped among processors without real memory allocation. They specify a processor on which elements of aligned arrays must be mapped.
Consider the following example.
Example 4.9. Aligning with template.
REAL A(100), B(100), C(100)
CDVM$ TEMPLATE TABC(102)
CDVM$ ALIGN B( I ) WITH TABC( I )
CDVM$ ALIGN A( I ) WITH TABC( I+1 )
CDVM$ ALIGN C( I ) WITH TABC( I+2 )
CDVM$ DISTRIBUTE TABC ( BLOCK )
. . .
DO 10 I = 2, 98
A(I) = C(I-1) + B(I+1)
10 CONTINUE
To avoid exchange between processors, it is necessary to allocate the elements A(I), C(I-1) and B(I+1) on the same processor. It is impossible to align arrays C and B with array A, because alignment functions I-1 and I+1 cause bounds violation of array A. Therefore the template TABS is declared. The elements of arrays A, B and C, which must be allocated on the same processor, are aligned with the same element of the template.
4.3.3Aligning dynamic arrays
To specify dynamic arrays alignment the syntax of ALIGN and REALIGN directives is extended in the following way.
alignee | is . . . |
or pointer-name | |
align-target | is . . . |
or pointer-name |
If a variable with POINTER attribute is specified as aligned array (alignee) in ALIGN directive, then directive executing is postponed up to execution of ALLOCATE function, defining the variable value. The REALIGN directive may be executed only after execution of the ALLOCATE function.
Example 4.10. Aligning dynamic arrays.
REAL HEAP(100000)
CDVM$ REAL, POINTER (:,:) :: PX, PY