1. “Parallelization Using OpenMP
Pro. Ranjit R. Banshpal
•What Is Parallelization?
•Parallel Programming Model
•Achieving Parallelism In Shared Memory Model Using
•What is Message Passing?
•OpenMP Vs MPI
•Pros & Cons Of OpenMP
•Pros & Cons Of MPI
• A more powerful machine leads to new kinds of applications, which in
turn fuel our demand for yet more powerful systems.
• Hardware engineers are striving harder to get the attainable performance,
however find limit after a certain point.
• This has given birth to what we call software parallelism.
• There are different types of tools such as OpenMP and MPI, which can be
used to model software program to work faster by parallelism.
Programming languages evolve just as natural languages do.
In the early days of computing, programs were serial.
It ran from start to finish on a single processor.
Parallel programming developed as a means of improving performance
The instructions from each part run simultaneously on different CPUs.
5. Literature Survey
Name Of Authors
Name of Paper
T.G. Mattson, B.A. Sanders,
and B. Massingill
Patterns for Parallel
B. Chapman, G. Jost, and R.
van der Pas
Parallel Programming Message Passing
9. Why Parallelization?
Carefully optimizing the serial version of code could lead to significant
Nevertheless, there will always be some codes which demand “too many”
resources in terms of CPU time or memory.
Parallelization is optimization technique. The goal is to reduce the execution
10. What Is Parallelization?
Something is parallel if there is certain level of independence in the order
In other words, it doesn’t matter in what order the operations are performed.
11. Parallel Programming Models
Parallel programming models exist as an abstraction above hardware and
These models are not specific to a particular type of machine or memory
There are several parallel programming models in common use:
• Shared Memory Model
• Thread Model
• Message Passing Model
12. Shared Memory Model
Tasks share a common address space, which they read and write
Task oriented and works at higher level of abstraction than the threads.
There is no need to specify explicitly the communication of
data between tasks. Program development can often be simplified.
In terms of performance, it becomes more difficult to
understand and manage data locality.
13. Thread Model
A single process can have multiple, concurrent execution paths.
Each thread has local data, but also shares the entire resources of program.
A thread's work may best be described as a subroutine within the main
Threads communicate with each other through global memory (updating
Threads are commonly associated with shared memory architectures and
14. Message Passing Model
A set of tasks that use their own local memory during computation.
Multiple tasks can reside on the same physical machine and/or across
an arbitrary number of machines.
Tasks exchange data through communications by sending and receiving
Data transfer usually requires cooperative operations to be performed
by each process.
15. Achieving Parallelism in Shared Memory
Model Using OpenMP
16. What Is OpenMP?
Open specifications for Multi Processing.
“Standard” API for defining multi-threaded shared-memory programs.
OpenMP is not a “language”.
OpenMP consists of three main parts:
17. Why OpenMP Is Popular?
No message passing .
OpenMP directives or library calls may be incorporated incrementally.
The code is in effect a serial code.
Code size increase is generally smaller.
OpenMP-enabled codes tend to be more readable .
18. The Basic Idea
• The code starts with one master thread.
• When a parallel tasks needs to be performed, additional threads are
• When the parallel tasks are finished, the additional threads are released.
OpenMP Execution Model
19. What is Message Passing ?
A computational model in which, processes are able to communicate
with other processes by sending and receiving messages.
Distributed Memory Systems.
• Networks of Workstations (clusters)
• Massively parallel machines
Shared Memory Systems.
• Supercomputer Setting
MPI is a library specification for message-passing.
Use for Distributed Memory Systems.
20. OpenMP Vs MPI
1. Works on shared memory systems.
1. Works on both shared memory and
distributed memory systems .
2. Has better performance on SMP systems,
2. Has poor performance on SMP systems.
3. Directive based.
3. Message passing style
4. Easier to program and debug.
4. More flexible and scalable
21. Pros & Cons of OpenMP
– Easy to Instrument (and check)
– Parallelism can be implemented incrementally
– Allows for coarse-grained or fine-grained parallelism
– Widely available, portable
– Not as scalable as MPI
– Available on Shared memory systems only
22. Pros & Cons of MPI
• Pros :
– runs on either shared or distributed memory architectures
– can be used on a wider range of problems than OpenMP
– each process has its own local variables
• Cons :
– requires more programming changes to go from serial to
– can be harder to debug
– performance is limited by the communication network
between the nodes
OpenMP is better option for parallelization in shared memory.
OpenMP is a compiler-based technique to create concurrent code from
(mostly) serial code.
OpenMP can enable (easy) parallelization of loop-based code.
OpenMP performs comparably to manually-coded threading
. Javier Diaz, Camelia Mun˜oz-Caro, and Alfonso Nin˜o, “A Survey of Parallel Programming
Models and Tools in the Multi and Many-Core Era”, IEEE transactions on parallel and
distributed systems, vol. 23, no. 8, august 2012.
. D. S. Henty, “Performance of Hybrid Message-Passing and Shared-Memory Parallelism for
Discrete Element Modeling”, Proceedings of the IEEE/ACM SC2000 Conference (SC’00),
. David Clark, “OpenMP: a parallel standard for the masses”, IEEE Concurrency, January–March
. Joe Throop, Kuck & Associates Inc., “OpenMP: Shared-Memory Parallelism From the Ashes”,
IEEE Standards, May 1999.
. Leonardo Dagum and Ramesh Menon“OpenMP: An Industry Standard API for Shared-Memory
Programming”, IEEE computationascli ence & engineering, May 1998.
. J. B. Dennis and E. C. Van Horn, “Programming semantics for multiprogrammed computations”,
Comm. ACM, 9(3):143–155, 1966.
. MPI Forum, “MPI: A Message Passing Interface”, Int. Journal of Supercomputing Applications,
. Barbara Chapman, Gabriele Jost, Ruud van der Pas, “Using OpenMP”, The MIT Press.
Cambridge, Massachusetts ,London, England, 2008.
. William Gropp, “Tutorial on MPI: The Message Passing Interface”, Mathematics and Computer
Science Division, Argonne National Laboratory, Argonne, IL 60439, January–March 1999.
. Ewing Lusk and Anthony Chan., “Early Experiments with the OpenMP/MPI Hybrid
Programming Model”, Mathematics and Computer Science Division Argonne National
Laboratory, ASCI FLASH Center, University of Chicago, 2008.
. Dieter an Mey, Thomas Reichstein Parallelization with OpenMP and MPI, A Simple Example
(C)”, October 26, 2007.
. Wahid Nasri and Karim Fathallah, “A Performance model for OpenMP programs on multicore machines.” IEEE 2013
. MPI Forum. “Hybrid MPI/OpenMP Optimization in Linpack Benchmark on Multi-core
Platforms”, The 8th International Conference on Computer Science & Education (ICCSE