Threaded Programming Lecture 2: Introduction to OpenMP.

Slides:



Advertisements
Similar presentations
OpenMP.
Advertisements

Introductions to Parallel Programming Using OpenMP
The OpenUH Compiler: A Community Resource Barbara Chapman University of Houston March, 2007 High Performance Computing and Tools Group
NewsFlash!! Earth Simulator no longer #1. In slightly less earthshaking news… Homework #1 due date postponed to 10/11.
PARALLEL PROGRAMMING WITH OPENMP Ing. Andrea Marongiu
Scientific Programming OpenM ulti- P rocessing M essage P assing I nterface.
1 Tuesday, November 07, 2006 “If anything can go wrong, it will.” -Murphy’s Law.
DISTRIBUTED AND HIGH-PERFORMANCE COMPUTING CHAPTER 7: SHARED MEMORY PARALLEL PROGRAMMING.
Computer Architecture II 1 Computer architecture II Programming: POSIX Threads OpenMP.
Parallel Programming by Tiago Sommer Damasceno Using OpenMP
1 ITCS4145/5145, Parallel Programming B. Wilkinson Feb 21, 2012 Programming with Shared Memory Introduction to OpenMP.
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.
Introduction to OpenMP Introduction OpenMP basics OpenMP directives, clauses, and library routines.
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.
Parallel Programming in Java with Shared Memory Directives.
OMPi: A portable C compiler for OpenMP V2.0 Elias Leontiadis George Tzoumas Vassilios V. Dimakopoulos University of Ioannina.
OpenMP China MCP.
OpenMP in a Heterogeneous World Ayodunni Aribuki Advisor: Dr. Barbara Chapman HPCTools Group University of Houston.
ICOM 5995: Performance Instrumentation and Visualization for High Performance Computer Systems Lecture 7 October 16, 2002 Nayda G. Santiago.
OpenMP - Introduction Süha TUNA Bilişim Enstitüsü UHeM Yaz Çalıştayı
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.
OpenMP Blue Waters Undergraduate Petascale Education Program May 29 – June
OpenMP OpenMP A.Klypin Shared memory and OpenMP Simple Example Threads Dependencies Directives Handling Common blocks Synchronization Improving load balance.
OpenMP: Open specifications for Multi-Processing What is OpenMP? Join\Fork model Join\Fork model Variables Variables Explicit parallelism Explicit parallelism.
O PEN MP (O PEN M ULTI -P ROCESSING ) David Valentine Computer Science Slippery Rock University.
OpenMP – Introduction* *UHEM yaz çalıştayı notlarından derlenmiştir. (uhem.itu.edu.tr)
04/10/25Parallel and Distributed Programming1 Shared-memory Parallel Programming Taura Lab M1 Yuuki Horita.
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
OpenMP fundamentials Nikita Panov
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
Introduction to OpenMP Eric Aubanel Advanced Computational Research Laboratory Faculty of Computer Science, UNB Fredericton, New Brunswick.
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,
Introduction to Pragnesh Patel 1 NICS CSURE th June 2015.
Threaded Programming Lecture 1: Concepts. 2 Overview Shared memory systems Basic Concepts in Threaded Programming.
Single Node Optimization Computational Astrophysics.
3/12/2013Computer Engg, IIT(BHU)1 OpenMP-3. OMP_INIT_LOCK OMP_INIT_NEST_LOCK Purpose: ● This subroutine initializes a lock associated with the lock variable.
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,
10/05/2010CS4961 CS4961 Parallel Programming Lecture 13: Task Parallelism in OpenMP Mary Hall October 5,
Special Topics in Computer Engineering OpenMP* Essentials * Open Multi-Processing.
CPE779: Shared Memory and OpenMP Based on slides by Laxmikant V. Kale and David Padua of the University of Illinois.
OpenMP – Part 2 * *UHEM yaz çalıştayı notlarından derlenmiştir. (uhem.itu.edu.tr)
OpenMP Lab Antonio Gómez-Iglesias Texas Advanced Computing Center.
Distributed and Parallel Processing George Wells.
Embedded Systems MPSoC Architectures OpenMP: Exercises Alberto Bosio
Introduction to OpenMP
SHARED MEMORY PROGRAMMING WITH OpenMP
SHARED MEMORY PROGRAMMING WITH OpenMP
CS427 Multicore Architecture and Parallel Computing
Loop Parallelism and OpenMP CS433 Spring 2001
Computer Engg, IIT(BHU)
Introduction to OpenMP
September 4, 1997 Parallel Processing (CS 667) Lecture 5: Shared Memory Parallel Programming with OpenMP* Jeremy R. Johnson Parallel Processing.
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.
Introduction to High Performance Computing Lecture 20
Programming with Shared Memory Introduction to OpenMP
Shared Memory Programming
Introduction to OpenMP
Parallel Computing Explained How to Parallelize a Code
Shared-Memory Paradigm & OpenMP
WorkSharing, Schedule, Synchronization and OMP best practices
Presentation transcript:

