fdvmLDe (1158336), страница 3
Текст из файла (страница 3)
Let NB( 1:P ) be an integer array. The following directive
CDVM$ DISTRIBUTE A( GEN_BLOCK(NB)) ONTO R
splits array A on P blocks. The block i of size NB( i ) is mapped on processor R( i ).
Here
P | |
NB( i ) = N | |
i=1 |
Example 4.2. Distribution by blocks of different size.
A | ||
R(1) | 1 | |
CDVM$ PROCESSORS R( 4 ) | 2 | |
R(2) | 3 | |
INTEGER BS(4) | 4 | |
5 | ||
6 | ||
DATA BS / 2, 4, 4, 2 / | ||
R(3) | 7 | |
8 | ||
REAL A(12) | 9 | |
10 | ||
CDVM$ DISTRIBUTE A (GEN_BLOCK(BS)) ONTO R | R(4) | 11 |
12 | ||
4.1.3WGT_BLOCK format
The WGT_BLOCK format specifies distribution by blocks according to their relative "weights".
Let WGT_BLOCK(WB, NBL) format is specified.
WB(i) defines weight of i ‑th block for 1 i NBL. The blocks are distributed on P processors with balancing of sums of block weights on every processor. The condition
P NBL
must be satisfied.
The processor weight is defined as a sum of weights of all the blocks distributed on it . The array dimension is distributed proportionally to processor weights.
BLOCK format is special case of WGT_BLOCK(WB,P) format, where WB(i) = 1 for 1 i P and NBL = P.
GEN_BLOCK format is special case of WGT_BLOCK format with some precision.
The example 4.2 can be rewritten using WGT_BLOCK format in the following way.
Example 4.3. Distribution by blocks according to weights.
CDVM$ PROCESSORS R( 4 )
DOUBLE PRECISION WB(12)
REAL A(12)
CDVM$ DISTRIBUTE A ( WGT_BLOCK( WB, 12 ) ) ONTO R
DATA WB / 2., 2., 1., 1., 1., 1., 1., 1., 1., 1., 2., 2. /
In the example 4.3 P = 4 and distribution is identical to the example 4.2.
As distinct from distribution by non-equal blocks, distribution by WGT_BLOCK format can be performed for any number of processors from range 1 P NBL. For given example the size of processor array R can be varied from 1 to 12.
4.1.4Format of *
Format of “*” means, that a dimension is localized on each processor (non-distributed or local dimension).
4.1.5Multidimensional distributions
For multidimensional distributions mapping format is specified for each dimension. The following correspondence is established between dimensions of the array to be distributed and the processor arrangement.
Let the processor arrangement has n dimensions. Number the dimensions not formatted as * from left to right d1, ..., dk. Then dimension di will be mapped on i-th dimension of processor arrangement. The condition kn must be satisfied.
Example 4.4. One-dimensional distribution.
Blocks A | Processors | ||||||
CDVM$ PROCESSORS R1( 2 ) | |||||||
REAL A(100,100) | 1 | A( 1: 50,1:100) | 1 | 1 | |||
CDVM$ DISTRIBUTE A (BLOCK,*) ONTO R1 | 2 | A(51:100,1:100) | 2 | 2 | |||
Example 4.5. Two-dimensional distribution.
CDVM$ PROCESSORS R1( 2 ) | Blocks A | Processors | |||
REAL A(100,100) | 1 | 2 | |||
CDVM$ DISTRIBUTE A (BLOCK,BLOCK) ONTO R2 | 1 | 2 | 1 | 1 | 2 |
3 | 4 | 2 | 3 | 4 | |
4.2Distribution of dynamic arrays
4.2.1Dynamic arrays in Fortran 77 program
There are no features to deal with dynamic arrays in Fortran 77. So a user is forced to simulate dynamic memory by so called working arrays. The dynamic memory is declared as a one-dimensional array of large size. The dynamic arrays of different shape are defined as continuous segments in the working array.
Example 4.6. Working array usage.
REAL W(100000)
READ (6 , *) N, M
C the arrays of size N*N and M*M are required in the program
CALL SUB1(W(1), N, W(1+N*N), M)
END
SUBROUTINE SUB1(A, N, B, M)
DIMENSION A(N,N), B(M,M)
. . .
END
An analysis of available programs showed that there is no certain discipline when dealing with simulated dynamic arrays. In particular, array allocation in memory is not fixed explicitly. An access to dynamic array is implemented by reference to the working array. Therefore the compiler can't to determine the array shape.
4.2.2Dynamic arrays in FDVM model. POINTER directive
Suggested model is a subset of dynamic array model in Fortran 90. It allows to execute this model without modifications in three program environments:
-
Sequential program in Fortran 77,
-
Parallel program in FDVM,
-
Parallel program in HPF.
For dynamic arrays, distributed by default, FDVM allows to use any methods of dynamic memory simulation. For the dynamic arrays, distributed by DISTRIBUTE and ALIGN directives, FDVM defines the following discipline of allocation and usage of dynamic arrays.
-
All explicitly distributed arrays are allocated in dynamic memory pool with the name HEAP
REAL HEAP (MAXM)
where MAXM is a number of dynamic memory words.
-
Data type and the rank of the dynamic array are fixed by the following FDVM directive
pointer-directive | is type , POINTER ( dimension-list ) :: pointer-name-list |
dimension | is : |
pointer-name | is scalar-int-variable-name |
or int-array-name |
The specification type defines data type of the dynamic array. The following constraints exist for the variables specified in POINTER directive.
-
Only value of function ALLOCATE or a value of other variable with POINTER attribute can be assigned to the variable with POINTER attribute.
-
A number of dimensions in left and right sides of the statement assigning a value to the variable with POINTER attribute must be the same.
-
The sizes of each dimension and dynamic array allocation in HEAP are fixed by the following statement
pointer = ALLOCATE ( sdim ,... )
where
pointer - | is a pointer to integer variable (scalar or array element) with POINTER attribute |
sdim - | is a integer one-dimensional array of the size ndim. ndim is a rank of multidimensional array, allocated in dynamic memory HEAP. The sdim( i ) value defines the size of i-th dimension. The size of allocated segment is equal to sdim( 1 ) sdim( 2 ) .... sdim( ndim ). |
Integer function ALLOCATE returns a number of initial element of allocated segment of dynamic memory HEAP. The ALLOCATE function is programmed by a user, therefore it can have additional arguments besides obligatory sdim one.
-
Only the following kind of a dynamic array reference is allowed in a procedure, where dynamic array allocation is performed
HEAP(pointer)
Moreover, this reference can be used only as the actual argument of a function or subroutine call.
Let several pools with identifiers ID1 , …, IDn. are used in a program. There is no necessity to rewrite the program with single pool HEAP of dynamic memory. It is enough to write following specification
CDVM$ HEAP ID1 , …, IDn
But every pool IDi must satisfy requirements above for HEAP pool. The pool can keep only the arrays, distributed by DISTRIBUTE and ALIGN directives.
4.2.3DISTRIBUTE and REDISTRIBUTE directives for dynamic arrays
Distribution of dynamic arrays is performed by DISTRIBUTE and REDISTRIBUTE directives. The syntax of directives is extended in the following way:
distributee | is . . . |
or pointer-name |
If a scalar or the array with POINTER attribute are specified as distributee, then distribution is postponed up to execution of ALLOCATE function, assigning a value to the pointer. Instead of ALLOCATE function, the array creation and distribution is done according to DISTRIBUTE directive formats.
The REDISTRIBUTE directive for dynamic array can be performed only after execution of the ALLOCATE function, assigning a value to correspondent POINTER variable.
If dynamic array pointer is an element of a pointer array, the dynamic array can be distributed by REDISTRIBUTE directive only. As only a reference to pointer name is allowed in REDISTRIBUTE directive, the element of the pointer array should be assigned previously to scalar variable-pointer. The array with PT(I) pointer can be distributed by the following statements sequence:
P1 = PT( I )
CDVM$ REDISTRIBUTE P1( BLOCK, BLOCK )
It is necessary to transform the program from example 4.6 in the following FDVM program.
Example 4.7. Mapping of FDVM dynamic arrays.
REAL HEAP(100000)
INTEGER ALLOCATE
CDVM$ REAL, POINTER (:,:) :: PA, PB
INTEGER PA, PB
C descriptors of dynamic arrays
INTEGER DESCA(2), DESCB(2)