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, sortingavg, mergingavg.
They work as follows:Main thread randomly generates an array of double values with a given size say N and divides it into two smaller arrays of equal size. It then passes each subarray to sortingavg thread creates two copies of the same thread and waits until these two subarrays are sorted and the average of the values in each array are computed. It then calls mergingavg thread by passing the already sorted two subarrays, and the averages of the first and second subarrays as parameters.
Sortingavg thread sorts the given subarray 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 subarray and its average.
Mergingavg thread takes both sorted subarrays 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 subarrays 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 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 sortingavg thread for the whole arrayHere is how your program should be executed with a sample output:prog or in case of Java java progj Sorting is done in ms when two threads are usedSorting is done in ms when one thread is usedThe numbers and 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 documentYou 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 valuesranges 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 subarrays 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 functionsmethods you need to implement a simple one insertion or selection sort by yourself!
Part In this part you will write your program in C with Pthreads.
Part In this part you will write your program in Java. Part Test both programs with different values of N and see how they perform.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
