SlideShare a Scribd company logo
1 of 30
Download to read offline
Introduction to OpenMP
Introduction to
OpenMP
Outline
Introduction to OpenMP 3
• What is OpenMP?
• Timeline
• Main Terminology
• OpenMP Programming Model
• Main Components
• Parallel Construct
• Work-sharing Constructs
• sections, single, workshare
• Data Clauses
• default, shared, private, firstprivate, lastprivate,
threadprivate, copyin
What is OpenMP?
4
OpenMP (Open specifications for Multi Processing)
– is an API for shared-memory parallel computing;
– is an open standard for portable and scalable parallel
programming;
– is flexible and easy to implement;
– is a specification for a set of compiler directives, library routines,
and environment variables;
– is designed for C, C++ and Fortran.
Introduction to OpenMP
Timeline
5
• OpenMP 4.0 Release Candidate 1 was released in November 2012.
• http://openmp.org/
Introduction to OpenMP
Main Terminology
6
1. OpenMP thread: a lightweight process
2. thread team: a set of threads which co-operate on a task
3. master thread: the thread which co-ordinates the team
4. thread-safety: correctly executed by multiple threads
5. OpenMP directive: line of code with meaning only to certain compilers
6. construct: an OpenMP executable directive
7. clause: controls the scoping of variables during the execution
Introduction to OpenMP
OpenMP Programming Model
7
OpenMP is designed for multi-processor/core UMA or NUMA
shared memory systems.
UMA NUMA
Introduction to OpenMP
Execution Model:
8
• Thread-based Parallelism
• Compiler Directive Based
• Explicit Parallelism
• Fork-Join Model
• Dynamic Threads
• Nested Parallelism
Introduction to OpenMP
9
Memory Model:
• All threads have access to the shared memory.
• Threads can share data with other threads, but also have private data.
• Threads sometimes synchronise against data race.
• Threads cache their data; Use OpenMP flush
CPU CPUPrivate data Private data
Thread 1 Thread 2 Thread 3
Private data
Shared data
CPU
Introduction to OpenMP
Main Components
10
• Compiler Directives and Clauses: appear as comments,
executed when the appropriate OpenMP flag is specified
– Parallel construct
– Work-sharing constructs
– Synchronization constructs
– Data Attribute clauses
C/C++:#pragma omp directive-name [clause[clause]...]
Fortran free form: !$omp directive-name [clause[clause]...]
Fortran fixed form: !$omp | c$omp | *$omp directive-name
[clause[clause]...]
Introduction to OpenMP
11
Compiling:
See: http://openmp.org/wp/openmp-compilers/ for the full list.
Compiler Flag
Intel icc (C)
icpc (C++)
ifort (Fortran)
-openmp
GNU gcc (C)
g++ (C++)
g77/gfortran (Fortran)
-fopenmp
PGI pgcc (C)
pgCC (C++)
pg77/pgfortran
(Fortran)
-mp
Introduction to OpenMP
12
• Runtime Functions: for managing the parallel program
– omp_set_num_threads(n) - set the desired number of threads
– omp_get_num_threads() - returns the current number of threads
– omp_get_thread_num() - returns the id of this thread
– omp_in_parallel() – returns .true. if inside parallel region
and more.
For C/C++: Add #include<omp.h>
For Fortran: Add use omp_lib
• Environment Variables: for controlling the execution of
parallel program at run-time.
– csh/tcsh: setenv OMP_NUM_THREADS n
– ksh/sh/bash: export OMP_NUM_THREADS=n
and more.
Introduction to OpenMP
Parallel Construct
13
• The fundamental construct in OpenMP.
• Every thread executes the same statements which are
inside the parallel region simultaneously.
• At the end of the parallel region there is an implicit barrier
for synchronization
Fortran:
!$omp parallel [clauses]
...
!$omp end
parallel
C/C++:
#pragma omp parallel [clauses]
{
…
}
Introduction to OpenMP
double A[1000];
omp_set_num_threads(4);
foo(0,A); foo(1,A); foo(2,A); foo(3,A);
printf(“All Donen”);
14
double A[1000];
omp_set_num_threads(4);
#pragma omp parallel
{
int tid=omp_get_thread_num();
foo(tid,A);
}
printf(“All Donen”);
• Create a 4-thread parallel
region
• Each thread with tid
from 0 to 3 calls foo(tid,
A)
• Threads wait for all
treads to finish before
proceeding
Introduction to OpenMP
15
Hello World Example:
C:
#include<omp.h>
#include<stdio.h>
int main(){
#pragma omp parallel
printf("Hello from thread %d out
of %dn", omp_get_thread_num(),
omp_get_num_threads());
}
Fortran:
program hello
use omp_lib
implicit none
!$omp parallel
PRINT*, 'Hello from
thread',omp_get_thread_num(),'out
of',omp_get_num_threads()
!$omp end parallel
end program hello
Introduction to OpenMP
16
Compile: (Intel)
>icc -openmp hello.c -o a.out
>ifort -openmp hello.f90 -o a.out
Execute:
>export OMP_NUM_THREADS=4
>./a.out
Hello from thread 0 out of 4
Hello from thread 3 out of 4
Hello from thread 1 out of 4
Hello from thread 2 out of 4
Introduction to OpenMP
17
• Dynamic threads:
– The number of threads used in a parallel region can vary from one
parallel region to another.
– omp_set_dynamic(), OMP_DYNAMIC
– omp_get_dynamic()
• Nested parallel regions:
– If a parallel directive is encountered within another parallel directive,
a new team of threads will be created.
– omp_set_nested(), OMP_NESTED
– omp_get_nested()
Introduction to OpenMP
18
• If Clause:
– Used to make the parallel region directive itself conditional.
– Only execute in parallel if expression is true.
Fortran:
!$omp parallel if(n>100)
...
!$omp end parallel
C/C++:
#pragma omp parallel if(n>100)
{
…
}
• nowait Clause:
– allows threads that finish earlier to proceed without waiting
Fortran:
!$omp parallel
...
!$omp end parallel
nowait
C/C++:
#pragma omp parallel nowait
{
…
}
(Checks the size
of the data)
Introduction to OpenMP
Data Clauses
19
• Used in conjunction with several directives to control the
scoping of enclosed variables.
– default(shared|private|none): The default scope for all of the variables
in the parallel region.
– shared(list): Variable is shared by all threads in the team. All threads
can read or write to that variable.
C: #pragma omp parallel default(none), shared(n)
Fortran: !$omp parallel default(none), shared(n)
– private(list): Each thread has a private copy of variable. It can only be
read or written by its own thread.
C: #pragma omp parallel default(none), shared(n), private(tid)
Fortran: !$omp parallel default(none), shared(n), private(tid)
Introduction to OpenMP
20
• Most variables are shared by default
– C/C++: File scope variables, static
– Fortran: COMMON blocks, SAVE variables, MODULE variables
– Both: dynamically allocated variables
• Variables declared in parallel region are always private
• How do we decide which variables should be shared and
which private?
– Loop indices - private
– Loop temporaries - private
– Read-only variables - shared
– Main arrays - shared
Introduction to OpenMP
Example:
21
C:
#include<omp.h>
#include<stdio.h>
int tid, nthreads;
int main(){
#pragma omp parallel private(tid),
shared(nthreads)
{
tid=omp_get_thread_num();
nthreads=omp_get_num_threads();
printf("Hello from thread %d out
of %dn", tid, nthreads);
}
}
Fortran:
program hello
use omp_lib
implicit none
integer tid, nthreads
!$omp parallel private(tid),
shared(nthreads)
tid=omp_get_thread_num()
nthreads=omp_get_num_threads()
PRINT*, 'Hello from
thread',tid,'out of',nthreads
!$omp end parallel
end program hello
Introduction to OpenMP
Some Additional Data Clauses:
22
– firstprivate(list): Private copies of a variable are initialized from the
original global object.
– lastprivate(list): On exiting the parallel region, variable has the value
that it would have had in the case of serial execution.
– threadprivate(list): Used to make global file scope variables (C/C++) or
common blocks (Fortran) local.
– copyin(list): Copies the threadprivate variables from master thread to
the team threads.
• copyprivate and reduction clauses will be described later.
Introduction to OpenMP
Work-Sharing Constructs
23
• To distribute the execution of the associated region
among threads in the team
• An implicit barrier at the end of the worksharing
region, unless the nowait clause is added
• Work-sharing Constructs:
– Loop
– Sections
– Single
– Workshare
Introduction to OpenMP
Sections Construct
24
• A non-iterative work-sharing construct.
• Specifies that the enclosed section(s) of code are to
be executed by different threads.
• Each section is executed by one thread.
Fortran:
!$omp sections [clauses]
!$omp section
...
!$omp section
...
!$omp end sections
[nowait]
C/C++:
#pragma omp sections [clauses] nowait
{
#pragma omp section
…
#pragma omp section
…
}
Introduction to OpenMP
25
#include <stdio.h>
#include <omp.h>
int main(){
int tid;
#pragma omp parallel private(tid)
{
tid=omp_get_thread_num();
#pragma omp sections
{
#pragma omp section
printf("Hello from thread %d n", tid);
#pragma omp section
printf("Hello from thread %d n", tid);
#pragma omp section
printf("Hello from thread %d n", tid);
}
}
}
>export
OMP_NUM_THREADS=4
Hello from thread 0
Hello from thread 2
Hello from thread
3
Introduction to OpenMP
Single Construct
26
• Specifies a block of code that is executed by only one of
the threads in the team.
• May be useful when dealing with sections of code that are
not thread-safe.
• Copyprivate(list): used to broadcast values obtained by a
single thread directly to all instances of the private
variables in the other threads. Fortran:
!$omp parallel [clauses]
!$omp single [clauses]
...
!$omp end single
!$omp end
parallel
C/C++:
#pragma omp parallel [clauses]
{
#pragma omp single [clauses]
…
}
Introduction to OpenMP
Workshare Construct
27
• Fortran only
• Divides the execution of the enclosed structured block
into separate units of work
• Threads of the team share the work
• Each unit is executed only once by one thread
• Allows parallelisation of
– array and scalar assignments
– WHERE statements and constructs
– FORALL statements and constructs
– parallel, atomic, critical constructs
!$omp workshare
...
!$omp end workshare
[nowait]
Introduction to OpenMP
28
Program WSex
use omp_lib
implicit none
integer i
real a(10), b(10), c(10)
do i=1,10
a(i)=i
b(i)=i+1
enddo
!$omp parallel shared(a, b, c)
!$omp workshare
c=a+b
!$omp end workshare nowait
!$omp end parallel
end program WSex
Introduction to OpenMP
References
29
1. http://openmp.org
2. https://computing.llnl.gov/tutorials/openMP
3. http://www.openmp.org/mp-documents/OpenMP4.0RC1_final.pdf
4. Michael J. Quinn, Parallel Programming in C with MPI and OpenMP,
Mc Graw Hill, 2003.
Introduction to OpenMP
Thank you!
30
Introduction to OpenMP

More Related Content

What's hot

Parallelization using open mp
Parallelization using open mpParallelization using open mp
Parallelization using open mpranjit banshpal
 
Open mp library functions and environment variables
Open mp library functions and environment variablesOpen mp library functions and environment variables
Open mp library functions and environment variablesSuveeksha
 
Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Akhila Prabhakaran
 
Programming using Open Mp
Programming using Open MpProgramming using Open Mp
Programming using Open MpAnshul Sharma
 
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...Chris Fregly
 
.Net Multithreading and Parallelization
.Net Multithreading and Parallelization.Net Multithreading and Parallelization
.Net Multithreading and ParallelizationDmitri Nesteruk
 
Erlang Message Passing Concurrency, For The Win
Erlang  Message  Passing  Concurrency,  For  The  WinErlang  Message  Passing  Concurrency,  For  The  Win
Erlang Message Passing Concurrency, For The Winl xf
 
Improving Robustness In Distributed Systems
Improving Robustness In Distributed SystemsImproving Robustness In Distributed Systems
Improving Robustness In Distributed Systemsl xf
 
Towards an Integration of the Actor Model in an FRP Language for Small-Scale ...
Towards an Integration of the Actor Model in an FRP Language for Small-Scale ...Towards an Integration of the Actor Model in an FRP Language for Small-Scale ...
Towards an Integration of the Actor Model in an FRP Language for Small-Scale ...Takuo Watanabe
 
Numba: Flexible analytics written in Python with machine-code speeds and avo...
Numba:  Flexible analytics written in Python with machine-code speeds and avo...Numba:  Flexible analytics written in Python with machine-code speeds and avo...
Numba: Flexible analytics written in Python with machine-code speeds and avo...PyData
 
Trends of SW Platforms for Heterogeneous Multi-core systems and Open Source ...
Trends of SW Platforms for Heterogeneous Multi-core systems and  Open Source ...Trends of SW Platforms for Heterogeneous Multi-core systems and  Open Source ...
Trends of SW Platforms for Heterogeneous Multi-core systems and Open Source ...Seunghwa Song
 

What's hot (20)

Parallelization using open mp
Parallelization using open mpParallelization using open mp
Parallelization using open mp
 
Open mp
Open mpOpen mp
Open mp
 
OpenMP And C++
OpenMP And C++OpenMP And C++
OpenMP And C++
 
OpenMp
OpenMpOpenMp
OpenMp
 
Open mp directives
Open mp directivesOpen mp directives
Open mp directives
 
Openmp
OpenmpOpenmp
Openmp
 
Open mp library functions and environment variables
Open mp library functions and environment variablesOpen mp library functions and environment variables
Open mp library functions and environment variables
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)
 
