fdvmLDe (1158420), страница 9
Текст из файла (страница 9)
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.
С NA - maximal number of blocks
PARAMETER ( NA=20 )
CDVM$ PROCESSORS R( NUMBER_OF_PROCESSORS( ) )
С memory for dynamic arrays
REAL HEAP(100000)
С sizes of dynamic arrays
INTEGER SIZE( 2, NA )
С arrays of pointers for А и В
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( )
С distribution of arrays on tasks
С dynamic allocation of the arrays and execution of postponed directives
С DISTRIBUTE и ALIGN
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
. . .
С 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.
Declaration in main program.
PROGRAM MAIN
CDVM$ DISTRIBUTE B ( *, BLOCK )
COMMON /COM1/ X, Y(12), B(12,30)
Declaration in subroutine. The error is another number of components.
SUBROUTINE SUB1
CDVM$ DISTRIBUTE B1 ( *, BLOCK )
COMMON /COM1/ X, Y(12), Z, B1(12,30)
Declaration in subroutine. The error is another distribution of the array.
SUBROUTINE SUB2
CDVM$ DISTRIBUTE B2 ( BLOCK, BLOCK )
COMMON /COM1/ X, Y(12), B2(12,30)
Declaration in subroutine. The error is another configuration of the array.
SUBROUTINE SUB3
CDVM$ DISTRIBUTE B3 ( *, BLOCK )
COMMON /COM1/ X, Y(12), B(30,12)
Declaration in subroutine. There is no errors.
SUBROUTINE SUB4
CDVM$ DISTRIBUTE B4 ( *, BLOCK )
COMMON /COM1/ X, Y(12), B(12,30)
9Procedures
-
Procedure call inside parallel loop.
A procedure, called inside parallel loop, must not have side effects and contains processor exchanges (purest procedure). As a consequence, the purest procedure doesn't contain:
-
input/output statements;
-
FDVM directives;
-
assignment of values of COMMON block variables.
-
Procedure call outside parallel loop.
If the actual argument is explicitly mapped array (distributed by DISTRIBUTE or ALIGN), it should be passed without shape changing. It means, that actual argument is the reference to the array beginning, and configurations of actual and corresponding formal arguments are the same.
-
Formal arguments.
If the actual argument is a distributed array, then corresponding formal argument must have explicit or inherited distribution.
Explicit distribution is described by DISTRIBUTE and ALIGN directives with the following restriction: a formal argument can be aligned only with other formal argument. The explicit distribution of formal argument means, that before the procedure call a user must provide actual argument distribution in exact correspondence with formal argument distribution.
Inherited distribution is described by the directive
| inherit-directive | is INHERIT dummy-array-name-list |
Inherited distribution means that formal argument inherits a distribution of actual argument for each procedure call. Inherited distribution doesn't require from a user to distribute actual argument in correspondence with the formal argument.
REDISTRIBUTE and REALIGN directives can be applied to formal arguments, if actual and formal arguments have DYNAMIC attribute.
-
Local arrays.
In the procedure local arrays can be distributed by DISTRIBUTE and ALIGN directives. A local array can be aligned with formal argument. The DISTRIBUTE directive distributes the local array on the processor subsystem, on which the procedure was called (current subsystem). If a processor arrangement section is specified in DISTRIBUTE directive, then the number of the processors must be equal to the number of processors of the current subsystem. The number of current subsystem processors is defined by intrinsic function ACTIVE_NUM_PROCS( ).
The special case is distributed local array with SAVE attribute. The following conditions must be satisfied for the array:
-
DISTRIBUTE and ALIGN directives have the identical parameters in each procedure call.
-
The array cannot be used in REDISTRIBUTE and REALIGN directives.
Example 9.1. Distribution of the local arrays and formal arguments.
SUBROUTINE DIST( A, B, C, N )
CDVM$ PROCESSORS PA ( ACTIVE_NUM_PROCS( ) )
DIMENSION A(N,N), B(N,N), C(N,N), X(N,N), Y(N,N)
C explicit distribution of formal argument
CDVM$ DISTRIBUTE A ( *, BLOCK )
C aligned formal argument
CDVM$ ALIGN B( I, J ) WITH A( I, J )
C inherited distribution of the formal argument
CDVM$ INHERIT C
C aligning local array with formal argument
CDVM$ ALIGN X( I, J ) WITH C( I, J )
C distribution of the local array
CDVM$ DISTRIBUTE Y ( *, BLOCK ) ONTO PA
. . .
END
10Input/Output
The statements of standard Fortran77 are used for data input/output in FDVM.
FDVM allows only restricted form of input/output statements for distributed arrays:
-
An input/output list may contain only one name of distributed array and may not contain other input/output items.
-
Only «*» format specifier may be used in formatted I/O statement.
-
A control information list may not contain ERR, END and IOSTAT specifiers.
-
Any variable specified in a control information list must be replicated variable.
The statements of distributed array input/output cannot be used in parallel loop and in task region.
Input/output statements for replicated variables have the following restrictions:
-
A control information list may not contain ERR and END specifiers.
-
Only the following simplified form of the implicit loop is allowed
(A(i1,i2,...,I), I = n1,n2)
when inputting replicated assumed-size array.
Input statement, INQUIRE statement, and any other input/output statement with controlled parameter IOSTAT may not be used in a parallel loop.
Usage of input/output statements in tasks. If each task (on-block) uses its own files, for input/output the restrictions above is in active. If several tasks use the same file additional differences from Fortran 77 standard occur. When dealing with sequential access file all tasks input data from the file beginning but output records from different tasks are placed to the file in arbitrary order. Note that FDVM program performing unformatted I/O of distributed arrays is not compatible with serial Fortran 77 program in common case. Data written by one program may not be read by the other one because of difference in record length.
11Compatibility with HPF
FDVM data mapping directives are based on the following HPF2 directives: DISTRIBUTE, REDISTRIBUTE, ALIGN, REALIGN, PROCESSORS, TEMPLATE, DYNAMIC, SHADOW and INHERIT. The following restrictions exist for a syntax and semantics of the directives.
-
DISTRIBUTE and REDISTRIBUTE directives have the formats BLOCK, GEN_BLOCK and “*” only.
-
There is no aligning by triplet in ALIGN and REALIGN directives.
-
There are permitted only two forms of formal argument specification : explicit distribution and inherited distribution.
-
EQUIVALENCE statement can't be applied to distributed arrays.
The directives of computation distribution are semantically a subset of the corresponding HPF2 directives. In particular, the PARALLEL directive is a subset of INDEPENDENT directive in HPF2.
The directives of remote data specifications have no analogues in HPF2, as it is assumed, that HPF2 compiler defines access to remote data automatically.
Thus the set of FDVM directives can be transformed to the set of HPF2 directives automatically.
12The difference between FDVM1.0 and FDVM2.0 versions
The FDVM 1.0 version is a subset of the FDVM 2.0 version. The following new possibilities are provided:
-
A model of dynamic arrays. This model can be automatically transformed for execution in Fortran 77, FDVM and HPF2 languages (section 4.2).
-
Task parallelism (section 7).
-
GEN_BLOCK format for array distribution (section 4.1.2).
-
Distribution of a loop with regular dependence on data (section 6.2.3).
-
Extended REMOTE_ACCESS specification(section 6.3).
-
Overlapping computations and data exchange (section 6.2.4, 6.3.3, 6.4.2)
References
-
Message-Passing Interface Forum, Document for a Standard Message-Passing Interface, 1993. Version 1.0.
-
OpenMP Consortium: OpenMP Fortran Application Program Interface, Version 1.0, October 1997.
-
High Performance Fortran Forum. High Performance Fortran Language Specification. Version 1.0
-
High Performance Fortran Forum. High Performance Fortran Language Specification. Version 2.0, January 31, 1997.
-
ANSI X3.9-1978 Programming Language Fotran. New York 1978.
Annex 1. Syntax
2.4. Syntax of FDVM directives
| directive-line | is CDVM$ dvm-directive |
| or *DVM$ dvm-directive | |
| dvm-directive | is specification-directive |
| or executable-directive | |
| specification-directive | is processors-directive |
| or align-directive | |
| or distribute-directive | |
| or template-directive | |
| or pointer-directive | |
| or shadow-directive | |
| or dynamic-directive | |
| or inherit-directive | |
| or remote-group-directive | |
| or reduction-group-directive | |
| or task-directive | |
| executable-directive | is realign-directive |
| or redistribute-directive | |
| or parallel-directive | |
| or remote-access-directive | |
| or shadow-group-directive | |
| or shadow-start-directive | |
| or shadow-wait-directive | |
| or reduction-start-directive | |
| or reduction-wait-directive | |
| or new-value-directive | |
| or prefetch-directive | |
| or reset-directive | |
| or parallel-task-loop-directive | |
| or map-directive | |
| or task-region-directive | |
| or end-task-region-directive | |
| or on-directive | |
| or end-on-directive |
Constraints:
-
A directive-line follows the rules of fixed form comment lines.
-
A specification-directive may appear only where a specification statement may appear.
-
An executable-directive may appear only where executable statement may appear.
-
Any expression, included in specification directive, must be the specification expression.
Definition. A specification expression is an expression where each primary is:
-
A constant,
-
A variable that is a dummy argument,
-
A variable that is in a common block,
-
An intrinsic function reference where each argument is a specification expression,
-
A specification expression enclosed in parentheses.
3. Virtual processor arrangements. PROCESSORS directive
| processors-directive | is PROCESSORS processors-decl-list |
| processors-decl | is processors-name ( explicit-shape-spec-list ) |
| explicit-shape-spec | is [ lower-bound : ] upper-bound |
| lower-bound | is int-expr |
| upper-bound | is int-expr |
4.1. DISTRIBUTE and REDISTRIBUTE directives
| distribute-directive | is dist-action distributee dist-directive-stuff |
| or dist-action [ dist-directive-stuff ] :: distributee-list |
| dist-action | is DISTRIBUTE |
| or REDISTRIBUTE |
| dist-directive-stuff | is dist-format-list [ dist-onto-clause ] |















