SlideShare a Scribd company logo
1 of 6
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)

Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Recursion
RecursionRecursion
Recursion
 
Recursion in c++
Recursion in c++Recursion in c++
Recursion in c++
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
Polymorphism in oop
Polymorphism in oopPolymorphism in oop
Polymorphism in oop
 
User datagram protocol (udp)
User datagram protocol (udp)User datagram protocol (udp)
User datagram protocol (udp)
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
CNIT 127: 8: Windows overflows (Part 2)
CNIT 127: 8: Windows overflows (Part 2)CNIT 127: 8: Windows overflows (Part 2)
CNIT 127: 8: Windows overflows (Part 2)
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
 
PDA (pushdown automaton)
PDA (pushdown automaton)PDA (pushdown automaton)
PDA (pushdown automaton)
 
Coma
ComaComa
Coma
 
C# Method overloading
C# Method overloadingC# Method overloading
C# Method overloading
 
Html lists
Html listsHtml lists
Html lists
 
Nested class in java
Nested class in javaNested class in java
Nested class in java
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programming
 
Presentation on cyclic redundancy check (crc)
Presentation on cyclic redundancy check (crc)Presentation on cyclic redundancy check (crc)
Presentation on cyclic redundancy check (crc)
 
Directed Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksDirected Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocks
 
Inheritance
InheritanceInheritance
Inheritance
 

Similar to Parallel programming Comparisions

ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdfADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdfRGPV De Bunkers
 
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP IJCSEIT Journal
 
Machine learning Experiments report
Machine learning Experiments report Machine learning Experiments report
Machine learning Experiments report AlmkdadAli
 
SMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docxSMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docxpbilly1
 
Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Akhila Prabhakaran
 
The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)theijes
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in CJabs6
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaRaghu nath
 
Intelligent Systems Project: Bike sharing service modeling
Intelligent Systems Project: Bike sharing service modelingIntelligent Systems Project: Bike sharing service modeling
Intelligent Systems Project: Bike sharing service modelingAlessio Villardita
 

Similar to Parallel programming Comparisions (20)

ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdfADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
 
Multithreading by rj
Multithreading by rjMultithreading by rj
Multithreading by rj
 
unit 2 hpc.pptx
unit 2 hpc.pptxunit 2 hpc.pptx
unit 2 hpc.pptx
 
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
 
An adaptive framework towards analyzing the parallel merge sort
An adaptive framework towards analyzing the parallel merge sortAn adaptive framework towards analyzing the parallel merge sort
An adaptive framework towards analyzing the parallel merge sort
 
1844 1849
1844 18491844 1849
1844 1849
 
1844 1849
1844 18491844 1849
1844 1849
 
Machine learning Experiments report
Machine learning Experiments report Machine learning Experiments report
Machine learning Experiments report
 
SMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docxSMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docx
 
REPORT_INTERNSHIP
REPORT_INTERNSHIPREPORT_INTERNSHIP
REPORT_INTERNSHIP
 
Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)
 
Gk3611601162
Gk3611601162Gk3611601162
Gk3611601162
 
RAJAT PROJECT.pptx
RAJAT PROJECT.pptxRAJAT PROJECT.pptx
RAJAT PROJECT.pptx
 
The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
Concurrency and parallel in .net
Concurrency and parallel in .netConcurrency and parallel in .net
Concurrency and parallel in .net
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Intelligent Systems Project: Bike sharing service modeling
Intelligent Systems Project: Bike sharing service modelingIntelligent Systems Project: Bike sharing service modeling
Intelligent Systems Project: Bike sharing service modeling
 
MultiThreading in Python
MultiThreading in PythonMultiThreading in Python
MultiThreading in Python
 

Recently uploaded

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
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
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
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
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 

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