Introduction to OpenMP
What does OpenMP stands for?
Open specifications for Multi Processing via collaborative work
between interested parties from the hardware and software
industry, government and academia.
OpenMP is an Application Program Interface (API) that may be used
to explicitly direct multi-threaded, shared memory parallelism.
API components: Compiler Directives, Runtime Library,Environment
variable.
4.
1.All threads haveaccess to the same,
globally shared memory
OpenMP Programming Model
: Shared Memory
Shared
Memory
Thread
Private
Thread
Private
5. Data transfer is transparent
to the programmer
2. Data can be Shared or Private
4. Private data can be accessed only
by the threads that owns it
3. Shared data can be accessible by all
threads
5.
OpenMP Program Execution
Model:: Fork-Join
A
B
C
A
B
C
D
Master
Thread
Parallel
Task 1
Parallel
Task 2
A B C A B C D
Master
Thread
Parallel Task 1 Parallel Task 2
Parallel
Regions
6.
When to considerusing OpenMP?
The compiler may not be able to do the parallelization
in the way you like to see it.
A loop is not parallelized
✔ The data dependency analysis is not able to
determine whether it is safe to parallelize or not
The granularity is not high enough
✔ The compiler lacks information to parallelize at
the highest possible level
This is when we use explicit parallelization through
OpenMP
The Effect onProgram Execution
Time
A B C
Each task takes .3 ms , Total Time= .12 ms (Using
single Thread, Single Processor)
Without Using
OpenMP
Using OpenMP
Thread 1
Thread 2
Thread 3
Master
Thread
Thread 0
.3 ms .3 ms
Total time = .6 ms ( Faster )
Parallel
Region