TutorialsTutorials HomeOpenMPIndexIntroduction PARALLEL DO PARALLEL DO SECTIONS SINGLE MASTER CRITICAL BARRIER FLUSH ATOMIC ORDERED Full Document
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 -l mppwidth=1 #PBS -l mppnppn=1 #PBS -l mppdepth=4 #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=4 aprun -n 1 -N 1 -d 4 ./pardo > qsub pardo.pbs 500719.nid00003 > cat pardo.out /opt/cray/xt-asyncpe/2.0/bin/ftn: INFO: linux target is being used pardo: 16, Parallel region activated 17, Parallel loop activated with runtime schedule schedule 24, Parallel region terminated Maximum of B=2.92E+01 found in 7.68E-02 seconds using 4 threads Application 2016575 resources: utime 0, stime 0 |
Page last modified: Fri, 06 Feb 2009 22:23:22 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 |