SlideShare a Scribd company logo
PARALLEL
PROGRAMMING
Comparison of Sorting Algorithm
using Pthreads vs OpenMP
BY:
Munir Hassan (16K-3761)
Basit Ali Khatri (16K-3762)
Muhammad Bilal Khan (16K-3778)
2
INSTRUCTOR: Ms. Tania Irum
SECTION: D
TABLE OF CONTENT
1-Introduction:..................................................................................... 3
2-POSIX Threads (PThreads):..................................................... 3
3-OpenMP ............................................................................................... 4
4-Quick Sort .......................................................................................... 4
5-Merge Sort ........................................................................................... 5
6-Bubble Sort........................................................................................ 6
3
1- Introduction:
Ever sincethe 1970’s when the microprocessor that we know today was developed and launched
increase in its performance been achieved by increasing the clock speed. All the way until early
2000 the increase in clock speed was statically, every two years the number of transistors that
would fit on a chip would double.
Today it’s very common with a multi-core processor in most computers, laptops, work stations,
servers, phones and tablets. Adding just the cores does not means high performance, in some
cases it can actually mean worse performance because the individual cores may not have as high
clock speed as a single core processor. It’s is absolutely vital that the software running on the
hardware utilize the cores that the processor offer in order to get enhanced performance.
Developing software that can take advantage of multiple cores can be done in many different
programming languages. If the languages do not have a standard library that supports threads
there is often a third-party library that can be added to allow usage of threads. For all
experiments in this paper C was used as main language,reasoning for using C was that C has been
and is avery popular programming languageand is used in many different areas of development,
GCC compiler on Linux also has support for the two libraries that was tested. The threading
techniques that was investigated in this paper was POSIX Threads and OpenMP.
2- POSIX Threads (PThreads):
POSIX Threads is acommon threading model when working in C or C++,it is a standardized model
to work with threads created by IEEE. POSIX Threads can be used to parallelize task of a program
in order to increase the execution speed.
POSIX Threads offers a header file and a library that must be included at compilation time or else
the program wont compile because functions and data structures won’t be found by the
compiler. POSIX Threads offers a lot of functions to create, manipulate, synchronize and kill
threads in a program. Starting point for threads in a Pthreads program is a function called
pthreads_create, this function takes a pointer to a function that is the starting point for the new
thread. Pthread_exit then is used to kill the thread and in the main thread pthread_join is used
to wait for the executing threads.
4
3- OpenMP
OpenMP is a model for parallel programming in shared-memory systems and was developed in
the 1990’s by SGI. OpenMP is available for three different programming languages, Fortran, C
and C++. It consists of a number of compiler directives that can be used in the source code, these
directives need functions to run and those functions is specifiedin alibrary that must be included
at compile time. It works by letting the compiler translate the directives in to functions that is
found in the OpenMP library, it does this at compile time. That means that the compiler must
have support for OpenMP, if it does not have support for OpenMP it won’t know what to do with
the directives. In most cases this won’t crash the application, that is a sub goal of OpenMP. It
should be portable between different systems, even systems that does not support it. Of course,
these systems won’t have the increased performance from parallel computing but they should
still be able to run the program. Note: Recursion in Open MP takes more time than Pthread
because of task creation again and again.
4- Quick Sort
Quick Sort is sort algorithm that was developed by Tony Hoare in 1959. It works by dividing the
original array into sub-arrays. The first sub-array contains all the elements that is less than a
chosen pivot element and the second sub-array contains all the elements that is larger than the
pivot element. Now both of the arrays can be sorted separately, but before this is done they are
partitioned again. To do this a new pivot is chosen in each of the sub arrays and then they are
portioned into even smaller sub-arrays. This whole process continues until we have one element
-0.5
0
0.5
1
1.5
2
2.5
3
3.5
4
- 2 0 0 0 0 0 0 2 0 0 0 0 0 4 0 0 0 0 0 6 0 0 0 0 0 8 0 0 0 0 0 1 0 0 0 0 0 0 1 2 0 0 0 0 0
COMPARISON
Sequential Pthread OpenMP
5
sub arrays that does not need to be sorted. In this partitioning process the array is sorted. In its
worst-case scenario, it has a computational complexity of O(n2) and an average of O (n log n).
5- Merge Sort
Merge sort is a stable divide and conquer algorithm and is considered to be one of the fastest. It
recursively divides the data set into subarrays until each subarray consists of a single element. It
then merges each subarray back, sorting each new subarray as it builds its way back to a single
sorted array. Regardless of the shape of the data set to be sorted, merge sort performs the same
number of steps, and will therefore have the same time complexity for all cases, O (n log n). Even
though it is an efficient algorithm in terms of sorting, it has a drawback in that it uses O(n) extra
memory when sorting. The implementation can spawn recursive tasks during both the sorting
and merge phases to increase the amount of work that can be done in parallel. This ensures that
even in the last steps of the algorithm, at the top of the merge sort hierarchy, where the longest,
sorted subsets of the input data are merged, plenty of concurrent work is available to keep all
worker threads busy.
-0.2
0
0.2
0.4
0.6
0.8
1
1.2
- 2 0 0 0 0 0 0 2 0 0 0 0 0 4 0 0 0 0 0 6 0 0 0 0 0 8 0 0 0 0 0 1 0 0 0 0 0 0 1 2 0 0 0 0 0
COMPARISON
Sequential Pthread OpenMP
6
6- Bubble Sort
Bubble sort is the oldest, the simplest and the slowest sorting algorithm in use having a
complexity level of O(n2). Bubble sort works by comparing each item in the list with the item next
to it and swapping them if required. The algorithm repeats this process until to make passes all
the way through the list without swapping any items. Such a situation means that all the items
are in the correct order. By this way the larger values move to the end of the list while smaller
values remain towards the beginning of the list. It is also used in order to sort the array such like
the larger values comes before the smaller values. In other words, all items are in the correct
order. It takes more time than other sorts like selection and insertion because it requires many
more component exchanges and is just good for a pretty well-ordered array. More importantly
bubble sort is usually the easiest one to write correctly.
7- Conclusion
We have used several inputs in above parallel sorting program to show properties of the Open
MP and POSIX Threads. Suggestions for enhancements to the specification were made whenever
it seemed appropriate. It is also shows the problem of recursion in Open MP. Both Pthreads and
Open MP has its own characteristics.
-5
0
5
10
15
20
25
30
35
40
45
- 2 0 0 0 0 0 2 0 0 0 0 4 0 0 0 0 6 0 0 0 0 8 0 0 0 0 1 0 0 0 0 0 1 2 0 0 0 0
COMPARISON
Sequential Pthread OpenMP