Programming using Open Mp
Programming using Open MpProgramming using Open Mp
Programming using Open Mp
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
 
Lecture8
Lecture8Lecture8
Lecture8
 
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...
 
.Net Multithreading and Parallelization
.Net Multithreading and Parallelization.Net Multithreading and Parallelization
.Net Multithreading and Parallelization
 
Erlang Message Passing Concurrency, For The Win
Erlang  Message  Passing  Concurrency,  For  The  WinErlang  Message  Passing  Concurrency,  For  The  Win
Erlang Message Passing Concurrency, For The Win
 
Improving Robustness In Distributed Systems
Improving Robustness In Distributed SystemsImproving Robustness In Distributed Systems
Improving Robustness In Distributed Systems
 
Towards an Integration of the Actor Model in an FRP Language for Small-Scale ...
Towards an Integration of the Actor Model in an FRP Language for Small-Scale ...Towards an Integration of the Actor Model in an FRP Language for Small-Scale ...
Towards an Integration of the Actor Model in an FRP Language for Small-Scale ...
 
Numba: Flexible analytics written in Python with machine-code speeds and avo...
Numba:  Flexible analytics written in Python with machine-code speeds and avo...Numba:  Flexible analytics written in Python with machine-code speeds and avo...
Numba: Flexible analytics written in Python with machine-code speeds and avo...
 
