Combined Parallel and Worksharing Constructs

The combined parallel/worksharing constructs provide an abbreviated way to specify a parallel region that contains a single worksharing construct. The combined parallel/worksharing constructs are:

For more details on these directives, see OpenMP* Fortran Compiler Directives in the Intel® Fortran Language Reference.

PARALLEL DO and END PARALLEL DO

Use the PARALLEL DO directive to specify a parallel region that implicitly contains a single DO directive. You can specify one or more of the clauses for the PARALLEL DO directives.

The following example shows how to parallelize a simple loop. The loop iteration variable is private by default, so it is not necessary to declare it explicitly. The END PARALLEL DO directive is optional:

Example

!$OMP PARALLEL DO

DO I=1,N

  B(I) = (A(I) + A(I-1)) / 2.0

END DO

!$OMP END PARALLEL DO

PARALLEL SECTIONS and END PARALLEL SECTIONS

Use the PARALLEL SECTIONS directive to specify a parallel region that implicitly contains a single SECTIONS directive. You can specify one or more of the clauses for the PARALLEL SECTIONS directives.

The last section ends at the END PARALLEL SECTIONS directive.

In the following example, subroutines X_AXIS, Y_AXIS, and Z_AXIS can be executed concurrently. The first SECTION directive is optional. Note that all SECTION directives must appear in the lexical extent of the PARALLEL SECTIONS/END PARALLEL SECTIONS construct:

Example

!$OMP PARALLEL SECTIONS

!$OMP SECTION

      CALL X_AXIS

!$OMP SECTION

      CALL Y_AXIS

!$OMP SECTION

      CALL Z_AXIS

!$OMP END PARALLEL SECTIONS

WORKSHARE and PARALLEL WORKSHARE

Use the WORKSHARE directive to divide work within blocks of worksharing statements or constructs into different units. This directive distributes the work of executing the units to threads of the team so each unit is only executed once.  

Use the PARALLEL WORKSHARE directive to specify parallel regions, in an abbreviated way, that contain a single WORKSHARE directive.

When using either directive, be aware that your code cannot branch in to or out of the block defined by these directives.