More Related Content

What's hot (20)

PPTX
Legal framework order 1970
Umair Iftikhar Natt
 
PPTX
Formatting features in microsoft word
RayadJahoor
 
PPTX
Global LNG Trend, Geopolitics and Geoeconomics Strategy
Sampe Purba
 
PPSX
Is The Iran Nuclear Deal a Historic Mistake?
Maps of World
 
PPTX
Dictactorship and Oligarchy
NaimAlmashoori
 
PPT
International Politics - International Relations - Chapter 1
kkrassan
 
PPTX
Geopolitic theory & myanmar's strategic location
aungkokotoe
 
PPTX
Planning machinery in pakistan
Moonzajer M.f.
 
PPTX
Geopolitics of myanmar
aungkokotoe
 
PPTX
Economic.Nationalism
s.tahira hussain
 
PPT
War in Afghanistan
mrbruns
 
PPTX
Political life
Lance Gerard G. Abalos LPT, MA
 
PPTX
Liberalism
Mildred Lanuza
 
PPTX
International north south corridor
Rohit Yadav
 
PPTX
Russian Foreign Policy towards the Post-soviet space
Elmir Badalov
 
PPTX
Nation state system
Asad Ali
 
RTF
State and elements
Talal
 
PPTX
International Conflict
Muhammad Syukhri Shafee
 
