Parallel Processing Thread Model

This topic explains the processing of the parallelized program and adds more definitions of the terms used in the parallel programming.

The Execution Flow

A program containing OpenMP Fortran API compiler directives begins execution as a single process, called the master thread of execution. The master thread executes sequentially until the first parallel construct is encountered.

In OpenMP Fortran API, the PARALLEL and END PARALLEL directives define the parallel construct. When the master thread encounters a parallel construct, it creates a team of threads, with the master thread becoming the master of the team. The program statements enclosed by the parallel construct are executed in parallel by each thread in the team. These statements include routines called from within the enclosed statements.

The statements enclosed lexically within a construct define the static extent of the construct. The dynamic extent includes the static extent as well as the routines called from within the construct. When the END PARALLEL directive is encountered, the threads in the team synchronize at that point, the team is dissolved, and only the master thread continues execution. The other threads in the team enter a wait state.

You can specify any number of parallel constructs in a single program. As a result, thread teams can be created and dissolved many times during program execution.

Using Orphaned Directives

In routines called from within parallel constructs, you can also use directives. Directives that are not in the lexical extent of the parallel construct, but are in the dynamic extent, are called orphaned directives. Orphaned directives allow you to execute major portions of your program in parallel with only minimal changes to the sequential version of the program. Using this functionality, you can code parallel constructs at the top levels of your program call tree and use directives to control execution in any of the called routines. For example:

subroutine F
!$OMP parallel...
call G
subroutine G
!$OMP DO...

The !$OMP DO is an orphaned directive because the parallel region it will execute in is not lexically present in G.

Data Environment Directive

A data environment directive controls the data environment during the execution of parallel constructs.

You can control the data environment within parallel and worksharing constructs. Using directives and data environment clauses on directives, you can:

The data scope attribute clauses are:

You can use several directive clauses to control the data scope attributes of variables for the duration of the construct in which you specify them. If you do not specify a data scope attribute clause on a directive, the default is SHARED for those variables affected by the directive.

For detailed descriptions of the clauses, see the OpenMP Fortran version 2.0 specifications.

Pseudo Code of the Parallel Processing Model

A sample program using some of the more common OpenMP directives is shown in the code example that follows. This example also indicates the difference between serial regions and parallel regions.

PROGRAM MAIN           ! Begin serial execution

...                    ! Only the master thread executes

!$OMP PARALLEL         ! Begin a Parallel construct, form a team

...                    ! This is Replicated Code where each team

                       !  member executes the same code

!$OMP SECTIONS         ! Begin a Worksharing construct

!$OMP SECTION          ! One unit of work

...                    !

!$OMP SECTION          ! Another unit of work

...                    !

!$OMP END SECTIONS     ! Wait until both units of work complete

...                    ! More Replicated Code

  !$OMP DO             ! Begin a Worksharing construct,

      DO               !  each iteration is a unit of work

      ...              ! Work is distributed among the team

      END DO           !

!$OMP END DO NOWAIT    ! End of Worksharing construct, NOWAIT

                       !  is specified (threads need not wait

                       !  until all work is completed before

                       !  proceeding)

...                    ! More Replicated Code

!$OMP END PARALLEL     ! End of PARALLEL construct, disband team

                       !  and continue with serial execution

...                    ! Possibly more PARALLEL Constructs

END PROGRAM MAIN       ! End serial execution