Trends of SW Platforms for Heterogeneous Multi-core systems and Open Source ...
Trends of SW Platforms for Heterogeneous Multi-core systems and  Open Source ...Trends of SW Platforms for Heterogeneous Multi-core systems and  Open Source ...
Trends of SW Platforms for Heterogeneous Multi-core systems and Open Source ...
 

Viewers also liked

Tutorial on Parallel Computing and Message Passing Model - C2
Tutorial on Parallel Computing and Message Passing Model - C2Tutorial on Parallel Computing and Message Passing Model - C2
Tutorial on Parallel Computing and Message Passing Model - C2Marcirio Chaves
 
Race conditions
Race conditionsRace conditions
Race conditionsMohd Arif
 
Parallel architecture-programming
Parallel architecture-programmingParallel architecture-programming
Parallel architecture-programmingShaveta Banda
 
Biref Introduction to OpenMP
Biref Introduction to OpenMPBiref Introduction to OpenMP
Biref Introduction to OpenMPJerryHe
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel ProgrammingUday Sharma
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.MOHIT DADU
 
Parallel computing
Parallel computingParallel computing
Parallel computingvirend111
 
Fortran introduction
Fortran introductionFortran introduction
Fortran introductionsanthosh833
 
Taking R to the Limit (High Performance Computing in R), Part 1 -- Paralleliz...
Taking R to the Limit (High Performance Computing in R), Part 1 -- Paralleliz...Taking R to the Limit (High Performance Computing in R), Part 1 -- Paralleliz...
Taking R to the Limit (High Performance Computing in R), Part 1 -- Paralleliz...Ryan Rosario
 

