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

SECTIONS Directive

The SECTIONS directive specifies that code in the the enclosed SECTION blocks are to be divided among the threads in the team. Each section is executed once.

!$OMP SECTIONS [clause[[,]clause ...]  

[!$OMP SECTION]
	code block                  
[!$OMP SECTION
	code block]
... 

!$OMP END SECTIONS [NOWAIT] 

The clause can be one of the following:

  • PRIVATE (list)
  • FIRSTPRIVATE (list)
  • LASTPRIVATE (list)
  • REDUCTION ({operator | intrinsic):list)

Example

!Filename: sections.f90
!
!This shows code that is executed 
!in sections.

PROGRAM SECTIONS 
        IMPLICIT NONE
        INTEGER OMP_GET_THREAD_NUM, tnumber 


!$OMP PARALLEL
!$OMP SECTIONS PRIVATE(tnumber) 

!$OMP SECTION
        tnumber=OMP_GET_THREAD_NUM()
        PRINT *,"This is section 1 being executed by thread",tnumber    
!$OMP SECTION
        tnumber=OMP_GET_THREAD_NUM()
        PRINT *,"This is section 2 being executed by thread",tnumber    
!$OMP SECTION
        tnumber=OMP_GET_THREAD_NUM()
        PRINT *,"This is section 3 being executed by thread",tnumber    
!$OMP SECTION
        tnumber=OMP_GET_THREAD_NUM()
        PRINT *,"This is section 4 being executed by thread",tnumber    
!$OMP END SECTIONS 
!$OMP END PARALLEL

END PROGRAM SECTIONS 

Compiling and running on franklin:

> cat sections.pbs
#PBS -N sections
#PBS -j oe
#PBS -o sections.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 sections -mp=nonuma -Minfo=mp sections.f90

export OMP_NUM_THREADS=2
aprun -n 1 -N 1 ./sections
> qsub sections.pbs
500738.nid00003
> cat sections.out
/opt/xt-pe/2.0.44a2/bin/snos64/ftn: INFO: linux target is being used
sections.f90:
sections:
    11, Parallel region activated
    12, Begin sections
    17, New section
    20, New section
    23, New section
    26, End sections
        Parallel region terminated
 This is section 2 being executed by thread            1
 This is section 4 being executed by thread            1
 This is section 1 being executed by thread            0
 This is section 3 being executed by thread            0
Application 4734431 resources: utime 0, stime 0

LBNL Home
Page last modified: Mon, 05 May 2008 19:34:02 GMT
Page URL: http://www.nersc.gov/nusers/help/tutorials/openmp/sections.php
Web contact: webmaster@nersc.gov
Computing questions: consult@nersc.gov

Privacy and Security Notice
DOE Office of Science