1 / 23

Short introduction to OpenMP

Short introduction to OpenMP. Jure Jerman, Environmental Agency of Slovenia. Outline. Motivation and Introduction Basic OpenMP structures Description of exercise Warning: far from being comprehensive introduction to OpenMP. Motivation.

kina
Download Presentation

Short introduction to 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. Short introduction to OpenMP Jure Jerman, Environmental Agency of Slovenia 1st ALADIN maintenance and phasing workshop

  2. Outline • Motivation and Introduction • Basic OpenMP structures • Description of exercise Warning: far from being comprehensive introduction to OpenMP 1st ALADIN maintenance and phasing workshop

  3. Motivation • Two kinds of parallelization in ALADIN: MPI and OpenMP • MPI: explicit parallelization • OpenMP: set of compiler directives in the code • It was believed for quite a long time, that OpenMP can not compete with MPI where programmer holds everything in hands, but: • with OpenMP the amount of computational overhead related to halo is reduced • Amount of communication is reduced as well • => Better scalability for bigger number of processors • The new computer architecture (SMP machines, or clusters of SMP machines) 1st ALADIN maintenance and phasing workshop

  4. Example of OpenMP efficiency for IFS code 1st ALADIN maintenance and phasing workshop

  5. Introduction to OpenMP • OpenMP: Higher level of abstraction model for parallelization set up by consortium of HPC vendors • Consisted of compiler directives, library routines and environmental variables • Suitable for SMP (symmetrical multi processing) computers) • For cluster of SMPs, the communication between computers has to be done via MPI 1st ALADIN maintenance and phasing workshop

  6. Our first program • OpenMP compiler directives • !$OMP !$OMP PARALLEL DEFAULT(NONE) & !$OMP SHARED(A,B) • !$ !$ I = OMP_get_thread_num() • Parallel region constructor !$OMP PARALLEL / $OMP END PARALLEL The constructs will be ignored by compiler without OpenMP. 1st ALADIN maintenance and phasing workshop

  7. Hello world in OpenMP (1) Program Hello $!OMP PARALLEL Write(*,*)’Hello’ $!OMP END PARALLEL End Program Hello 1st ALADIN maintenance and phasing workshop

  8. Hello world (2) 1st ALADIN maintenance and phasing workshop

  9. Hello world (3) • Now we want just one thread to print on the screen: • We use !$OMP SINGLE directive !$OMP SINGLE Write(*,*) “Hello” !$OMP END SINGLE 1st ALADIN maintenance and phasing workshop

  10. Hello world (4) 1st ALADIN maintenance and phasing workshop

  11. Nesting of parallel regions 1st ALADIN maintenance and phasing workshop

  12. Variables in parallel regions The output for 2 threads is 125 Every thread has access to variable trough shared memory Variables can be declared as shared or private to the threads like: !$PARALLEL SHARED(A) PRIVATE(I) Program Hello I=5 $!OMP PARALLEL I=I*5 $!OMP END PARALLEL Write(*,*) I End Program Hello 1st ALADIN maintenance and phasing workshop

  13. Worksharing constructs • Purpose: To do some real parallelism • The work sharing directives have to be put inside !$OMP PARALLEL and !$ END PARALLEL • Best example: !$OMP DO clause/ !$OMP END DO !$OMP DO do i=1,1000 ... Enddo !$OMP END DO 1st ALADIN maintenance and phasing workshop

  14. !$OMP DO / !$OMP END DO 1st ALADIN maintenance and phasing workshop

  15. !$OMP DO clause1, clause2, .. • Clause could be: • PRIVATE() • ORDERED • SCHEDULE • .... • SCHEDULE (type, chunck): • Way how to control the distribution of iterations between different threads (type can be DYNAMIC, STATIC), chunk is the portion of the loop distributed to separate threads 1st ALADIN maintenance and phasing workshop

  16. Parallelizing some loops might be tricky... • Not all of loops can be made parallel: • The chunks of loops are distributed in unpredictable way REAL :: A(1000) DO I = 1..999 A(I)=A(I+1) ENDDO 1st ALADIN maintenance and phasing workshop

  17. !$OMP SECTION(1) • It is possible to create MPMD (Multiple Program, Multiple Data) style of programs with !$OMP SECTION !$OMP SECTIONS !$OMP SECTION Write(*,*)”Hello” !$OMP SECTION Write(*,*)”Hi” !$OMP SECTION Write(*,*)”Bye” !$OMP END SECTIONS 1st ALADIN maintenance and phasing workshop

  18. !$OMP SECTION(2) 1st ALADIN maintenance and phasing workshop

  19. OpenMP run-time library • OpenMP Fortran API run-time library: control and query tool for the parallel execution environment • Set of external procedures with clearly defined interfaces delivered trough omp_lib Fortran module • Main categories: • Execution environment routines • Lock routines • Timing routines 1st ALADIN maintenance and phasing workshop

  20. Some OMP function examples • OMP_get_num_threads: number of currently used threads • OMP_get_thread_number: The identification number of current thread • Locking routines: synchronization mechanism different from OpenMP directives 1st ALADIN maintenance and phasing workshop

  21. The environment variables Provide control of OpenMP behavior at runtime: OPM_NUM_THREADS: Number of threads to be used during execution of parallel region OMP_SCHEDULE: What to do with !$OMP DO loops OMP_DYNAMIC (boolean):Dynamical adjustment of number of threads by Operating System OMP_NESTED (boolean): What to with nested parallelizem 1st ALADIN maintenance and phasing workshop

  22. OpenMP constructs in IFS/Arpege/ALADIN code • !$OMP PARALLEL / $OMP END PARALLEL • !$OMP DO / !$OMP END DO !$OMP DO PRIVATE() SHARED() !$OMP DO SCHEDULE(DYNAMIC,1) 1st ALADIN maintenance and phasing workshop

  23. Description of excersize • Paralleliize the serial Fortran95 code (400 lines) • Shallow water model with periodic LBC • One main program, no subroutines REFERENCES: • http://www.openmp.org • OpenMP Fortran interface specification 2.0 • Parallel Programming in Fortran 95 using OpenMP 1st ALADIN maintenance and phasing workshop

More Related