Viewers also liked (14)

ALGOL ailesi programlama dilleri
ALGOL ailesi programlama dilleriALGOL ailesi programlama dilleri
ALGOL ailesi programlama dilleri
 
Tutorial on Parallel Computing and Message Passing Model - C2
Tutorial on Parallel Computing and Message Passing Model - C2Tutorial on Parallel Computing and Message Passing Model - C2
Tutorial on Parallel Computing and Message Passing Model - C2
 
Race conditions
Race conditionsRace conditions
Race conditions
 
Parallel architecture-programming
Parallel architecture-programmingParallel architecture-programming
Parallel architecture-programming
 
Openmp combined
Openmp combinedOpenmp combined
Openmp combined
 
Wolfgang Lehner Technische Universitat Dresden
Wolfgang Lehner Technische Universitat DresdenWolfgang Lehner Technische Universitat Dresden
Wolfgang Lehner Technische Universitat Dresden
 
Biref Introduction to OpenMP
Biref Introduction to OpenMPBiref Introduction to OpenMP
Biref Introduction to OpenMP
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
Parallel computing
Parallel computingParallel computing
Parallel computing
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
Fortran introduction
Fortran introductionFortran introduction
Fortran introduction
 
Taking R to the Limit (High Performance Computing in R), Part 1 -- Paralleliz...
Taking R to the Limit (High Performance Computing in R), Part 1 -- Paralleliz...Taking R to the Limit (High Performance Computing in R), Part 1 -- Paralleliz...
Taking R to the Limit (High Performance Computing in R), Part 1 -- Paralleliz...
 
OpenMP
OpenMPOpenMP
OpenMP
 

Similar to Open mp intro_01

Omp tutorial cpugpu_programming_cdac
Omp tutorial cpugpu_programming_cdacOmp tutorial cpugpu_programming_cdac
Omp tutorial cpugpu_programming_cdacGanesan Narayanasamy
 
Algoritmi e Calcolo Parallelo 2012/2013 - OpenMP
Algoritmi e Calcolo Parallelo 2012/2013 - OpenMPAlgoritmi e Calcolo Parallelo 2012/2013 - OpenMP
Algoritmi e Calcolo Parallelo 2012/2013 - OpenMPPier Luca Lanzi
 
Parallel and Distributed Computing Chapter 5
Parallel and Distributed Computing Chapter 5Parallel and Distributed Computing Chapter 5
Parallel and Distributed Computing Chapter 5AbdullahMunir32
 
Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginnersRajKumar Rampelli
 
openmp.New.intro-unc.edu.ppt
openmp.New.intro-unc.edu.pptopenmp.New.intro-unc.edu.ppt
openmp.New.intro-unc.edu.pptMALARMANNANA1
 
OpenPOWER Application Optimization
OpenPOWER Application Optimization OpenPOWER Application Optimization
OpenPOWER Application Optimization Ganesan Narayanasamy
 
Compiler design notes phases of compiler
Compiler design notes phases of compilerCompiler design notes phases of compiler
Compiler design notes phases of compilerovidlivi91
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scriptingAmirul Shafeeq
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersKirk Kimmel
 

Similar to Open mp intro_01 (20)

