XL Fortran for AIX 8.1

Language Reference

DO / END DO

Purpose

The DO (work-sharing) construct enables you to divide the execution of the loop among the members of the team that encounter it. The END DO directive enables you to indicate the end of a DO loop that is specified by the DO (work-sharing) directive.

The DO (work-sharing) and END DO directives only take effect when you specify the -qsmp compiler option.

Format



        .----------------------.
        V                      |
>>- DO----+------------------+-+-------------------------------><
          '-+---+--do_clause-'
            '-,-'
 
 
>>-do_loop-----------------------------------------------------><
 
 
>>-+---------------------+-------------------------------------><
   '-END DO--+---------+-'
             '- NOWAIT-'
 
 

where do_clause is:



>>-+-firstprivate_clause----------------+----------------------><
   +-lastprivate_clause-----------------+
   +-ORDERED----------------------------+
   +-private_clause---------------------+
   +-reduction_clause-------------------+
   '-SCHEDULE--(--sched_type--+----+--)-'
                              '-,n-'
 
 

firstprivate_clause
See -- FIRSTPRIVATE.

lastprivate_clause
See -- LASTPRIVATE.

ORDERED
The loop may contain ORDERED sections in its dynamic extent.

private_clause
See -- PRIVATE.

reduction_clause
See -- REDUCTION

SCHEDULE(sched_type[,n])

sched_type
is one of AFFINITY, DYNAMIC, GUIDED, RUNTIME, or STATIC

n
must be a positive scalar integer expression; it must not be specified for the RUNTIME sched_type. See SCHEDULE for definitions of these scheduling types. If you are using the trigger_constant $OMP, do not specify the scheduling type AFFINITY.

Rules

The first noncomment line (not including other directives) that follows the DO (work-sharing) directive must be a DO loop. This line cannot be an infinite DO or DO WHILE loop. The DO (work-sharing) directive applies only to the DO loop that is immediately following the directive, and not to any nested DO loops.

The END DO directive is optional. If you use the END DO directive, it must immediately follow the end of the DO loop.

You may have a DO construct that contains several DO statements. If the DO statements share the same DO termination statement, and an END DO directive follows the construct, you can only specify a work-sharing DO directive for the outermost DO statement of the construct.

If you specify NOWAIT on the END DO directive, a thread that completes its iterations of the loop early will proceed to the instructions following the loop. The thread will not wait for the other threads of the team to complete the DO loop. If you do not specify NOWAIT on the END DO directive, each thread will wait for all other threads within the same team at the end of the DO loop.

If you do not specify the NOWAIT clause, the END DO directive implies the FLUSH directive.

All threads in the team must encounter the DO (work-sharing) directive if any thread encounters it. A DO loop must have the same loop boundary and step value for each thread in the team. All work-sharing constructs and BARRIER directives that are encountered must be encountered in the same order by all threads in the team.

A DO (work-sharing) directive must not appear within the dynamic extent of a CRITICAL or MASTER construct. In addition, it must not appear within the dynamic extent of a PARALLEL SECTIONS construct, work-sharing construct, or PARALLEL DO loop, unless it is within the dynamic extent of a PARALLEL construct.

You cannot follow a DO (work-sharing) directive by another DO (work-sharing) directive. You can only specify one DO (work-sharing) directive for a given DO loop.

The DO (work-sharing) directive cannot appear with either an INDEPENDENT or DO SERIAL directive for a given DO loop. The SCHEDULE clause may appear at most once in a DO (work-sharing) directive.

Examples

Example 1: An example of several independent DO loops within a PARALLEL construct. No synchronization is performed after the first work-sharing DO loop, because NOWAIT is specified on the END DO directive.

!$OMP PARALLEL
!$OMP DO
      DO I = 2, N
        B(I)= (A(I) + A(I-1)) / 2.0
      END DO
!$OMP END DO NOWAIT
!$OMP DO
      DO J = 2, N
         C(J) = SQRT(REAL(J*J))
      END DO
!$OMP END DO
      C(5) = C(5) + 10
!$OMP END PARALLEL
      END
 

Example 2: An example of SHARED, and SCHEDULE clauses.

!$OMP PARALLEL SHARED(A)
!$OMP DO SCHEDULE(STATIC,10)
      DO I = 1, 1000
         A(I) = 1 * 4
      END DO
!$OMP END DO
!$OMP END PARALLEL

Example 3: An example of both a MASTER and a DO (work-sharing) directive that bind to the closest enclosing PARALLEL directive.

!$OMP PARALLEL DEFAULT(PRIVATE)
      Y = 100
!$OMP MASTER
      PRINT *, Y
!$OMP END MASTER
!$OMP DO
      DO I = 1, 10
         X(I) = I
         X(I) = X(I) + Y
      END DO
!$OMP END PARALLEL
      END
 

Example 4: An example of both the FIRSTPRIVATE and the LASTPRIVATE clauses on DO (work-sharing) directives.

      X = 100
 
!$OMP PARALLEL PRIVATE(I), SHARED(X,Y)
!$OMP DO FIRSTPRIVATE(X), LASTPRIVATE(X)
      DO I = 1, 80
         Y(I) = X + I
         X = I
      END DO
!$OMP END PARALLEL
      END

Example 5: A valid example of the END DO directive.

         REAL A(100), B(2:100), C(100)
!$OMP PARALLEL
!$OMP DO
         DO I = 2, 100
             B(I) = (A(I) + A(I-1))/2.0
         END DO
!$OMP END DO NOWAIT
!$OMP DO
         DO 200 J = 1, 100
            C(J) = SQRT(REAL(J*J))
200      CONTINUE
!$OMP END DO
!$OMP END PARALLEL
      END

Example 6: A valid example of a work-sharing DO directive applied to nested DO statements with a common DO termination statement.

!$OMP DO              ! A work-sharing DO directive can
only
                      ! precede the outermost DO statement.
      DO 100 I= 1,10
 
! !$OMP DO **Error**  ! Placing the OMP DO directive here is
                      ! invalid
 
         DO 100 J= 1,10
 
!         ...
 
100   CONTINUE
!$OMP END DO

Related Information


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