NERSC logo National Energy Research Scientific Computing Center
  A DOE Office of Science User Facility
  at Lawrence Berkeley National Laboratory
 

ORDERED Directive

The code enclosed with ORDERED and END ORDERED directives is executed in the order in which iterations would be executed in a sequential execution of the loop. The ORDERED directive can only appear in the context of a DO or PARALLEL DO directive. It is illegal to branch into or out of an ORDERED block.

!$OMP ORDERED              
	block                   
!$OMP END ORDERED          

Example

PROGRAM ORDERED
        IMPLICIT NONE

        INTEGER, PARAMETER:: N=1000, M=4000
        REAL, DIMENSION(N,M):: X,Y
        REAL, DIMENSION(N):: Z
        INTEGER I,J

        CALL RANDOM_NUMBER(X)
        CALL RANDOM_NUMBER(Y)
        Z=0.0

        PRINT *, 'The first 20 values of Z are:'

!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(I,J)

!$OMP DO SCHEDULE(DYNAMIC,2) ORDERED
        DO I=1,N
                DO J=1,M
                        Z(I) = Z(I) + X(I,J)*Y(J,I)
                END DO

!$OMP ORDERED
                IF(I<21) THEN
                        PRINT *, 'Z(',I,') =',Z(I)
                END IF
!$OMP END ORDERED

        END DO

!$OMP END DO

!$OMP END PARALLEL


END PROGRAM ORDERED

Compiling and running on franklin:

> cat ordered.pbs
#PBS -N ordered
#PBS -j oe
#PBS -o ordered.out
#PBS -q interactive
#PBS -S /bin/bash
#PBS -l mppwidth=1
#PBS -l mppnppn=1
#PBS -l mppdepth=2
#PBS -l walltime=00:05:00
#PBS -V

cd $PBS_O_WORKDIR

ftn -o ordered -mp=nonuma -Minfo=mp ordered.f90

export OMP_NUM_THREADS=2
aprun -n 1 -N 1 ./ordered
> qsub ordered.pbs
500980.nid00003
> cat ordered.out
/opt/xt-pe/2.0.44a2/bin/snos64/ftn: INFO: linux target is being used
ordered.f90:
ordered:
    15, Parallel region activated
    18, Parallel loop activated; dynamic iteration allocation
    31, Barrier
        Parallel region terminated
 The first 20 values of Z are:
 Z(            1 ) =    1028.067    
 Z(            2 ) =    1015.378    
 Z(            3 ) =    1010.786    
 Z(            4 ) =    1003.594    
 Z(            5 ) =    990.9749    
 Z(            6 ) =    982.2872    
 Z(            7 ) =    1021.567    
 Z(            8 ) =    1019.952    
 Z(            9 ) =    1011.410    
 Z(           10 ) =    986.6424    
 Z(           11 ) =    987.3596    
 Z(           12 ) =    992.1103    
 Z(           13 ) =    1001.674    
 Z(           14 ) =    1000.352    
 Z(           15 ) =    1021.354    
 Z(           16 ) =    1009.728    
 Z(           17 ) =    996.0969    
 Z(           18 ) =    1005.107    
 Z(           19 ) =    993.8898    
 Z(           20 ) =    981.4053    
Application 4736903 resources: utime 22, stime 3

Without the ordered directive, sample output looks like this:

 The first 20 values of Z are:
 Z(            3 ) =    1010.786    
 Z(            1 ) =    1028.067    
 Z(            2 ) =    1015.378    
 Z(            5 ) =    990.9749    
 Z(            6 ) =    982.2872    
 Z(            7 ) =    1021.567    
 Z(            8 ) =    1019.952    
 Z(            9 ) =    1011.410    
 Z(           10 ) =    986.6424    
 Z(           11 ) =    987.3596    
 Z(           12 ) =    992.1103    
 Z(           13 ) =    1001.674    
 Z(           14 ) =    1000.352    
 Z(           15 ) =    1021.354    
 Z(           16 ) =    1009.728    
 Z(           17 ) =    996.0969    
 Z(           18 ) =    1005.107    
 Z(           19 ) =    993.8898    
 Z(           20 ) =    981.4053    
 Z(            4 ) =    1003.594    
Application 4736940 resources: utime 24, stime 2

LBNL Home
Page last modified: Mon, 05 May 2008 22:25:17 GMT
Page URL: http://www.nersc.gov/nusers/help/tutorials/openmp/ordered.php
Web contact: webmaster@nersc.gov
Computing questions: consult@nersc.gov

Privacy and Security Notice
DOE Office of Science