TutorialsTutorials HomeOpenMPIndexIntroduction PARALLEL DO PARALLEL DO SECTIONS SINGLE MASTER CRITICAL BARRIER FLUSH ATOMIC ORDERED
FullDocument
Related InfoOpenMP Home Page |
PARALLEL DO DirectiveThe PARALLEL DO directive provides a shortcut form for specifying a parallel region that contains a single DO directive. The semantics are identical to specifying a PARALLEL directive followed by a DO directive. !$OMP PARALLEL DO [clause[[,]clause ...] do_loop !$OMP END PARALLEL DO The clause can be any of those associated with the PARALLEL and DO directives described above. Example
!Filename: pardo.f90
!
PROGRAM PARDO
IMPLICIT NONE
INTEGER I,J
INTEGER, PARAMETER:: DIM1=10000, DIM2=200
REAL A(DIM1),B(DIM2,DIM1),C(DIM2,DIM1)
REAL before, after, elapsed,S
INTEGER nthreads,OMP_GET_NUM_THREADS
CALL RANDOM_NUMBER(A)
call cpu_time(before)
!$OMP PARALLEL DO SCHEDULE(RUNTIME) PRIVATE(I,J) SHARED (A,B,C,nthreads)
DO J=1,DIM2
nthreads = OMP_GET_NUM_THREADS()
DO I=2, DIM1
B(J,I) = ( (A(I)+A(I-1))/2.0 ) / SQRT(A(I))
C(J,I) = SQRT( A(I)*2 ) / ( A(I)-(A(I)/2.0) )
B(J,I) = C(J,I) * ( B(J,I)**2 ) * SIN(A(I))
END DO
END DO
!$OMP END PARALLEL DO
call cpu_time(after)
!Find elapsed time; convert to seconds from ms
elapsed = after-before
S=MAXVAL(B)
WRITE(6,'("Maximum of B=",1pe8.2," found in ",1pe8.2," &
&seconds using", I2," threads")') S,elapsed,nthreads
END PROGRAM PARDO
Compiling and running on Franklin:
> cat pardo.pbs
#PBS -N pardo
#PBS -j oe
#PBS -o pardo.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 pardo -mp=nonuma -Minfo=mp pardo.f90
export OMP_NUM_THREADS=2
aprun -n 1 -N 1 ./pardo
> qsub pardo.pbs
500719.nid00003
> cat pardo.out
/opt/xt-pe/2.0.44a2/bin/snos64/ftn: INFO: linux target is being used
pardo.f90:
pardo:
16, Parallel region activated
17, Parallel loop activated; runtime schedule iteration allocation
24, Parallel region terminated
Maximum of B=2.92E+01 found in 1.12E-01 seconds using 2 threads
Application 4734298 resources: utime 0, stime 0
|
![]() |
Page last modified: Mon, 05 May 2008 19:19:47 GMT Page URL: http://www.nersc.gov/nusers/help/tutorials/openmp/parallel_do.php Web contact: webmaster@nersc.gov Computing questions: consult@nersc.gov Privacy and Security Notice |
![]() |