TutorialsTutorials HomeOpenMPIndexIntroduction PARALLEL DO PARALLEL DO SECTIONS SINGLE MASTER CRITICAL BARRIER FLUSH ATOMIC ORDERED
FullDocument
Related InfoOpenMP Home Page |
SINGLE DirectiveThe SINGLE directive specifies that the enclosed code is to be executed by only one thread in the team. Threads that are not executing in the SINGLE directive wait at the END SINGLE directive unless NOWAIT is specified. It is illegal to branch out of a SINGLE block. !$OMP SINGLE [clause[[,]clause ...] block !$OMP END SINGLE [NOWAIT] The clause can be on of the following:
Example
!Filename: single.f90
!
!This shows use of the SINGLE directive.
!
PROGRAM SINGLE
IMPLICIT NONE
INTEGER, PARAMETER:: N=12
REAL, DIMENSION(N):: A,B,C,D
INTEGER:: I
REAL:: SUMMED
!$OMP PARALLEL SHARED(A,B,C,D) PRIVATE(I)
!***** Reading files fort.10, fort.11, fort.12 in parallel
!$OMP SECTIONS
!$OMP SECTION
READ(10,*) (A(I),I=1,N)
!$OMP SECTION
READ(11,*) (B(I),I=1,N)
!$OMP SECTION
READ(12,*) (C(I),I=1,N)
!$OMP END SECTIONS
!$OMP SINGLE
SUMMED = SUM(A) + SUM(B) + SUM(C)
PRINT *, "Sum of A+B+C=",SUMMED
!$OMP END SINGLE
!$OMP DO SCHEDULE(STATIC,4)
DO I=1,N
D(I) = A(I) + B(I)*C(I)
END DO
!$OMP END DO
!$OMP END PARALLEL
PRINT *, "The values of D are", D
END PROGRAM SINGLE
Compiling and running on franklin. The files named fort.10, fort.11, and fort.12 each has 12 1.0's:
> cat single.pbs
#PBS -N single
#PBS -j oe
#PBS -o single.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 single -mp=nonuma -Minfo=mp single.f90
export OMP_NUM_THREADS=2
aprun -n 1 -N 1 ./single
> qsub single.pbs
500801.nid00003
> cat single.out
/opt/xt-pe/2.0.44a2/bin/snos64/ftn: INFO: linux target is being used
single.f90:
single:
13, Parallel region activated
17, Begin sections
20, New section
22, New section
24, End sections
26, Begin single section
29, End single section
Barrier
32, Parallel loop activated; static block-cyclic iteration allocation
35, Barrier
Parallel region terminated
Sum of A+B+C= 36.00000
The values of D are 2.000000 2.000000 2.000000
2.000000 2.000000 2.000000 2.000000
2.000000 2.000000 2.000000 2.000000
2.000000
Application 4735339 resources: utime 0, stime 0
|
![]() |
Page last modified: Mon, 05 May 2008 20:41:14 GMT Page URL: http://www.nersc.gov/nusers/help/tutorials/openmp/single.php Web contact: webmaster@nersc.gov Computing questions: consult@nersc.gov Privacy and Security Notice |
![]() |