Question: C Write a multithreaded sorting program that works as follows:A list of integers is divided into two smaller lists of equal size. Two separate threads
C
Write a multithreaded sorting program that works as follows:A list of integers is divided into two smaller lists of equal size. Two separate threads (which we will term sorting threads) sort each sublist using a sorting algorithm of your choice. The two sublists are then merged by a third thread (i.e., merging thread) which merges the two sublists into a single sorted list
Your program should take take an integer (say N) from the command line. This number N represents the size of the array that needs to be sorted. Accordingly, you should create an array of N double values and randomly select the values from the range of [1.0, 100.0].
Then sort them using multhithreading as described above and measure how long does it take to finish this sorting task. For the comparision purposes, you are also asked to simply call your sort function to sort the whole array and measure how long does it take if we do not use multuthreading (basically one (the main) thread is doing the sorting job)
Here is how your program should be executed and a sample output
>prog 1000
>Sorting is done in 10.0ms when two threads are used
>Sorting is done in 20.0ms when one thread is used
You need to implement this program in C (Pthreads)! Because global data are shared cross all threads, perhaps the easiest way to set up the data is to create a global array.
Part 2 Test both programs(with threads vs without) with different values of N (1000, 10000, 100000, 1000000) and see how they perform
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
