A worksharing construct must be enclosed dynamically within a parallel region if the worksharing directive is to execute in parallel. No new threads are launched and there is no implied barrier on entry to a worksharing construct.
The worksharing constructs are:
DO and END DO directives
SECTIONS, SECTION, and END SECTIONS directives
SINGLE and END SINGLE directives
For more details on these directives, see OpenMP* Fortran Compiler Directives in the Intel® Fortran Language Reference.
The DO directive specifies that the iterations of the immediately following DO loop must be dispatched across the team of threads so that each iteration is executed by a single thread. The loop that follows a DO directive cannot be a DO WHILE or a DO loop that does not have loop control. The iterations of the DO loop are dispatched among the existing team of threads.
The DO directive optionally lets you:
Control data scope attributes
Use the SCHEDULE clause to specify schedule type and chunk size (see Specifying Schedule Type and Chunk Size)
The clauses for DO directive specify:
Whether variables are PRIVATE, FIRSTPRIVATE, LASTPRIVATE, or REDUCTION
How loop iterations are SCHEDULED onto threads
In addition, the ORDERED clause must be specified if the ORDERED directive appears in the dynamic extent of the DO directive.
If you do not specify the optional NOWAIT clause on the END DO directive, threads synchronize at the END DO directive. If you specify NOWAIT, threads do not synchronize, and threads that finish early proceed directly to the instructions following the END DO directive.
You cannot use a GOTO statement, or any other statement, to transfer control onto or out of the DO construct.
If you specify the optional END DO directive, it must appear immediately after the end of the DO loop. If you do not specify the END DO directive, an END DO directive is assumed at the end of the DO loop, and threads synchronize at that point.
The loop iteration variable is private by default, so it is not necessary to declare it explicitly.
Use the noniterative worksharing SECTIONS directive to divide the enclosed sections of code among the team. Each section is executed just one time by one thread.
Each section should be preceded with a SECTION directive, except for the first section, in which the SECTION directive is optional. The SECTION directive must appear within the lexical extent of the SECTIONS and END SECTIONS directives.
The last section ends at the END SECTIONS directive. When a thread completes its section and there are no undispatched sections, it waits at the END SECTION directive unless you specify NOWAIT.
The SECTIONS directive takes an optional comma-separated list of clauses that specifies which variables are PRIVATE, FIRSTPRIVATE, LASTPRIVATE, or REDUCTION.
The following example shows how to use the SECTIONS and SECTION directives to execute subroutines X_AXIS, Y_AXIS, and Z_AXIS in parallel. The first SECTIONS directive is optional:
Example |
---|
!$OMP PARALLEL |
Use the SINGLE directive when you want just one thread of the team to execute the enclosed block of code.
Threads that are not executing the SINGLE directive wait at the END SINGLE directive unless you specify NOWAIT.
The SINGLE directive takes an optional comma-separated list of clauses that specifies which variables are PRIVATE or FIRSTPRIVATE.
When the END SINGLE directive is encountered, an implicit barrier is erected and threads wait until all threads have finished. This can be overridden by using the NOWAIT option.
In the following example, the first thread that encounters the SINGLE directive executes subroutines OUTPUT and INPUT:
Example |
---|
!$OMP PARALLEL DEFAULT(SHARED) |