DOCX
How to pull Pakistan out of heavy debt?
Zulqarnayn Awan
 
PPTX
Russian ukraine conflict crisis
maheshkumar873551
 
Legal framework order 1970
Umair Iftikhar Natt
 
Formatting features in microsoft word
RayadJahoor
 
Global LNG Trend, Geopolitics and Geoeconomics Strategy
Sampe Purba
 
Is The Iran Nuclear Deal a Historic Mistake?
Maps of World
 
Dictactorship and Oligarchy
NaimAlmashoori
 
International Politics - International Relations - Chapter 1
kkrassan
 
Geopolitic theory & myanmar's strategic location
aungkokotoe
 
Planning machinery in pakistan
Moonzajer M.f.
 
Geopolitics of myanmar
aungkokotoe
 
Economic.Nationalism
s.tahira hussain
 
War in Afghanistan
mrbruns
 
Liberalism
Mildred Lanuza
 
International north south corridor
Rohit Yadav
 
Russian Foreign Policy towards the Post-soviet space
Elmir Badalov
 
Nation state system
Asad Ali
 
State and elements
Talal
 
International Conflict
Muhammad Syukhri Shafee
 
How to pull Pakistan out of heavy debt?
Zulqarnayn Awan
 
Russian ukraine conflict crisis
maheshkumar873551
 

Similar to Parallel programming Comparisions (20)

PDF
29 19 sep17 17may 6637 10140-1-ed(edit)
IAESIJEECS
 
PDF
29 19 sep17 17may 6637 10140-1-ed(edit)
IAESIJEECS
 
PPT
openmp.New.intro-unc.edu.ppt
MALARMANNANA1
 
PPT
Lecture6
tt_aljobory
 
PDF
Sequential and Parallel Searching Algorithms
Suresh Pokharel
 
PPTX
Parallelization using open mp
ranjit banshpal
 
PDF
Algorithms devised for a google interview
Russell Childs
 
PPTX
Threads and multi threading
Antonio Cesarano
 
PDF
Multithreaded Programming Part- II.pdf
Harika Pudugosula
 
PPTX
12. Parallel Algorithms.pptx
MohAlyasin1
 
PPTX
Shared Memory Programming with Pthreads and OpenMP
Dilum Bandara
 
PPT
parallel programming models
Swetha S
 
PPTX
Review to the data structure and algorithm
lochanraj1
 
PPTX
6-9-2017-slides-vFinal.pptx
SimRelokasi2
 
ODP
OpenMp
Neel Bhad
 
KEY
OpenMP
Eric Cheng
 
PDF
Parallel Programming
Roman Okolovich
 
PDF
Parallel Algorithms
Dr Sandeep Kumar Poonia
 
PDF
Introducing Parallel Pixie Dust
Jason Hearne-McGuiness
 
PDF
Os Lamothe
oscon2007
 
29 19 sep17 17may 6637 10140-1-ed(edit)
IAESIJEECS
 
29 19 sep17 17may 6637 10140-1-ed(edit)
IAESIJEECS
 
openmp.New.intro-unc.edu.ppt
MALARMANNANA1
 
Lecture6
tt_aljobory
 
Sequential and Parallel Searching Algorithms
Suresh Pokharel
 
Parallelization using open mp
ranjit banshpal
 
Algorithms devised for a google interview
Russell Childs
 
Threads and multi threading
Antonio Cesarano
 
Multithreaded Programming Part- II.pdf
Harika Pudugosula
 
12. Parallel Algorithms.pptx
MohAlyasin1
 
Shared Memory Programming with Pthreads and OpenMP
Dilum Bandara
 
parallel programming models
Swetha S
 
Review to the data structure and algorithm
lochanraj1
 
6-9-2017-slides-vFinal.pptx
SimRelokasi2
 
OpenMp
Neel Bhad
 
OpenMP
Eric Cheng
 
Parallel Programming
Roman Okolovich
 
Parallel Algorithms
Dr Sandeep Kumar Poonia
 
Introducing Parallel Pixie Dust
Jason Hearne-McGuiness
 