Omp tutorial cpugpu_programming_cdac
Omp tutorial cpugpu_programming_cdacOmp tutorial cpugpu_programming_cdac
Omp tutorial cpugpu_programming_cdac
 
Algoritmi e Calcolo Parallelo 2012/2013 - OpenMP
Algoritmi e Calcolo Parallelo 2012/2013 - OpenMPAlgoritmi e Calcolo Parallelo 2012/2013 - OpenMP
Algoritmi e Calcolo Parallelo 2012/2013 - OpenMP
 
OpenMP.pptx
OpenMP.pptxOpenMP.pptx
OpenMP.pptx
 
openmpfinal.pdf
openmpfinal.pdfopenmpfinal.pdf
openmpfinal.pdf
 
Parallel and Distributed Computing Chapter 5
Parallel and Distributed Computing Chapter 5Parallel and Distributed Computing Chapter 5
Parallel and Distributed Computing Chapter 5
 
Lecture6
Lecture6Lecture6
Lecture6
 
25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx
 
Nug2004 yhe
Nug2004 yheNug2004 yhe
Nug2004 yhe
 
Introduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimizationIntroduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimization
 
Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginners
 
Introduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimizationIntroduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimization
 
openmp.New.intro-unc.edu.ppt
openmp.New.intro-unc.edu.pptopenmp.New.intro-unc.edu.ppt
openmp.New.intro-unc.edu.ppt
 
OpenPOWER Application Optimization
OpenPOWER Application Optimization OpenPOWER Application Optimization
OpenPOWER Application Optimization
 
Compiler design notes phases of compiler
Compiler design notes phases of compilerCompiler design notes phases of compiler
Compiler design notes phases of compiler
 
Lecture7
Lecture7Lecture7
Lecture7
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scripting
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
 
CS4961-L9.ppt
CS4961-L9.pptCS4961-L9.ppt
CS4961-L9.ppt
 
Lecture5
Lecture5Lecture5
Lecture5
 
Perl Modules
Perl ModulesPerl Modules
Perl Modules
 

More from Oleg Nazarevych

Етикет службового листування
Етикет службового листуванняЕтикет службового листування
Етикет службового листуванняOleg Nazarevych
 
Оцінка трудомісткості і термінів проекту
Оцінка трудомісткості і термінів проектуОцінка трудомісткості і термінів проекту
Оцінка трудомісткості і термінів проектуOleg Nazarevych
 
5 Управління ризиками (2016)
5 Управління ризиками (2016)5 Управління ризиками (2016)
5 Управління ризиками (2016)Oleg Nazarevych
 
Л2 Управління проектами. Визначення та концепції
Л2 Управління проектами. Визначення та концепціїЛ2 Управління проектами. Визначення та концепції
Л2 Управління проектами. Визначення та концепціїOleg Nazarevych
 
Л1 Введення в програмну інженерію
Л1 Введення в програмну інженеріюЛ1 Введення в програмну інженерію
Л1 Введення в програмну інженеріюOleg Nazarevych
 
Ініціація проекту
Ініціація проектуІніціація проекту
Ініціація проектуOleg Nazarevych
 
4 Планування проекту (2018)
4 Планування проекту (2018)4 Планування проекту (2018)
4 Планування проекту (2018)Oleg Nazarevych
 
Введення в програмну інженерію. Моделі розробки проектів
Введення в програмну інженерію. Моделі розробки проектівВведення в програмну інженерію. Моделі розробки проектів
Введення в програмну інженерію. Моделі розробки проектівOleg Nazarevych
 
Відеоскрайбінг
ВідеоскрайбінгВідеоскрайбінг
ВідеоскрайбінгOleg Nazarevych
 
Основи графічного дизайну
Основи графічного дизайнуОснови графічного дизайну
Основи графічного дизайнуOleg Nazarevych
 
Тема 1 Основні терміни і поняття
Тема 1 Основні терміни і поняттяТема 1 Основні терміни і поняття
Тема 1 Основні терміни і поняттяOleg Nazarevych
 
Дебетові системи електронних платежів
Дебетові системи електронних платежівДебетові системи електронних платежів
Дебетові системи електронних платежівOleg Nazarevych
 
Тема 15 Банерна реклама
Тема 15 Банерна рекламаТема 15 Банерна реклама
Тема 15 Банерна рекламаOleg Nazarevych
 
Тема 3 (2) Основні принципи функціонування та роботи систем електронної комерції
Тема 3 (2) Основні принципи функціонування та роботи систем електронної комерціїТема 3 (2) Основні принципи функціонування та роботи систем електронної комерції
Тема 3 (2) Основні принципи функціонування та роботи систем електронної комерціїOleg Nazarevych
 
Тема 14 Пошукова оптимізація. SEO оптимізація
Тема 14 Пошукова оптимізація. SEO оптимізаціяТема 14 Пошукова оптимізація. SEO оптимізація
Тема 14 Пошукова оптимізація. SEO оптимізаціяOleg Nazarevych
 
