Workshare Construct
The workshare construct can appear in a parallel region of a Fortran program. There is no equivalent functionality for C/C++. It is intended to be used in conjunction with Fortran 90 array syntax, where operators can be applied to whole arrays. In principle, the loops underlying these array operations can be efficiently parallelized by the compiler.
The workshare
directive begins with the OpenMP sentinel and takes no clauses. The workshare region must end with an END WORKSHARE
directive.
Example
!$OMP PARALLEL [clause [,clause]]
⋮
!$OMP WORKSHARE
⋮
!$OMP END WORKSHARE
⋮
!$OMP END PARALLEL
There are restrictions on what can appear in a workshare region. Only the following can appear there:
- array assignments
- scalar assignments
- FORALL statements and constructs
- WHERE statements and constructs
- atomic constructs
- critical constructs
- parallel constructs
The result of executing a workshare region in OpenMP must be the same as they would be in a serial context. To accomplish this, the statements in the workshare region are divided up into units of work and these are assigned to the threads in the parallel region to which the workshare is bound. The assignment of units of work and their synchronization must be such that dependencies between statements in the block are satisfied. Also, the evaluation of the right-hand side of an assignment must appear to be complete before assignments are made on the left-hand side.
The only further restriction on the user is that if any user-defined functions are found in the workshare region, they must be ELEMENTAL
because their evaluation will be assigned as a single unit of work.
There is an implicit barrier at the end of this construct unless the nowait clause is used on the END WORKSHARE
construct.