XL Fortran for AIX 8.1

Language Reference

PARALLEL SECTIONS / END PARALLEL SECTIONS

Purpose

The PARALLEL SECTIONS construct enables you to define independent blocks of code that the compiler can execute concurrently. The PARALLEL SECTIONS construct includes a PARALLEL SECTIONS directive followed by one or more blocks of code delimited by the SECTION directive, and ends with an END PARALLEL SECTIONS directive.

The PARALLEL SECTIONS, SECTION and END PARALLEL SECTIONS directives only take effect if you specify the -qsmp compiler option.

Format



                      .-------------------------------------.
                      V                                     |
>>-PARALLEL SECTIONS----+---------------------------------+-+--><
                        '-+---+--parallel_sections_clause-'
                          '-,-'
 
 
                       .--------------------.
                       V                    |
>>-+---------+--block----+----------------+-+------------------><
   '-SECTION-'           '-SECTION--block-'
 
 
>>-END PARALLEL SECTIONS---------------------------------------><
 
 

where parallel_sections_clause is:



>>-+-copyin_clause-----------------+---------------------------><
   +-default_clause----------------+
   +-firstprivate_clause-----------+
   +-IF--(--scalar_logical_expr--)-+
   +-lastprivate_clause------------+
   +-num_threads_clause------------+
   +-private_clause----------------+
   +-reduction_clause--------------+
   '-shared_clause-----------------'
 
 

copyin_clause
See -- COPYIN

default_clause
See -- DEFAULT

firstprivate_clause
See -- FIRSTPRIVATE.

IF(scalar_logical_expr)

If you specify the IF clause, the run-time environment performs a test to determine whether to run the block in serial or parallel. If scalar_logical_expr is true, then the block is run in parallel; if not, then the block is run in serial.

lastprivate_clause
See -- LASTPRIVATE.

num_threads_clause
See -- NUM_THREADS.

private_clause
See -- PRIVATE.

reduction_clause
See -- REDUCTION

shared_clause
See -- SHARED

Rules

The PARALLEL SECTIONS construct includes the delimiting directives, and the blocks of code they enclose. The rules below also refer to sections. You define a section as the block of code within the delimiting directives.

The SECTION directive marks the beginning of a block of code. At least one SECTION and its block of code must appear within the PARALLEL SECTIONS construct. Note, however, that you do not have to specify the SECTION directive for the first section. The end of a block is delimited by either another SECTION directive or by the END PARALLEL SECTIONS directive.

You can use the PARALLEL SECTIONS construct to specify parallel execution of the identified sections of code. There is no assumption as to the order in which sections are executed. Each section must not interfere with any other section in the construct unless the interference occurs within a CRITICAL construct. See the definition of interference outside a CRITICAL construct, for more information.

It is illegal to branch into or out of any block of code that is defined by the PARALLEL SECTIONS construct.

The compiler determines how to divide the work among the threads based on a number of factors, such as the number of threads and the number of sections to be executed in parallel. Therefore, a single thread may execute more than one SECTION, or a thread may not execute any SECTION.

All work-sharing constructs and BARRIER directives that are encountered must be encountered in the same order by all threads in the team.

Within a PARALLEL SECTIONS construct, variables that are not appearing in the PRIVATE clause are assumed to be SHARED by default.

The IF clause may appear at most once in the a PARALLEL SECTIONS directive.

An IF expression is evaluated outside of the context of the parallel construct. Any function reference in the IF expression must not have side effects.

By default, a nested parallel loop is serialized, regardless of the setting of the IF clause. You can change this default by using the -qsmp=nested_par compiler option.

In a PARALLEL SECTIONS construct, a variable that appears in the REDUCTION clause of an INDEPENDENT directive or the PARALLEL DO directive of an enclosing DO loop must not also appear in the data_scope_entity_list of the PRIVATE clause.

If the REDUCTION variable of the inner PARALLEL SECTIONS construct appears in the PRIVATE clause of an enclosing DO loop or PARALLEL SECTIONS construct, the variable must be initialized before the inner PARALLEL SECTIONS construct.

The PARALLEL SECTIONS construct must not appear within a CRITICAL construct.

You should be careful when you perform input/output operations in a parallel region. If multiple threads execute a Fortran I/O statement on the same unit, you should make sure that the threads are synchronized. If you do not, the behaviour is undefined. Also note that although in the XL Fortran implementation each thread has exclusive access to the I/O unit, the OpenMP specification does not require exclusive access.

Directives that bind to a parallel region will bind to that parallel region even if it is serialized.

The END PARALLEL SECTIONS directive implies the FLUSH directive.

Examples

Example 1:

!$OMP PARALLEL SECTIONS
!$OMP   SECTION
          DO I = 1, 10
            C(I) = MAX(A(I), A(I+1))
          END DO
!$OMP   SECTION
          W = U + V
          Z = X + Y
!$OMP END PARALLEL SECTIONS

Example 2: In this example, the index variable I is declared as PRIVATE. Note also that the first optional SECTION directive has been omitted.

!$OMP PARALLEL SECTIONS PRIVATE(I)
          DO I = 1, 100
            A(I) = A(I) * I
          END DO
!$OMP   SECTION
          CALL NORMALIZE (B)
          DO I = 1, 100
            B(I) = B(I) + 1.0
          END DO
!$OMP   SECTION
          DO I = 1, 100
            C(I) = C(I) * C(I)
          END DO
!$OMP END PARALLEL SECTIONS

Example 3: This example is invalid because there is a data dependency for the variable C across sections.

!$OMP PARALLEL SECTIONS
!$OMP   SECTION
          DO I = 1, 10
            C(I) = C(I) * I
          END DO
!$OMP   SECTION
          DO K = 1, 10
            D(K) = C(K) + K
          END DO
!$OMP END PARALLEL SECTIONS

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]