Тема № 12. Дебетові системи електронних платежів
Тема № 12. Дебетові системи електронних платежівТема № 12. Дебетові системи електронних платежів
Тема № 12. Дебетові системи електронних платежівOleg Nazarevych
 
Тема 5 Системи електронної комерції B2C
Тема 5 Системи електронної комерції B2CТема 5 Системи електронної комерції B2C
Тема 5 Системи електронної комерції B2COleg Nazarevych
 
Тема 7 (2) Послуги в електронній комерції
Тема 7 (2) Послуги в електронній комерціїТема 7 (2) Послуги в електронній комерції
Тема 7 (2) Послуги в електронній комерціїOleg Nazarevych
 
Тема 18 Методи аналізу ефективності інтернет реклами
Тема 18 Методи аналізу ефективності інтернет рекламиТема 18 Методи аналізу ефективності інтернет реклами
Тема 18 Методи аналізу ефективності інтернет рекламиOleg Nazarevych
 

More from Oleg Nazarevych (20)

Етикет службового листування
Етикет службового листуванняЕтикет службового листування
Етикет службового листування
 
Оцінка трудомісткості і термінів проекту
Оцінка трудомісткості і термінів проектуОцінка трудомісткості і термінів проекту
Оцінка трудомісткості і термінів проекту
 
5 Управління ризиками (2016)
5 Управління ризиками (2016)5 Управління ризиками (2016)
5 Управління ризиками (2016)
 
Л2 Управління проектами. Визначення та концепції
Л2 Управління проектами. Визначення та концепціїЛ2 Управління проектами. Визначення та концепції
Л2 Управління проектами. Визначення та концепції
 
Л1 Введення в програмну інженерію
Л1 Введення в програмну інженеріюЛ1 Введення в програмну інженерію
Л1 Введення в програмну інженерію
 
Ініціація проекту
Ініціація проектуІніціація проекту
Ініціація проекту
 
4 Планування проекту (2018)
4 Планування проекту (2018)4 Планування проекту (2018)
4 Планування проекту (2018)
 
Введення в програмну інженерію. Моделі розробки проектів
Введення в програмну інженерію. Моделі розробки проектівВведення в програмну інженерію. Моделі розробки проектів
Введення в програмну інженерію. Моделі розробки проектів
 
Відеоскрайбінг
ВідеоскрайбінгВідеоскрайбінг
Відеоскрайбінг
 
3D графіка
3D графіка3D графіка
3D графіка
 
Основи графічного дизайну
Основи графічного дизайнуОснови графічного дизайну
Основи графічного дизайну
 
Тема 1 Основні терміни і поняття
Тема 1 Основні терміни і поняттяТема 1 Основні терміни і поняття
Тема 1 Основні терміни і поняття
 
Дебетові системи електронних платежів
Дебетові системи електронних платежівДебетові системи електронних платежів
Дебетові системи електронних платежів
 
Тема 15 Банерна реклама
Тема 15 Банерна рекламаТема 15 Банерна реклама
Тема 15 Банерна реклама
 
Тема 3 (2) Основні принципи функціонування та роботи систем електронної комерції
Тема 3 (2) Основні принципи функціонування та роботи систем електронної комерціїТема 3 (2) Основні принципи функціонування та роботи систем електронної комерції
Тема 3 (2) Основні принципи функціонування та роботи систем електронної комерції
 
Тема 14 Пошукова оптимізація. SEO оптимізація
Тема 14 Пошукова оптимізація. SEO оптимізаціяТема 14 Пошукова оптимізація. SEO оптимізація
Тема 14 Пошукова оптимізація. SEO оптимізація
 
Тема № 12. Дебетові системи електронних платежів
Тема № 12. Дебетові системи електронних платежівТема № 12. Дебетові системи електронних платежів
Тема № 12. Дебетові системи електронних платежів
 
Тема 5 Системи електронної комерції B2C
Тема 5 Системи електронної комерції B2CТема 5 Системи електронної комерції B2C
Тема 5 Системи електронної комерції B2C
 
Тема 7 (2) Послуги в електронній комерції
Тема 7 (2) Послуги в електронній комерціїТема 7 (2) Послуги в електронній комерції
Тема 7 (2) Послуги в електронній комерції
 
Тема 18 Методи аналізу ефективності інтернет реклами
Тема 18 Методи аналізу ефективності інтернет рекламиТема 18 Методи аналізу ефективності інтернет реклами
Тема 18 Методи аналізу ефективності інтернет реклами
 

Recently uploaded

Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 

Recently uploaded (20)

Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 

