DIGITAL Fortran 90
User Manual for
DIGITAL UNIX Systems


Previous Contents Index

6.2.4 The Parallel Processing Thread Model

The concepts of the parallel processing thread model are the same as those for OpenMP Fortran API (see Section 6.1.4).

6.2.5 Controlling the Data Environment

The following sections describe how you control the data environment within parallel and worksharing constructs. Using directives and data environment options on directives, you can:

6.2.5.1 Privitizing Named Common Blocks

You can make named common blocks private to a thread, but global within the thread by using the TASKCOMMON or the INSTANCE PARALLEL directive:

Only named common blocks can be made thread private.

Each thread gets its own copy of the common block, with the result that data written to the common block by one thread is not directly visible to other threads. During serial portions of the program, accesses are to the master thread copy of the common block.

You should assume that the data in thread private common blocks is undefined upon entry into the first parallel region unless you specified the COPYIN option in the PARALLEL directive (see COPYIN Option).

When you make thread private a common block that is initialized using DATA statements, the copy of the common block for each thread has that initial value. If no initial value is provided, the variables in the common block are assigned the value of zero.

You can also specify INSTANCE SINGLE, which is the default in the absence of any instance attribute. In this case, all threads share the same copy of the common block in the master thread. Assignments made by one thread affect the copy in all other threads.

6.2.5.2 Controlling Data Scope Attributes

You can use several options 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 option on a directive, the default is SHARED for those variables affected by the directive.

Each of the data scope attribute options accepts a list, which is a comma-separated list of named variables or named common blocks that are accessible in the scoping unit. When you specify named common blocks, they must appear between slashes (/name/).

Not all of the options are allowed on all directives, but the directives to which each option applies are listed in the clause descriptions.

The data scope attribute options are:

COPYIN Option

Use the COPYIN option on the PARALLEL, PARALLEL DO, and PARALLEL SECTIONS directives to copy named common block values from the master thread copy to threads at the beginning of a parallel region, use the COPYIN option on the PARALLEL directive. The COPYIN option applies only to named common blocks that have been previously declared thread private using the TASKCOMMON or the INSTANCE PARALLEL directive (see Section 6.2.5.1).

Use a comma-separated list to name the common blocks and variables in common blocks you want to copy.

DEFAULT Option

This option is the same as the OpenMP Fortran API DEFAULT clause (see Section 6.1.5.2).

FIRSTPRIVATE Option

The FIRSTPRIVATE option is the same as the OpenMP Fortran API FIRSTPRIVATE clause (see Section 6.1.5.2).

LASTLOCAL or LAST LOCAL Option

Except for differences in directive name spelling, the LASTLOCAL or LAST LOCAL option is the same as the OpenMP Fortran API LASTPRIVATE clause (see Section 6.1.5.2).

PRIVATE or LOCAL Option

Except for the alternate directive spelling of LOCAL, the PRIVATE (or LOCAL) option is the same as the OpenMP Fortran API PRIVATE clause (see Section 6.1.5.2).

REDUCTION Option

Use the REDUCTION option on the PDO directive to declare variables that are to be the object of a reduction operation. Use a comma-separated list to name the variables you want to declare as objects of a reduction.

The REDUCTION option in the DIGITAL Fortran parallel compiler directive set is different from the REDUCTION clause in the OpenMP Fortran API directive set. In the OpenMP Fortran API directive set, both a variable and an operator type are given. In the DIGITAL Fortran parallel compiler directive set, the operator is not given in the directive. The compiler must be able to determine the reduction operation from the source code. The REDUCTION option can be applied to a variable in a DO loop only if the variable meets the following criteria:


x = x operator expr 
 
x = expr operator x (except for subtraction)
 
x = operator(x, expr) 
 
x = operator(expr, x) 

where operator is one of the following supported reduction operations: +, -, *, .AND., .OR., .EQV., .NEQV., MAX, MIN, IAND, or IOR.

The compiler rewrites the reduction operation by computing partial results into local variables and then combining the results into the reduction variable. The reduction variable must be SHARED in the enclosing context.

SHARED or SHARE Option

Except for the alternate directive spelling of SHARE, the SHARED (or SHARE) option is the same as the OpenMP Fortran API SHARED clause (see Section 6.1.5.2).

6.2.6 Parallel Region Construct

The concepts of using a parallel region construct are the same as those for OpenMP Fortran API (see Section 6.1.6). However, the environment variable you use to set the default number of threads is MP_THREAD_COUNT and the run-time library routine is OtsSetNumThreads.

6.2.7 Worksharing Constructs

At the heart of parallel processing is the concept of the worksharing construct. A worksharing construct divides the execution of the enclosed code region among the members of the team created upon entering the enclosing parallel region construct.

A worksharing construct must be enclosed lexically within a parallel region if the worksharing directive is to execute in parallel. No new threads are launched and there is no implied barrier upon entry to a worksharing construct.

The worksharing constructs are:

6.2.7.1 PDO and END PDO Directives

The PDO directive specifies that the iterations of the immediately following DO loop must be dispatched across the team of threads so that each iteration is executed in parallel by a single thread. The loop that follows a PDO directive cannot be a DO WHILE or a DO loop that does not have loop control. The iterations of the DO loop are divided among and dispatched to the existing threads in the team.

You cannot use a GOTO statement, or any other statement, to transfer control into or out of the PDO construct.

