OpenMP Tutorial. Dirk Schmidl. IT Center, RWTH Aachen University. Member of the HPC Group Christian Terboven

Similar documents
[Potentially] Your first parallel application

Module 10: Open Multi-Processing Lecture 19: What is Parallelization? The Lecture Contains: What is Parallelization? Perfectly Load-Balanced Program

15-418, Spring 2008 OpenMP: A Short Introduction

OpenMP. Dr. William McDoniel and Prof. Paolo Bientinesi WS17/18. HPAC, RWTH Aachen

OpenMP - II. Diego Fabregat-Traver and Prof. Paolo Bientinesi WS15/16. HPAC, RWTH Aachen

Introduction to OpenMP

Introduction to OpenMP

Lecture 4: OpenMP Open Multi-Processing

Computing on Graphs An Overview

OpenMP 4.0/4.5: New Features and Protocols. Jemmy Hu

An Introduction to OpenMP

OpenMP Algoritmi e Calcolo Parallelo. Daniele Loiacono

OpenMP - Introduction

EPL372 Lab Exercise 5: Introduction to OpenMP

Introduction to. Slides prepared by : Farzana Rahman 1

CME 213 S PRING Eric Darve

Distributed Systems + Middleware Concurrent Programming with OpenMP

Compiling and running OpenMP programs. C/C++: cc fopenmp o prog prog.c -lomp CC fopenmp o prog prog.c -lomp. Programming with OpenMP*

OpenMP. Diego Fabregat-Traver and Prof. Paolo Bientinesi WS16/17. HPAC, RWTH Aachen

Topics. Introduction. Shared Memory Parallelization. Example. Lecture 11. OpenMP Execution Model Fork-Join model 5/15/2012. Introduction OpenMP

Shared Memory Parallelism using OpenMP

Introduction to OpenMP

Speeding Up Reactive Transport Code Using OpenMP. OpenMP

Introduction to OpenMP

Parallel Computing Using OpenMP/MPI. Presented by - Jyotsna 29/01/2008

OpenMP Overview. in 30 Minutes. Christian Terboven / Aachen, Germany Stand: Version 2.

The OpenMP Memory Model

Introduction to OpenMP. Tasks. N.M. Maclaren September 2017

OpenMP I. Diego Fabregat-Traver and Prof. Paolo Bientinesi WS16/17. HPAC, RWTH Aachen

OpenMP. Dr. William McDoniel and Prof. Paolo Bientinesi WS17/18. HPAC, RWTH Aachen

OpenMP+F90 p OpenMP+F90

Introduction to Standard OpenMP 3.1

1 of 6 Lecture 7: March 4. CISC 879 Software Support for Multicore Architectures Spring Lecture 7: March 4, 2008

Introduction to OpenMP. Lecture 4: Work sharing directives

Advanced C Programming Winter Term 2008/09. Guest Lecture by Markus Thiele

Parallelising Scientific Codes Using OpenMP. Wadud Miah Research Computing Group

Shared Memory Parallelism - OpenMP

OpenMP for Accelerators

Practical in Numerical Astronomy, SS 2012 LECTURE 12

C++ and OpenMP. 1 ParCo 07 Terboven C++ and OpenMP. Christian Terboven. Center for Computing and Communication RWTH Aachen University, Germany

Jukka Julku Multicore programming: Low-level libraries. Outline. Processes and threads TBB MPI UPC. Examples

CSL 860: Modern Parallel

Programming with Shared Memory PART II. HPC Fall 2012 Prof. Robert van Engelen

OpenMP, Part 2. EAS 520 High Performance Scientific Computing. University of Massachusetts Dartmouth. Spring 2015

C++ and OpenMP Christian Terboven Center for Computing and Communication RWTH Aachen University, Germany

Tasking in OpenMP 4. Mirko Cestari - Marco Rorro -

OpenMP. OpenMP. Portable programming of shared memory systems. It is a quasi-standard. OpenMP-Forum API for Fortran and C/C++

Practical stuff! ü OpenMP. Ways of actually get stuff done in HPC:

Tasking and OpenMP Success Stories

Programming with Shared Memory PART II. HPC Fall 2007 Prof. Robert van Engelen

Introduction to OpenMP. OpenMP basics OpenMP directives, clauses, and library routines

Introduction to OpenMP

Barbara Chapman, Gabriele Jost, Ruud van der Pas

Programming Shared Memory Systems with OpenMP Part I. Book

HPC Workshop University of Kentucky May 9, 2007 May 10, 2007

A brief introduction to OpenMP

Introduction to OpenMP

Shared Memory Programming with OpenMP. Lecture 8: Memory model, flush and atomics

Advanced OpenMP Features

EE/CSCI 451 Introduction to Parallel and Distributed Computation. Discussion #4 2/3/2017 University of Southern California

OpenMP C and C++ Application Program Interface Version 1.0 October Document Number

Shared Memory programming paradigm: openmp

Department of Informatics V. HPC-Lab. Session 2: OpenMP M. Bader, A. Breuer. Alex Breuer

OpenMP 2. CSCI 4850/5850 High-Performance Computing Spring 2018