Open mp intro_01

  • 3. Outline Introduction to OpenMP 3 • What is OpenMP? • Timeline • Main Terminology • OpenMP Programming Model • Main Components • Parallel Construct • Work-sharing Constructs • sections, single, workshare • Data Clauses • default, shared, private, firstprivate, lastprivate, threadprivate, copyin
  • 4. What is OpenMP? 4 OpenMP (Open specifications for Multi Processing) – is an API for shared-memory parallel computing; – is an open standard for portable and scalable parallel programming; – is flexible and easy to implement; – is a specification for a set of compiler directives, library routines, and environment variables; – is designed for C, C++ and Fortran. Introduction to OpenMP
  • 5. Timeline 5 • OpenMP 4.0 Release Candidate 1 was released in November 2012. • http://openmp.org/ Introduction to OpenMP
  • 6. Main Terminology 6 1. OpenMP thread: a lightweight process 2. thread team: a set of threads which co-operate on a task 3. master thread: the thread which co-ordinates the team 4. thread-safety: correctly executed by multiple threads 5. OpenMP directive: line of code with meaning only to certain compilers 6. construct: an OpenMP executable directive 7. clause: controls the scoping of variables during the execution Introduction to OpenMP
  • 7. OpenMP Programming Model 7 OpenMP is designed for multi-processor/core UMA or NUMA shared memory systems. UMA NUMA Introduction to OpenMP
  • 8. Execution Model: 8 • Thread-based Parallelism • Compiler Directive Based • Explicit Parallelism • Fork-Join Model • Dynamic Threads • Nested Parallelism Introduction to OpenMP
  • 9. 9 Memory Model: • All threads have access to the shared memory. • Threads can share data with other threads, but also have private data. • Threads sometimes synchronise against data race. • Threads cache their data; Use OpenMP flush CPU CPUPrivate data Private data Thread 1 Thread 2 Thread 3 Private data Shared data CPU Introduction to OpenMP
  • 10. Main Components 10 • Compiler Directives and Clauses: appear as comments, executed when the appropriate OpenMP flag is specified – Parallel construct – Work-sharing constructs – Synchronization constructs – Data Attribute clauses C/C++:#pragma omp directive-name [clause[clause]...] Fortran free form: !$omp directive-name [clause[clause]...] Fortran fixed form: !$omp | c$omp | *$omp directive-name [clause[clause]...] Introduction to OpenMP
  • 11. 11 Compiling: See: http://openmp.org/wp/openmp-compilers/ for the full list. Compiler Flag Intel icc (C) icpc (C++) ifort (Fortran) -openmp GNU gcc (C) g++ (C++) g77/gfortran (Fortran) -fopenmp PGI pgcc (C) pgCC (C++) pg77/pgfortran (Fortran) -mp Introduction to OpenMP
  • 12. 12 • Runtime Functions: for managing the parallel program – omp_set_num_threads(n) - set the desired number of threads – omp_get_num_threads() - returns the current number of threads – omp_get_thread_num() - returns the id of this thread – omp_in_parallel() – returns .true. if inside parallel region and more. For C/C++: Add #include<omp.h> For Fortran: Add use omp_lib • Environment Variables: for controlling the execution of parallel program at run-time. – csh/tcsh: setenv OMP_NUM_THREADS n – ksh/sh/bash: export OMP_NUM_THREADS=n and more. Introduction to OpenMP
  • 13. Parallel Construct 13 • The fundamental construct in OpenMP. • Every thread executes the same statements which are inside the parallel region simultaneously. • At the end of the parallel region there is an implicit barrier for synchronization Fortran: !$omp parallel [clauses] ... !$omp end parallel C/C++: #pragma omp parallel [clauses] { … } Introduction to OpenMP
  • 14. double A[1000]; omp_set_num_threads(4); foo(0,A); foo(1,A); foo(2,A); foo(3,A); printf(“All Donen”); 14 double A[1000]; omp_set_num_threads(4); #pragma omp parallel { int tid=omp_get_thread_num(); foo(tid,A); } printf(“All Donen”); • Create a 4-thread parallel region • Each thread with tid from 0 to 3 calls foo(tid, A) • Threads wait for all treads to finish before proceeding Introduction to OpenMP
  • 15. 15 Hello World Example: C: #include<omp.h> #include<stdio.h> int main(){ #pragma omp parallel printf("Hello from thread %d out of %dn", omp_get_thread_num(), omp_get_num_threads()); } Fortran: program hello use omp_lib implicit none !$omp parallel PRINT*, 'Hello from thread',omp_get_thread_num(),'out of',omp_get_num_threads() !$omp end parallel end program hello Introduction to OpenMP
  • 16. 16 Compile: (Intel) >icc -openmp hello.c -o a.out >ifort -openmp hello.f90 -o a.out Execute: >export OMP_NUM_THREADS=4 >./a.out Hello from thread 0 out of 4 Hello from thread 3 out of 4 Hello from thread 1 out of 4 Hello from thread 2 out of 4 Introduction to OpenMP
  • 17. 17 • Dynamic threads: – The number of threads used in a parallel region can vary from one parallel region to another. – omp_set_dynamic(), OMP_DYNAMIC – omp_get_dynamic() • Nested parallel regions: – If a parallel directive is encountered within another parallel directive, a new team of threads will be created. – omp_set_nested(), OMP_NESTED – omp_get_nested() Introduction to OpenMP
  • 18. 18 • If Clause: – Used to make the parallel region directive itself conditional. – Only execute in parallel if expression is true. Fortran: !$omp parallel if(n>100) ... !$omp end parallel C/C++: #pragma omp parallel if(n>100) { … } • nowait Clause: – allows threads that finish earlier to proceed without waiting Fortran: !$omp parallel ... !$omp end parallel nowait C/C++: #pragma omp parallel nowait { … } (Checks the size of the data) Introduction to OpenMP
  • 19. Data Clauses 19 • Used in conjunction with several directives to control the scoping of enclosed variables. – default(shared|private|none): The default scope for all of the variables in the parallel region. – shared(list): Variable is shared by all threads in the team. All threads can read or write to that variable. C: #pragma omp parallel default(none), shared(n) Fortran: !$omp parallel default(none), shared(n) – private(list): Each thread has a private copy of variable. It can only be read or written by its own thread. C: #pragma omp parallel default(none), shared(n), private(tid) Fortran: !$omp parallel default(none), shared(n), private(tid) Introduction to OpenMP
  • 20. 20 • Most variables are shared by default – C/C++: File scope variables, static – Fortran: COMMON blocks, SAVE variables, MODULE variables – Both: dynamically allocated variables • Variables declared in parallel region are always private • How do we decide which variables should be shared and which private? – Loop indices - private – Loop temporaries - private – Read-only variables - shared – Main arrays - shared Introduction to OpenMP
  • 21. Example: 21 C: #include<omp.h> #include<stdio.h> int tid, nthreads; int main(){ #pragma omp parallel private(tid), shared(nthreads) { tid=omp_get_thread_num(); nthreads=omp_get_num_threads(); printf("Hello from thread %d out of %dn", tid, nthreads); } } Fortran: program hello use omp_lib implicit none integer tid, nthreads !$omp parallel private(tid), shared(nthreads) tid=omp_get_thread_num() nthreads=omp_get_num_threads() PRINT*, 'Hello from thread',tid,'out of',nthreads !$omp end parallel end program hello Introduction to OpenMP
  • 22. Some Additional Data Clauses: 22 – firstprivate(list): Private copies of a variable are initialized from the original global object. – lastprivate(list): On exiting the parallel region, variable has the value that it would have had in the case of serial execution. – threadprivate(list): Used to make global file scope variables (C/C++) or common blocks (Fortran) local. – copyin(list): Copies the threadprivate variables from master thread to the team threads. • copyprivate and reduction clauses will be described later. Introduction to OpenMP
  • 23. Work-Sharing Constructs 23 • To distribute the execution of the associated region among threads in the team • An implicit barrier at the end of the worksharing region, unless the nowait clause is added • Work-sharing Constructs: – Loop – Sections – Single – Workshare Introduction to OpenMP
  • 24. Sections Construct 24 • A non-iterative work-sharing construct. • Specifies that the enclosed section(s) of code are to be executed by different threads. • Each section is executed by one thread. Fortran: !$omp sections [clauses] !$omp section ... !$omp section ... !$omp end sections [nowait] C/C++: #pragma omp sections [clauses] nowait { #pragma omp section … #pragma omp section … } Introduction to OpenMP
  • 25. 25 #include <stdio.h> #include <omp.h> int main(){ int tid; #pragma omp parallel private(tid) { tid=omp_get_thread_num(); #pragma omp sections { #pragma omp section printf("Hello from thread %d n", tid); #pragma omp section printf("Hello from thread %d n", tid); #pragma omp section printf("Hello from thread %d n", tid); } } } >export OMP_NUM_THREADS=4 Hello from thread 0 Hello from thread 2 Hello from thread 3 Introduction to OpenMP
  • 26. Single Construct 26 • Specifies a block of code that is executed by only one of the threads in the team. • May be useful when dealing with sections of code that are not thread-safe. • Copyprivate(list): used to broadcast values obtained by a single thread directly to all instances of the private variables in the other threads. Fortran: !$omp parallel [clauses] !$omp single [clauses] ... !$omp end single !$omp end parallel C/C++: #pragma omp parallel [clauses] { #pragma omp single [clauses] … } Introduction to OpenMP
  • 27. Workshare Construct 27 • Fortran only • Divides the execution of the enclosed structured block into separate units of work • Threads of the team share the work • Each unit is executed only once by one thread • Allows parallelisation of – array and scalar assignments – WHERE statements and constructs – FORALL statements and constructs – parallel, atomic, critical constructs !$omp workshare ... !$omp end workshare [nowait] Introduction to OpenMP
  • 28. 28 Program WSex use omp_lib implicit none integer i real a(10), b(10), c(10) do i=1,10 a(i)=i b(i)=i+1 enddo !$omp parallel shared(a, b, c) !$omp workshare c=a+b !$omp end workshare nowait !$omp end parallel end program WSex Introduction to OpenMP
  • 29. References 29 1. http://openmp.org 2. https://computing.llnl.gov/tutorials/openMP 3. http://www.openmp.org/mp-documents/OpenMP4.0RC1_final.pdf 4. Michael J. Quinn, Parallel Programming in C with MPI and OpenMP, Mc Graw Hill, 2003. Introduction to OpenMP