fdvmLDe (1158336), страница 10
Текст из файла (страница 10)
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(processors-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 ) |
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.6) is presented below.
CDVM$ PROCESSORS P(NUMBER_OF_PROCESSORS( ))
C arrays A1,A2,A3 - the function values on the previous iteration
C arrays B1,B2,B3 - 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)
C declaration of task array
CDVM$ TASK MB( 3 )
C 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)
C
CDVM$ DISTRIBUTE :: A1, A2, A3
CDVM$ REMOTE_GROUP RS
C distribution of tasks on processor arrangement sections and
C distribution of arrays on tasks
C ( 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
. . .
C 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
CDVM$ ON MB( 3 )
CALL JACOBY( A3, B3, M2+1, N2+1 )
CDVM$ END ON
CDVM$ END TASK_REGION
10 CONTINUE
7.7Fragment of dynamic multi-block problem
Let us consider the fragment of the program, which is dynamically tuned on the number of blocks and the size of each block.
C NA - maximal number of blocks
PARAMETER ( NA=20 )
CDVM$ PROCESSORS R(NUMBER_OF_PROCESSORS( ))
C memory for dynamic arrays
REAL HEAP(100000)
C sizes of dynamic arrays
INTEGER SIZE(2,NA)
C arrays of pointers for A and B
CDVM$ REAL, POINTER (:,:) :: PA, PB, P1, P2
INTEGER P1, P2, PA(NA), PB(NA)
CDVM$ TASK PT( NA )
CDVM$ ALIGN :: PB, P2
CDVM$ DISTRIBUTE :: PA, P1
. . .
NP = NUMBER_OF_PROCESSORS( )
C distribution of arrays on tasks
C dynamic allocation of the arrays and execution of postponed
C DISTRIBUTE and ALIGN directives
IP = 1
DO 20 I = 1, NA
CDVM$ MAP PT( I ) ONTO R(IP:IP+1)
PA(I) = ALLOCATE ( SIZE(1,I), HEAP )
P1 = PA(I)
CDVM$ REDISTRIBUTE (*,BLOCK) ONTO PT( I ) :: P1
PB(I) = ALLOCATE ( SIZE(1,I), HEAP )
P2 = PB(I)
CDVM$ REALIGN P2(I,J) WITH P1(I,J)
IP = IP + 2
IF( IP .GT. NP ) THEN IP = 1
20 CONTINUE
. . .
C distribution of computations on tasks
CDVM$ TASK_REGION PT
CDVM$ PARALLEL ( I ) ON PT( I )
DO 50 I = 1,NA
CALL JACOBY(HEAP(PA(I)), HEAP(PB(I)), SIZE(1, I), SIZE(2, I))
50 CONTINUE
CDVM$ END TASK_REGION
The arrays (blocks) are cyclically distributed on two processor sections. If NA > NP/2, then several arrays will be distributed on some sections. The loop iterations, distributed on the same section, will be executed sequentially in data parallelism model.
8COMMON and EQUIVALENCE
The arrays, distributed by default, can be used in COMMON blocks and EQUIVALENCE statements without restrictions.
The arrays, distributed by DISTRIBUTE or ALIGN directive, can't be used in EQUIVALENCE statements. Moreover, these arrays can't be associated with other data objects. Explicitly distributed arrays can be the components of COMMON block under the following conditions:
-
COMMON block must be described in main program unit.
-
Every occurrence of the COMMON block must have the same number of components and each corresponding component must have a storage sequences of the same size;
-
If explicitly mapped array is the component of the COMMON block, then the array declarations in different program units must specify the same data type and shape. The DISRIBUTE and ALIGN directives, applied to the array, must have the identical parameters.
Example 8.1. Explicitly distributed array in COMMON block.