Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 3/31/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

WORKSHARE

OpenMP* Fortran Compiler Directive: Divides the work of executing a block of statements or constructs into separate units. It also distributes the work of executing the units to threads of the team so each unit is only executed once.

Syntax

!$OMP WORKSHARE

   loosely-structured-block

!$OMP END WORKSHARE [NOWAIT]

-or-

!$OMP WORKSHARE

   strictly-structured-block

[!$OMP END WORKSHARE [NOWAIT]]

loosely-structured-block

Is a structured block (section) of statements or constructs. You cannot branch into or out of the block.

strictly-structured-block

Is a Fortran BLOCK construct. You cannot branch into or out of the BLOCK construct.

The loosely-structured-block or strictly-structured-block is executed so that each statement is completed before the next statement is started and the evaluation of the right hand side of an assignment is completed before the effects of assigning to the left hand side occur.

The following are additional rules for the block:

  • It may contain statements that bind to lexically enclosed PARALLEL constructs. Statements in these PARALLEL constructs are not restricted.

  • It may contain ATOMIC directives and CRITICAL constructs.

  • It must only contain array assignment statements, scalar assignment statements, FORALL statements, FORALL constructs, WHERE statements, or WHERE constructs.

  • It must not contain any user-defined function calls unless the function is ELEMENTAL.

The binding thread set for a WORKSHARE construct is the current team. A workshare region binds to the innermost enclosing parallel region.

If you do not specify the NOWAIT keyword, synchronization is implied following the code.

Multithreaded code is not always generated for the statements inside the block of an OMP WORKSHARE construct. Some statements parallelize; others do not parallelize and instead execute sequentially inside an OMP SINGLE construct to preserve the correct semantics of WORKSHARE. Some specific details follow:

  • Simple array assignments such as A = B + C parallelize.

  • Simple array assignments with overlap such as A = A + B + C parallelize.

  • Array assignments with user-defined function calls parallelize such as A = A + F (B). F must be ELEMENTAL.

  • Array assignments with array slices on the right hand side of the assignment such as A = A + B(1:4) + C(1:4) parallelize. If the lower bound of the left hand side or the array slice lower bound or the array slice stride on the right hand side is not 1, then the statement does not parallelize.

  • Assigning into array slices does not parallelize.

  • Scalar assignments do not parallelize – there is no work that needs to be done in parallel.

  • FORALL and WHERE constructs do not parallelize.