If you specify the optional END PDO directive, it must appear immediately after the end of the DO loop. If you do not specify the END PDO directive, an END PDO directive is assumed at the end of the DO loop.

If you do not specify the optional NOWAIT clause on the END PDO directive, threads synchronize at the END PDO directive. If you specify NOWAIT, threads do not synchronize at the END PDO directive. Threads that finish early proceed directly to the instructions following the END PDO directive.

The PDO directive optionally lets you:

Specifying Chunk Size

A chunk is a contiguous group of iterations dispatched to a thread. You can explicitly define a chunk size for the current PDO directive by using the CHUNK or BLOCKED option. Chunk size must be a scalar integer expression. The specified chunk size overrides any chunk size specified by an earlier CHUNK directive, and applies only to the current PDO directive.

Refer to Section 6.2.10 for information about how chunk size and schedule type interact.

You can determine the chunk size for the current PDO or PARALLEL DO directive by using the following prioritized list. The available chunk size closest to the top of the list is used:

Specifying Schedule Type

The schedule type specifies a scheduling algorithm that determines how chunks of loop iterations are dispatched to the threads of a team. You can explicitly define a schedule type for the current PDO or PARALLEL DO directive by using the MP_SCHEDTYPE option. The specified schedule type overrides any default schedule type specified by an earlier MP_SCHEDTYPE directive, and applies to the current PDO or PARALLEL DO directive only.

You can determine the schedule type used for the current PDO or PARALLEL DO directive by using the following prioritized list. The available schedule type closest to the top of the list is used:

For information about schedule types, see Section 6.2.11.

Another option you can use to affect the way threads are dispatched is the ORDERED option. When you specify this option, iterations are dispatched to threads in the same order they would be for sequential execution.

Terminating Loop Execution Early

If you want to terminate loop execution early because a specified condition has been satisfied, use the PDONE directive. This is an executable directive and any undispatched iterations are not executed. However, all previously dispatched iterations are completed. When the schedule type is STATIC or INTERLEAVED, this directive has no effect because all iterations are dispatched prior to loop execution.

Overriding Implicit Synchronization

Whether or not you include the END PDO directive at the end of the DO loop, by default an implicit synchronization point exists immediately after the last statement in the loop. Threads reaching this point wait until all threads complete their work and reach this synchronization point.

If there are no data dependences between the variables inside the loop and those outside the loop, there may be no reason to make threads wait. In this case, use the NOWAIT clause on the END PDO directive to override synchronization and allow threads to continue.

6.2.7.2 PSECTIONS, SECTION, and END PSECTIONS Directives

Except for the different PSECTIONS directive name, this directive is the same as the OpenMP Fortran API SECTIONS directive (see Section 6.1.7.2).

6.2.7.3 SINGLE PROCESS and END SINGLE PROCESS Directives

Except for the different SINGLE PROCESS directive name, this directive is the same as the OpenMP Fortran API SINGLE directive (see Section 6.1.7.3).

6.2.8 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:

6.2.8.1 PARALLEL DO and END PARALLEL DO Directives

This directive is the same as the OpenMP Fortran API PARALLEL DO directive with the following exceptions:

For information about the OpenMP Fortran API PARALLEL DO directive, see Section 6.1.8.1.

6.2.8.2 PARALLEL SECTIONS and END PARALLEL SECTIONS Directives

This directive is the same as the OpenMP Fortran API PARALLEL SECTIONS directive with the following exception:

For more information about the OpenMP Fortran API PARALLEL SECTIONS directive, see Section 6.1.8.2.

6.2.9 Synchronization Constructs

Synchronization refers to the interthread communication that ensures the consistency of shared data and coordinates parallel execution among threads.

Shared data is consistent within a team of threads when all threads obtain the identical value when the data is accessed.

To achieve explicit thread synchronization, you can use:

6.2.9.1 BARRIER Directive

The BARRIER directive is the same as the OpenMP Fortran API BARRIER directive (see Section 6.1.9.2).

6.2.9.2 CRITICAL SECTION and END CRITICAL SECTION Directives

The CRITICAL SECTION and END CRITICAL SECTION directives are the same as the OpenMP Fortran API CRITICAL and END CRITICAL directives with the following exceptions:

For additional information about the OpenMP Fortran API CRITICAL directive, see Section 6.1.9.3.

6.2.10 Specifying a Default Chunk Size

To specify a default chunk size, use the CHUNK directive. Chunk size must be a scalar integer expression. The interaction between the chunk size and the schedule type are:

You can also specify a chunk size by using the CHUNK option of the PDO or PARALLEL DO directive (see Specifying Chunk Size.)

6.2.11 Specifying a Default Schedule Type

To specify a default schedule type, use the MP_SCHEDTYPE directive. The following list describes the schedule types and how the chunk size affects scheduling:

The DYNAMIC and GUIDED schedule types introduce some amount of overhead required to manage the continuing dispatching of iterations to threads. However, this overhead is sometimes offset by better load balancing when the average execution time of iterations is not uniform throughout the loop.

The STATIC and INTERLEAVED schedule types dispatch all of the iterations to the threads in advance, with each thread receiving approximately equal numbers of iterations. One of these types is usually the most efficient schedule type when the average execution time of iterations is uniform throughout the loop.

You can also specify a schedule type using the MP_SCHEDTYPE option of the PDO or PARALLEL DO directive (see Specifying Schedule Type.)


Previous Next Contents Index