Threaded Programming Lecture 2: Introduction to OpenMP

2 Overview Basic Concepts in OpenMP History of OpenMP Compiling and running OpenMP programs

3 What is OpenMP? OpenMP is an API designed for programming shared memory parallel computers. OpenMP uses the concepts of threads and tasks OpenMP is a set of extensions to Fortran, C and C++ The extensions consist of: –Compiler directives –Runtime library routines –Environment variables

4 Directives and sentinels A directive is a special line of source code with meaning only to certain compilers. A directive is distinguished by a sentinel at the start of the line. OpenMP sentinels are: –Fortran: !$OMP –C/C++: #pragma omp This means that OpenMP directives are ignored if the code is compiled as regular sequential Fortran/C/C++.

5 Parallel region The parallel region is the basic parallel construct in OpenMP. A parallel region defines a section of a program. Program begins execution on a single thread (the master thread). When the first parallel region is encountered, the master thread creates a team of threads (fork/join model). Every thread executes the statements which are inside the parallel region At the end of the parallel region, the master thread waits for the other threads to finish, and continues executing the next statements

6 Parallel region Sequential part Parallel region

7 Shared and private data Inside a parallel region, variables can either be shared or private. All threads see the same copy of shared variables. All threads can read or write shared variables. Each thread has its own copy of private variables: these are invisible to other threads. A private variable can only be read or written by its own thread.

8 Parallel loops In a parallel region, all threads execute the same code OpenMP also has directives which indicate that work should be divided up between threads, not replicated. –this is called worksharing Since loops are the main source of parallelism in many applications, OpenMP has extensive support for parallelising loops. The are a number of options to control which loop iterations are executed by which threads. It is up to the programmer to ensure that the iterations of a parallel loop are independent. Only loops where the iteration count can be computed before the execution of the loop begins can be parallelised in this way.

9 Synchronisation The main synchronisation concepts used in OpenMP are: Barrier –all threads must arrive at a barrier before any thread can proceed past it –e.g. delimiting phases of computation Critical region –a section of code which only one thread at a time can enter –e.g. modification of shared variables Atomic update –an update to a variable which can be performed only by one thread at a time –e.g. modification of shared variables (special case) Master region –a section of code executed by one thread only –e.g. initialisation, writing a file

10 Brief history of OpenMP Historical lack of standardisation in shared memory directives. –each hardware vendor provided a different API –mainly directive based –almost all for Fortran –hard to write portable code OpenMP forum set up by Digital, IBM, Intel, KAI and SGI. Now includes most major vendors (and some academic organisations, including EPCC). OpenMP Fortran standard released October 1997, minor revision (1.1) in November Major revision (2.0) in November 2000.

11 History (cont.) OpenMP C/C++ standard released October Major revision (2.0) in March Combined OpenMP Fortran/C/C++ standard (2.5) released in May –no new features, but extensive rewriting and clarification Version 3.0 released in May 2008 –new features, including tasks, better support for loop parallelism and nested parallelism Version 3.1 released in June 2011 –corrections and some minor new features –most current compilers support this Version 4.0 released in July 2013 –not yet available in implementations

12 OpenMP resources Web site: –Official web site: language specifications, links to compilers and tools, mailing lists Book: –“Using OpenMP: Portable Shared Memory Parallel Programming” Chapman, Jost and Van der Pas, MIT Press, ISBN: –however, does not contain OpenMP 3.0/3.1 features

13 Compiling and running OpenMP programs OpenMP is built-in to most of the compilers you are likely to use. To compile an OpenMP program you need to add a (compiler-specific) flag to your compile and link commands. –-fopenmp for gcc/gfortran –-mp for PGI compilers The number of threads which will be used is determined at runtime by the OMP_NUM_THREADS environment variable –set this before you run the program –e.g. export OMP_NUM_THREADS=4 Run in the same way you would a sequential program –type the name of the executable

14 Running (cont) Our system is configured as two back ends (64 cores each) The backend for batch jobs only. Development and debugging should be done on the CPLab machines. For performance measurements, run on the backend in a batch queue, e.g.: qsub -pe omp 8 -cwd scriptfile puts output in current directory reserves 8 cores Unix script containing commands to run program

15 Running (cont.) The number of threads must be set inside the script file: #! /usr/bin/bash export OMP_NUM_THREADS=8./fred N.B. The number of processors requested should match the value of OMP_NUM_THREADS (use export OMP_NUM_THREADS=$NSLOTS ) Note well: execution times for code on workstations are not reliable/repeatable!

16 Exercise Hello World Aim: to compile and run a trivial program. Vary the number of threads using the OMP_NUM_THREADS environment variable. Run the code several times - is the output always the same?