OpenMP fundamentials Nikita Panov

Slides:



Advertisements
Similar presentations
Implementing Domain Decompositions Intel Software College Introduction to Parallel Programming – Part 3.
Advertisements

OpenMP.
NewsFlash!! Earth Simulator no longer #1. In slightly less earthshaking news… Homework #1 due date postponed to 10/11.
1 Programming Explicit Thread-level Parallelism  As noted previously, the programmer must specify how to parallelize  But, want path of least effort.
Indian Institute of Science Bangalore, India भारतीय विज्ञान संस्थान बंगलौर, भारत Supercomputer Education and Research Centre (SERC) Adapted from: o “MPI-Message.
Open[M]ulti[P]rocessing Pthreads: Programmer explicitly define thread behavior openMP: Compiler and system defines thread behavior Pthreads: Library independent.
PARALLEL PROGRAMMING WITH OPENMP Ing. Andrea Marongiu
1 OpenMP—An API for Shared Memory Programming Slides are based on:
1 Tuesday, November 07, 2006 “If anything can go wrong, it will.” -Murphy’s Law.
Computer Architecture II 1 Computer architecture II Programming: POSIX Threads OpenMP.
Parallel Programming in C with MPI and OpenMP Michael J. Quinn.
Introduction to OpenMP For a more detailed tutorial see: Look at the presentations.
1 ITCS4145/5145, Parallel Programming B. Wilkinson Feb 21, 2012 Programming with Shared Memory Introduction to OpenMP.
CSCI-6964: High Performance Parallel & Distributed Computing (HPDC) AE 216, Mon/Thurs 2-3:20 p.m. Pthreads (reading Chp 7.10) Prof. Chris Carothers Computer.
OpenMPI Majdi Baddourah
A Very Short Introduction to OpenMP Basile Schaeli EPFL – I&C – LSP Vincent Keller EPFL – STI – LIN.
INTEL CONFIDENTIAL OpenMP for Domain Decomposition Introduction to Parallel Programming – Part 5.
INTEL CONFIDENTIAL Reducing Parallel Overhead Introduction to Parallel Programming – Part 12.
Introduction to OpenMP Introduction OpenMP basics OpenMP directives, clauses, and library routines.
1 Parallel Programming With OpenMP. 2 Contents  Overview of Parallel Programming & OpenMP  Difference between OpenMP & MPI  OpenMP Programming Model.
Budapest, November st ALADIN maintenance and phasing workshop Short introduction to OpenMP Jure Jerman, Environmental Agency of Slovenia.
Programming with Shared Memory Introduction to OpenMP
Shared Memory Parallelization Outline What is shared memory parallelization? OpenMP Fractal Example False Sharing Variable scoping Examples on sharing.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Chapter 5 Shared Memory Programming with OpenMP An Introduction to Parallel Programming Peter Pacheco.
Shared Memory Parallelism - OpenMP Sathish Vadhiyar Credits/Sources: OpenMP C/C++ standard (openmp.org) OpenMP tutorial (
Parallel Programming in Java with Shared Memory Directives.
Lecture 5: Shared-memory Computing with Open MP. Shared Memory Computing.
Chapter 17 Shared-Memory Programming. Introduction OpenMP is an application programming interface (API) for parallel programming on multiprocessors. It.
OpenMP China MCP.
OpenMP - Introduction Süha TUNA Bilişim Enstitüsü UHeM Yaz Çalıştayı
ECE 1747 Parallel Programming Shared Memory: OpenMP Environment and Synchronization.
1 OpenMP Writing programs that use OpenMP. Using OpenMP to parallelize many serial for loops with only small changes to the source code. Task parallelism.
Introduction to OpenMP. OpenMP Introduction Credits:
Lecture 8: OpenMP. Parallel Programming Models Parallel Programming Models: Data parallelism / Task parallelism Explicit parallelism / Implicit parallelism.
OpenMP – Introduction* *UHEM yaz çalıştayı notlarından derlenmiştir. (uhem.itu.edu.tr)
CS 838: Pervasive Parallelism Introduction to OpenMP Copyright 2005 Mark D. Hill University of Wisconsin-Madison Slides are derived from online references.
Work Replication with Parallel Region #pragma omp parallel { for ( j=0; j
High-Performance Parallel Scientific Computing 2008 Purdue University OpenMP Tutorial Seung-Jai Min School of Electrical and Computer.
Threaded Programming Lecture 4: Work sharing directives.
Introduction to OpenMP
09/09/2010CS4961 CS4961 Parallel Programming Lecture 6: Data Parallelism in OpenMP, cont. Introduction to Data Parallel Algorithms Mary Hall September.
Shared Memory Parallelism - OpenMP Sathish Vadhiyar Credits/Sources: OpenMP C/C++ standard (openmp.org) OpenMP tutorial (
9/22/2011CS4961 CS4961 Parallel Programming Lecture 9: Task Parallelism in OpenMP Mary Hall September 22,
Threaded Programming Lecture 2: Introduction to OpenMP.
3/12/2013Computer Engg, IIT(BHU)1 OpenMP-1. OpenMP is a portable, multiprocessing API for shared memory computers OpenMP is not a “language” Instead,
Heterogeneous Computing using openMP lecture 2 F21DP Distributed and Parallel Technology Sven-Bodo Scholz.
CPE779: Shared Memory and OpenMP Based on slides by Laxmikant V. Kale and David Padua of the University of Illinois.
COMP7330/7336 Advanced Parallel and Distributed Computing OpenMP: Programming Model Dr. Xiao Qin Auburn University
OpenMP – Part 2 * *UHEM yaz çalıştayı notlarından derlenmiştir. (uhem.itu.edu.tr)
B. Estrade, LSU – High Performance Computing Enablement Group OpenMP II B. Estrade.
NPACI Parallel Computing Institute August 19-23, 2002 San Diego Supercomputing Center S an D IEGO S UPERCOMPUTER C ENTER N ATIONAL P ARTNERSHIP FOR A DVANCED.
OpenMP An API : For Writing Portable SMP Application Software Rider NCHC GTD.
Introduction to OpenMP
SHARED MEMORY PROGRAMMING WITH OpenMP
Shared Memory Parallelism - OpenMP
CS427 Multicore Architecture and Parallel Computing
Open[M]ulti[P]rocessing
Computer Engg, IIT(BHU)
Introduction to OpenMP
Shared-Memory Programming
September 4, 1997 Parallel Processing (CS 667) Lecture 5: Shared Memory Parallel Programming with OpenMP* Jeremy R. Johnson Parallel Processing.
Computer Science Department
Multi-core CPU Computing Straightforward with OpenMP
September 4, 1997 Parallel Processing (CS 730) Lecture 5: Shared Memory Parallel Programming with OpenMP* Jeremy R. Johnson Wed. Jan. 31, 2001 *Parts.
September 4, 1997 Parallel Processing (CS 730) Lecture 5: Shared Memory Parallel Programming with OpenMP* Jeremy R. Johnson *Parts of this lecture.
Programming with Shared Memory Introduction to OpenMP
Introduction to OpenMP
OpenMP Martin Kruliš.
OpenMP Parallel Programming
Shared-Memory Paradigm & OpenMP
Presentation transcript:

OpenMP fundamentials Nikita Panov

OpenMP is An application programming interface (API) that supports shared-memory programming for C/C++ and Fortran Pros: Simple Cross-platform Small overhead Data parallelism support

Usage Compiler directives: C/C++ #pragma omp directive [clause, …] Fortran !$OMP directive [clause, …] C$OMP directive [clause, …] *$OMP directive [clause, …]

Parallel execution Parallel Regions Main OpenMP directive #pragma omp parallel { printf( “hello world from thread %d of %d\n”, omp_get_thread_num(), omp_get_num_threads() ); }

Параллельное исполнение Most of the OpenMP instructions are preprocessor directives Main construction is “omp parallel [smth]”

OpenMP parallel model Memory is shared Task is divided into the threads. – Variables can be shared by the threads private, available only for one thread Uncareful or wrong variable usage can lead to wrong execution results.

OpenMP parallel model Fork-join model Program execution starts from the master thread With OpenMP directive master thread creates the additional threads After the parallel region is finished all threads are synchronized Main thread continues to execute the sequential part

Основные конструкции OpenMP #pragma omp for Each thread gets its own amount of data – data parallelism #pragma omp section Each section will be executed in a separate thread – functional parallelism #pragma omp single Sequential execution. Only one thread will execute this code

OpenMP sections #pragma omp sections [ clause [ clause ]... ] new-line { [#pragma omp section new-line ] structured-block1 [#pragma omp section new-line structured-block2 ]... }

OpenMP sections #pragma omp parallel #pragma omp sections nowait { thread1_work(); #pragma omp section thread2_work(); #pragma omp section thread3_work(); #pragma omp section thread4_work(); } Functional Parallelism

OpenMP for directive #pragma omp for [ clause [ clause ]... Following loop will be executed in parallel (the iterations will be divided by the execution threads)

OpenMP for directive #pragma omp parallel private(f) { f=7; #pragma omp for for (i=0; i<20; i++) a[i] = b[i] + f * (i+1); } /* omp end parallel */

OpenMP for directive Available definitions: private( list ) reduction( operator: list ) schedule( type [, chunk ] ) nowait (для #pragma omp for) At the end of the loop all threads will be synchronized unless “nowait” directive is mentioned schedule defines iteration space scattering method (default behaviour depend on OpenMP version)

OpenMP variables private ( list ) Each of the listed variables will have the local copy for each exection thread shared ( list ) All the thread will share the same instance of the variable firstprivate ( list ) All the local copies will be initialized by master thread value lastprivate ( list ) The resulting master thread value will be taken from the last thread executed … All the variables are shared by default, except the local variables inside a function calls and the loop iterators

Example int x; x = 0;// Initialize x to zero #pragma omp parallel for firstprivate(x) // Copy value // of x // from master for (i = 0; i < 10000; i++) { x = x + i; } printf( “x is %d\n”, x );// Print out value of x /* Actually needs lastprivate(x) to copy value back out to master */

OpenMP schedule clause schedule( type [, chunk ] ) static: Every thread gets fixed amount of data dynamic:Amount of data will depend on the thread execution speed guided: Threads will get decreased amounts of data dymamically runtime: Schedule type will be defined at runtime

Loop scheduling

Main OpenMP functions int omp_get_num_threads(void); int omp_get_thread_num(void); …

OpenMP synchronization Implicit sunchrionization is performed at the end of any parallel section (unless nowait option is mentioned)

OpenMP synchroniztion сritical – can be executed only by one thread at a time. atomic – Special critical section version for the atomic operations barrier – synchronization point ordered – sequential execution master – only the main thread will execute the following code …

OpenMP critical cnt = 0; f=7; #pragma omp parallel { #pragma omp for for (i=0; i<20; i++) { if (b[i] == 0) { #pragma omp critical cnt ++; } /* endif */ a[i] = b[i] + f * (i+1); } /* end for */ } /*omp end parallel */

More information OpenMP Homepage: Introduction to OpenMP - tutorial from WOMPEI 2000 (link)(link) Writing and Tuning OpenMP Programs on Distributed Shared Memory Machines (link)(link) R.Chandra, L. Dagum, D. Kohr, D. Maydan, J. McDonald, R. Menon: Parallel programming in OpenMP. Academic Press, San Diego, USA, 2000, ISBN R. Eigenmann, Michael J. Voss (Eds): OpenMP Shared Memory Parallel Programming. Springer LNCS 2104, Berlin, 2001, ISBN X

10/17/10 Thank you!