cdvmLDe (1158401), страница 2
Текст из файла (страница 2)
#define NUMBER_OF_PROCESSORS() 1
Example 3.1. Description of virtual processor arrangements.
DVM(PROCESSORS) void *P[N];
DVM(PROCESSORS) void *Q[NUMBER_OF_PROCESSORS()],
*R[2][NUMBER_OF_PROCESSORS()/2];
The value N has to be equal to the value of the function NUMBER_OF_PROCESSORS ( ), and both have to be even.
4Data Mapping
C-DVM supports distribution by blocks (of equal or different size) and distribution via alignment.
4.1DISTRIBUTE and REDISTRIBUTE directives
Syntax.
| distribute-directive | ::= | DISTRIBUTE [ dist-directive-stuff ] |
| redistribute-directive | ::= | REDISTRIBUTE |
| distributee | ::= | array-name |
| dist-directive-stuff | ::= | dist-format... [ dist-onto-clause ] |
| dist-format | ::= | [BLOCK] |
| dist-onto-clause | ::= | ONTO dist-target |
| dist-target | ::= | processors-name [ section-subscript ]… |
| section-subscript | ::= | [ subscript [ : subscript ] ] |
Constraints:
-
The length of dist-format… list must be equal to the array rank. That is, distribution format must be specified for every dimension.
-
The number of distributed dimensions of the array (format is not specified as ‘[]’) has to be less or equal to the number of dimensions of dist-target.
-
The array block-array-name in GENBLOCK specification must be one-dimensional integer array, with size equal to the size of corresponding dimension of processor arrangement, and a sum of its element values is equal to the size of distributed dimension;
-
dist-directive-stuff can be omitted in DISTRIBUTE directive only. In this case distributed array can be used after REDISTRIBUTE directive execution only.
-
The ONTO clause specifies a virtual processor arrangement or its section. If ONTO specification is omitted, then the array is distributed upon the current processors arrangement the program or the subtask.
-
NEW specification in REDISTRIBUTE directive means that there is no need to copy old values of elements of array, they will be updated.
Let us consider distribution formats for one dimension of the array (one-dimensional array A[N]) and for one dimension of the processor arrangement (one-dimensional array R[P]). Multi-dimensional distributions are considered in section 4.1.4.
4.1.1 Format BLOCK
An array dimension is distributed succesively by blocks of [N/P] elements. If N is not divisible by P there will be one partially filled block and may be some empty blocks.
Example 4.1. Distribution by format BLOCK.
| A | B | C | ||||
| R[0] | 0 | 0 | 0 | |||
| 1 | 1 | 1 | ||||
| DVM(PROCESSORS) void * R[4]; | 2 | 2 | ||||
| DVM(DISTRIBUTE [BLOCK] ONTO R) | 3 | |||||
| float A [12], B[13], C[5]; | ||||||
| R[1] | 3 | 4 | 2 | |||
| 4 | 5 | 3 | ||||
| 5 | 6 | |||||
| 7 | ||||||
| R[2] | 6 | 8 | 4 | |||
| 7 | 9 | |||||
| 8 | 10 | |||||
| 11 | ||||||
| R[3] | 9 | 12 | ||||
| 10 | ||||||
| 11 | ||||||
4.1.2Format GEN_BLOCK
Distribution by blocks of different sizes allows affecting on processor loading balance for algorithms performing different volume of computations for different parts of data area.
Let NB[P] - be an integer array. The following directive
DVM(DISTRIBUTE [ GENBLOCK(NB) ] ONTO R) float A[N];
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[0] | 0 | |
| DVM(PROCESSORS) void * R[ 4]; | 1 | |
| int BS[4]={2,4,4,2}; | ||
| DVM(DISTRIBUTE [ GENBLOCK(BS)] ONTO R) | R[1] | 2 |
| float A[12]; | 3 | |
| 4 | ||
| 5 | ||
| R[2] | 6 | |
| 7 | ||
| 8 | ||
| 9 | ||
| R[3] | 10 | |
| 11 | ||
4.1.3Format []
Format [] means, that a dimension is not distributed, that is localized on each processor wholly.
4.1.4Multidimensional 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.3. One-dimensional distribution.
| DVM(PROCESSORS) void R1[2]; | Blocks A | Processors | ||||
| DVM(DISTRIBUTE [BLOCK][] ONTO R1) | 1 | 0 | 1 | |||
| float A[100][100]; | 2 | 1 | 2 | |||
Example 4.4. Two-dimensional distribution.
| DVM(PROCESSORS) void *R2 [2][2]; | Blocks A | Processors | |||
| 0 | 1 | ||||
| DVM(DISTRIBUTE [BLOCK][BLOCK] | 1 | 2 | 0 | 1 | 2 |
| ONTO R2) float A[100][100]; | 3 | 4 | 1 | 3 | 4 |
4.2Multidimensional dynamic arrays
4.2.1Dynamic arrays in C program
DVM system provides extended features to use dynamic arrays. It allows to create multidimensional arrays which sizes along all dimensions are calculated at runtime. (C language allows this for the first dimension only). Multidimensional arrays of different sizes (and sometimes even of different rank) may be passed as parameters. There are two different ways to deal with multidimensional dynamic arrays in C-DVM language. The first one is based on usage of C-style multidimensional arrays; the second one is to simulate multidimensional arrays using one-dimensional ones.
4.2.2Using C-style multidimensional arrays
The following discipline of declaration, creation, destruction and usage of multidimensional dynamic array elements is provided:
-
n-dimensional array is declared as a pointer to (n-1)-dimensional array:
elem_type(*arrid)[dim2]...[dimn];
In particular, a one-dimensional array is declared as a pointer to scalar:
elem_type *arrid;
-
The array is created by the statement
arrid=malloc(dim1*dim2...* sizeof(elem_type));
Here:
| elem_type | - element type, |
| arrid | - name (identifier) of the array, |
| dimi | - size of i-th dimension of the array. |
-
Array destruction is performed using free(arrid) statement.
-
Reference to the array element in the program text is denoted as arrid[ind1]...[indn].
The C-DVM compiler translates these constructions to correct descriptions and Run-Time Library calls. But to translate the program as sequential by ordinary C compiler, the sizes of all the array dimensions dimi (except the first one) must be constants. It is proposed to redefine temporarily them as constants (#define dimi const …#undef dimi). The converter removes these redefinitions, more precisely, moves them to the file beginning. Of course, actual ("calculated" in variables) dimensions in case of sequential execution must be equal to selected constant values (see example of Red-black SOR program in Appendix 1).
Example of declaration.
DVM(DISTRIBUTE [BLOCK][BLOCK]) float (*C)[N];
/* two-dimensional distributed array */
4.2.3Simulation of multidimensional arrays via one-dimensional ones
To operate with multidimensional dynamic arrays in C language other method is used. Memory area (one-dimensional) of required size is created and multidimensional array is simulated by macros arrid(ind1,...,indn) similar to Fortran notation. The macros calculates position of element with specified indexes in the memory area, assigned to the array.















