OpenMp
Name: Tanjilla Sarkar
Roll: 14235427
Department of Computer Science and
Engineering
University of Rajshahi
Motivation
Think about Large
Computations…
Example: Matrix Multiplication , Large
point DFT calculations and so on.
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.
1.All threads have access 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
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
When to consider using 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
A Simple Example
 A simple C++ code:
Previous code in OpenMp
 OpenMp code:
Task Distributions in
Threades
Thread_id=1
i=1
for (int j=0; j<4; j++)
{sum += b[i][j]*c[j];}
a[i] = sum;
Thread_id=2
i=2
for (int j=0; j<4; j++)
{sum += b[i][j]*c[j];}
a[i] = sum;
Thread_id=3
i=3
for (int j=0; j<4; j++)
{sum += b[i][j]*c[j];}
a[i] = sum;
The Effect on Program 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
Any Question?
Thanks
  

Parallel processing -open mp

  • 1.
    OpenMp Name: Tanjilla Sarkar Roll:14235427 Department of Computer Science and Engineering University of Rajshahi
  • 2.
    Motivation Think about Large Computations… Example:Matrix Multiplication , Large point DFT calculations and so on.
  • 3.
    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
  • 7.
    A Simple Example A simple C++ code:
  • 8.
    Previous code inOpenMp  OpenMp code:
  • 9.
    Task Distributions in Threades Thread_id=1 i=1 for(int j=0; j<4; j++) {sum += b[i][j]*c[j];} a[i] = sum; Thread_id=2 i=2 for (int j=0; j<4; j++) {sum += b[i][j]*c[j];} a[i] = sum; Thread_id=3 i=3 for (int j=0; j<4; j++) {sum += b[i][j]*c[j];} a[i] = sum;
  • 10.
    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
  • 11.
  • 12.