Os Lamothe
oscon2007
 
Ad

Recently uploaded (20)

PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PPTX
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
PPTX
How to Add New Item in CogMenu in Odoo 18
Celine George
 
PPTX
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
PPTX
Aerobic and Anaerobic respiration and CPR.pptx
Olivier Rochester
 
PDF
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
PPTX
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
PDF
The Power of Compound Interest (Stanford Initiative for Financial Decision-Ma...
Stanford IFDM
 
PDF
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
 
PPTX
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PDF
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
PPTX
How to use grouped() method in Odoo 18 - Odoo Slides
Celine George
 
PDF
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
PDF
Andreas Schleicher_Teaching Compass_Education 2040.pdf
EduSkills OECD
 
PDF
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
DOCX
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
PDF
VCE Literature Section A Exam Response Guide
jpinnuck
 
PPTX
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
PPTX
Peer Teaching Observations During School Internship
AjayaMohanty7
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
How to Add New Item in CogMenu in Odoo 18
Celine George
 
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
Aerobic and Anaerobic respiration and CPR.pptx
Olivier Rochester
 
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
The Power of Compound Interest (Stanford Initiative for Financial Decision-Ma...
Stanford IFDM
 
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
 
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
How to use grouped() method in Odoo 18 - Odoo Slides
Celine George
 
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
Andreas Schleicher_Teaching Compass_Education 2040.pdf
EduSkills OECD
 
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
VCE Literature Section A Exam Response Guide
jpinnuck
 
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
Peer Teaching Observations During School Internship
AjayaMohanty7
 
Ad

Parallel programming Comparisions

  • 1. PARALLEL PROGRAMMING Comparison of Sorting Algorithm using Pthreads vs OpenMP BY: Munir Hassan (16K-3761) Basit Ali Khatri (16K-3762) Muhammad Bilal Khan (16K-3778)
  • 2. 2 INSTRUCTOR: Ms. Tania Irum SECTION: D TABLE OF CONTENT 1-Introduction:..................................................................................... 3 2-POSIX Threads (PThreads):..................................................... 3 3-OpenMP ............................................................................................... 4 4-Quick Sort .......................................................................................... 4 5-Merge Sort ........................................................................................... 5 6-Bubble Sort........................................................................................ 6
  • 3. 3 1- Introduction: Ever sincethe 1970’s when the microprocessor that we know today was developed and launched increase in its performance been achieved by increasing the clock speed. All the way until early 2000 the increase in clock speed was statically, every two years the number of transistors that would fit on a chip would double. Today it’s very common with a multi-core processor in most computers, laptops, work stations, servers, phones and tablets. Adding just the cores does not means high performance, in some cases it can actually mean worse performance because the individual cores may not have as high clock speed as a single core processor. It’s is absolutely vital that the software running on the hardware utilize the cores that the processor offer in order to get enhanced performance. Developing software that can take advantage of multiple cores can be done in many different programming languages. If the languages do not have a standard library that supports threads there is often a third-party library that can be added to allow usage of threads. For all experiments in this paper C was used as main language,reasoning for using C was that C has been and is avery popular programming languageand is used in many different areas of development, GCC compiler on Linux also has support for the two libraries that was tested. The threading techniques that was investigated in this paper was POSIX Threads and OpenMP. 2- POSIX Threads (PThreads): POSIX Threads is acommon threading model when working in C or C++,it is a standardized model to work with threads created by IEEE. POSIX Threads can be used to parallelize task of a program in order to increase the execution speed. POSIX Threads offers a header file and a library that must be included at compilation time or else the program wont compile because functions and data structures won’t be found by the compiler. POSIX Threads offers a lot of functions to create, manipulate, synchronize and kill threads in a program. Starting point for threads in a Pthreads program is a function called pthreads_create, this function takes a pointer to a function that is the starting point for the new thread. Pthread_exit then is used to kill the thread and in the main thread pthread_join is used to wait for the executing threads.
  • 4. 4 3- OpenMP OpenMP is a model for parallel programming in shared-memory systems and was developed in the 1990’s by SGI. OpenMP is available for three different programming languages, Fortran, C and C++. It consists of a number of compiler directives that can be used in the source code, these directives need functions to run and those functions is specifiedin alibrary that must be included at compile time. It works by letting the compiler translate the directives in to functions that is found in the OpenMP library, it does this at compile time. That means that the compiler must have support for OpenMP, if it does not have support for OpenMP it won’t know what to do with the directives. In most cases this won’t crash the application, that is a sub goal of OpenMP. It should be portable between different systems, even systems that does not support it. Of course, these systems won’t have the increased performance from parallel computing but they should still be able to run the program. Note: Recursion in Open MP takes more time than Pthread because of task creation again and again. 4- Quick Sort Quick Sort is sort algorithm that was developed by Tony Hoare in 1959. It works by dividing the original array into sub-arrays. The first sub-array contains all the elements that is less than a chosen pivot element and the second sub-array contains all the elements that is larger than the pivot element. Now both of the arrays can be sorted separately, but before this is done they are partitioned again. To do this a new pivot is chosen in each of the sub arrays and then they are portioned into even smaller sub-arrays. This whole process continues until we have one element -0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 - 2 0 0 0 0 0 0 2 0 0 0 0 0 4 0 0 0 0 0 6 0 0 0 0 0 8 0 0 0 0 0 1 0 0 0 0 0 0 1 2 0 0 0 0 0 COMPARISON Sequential Pthread OpenMP
  • 5. 5 sub arrays that does not need to be sorted. In this partitioning process the array is sorted. In its worst-case scenario, it has a computational complexity of O(n2) and an average of O (n log n). 5- Merge Sort Merge sort is a stable divide and conquer algorithm and is considered to be one of the fastest. It recursively divides the data set into subarrays until each subarray consists of a single element. It then merges each subarray back, sorting each new subarray as it builds its way back to a single sorted array. Regardless of the shape of the data set to be sorted, merge sort performs the same number of steps, and will therefore have the same time complexity for all cases, O (n log n). Even though it is an efficient algorithm in terms of sorting, it has a drawback in that it uses O(n) extra memory when sorting. The implementation can spawn recursive tasks during both the sorting and merge phases to increase the amount of work that can be done in parallel. This ensures that even in the last steps of the algorithm, at the top of the merge sort hierarchy, where the longest, sorted subsets of the input data are merged, plenty of concurrent work is available to keep all worker threads busy. -0.2 0 0.2 0.4 0.6 0.8 1 1.2 - 2 0 0 0 0 0 0 2 0 0 0 0 0 4 0 0 0 0 0 6 0 0 0 0 0 8 0 0 0 0 0 1 0 0 0 0 0 0 1 2 0 0 0 0 0 COMPARISON Sequential Pthread OpenMP
  • 6. 6 6- Bubble Sort Bubble sort is the oldest, the simplest and the slowest sorting algorithm in use having a complexity level of O(n2). Bubble sort works by comparing each item in the list with the item next to it and swapping them if required. The algorithm repeats this process until to make passes all the way through the list without swapping any items. Such a situation means that all the items are in the correct order. By this way the larger values move to the end of the list while smaller values remain towards the beginning of the list. It is also used in order to sort the array such like the larger values comes before the smaller values. In other words, all items are in the correct order. It takes more time than other sorts like selection and insertion because it requires many more component exchanges and is just good for a pretty well-ordered array. More importantly bubble sort is usually the easiest one to write correctly. 7- Conclusion We have used several inputs in above parallel sorting program to show properties of the Open MP and POSIX Threads. Suggestions for enhancements to the specification were made whenever it seemed appropriate. It is also shows the problem of recursion in Open MP. Both Pthreads and Open MP has its own characteristics. -5 0 5 10 15 20 25 30 35 40 45 - 2 0 0 0 0 0 2 0 0 0 0 4 0 0 0 0 6 0 0 0 0 8 0 0 0 0 1 0 0 0 0 0 1 2 0 0 0 0 COMPARISON Sequential Pthread OpenMP