1 / 30

OpenMP

OpenMP. E. Bruce Pitman October, 2002. Outline . What is OpenMP Multi-threading How to use OpenMP Limitations OpenMP + MPI References. What is OpenMP?. A portable standard for shared memory multi-processing A library of compiler directives Fine-grained (loop-level)

schuyler
Download Presentation

OpenMP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OpenMP E. Bruce Pitman October, 2002

  2. Outline • What is OpenMP • Multi-threading • How to use OpenMP • Limitations • OpenMP + MPI • References

  3. What is OpenMP? • A portable standard for shared memory multi-processing • A library of compiler directives • Fine-grained (loop-level) • To varying degrees, Sun, SGI, IBM, HP, Intel

  4. Multi-threading

  5. Multi-threading

  6. How to use OpenMP

  7. How to use OpenMP

  8. How to use OpenMP

  9. How to use OpenMP

  10. How to use OpenMP

  11. How to use OpenMP

  12. How to use OpenMP • schedule(static [,chunk]) • Deal-out blocks of iterations of size “chunk” to each thread. • schedule(dynamic[,chunk]) • Each thread grabs “chunk” iterations off a queue until all iterations have been handled. • uschedule(guided[,chunk]) • Threads dynamically grab blocks of iterations. The size of the block starts large and shrinks down to size “chunk” as the calculation proceeds.

  13. How to use OpenMP • schedule(runtime) • Schedule and chunk size taken from the OMP_SCHEDULE environment variable.

  14. How to use OpenMP Here’s an example of PRIVATE and FIRSTPRIVATE variables A,B, and C = 1C$OMP PARALLEL PRIVATE(B) C$OMP& FIRSTPRIVATE(C) Inside this parallel region “A” is shared by all threads and equals 1 “B” and “C” are local to each thread - B’s initial value is undefined - C’s initial value equals 1 Outside this parallel region the values of “B” and “C” are undefined.

  15. How to use OpenMP

  16. How to use OpenMP

  17. How to use OpenMP

  18. How to use OpenMP

  19. How to use OpenMP

  20. How to use OpenMP

  21. How to use OpenMP

  22. How to use OpenMP • #!/bin/csh -f • #PBS -l ncpus=8 • #PBS -V • #PBS -q medium_p • #PBS -M pitman@math.buffalo.edu

  23. How to use OpenMP • cp /CCRSGI/home/pitman/fortran/sph/sph* $PBSTMPDIR • cd $PBSTMPDIR • setenv OMP_NUM_THREADS 8 • f90 -O2 -LNO -IPA -n32 -mips4 -r12000 -mp -o sph sphomp.f • time ./sph > outfile • cp outfile /CCRSGI/home/pitman/fortran/sph/ • # remove scratch directory • cd /FCScratch • \rm -r $PBSTMPDIR

  24. How to use OpenMP k = 1 do while (k .le. maxit .and. error .gt. tol) error = 0.0 !$omp parallel !$omp do do j=1,m do i=1,n uold(i,j) = u(i,j) enddo enddo

  25. How to use OpenMP !$omp do private(resid) reduction(+:error) do j = 2,m-1 do i = 2,n-1 resid = (ax*(uold(i-1,j) + uold(i+1,j)) & + ay*(uold(i,j-1) + uold(i,j+1)) & + b * uold(i,j) - f(i,j))/b u(i,j) = uold(i,j) - omega error = error + resid*resid end do enddo

  26. How to use OpenMP !$omp enddo nowait !$omp end parallel $omp end parallel k = k + 1 error = sqrt(error)/dble(n*m) enddo

  27. Limitations • Easy to port serial code to OpenMP • OpenMP code can run in serial mode HOWEVER • Shared memory machines only • Limited scalability -- after ~8 processors, not much speed-up • Overhead of parallel do, parallel regions

  28. Limitations • OpenMP currently does not specify or provide constructs for controlling the binding of threads to processors. • Processors can migrate, causing overhead. • This behavior is system-dependent. • System-dependent solutions may be available.

  29. OpenMP and MPI

  30. References • www.openmp.org • http://www.ccr.buffalo.edu/documents/CCR_openmp_pbs.PDF • http://www.epcc.ed.ac.uk/research/openmpbench/ • http://www.llnl.gov/computing/tutorials/workshops/workshop/openMP/MAIN.html • http://scv.bu.edu/SCV/Tutorials/OpenMP/

More Related