fdvmLDe (1158420), страница 8
Текст из файла (страница 8)
. . .
C edge exchange along division line D
CDVM$ PREFETCH RS
. . .
CDVM$ PARALLEL ( I ) ON A1 ( I, N1+1 ), REMOTE_ACCESS ( RS: A2(I,2))
DO 10 I = 1, M1
10 A1(I,N1+1) = A2(I,2)
CDVM$ PARALLEL ( I ) ON A1 ( I, N1+1 ), REMOTE_ACCESS ( RS: A3(I-M1,2))
DO 20 I = M1+1, M
20 A1(I,N1+1) = A3(I-M1,2)
CDVM$ PARALLEL ( I ) ON A2 ( I, 1 ), REMOTE_ACCESS ( RS: A1(I,N1))
DO 30 I = 1, M1
30 A2(I,1) = A1(I,N1)
CDVM$ PARALLEL ( I ) ON A3 ( I, 1 ), REMOTE_ACCESS ( RS: A1(I+M1,N1))
DO 40 I = 1, M2
40 A3(I,1) = A1(I+M1,N1)
. . .
IF (NOBLN) THEN
C redistribution of arrays to balance loading
. . .
CDVM$ RESET RS
END IF
. . .
1 CONTINUE
6.4REDUCTION type references
6.4.1Synchronous specification of REDUCTION type references
If there is no group name in REDUCTION specification of parallel loop, it is synchronous specification and executed in the following way.
-
Local reduction calculation. During the loop execution on each processor local value of reduction is calculated for the part of data, allocated at the processor.
-
Global reduction calculation. After the loop completion inter-processor reduction of local values is automatically calculated. Resulted value is assigned to the reduction variable on each processor.
6.4.2Asynchronous specification of REDUCTION type references
Asynchronous specification allows:
-
to joint in one group the reduction variables, calculated in different loops;
-
overlap global group reduction execution with other computations.
For asynchronous specification besides REDUCTION directive (with the group name) the following additional directives are required.
| reduction-group-directive | is REDUCTION_GROUP reduction-group-name-list |
| reduction-start-directive | is REDUCTION_START reduction-group-name |
| reduction-wait-directive | is REDUCTION_WAIT reduction-group-name |
Typical sequence of asynchronous specifications of REDUCTION type is the following.
CDVM$ REDUCTION_GROUP RD
. . .
CDVM$ PARALLEL . . . , REDUCTION (RD : d1)
C local reduction d1
. . .
CDVM$ PARALLEL . . . , REDUCTION (RD : dn)
C local reduction dn
. . .
CDVM$ REDUCTION_START RD
C beginning of global reduction di ... dn
. . .
CDVM$ REDUCTION_WAIT RD
C end of global reduction di ... dn
Constraints.
-
Before executing REDUCTION_START directive, the reduction variables of the group may be used in reduction statements of parallel loops only.
-
REDUCTION_START and REDUCTION_WAIT directives must be executed after the completion of the loop (loops) where the local values of the reduction variables were calculated. The only statements allowed between these directives are those that don't use the reduction variable values.
-
REDUCTION_WAIT directive deletes the reduction group.
Example 6.7. Asynchronous specification of REDUCTION type.
CDVM$ DISTRIBUTE A ( BLOCK )
CDVM$ ALIGN B( I ) WITH A( I )
CDVM$ REDUCTION_GROUP RD
. . .
S = 0
CDVM$ PARALLEL ( I ) ON A( I ),
CDVM$* REDUCTION ( RD : SUM(S))
DO 10 I = 1, N
10 S = S + A(I)
X = B( 1 )
CDVM$ PARALLEL ( I ) ON B( I ),
CDVM$* REDUCTION ( RD : MAX(X))
DO 20 I = 1, N
20 X = MAX(X, A(I))
CDVM$ REDUCTION_START RD
C beginning of global reduction SUM(S) and MAX(X)
CDVM$ PARALLEL ( I ) ON A( I )
DO 30 I = 1, N
30 A(I) = A(I) + B(I)
CDVM$ REDUCTION_WAIT RD
C end of global reduction
PRINT *, S, X
While the reduction group is executed the values of array A elements will be computed.
7Task parallelism
DVM parallel model joins data parallelism and task parallelism.
Data parallelism is implemented by distribution of arrays and loop iterations over virtual processor subsystem. Virtual processor subsystem can include as whole processor arrangement as its section.
Task parallelism is implemented by independent computations on sections of processor arrangement.
Let us define a set of virtual processors, where a procedure is executed, as current virtual processor system. For main program the current system consists of whole set of virtual processors.
The separate task group is defined by the following directives.
-
Declaration of task array (TASK directive).
-
Mapping task array on the sections of the processor arrangement (MAP directive).
-
Distribution of arrays over tasks (REDISTRIBUTE directive)
-
Distribution of computations (blocks of statements or iterations of parallel loop) over tasks (TASK_REGION construct).
Several tasks can be described in a procedure. Nested tasks are not allowed.
7.1Declaration of task array
A task array is described by the following directive:
| task-directive | is TASK task-list |
| task | is task-name ( max-task ) |
TASK directive declares one-dimensional task array, which then will be mapped on the processor arrangement sections.
7.2Mapping tasks on processors. MAP directive
The task mapping on processor arrangement section is performed by MAP directive
| map-directive | is MAP task-name (index-task) |
| ONTO processors-name( section-subscript-list)) |
Several tasks can be mapped on the same section.
7.3Array distribution on tasks
Array distribution on tasks is performed by REDISTRIBUTE directive with the following extension:
| dist-target | is . . . |
| or task-name ( task-index) |
The array is distributed on processor arrangement section, provided to the specified task.
7.4Distribution of computations. TASK_REGION directive
Distribution of statement blocks on the tasks is described by TASK_REGION construct:
| block-task-region | is task-region-directive |
| on-block | |
| [ on-block ]... | |
| end-task-region-directive | |
| task-region-directive | is TASK_REGION task-name [ , reduction-clause ] |
| end-task-region-directive | is END TASK_REGION |
| on-block | is on-directive |
| block | |
| end-on-directive | |
| on-directive | is ON task-name ( task-index ) [ , new-clause ] |
| end-on-directive | is END ON |
Task region and each on-block are sequences of statements with single entry (a first statement) and single exit (after last statement). TASK_REGION construct is semantically equivalent to parallel section construction for common memory model. The difference is that statement block in task region can be executed on several processors in data parallelism model.
Distribution of the parallel loop iterations on tasks is performed by the following construct:
| loop-task-region | is task-region-directive |
| parallel-task-loop | |
| end-task-region-directive | |
| parallel-task-loop | is parallel-task-loop-directive |
| do-loop | |
| parallel-task-loop-directive | is PARALLEL ( do-variable ) ON task-name ( do-variable ) [ , new-clause ] |
Distributed computation unit is an iteration of one-dimensional parallel loop. The difference from usual parallel loop is the distribution of the iteration on processor arrangement section, the section being defined by reference to the element of the task array.
Specifications reduction-clause and new-clause have the same semantics as for parallel loop. Reduction variable value must be calculated in each task. After task completion (END TASK_REGION) in the case of synchronous specification the reduction over all values of reduction variable on all the tasks are automatically performed. In the case of asynchronous specification the reduction is started by REDUCTION_START directive.
Constraint.
-
If the reduction operation is performed between tasks, these tasks must be distributed on disjoined sections of the processor arrangement.
7.5Data localization in tasks
A task is on-block or loop iteration. The tasks of the same group have the following constraints on data
-
there are no data dependencies;
-
all used and computed data are allocated (localized) on processor arrangement section of the given task;
-
task can update only the values of arrays, distributed on the section, reduction variable values and the NEW-variable values.
After the task completion each array must have same distribution as before the task startup. If the array distribution is changed in the task, it must be restored after the task completion.
7.6Fragment of static multi-block problem
The program fragment, describing realization of three-block problem (fig.6.3) is presented below.
CDVM$ PROCESSORS P( NUMBER_OF_PROCESSORS( ) )
С arrays A1,А2,А3 - the function values on the previous iteration
С arrays В1,В2,В3 - the function values on the current iteration
REAL A1( M, N1+1 ), B1( M, N1+1 )
REAL A2( M1+1, N2+1 ), B2(M1+1, N2+1 )
REAL A3( M2+1, N2+1 ), B3(M2+1, N2+1 )
С declaration of task array
CDVM$ TASK MB (3)
С aligning arrays of each block
CDVM$ ALIGN B1( I, J ) WITH A1( I, J )
CDVM$ ALIGN B2( I, J ) WITH A2( I, J )
CDVM$ ALIGN B3( I, J ) WITH A3( I, J )
С
CDVM$ DISTRIBUTE :: A1, A2, A3
CDVM$ REMOTE_GROUP RS
. . .
C distribution of tasks on processor arrangement sections and
С distribution of arrays on tasks
С ( each section contains third of all the processors)
NP = NUMBER_OF_PROCESSORS( ) / 3
CDVM$ MAP MB( 1 ) ONTO P( 1 : NP )
CDVM$ REDISTRIBUTE ( *, BLOCK ) ONTO MB( 1 ) :: A1
CDVM$ MAP MB( 2 ) ONTO P( NP+1 : 2*NP )
CDVM$ REDISTRIBUTE ( *, BLOCK ) ONTO MB( 2 ) :: A2
CDVM$ MAP MB( 3 ) ONTO P( 2*NP+1 : 3*NP )
CDVM$ REDISTRIBUTE ( *, BLOCK ) ONTO MB( 3 ) :: A3
. . .
DO 10 IT = 1, MAXIT
. . .
CDVM$ PREFETCH RS
C exchanging edges of adjacent blocks
. . .
С distribution of computations (statement blocks) on tasks
CDVM$ TASK_REGION MB
CDVM$ ON MB( 1 )
CALL JACOBY( A1, B1, M, N1+1 )
CDVM$ END ON
CDVM$ ON MB( 2 )
CALL JACOBY( A2, B2, M1+1, N2+1 )
CDVM$ END ON















