Combined Parallel/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:

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 and the 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:

!$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 and the 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:

!$OMP PARALLEL SECTIONS
!$OMP SECTION
    CALL X_AXIS
!$OMP SECTION
    CALL Y_AXIS
!$OMP SECTION
    CALL Z_AXIS
!$OMP END PARALLEL SECTIONS