ECE 574 Cluster Computing Lecture 10

Computer Architecture

Programming Shared-memory Platforms with OpenMP. Xu Liu

Introduction [1] 1. Directives [2] 7

OpenMP 4. CSCI 4850/5850 High-Performance Computing Spring 2018

CS 470 Spring Mike Lam, Professor. Advanced OpenMP

Alfio Lazzaro: Introduction to OpenMP

Overview: The OpenMP Programming Model

Multi-core Architecture and Programming

Advanced OpenMP. Tasks

OpenMP. Application Program Interface. CINECA, 14 May 2012 OpenMP Marco Comparato

Synchronization. Event Synchronization

Multithreading in C with OpenMP

Allows program to be incrementally parallelized

Introduction to OpenMP

OPENMP TIPS, TRICKS AND GOTCHAS

Parallel Programming

Parallel Processing Top manufacturer of multiprocessing video & imaging solutions.

High Performance Computing: Tools and Applications

Introduction to OpenMP

MPI and OpenMP (Lecture 25, cs262a) Ion Stoica, UC Berkeley November 19, 2016

OpenMP. António Abreu. Instituto Politécnico de Setúbal. 1 de Março de 2013

OpenMP Examples - Tasking

HPC Practical Course Part 3.1 Open Multi-Processing (OpenMP)

OpenMP on Ranger and Stampede (with Labs)

Programming Shared-memory Platforms with OpenMP

EE/CSCI 451: Parallel and Distributed Computation

!OMP #pragma opm _OPENMP

OpenMP loops. Paolo Burgio.

CS4961 Parallel Programming. Lecture 13: Task Parallelism in OpenMP 10/05/2010. Programming Assignment 2: Due 11:59 PM, Friday October 8

GUIDE Reference Manual (C/C++ Edition)

Parallel Programming with OpenMP

OpenMP Shared Memory Programming

Shared Memory Programming Paradigm!

Towards OpenMP for Java

Introduction to Programming with OpenMP

Transcription:

OpenMP Tutorial Dirk Schmidl IT Center, RWTH Aachen University Member of the HPC Group schmidl@itc.rwth-aachen.de IT Center, RWTH Aachen University Head of the HPC Group terboven@itc.rwth-aachen.de 1

IWOMP Tutorial: October 5th, 2016 Members of the OpenMP Language Committee 2

- Topics Core Concepts Synchronization 3

Defining Parallelism in OpenMP A parallel region is a block of code executed by all threads in the team #pragma omp parallel [clause[[,] clause]...] "this code is executed in parallel" } // End of parallel section (note: implied barrier)!$omp parallel [clause[[,] clause]...] "this code is executed in parallel"!$omp end parallel (note: implied barrier) 4

The OpenMP Execution Model Master Thread Fork and Join Model Parallel region Worker Threads Synchronization Parallel region Worker Threads Synchronization 5

The Worksharing Constructs #pragma omp for... }!$OMP DO...!$OMP END DO #pragma omp sections... }!$OMP SECTIONS...!$OMP END SECTIONS #pragma omp single... }!$OMP SINGLE...!$OMP END SINGLE The work is distributed over the threads Must be enclosed in a parallel region Must be encountered by all threads in the team, or none at all No implied barrier on entry Implied barrier on exit (unless the nowait clause is specified) A work-sharing construct does not launch any new threads 6

The Single Directive Only one thread in the team executes the code enclosed #pragma omp single [private][firstprivate] \ [copyprivate][nowait] <code-block> }!$omp single [private][firstprivate] <code-block>!$omp end single [copyprivate][nowait] 7

The OpenMP Memory Model private private T T Shared Memory T T private T private private All threads have access to the same, globally shared Data in private is only accessible by the thread owning this No other thread sees the change(s) in private Data transfer is through shared and is 100% transparent to the application 8

Gotcha s Need to get this right Part of the learning curve Private data is undefined on entry and exit Can use firstprivate and lastprivate to address this Each thread has its own temporary view on the data Applicable to shared data only Means different threads may temporarily not see the same value for the same variable... Let me explain 9

The Flush Directive Thread A X = 0 X = 1 Thread B while (X == 0) wait } If shared variable X is kept within a register, the modification may not be made visible to the other thread(s) 10

About The Flush Strongly recommended: do not use this directive unless really necessary. Really. Could give very subtle interactions with compilers If you insist on still doing so, be prepared to face the OpenMP language lawyers Implied on many constructs A good thing This is your safety net 11

The OpenMP Barrier Several constructs have an implied barrier This is another safety net (has implied flush by the way) In some cases, the implied barrier can be left out through the nowait clause This can help fine tuning the application But you d better know what you re doing The explicit barrier comes in quite handy then #pragma omp barrier!$omp barrier 12

The Nowait Clause To minimize synchronization, some directives support the optional nowait clause If present, threads do not synchronize/wait at the end of that particular construct In C, it is one of the clauses on the pragma In Fortran, it is appended at the closing part of the construct #pragma omp for nowait : }!$omp do : :!$omp end do nowait 13