Question: PLZ Help: Java and C: In this assignment you will learn and practice developing a multithreaded application using both Java and C with Pthreads. So

PLZ Help: Java and C: In this assignment you will learn and practice developing a multithreaded application using both Java and C with Pthreads. So you will submit two programs!The application you are asked to implement is from our textbook (SGG), namely Multithreaded Sorting Application with an addition of computing average of the given values.
Here is the description of it for convenience: Write a multithreaded sorting program consisting of three threads: main, sorting_avg, merging_avg.
They work as follows:Main thread randomly generates an array of double values with a given size (say, N=1000), and divides it into two smaller arrays of equal size. It then passes each sub-array to sorting_avg thread (creates two copies of the same thread), and waits until these two sub-arrays are sorted and the average of the values in each array are computed. It then calls merging_avg thread by passing the already sorted two sub-arrays, and the averages of the first and second sub-arrays as parameters.
Sorting_avg thread sorts the given sub-array using insertion sort or selection sort (one is enough and you need to implement either one), and computes the average of the values in the given array. So this thread returns sorted sub-array and its average.
Merging_avg thread takes both sorted sub-arrays and the their averages as parameters. It then merges them into a single sorted array in a linear time (so don't call sorting function again! You can simply have a loop and take the smallest from the sorted arrays until they are all merged!), and simply find the overall average by taking the average of the given two averages (this will work because we assume both sub-arrays have the same size!).
Your program should take take an integer (say N) from the command line (you can assume that we will always give an even number). This number N represents the size of the array that needs to be sorted. Accordingly, your main thread should create an array of N double values and randomly select the values from the range of [1.0,1000.0]. Then sort them using multithreading and compute the average of these values as described above. While doing these, we like to also measure how long it takes to finish this task. For the comparison purposes, you are also asked to simply call your sort function to sort the whole array and compute average without multithreading and measure how long it takes (basically the main thread simply calls the sorting_avg thread for the whole array).Here is how your program should be executed with a sample output:>./prog 1000or in case of Java> java prog_j 1000Sorting is done in 10.0ms when two threads are usedSorting is done in 20.0ms when one thread is usedThe numbers 10.0 and 20.0 here are just an example! Your actual numbers will be different and depend on the runs. (I have some more discussion at the end of this document).You need to figure out how to implement this program in Java and C (Pthreads)! You need to be careful about how to pass parameters in C and Java. For example, in C, because global data are shared across all threads, perhaps the easiest way is to create a global array and just pass index values/ranges as parameters. Each sorting thread will work on one half of this array. A second global array of the same size will also be created so that the merging thread will then merge the two sub-arrays into this second array. This programming project will require passing parameters to each of the sorting threads. In particular, it will be necessary to identify the starting index from which each thread is to begin sorting. You need to deal with similar issues in Java as well. In both case please do not use readily available sort functions/methods, you need to implement a simple one (insertion or selection sort) by yourself!
Part 1In this part you will write your program in C with Pthreads.
Part 2In this part you will write your program in Java. Part 3Test both programs with different values of N (1000,5000,10000) and see how they perform.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!