Download presentation
Presentation is loading. Please wait.
1
OpenMP Andrew Williams A.Williams@bolton.ac.uk
2
References Chandra et al, Parallel Programming in OpenMP, Morgan Kaufmann Publishers 1999 OpenMP home: http://www.openmp.org/http://www.openmp.org/ Intel has superb resources, including some podcasts: http://www.intel.com/cd/ids/developer/asmo-na/eng/296614.htm http://www.intel.com/cd/ids/developer/asmo-na/eng/296614.htm –Have a look round their site
3
OpenMP Development MS Visual Studio 2005 Professional has support for OpenMP –Not available in Express or Standard editions –You have to set a flag in your Project Settings It is under Code Gen / C++ / Language The Intel C++ compilers have OpenMP support (version 10.0 onwards) –Free for non-commercial use –Not free for us to install here
4
OpenMP Development Omni OpenMP compiler –More of a command-line facility –Drives gcc / g++ I’ve tried it on Linux (Ubuntu Dapper) but it wouldn’t install properly –Will try to sort that out when I have time
5
Parallel Regions Fundamental to understanding OpenMP In a parallel region, every thread executes every instruction See “hello world” example later –For non-trivial problems, this takes some thinking about –It’s actually easier to understand with for- loops
6
Parallel Regions Regions where the work is shared between many threads #pragma omp parallel #pragma omp barrier Single thread Multiple threads Single thread
7
OpenMP Syntax OpenMP is implemented as a set of directives which are implemented using #pragma in C or C++ –Also available for Fortran A #pragma is used to give some information to the compiler Used to implement extra features which are not defined as part of a language –Ideal for OpenMP
8
OpenMP Syntax Examples: #pragma omp parallel Splits thread of execution (see later) #pragma omp parallel for for(i=0; i < 1000; i++) { do_something_or_other(); } This divides the iterations of the loop among the available threads –Note there are severe restrictions on the for() loop
9
OpenMP Syntax A #pragma is divided into a directive and clauses –There may be no clauses #pragma omp parallel num_threads(6)
10
OpenMP Syntax A #pragma is divided into a directive and clauses –There may be no clauses #pragma omp parallel num_threads(6) Directive
11
OpenMP Syntax A #pragma is divided into a directive and clauses –There may be no clauses #pragma omp parallel num_threads(6) Clause
12
OpenMP Syntax #pragma omp parallel for private(temp)
13
OpenMP Syntax #pragma omp parallel for private(temp) Directive
14
OpenMP Syntax #pragma omp parallel for private(temp) Directive Clause
15
Task or Data Parallelism? Last week we contrasted task parallelism and data parallelism –Which one do we have here? #pragma omp parallel for for(i=0; i < 1000; i++) { do_something_or_other(); }
16
Parallel Sections We will look at this in more detail later #pragma omp parallel sections { #pragma omp section { do_AI(); } #pragma omp section { do_physics(); }
17
Shared Data Everything we have discussed ignores the problem of data which is being shared between threads We’ll not bother with that too much this week But you must understand that having two threads write to the same data in an uncontrolled manner must result in disaster
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.