Summary The workshare construct divides the execution of the enclosed structured block into separate units of work, and causes the threads of the team to share the work such that each unit is executed only once by one thread, in the context of its implicit task.
The syntax of the workshare construct is as follows:
!$omp end workshare [nowait]
[!$omp end workshare [nowait]]
Binding The binding thread set for a workshare region is the current team. A workshare region binds to the innermost enclosing parallel region. Only the threads of the team that executes the binding parallel region participate in the execution of the units of work and the implied barrier of the workshare region if the barrier is not eliminated by a nowait clause.
Description An implicit barrier occurs at the end of a workshare region if a nowait clause is not specified.
An implementation of the workshare construct must insert any synchronization that is required to maintain standard Fortran semantics. For example, the effects of one statement within the structured block must appear to occur before the execution of succeeding statements, and the evaluation of the right hand side of an assignment must appear to complete prior to the effects of assigning to the left hand side.
The statements in the workshare construct are divided into units of work as follows:
The transformational array intrinsic functions are MATMUL, DOT_PRODUCT, SUM, PRODUCT, MAXVAL, MINVAL, COUNT, ANY, ALL, SPREAD, PACK, UNPACK, RESHAPE, TRANSPOSE, EOSHIFT, CSHIFT, MINLOC, and MAXLOC.
It is unspecified how the units of work are assigned to the threads that execute a workshare region.
If an array expression in the block references the value, association status, or allocation status of private variables, the value of the expression is undefined, unless the same value would be computed by every thread.
If an array assignment, a scalar assignment, a masked array assignment, or a FORALL assignment assigns to a private variable in the block, the result is unspecified.
The workshare directive causes the sharing of work to occur only in the workshare construct, and not in the remainder of the workshare region.
Execution Model Events The workshare-begin event occurs after an implicit task encounters a workshare construct but before the task starts to execute the structured block of the workshare region.
The workshare-end event occurs after an implicit task finishes execution of a workshare region but before it resumes execution of the enclosing context.
Tool Callbacks A thread dispatches a registered ompt_callback_work callback with ompt_scope_begin as its endpoint argument and ompt_work_workshare as its wstype argument for each occurrence of a workshare-begin event in that thread. Similarly, a thread dispatches a registered ompt_callback_work callback with ompt_scope_end as its endpoint argument and ompt_work_workshare as its wstype argument for each occurrence of a workshare-end event in that thread. The callbacks occur in the context of the implicit task. The callbacks have type signature ompt_callback_work_t.
Restrictions Restrictions to the workshare construct are as follows: