a.Write a multithreaded sorting program that works as follows: A list of integersis divided into Foursmaller lists of equal size. Fourseparate threads (which wewill term sorting threads) sort each sub-list using a sorting algorithm of your choice.(You may use any built insorting function). TheFoursub-lists are then merged by a Fifththread—a merging thread—which merges the Foursub-lists into a single sorted list.Because global data are shared cross all threads, perhaps the easiest wayto set up the data is to create a global array. Each sorting thread will work onone 1/4of this array. A second global array of the same size as the unsortedinteger array will also be established. The merging thread will then mergethe Foursub-lists into this second array. Graphically, this program is structuredsimilarlyaccording to Figure 4.20 if we intend to partition the array into two parts.This programming project will require passing parameters to each of thesorting threads. In particular, it will be necessary to identify the starting indexfrom which each thread is to begin sorting. Refer to the instructions in Project1 for details on passing parameters to a thread.The parentthread will output the sorted array once all sorting threads haveexited.b.Solve the previous problemwithout using threads. Use thetimefunctionwith each part(a and b)and show, for each one, what is the exact execution time? Is there any difference? Why? You have to answer these questions in your report.
Answers
tex
bf
huge
wewill term sorting threads) sort each sub-list using a sorting algorithm of your choice.(You may use any built insorting function). TheFoursub-lists are then merged by a Fifththread—a merging thread—which merges the Foursub-lists into a single sorted list.Because global data are shared cross all threads, perhaps the easiest wayto set up the data is to create a global array. Each sorting thread will work onone 1/4of this array. A second global array of the same size as the unsortedinteger array will also be established. The merging thread will then mergethe Foursub-lists into this second array. Graphically, this program is structuredsimilarlyaccording to Figure 4.20 if we intend to partition the array into two parts.This programming project will require passing parameters to each of thesorting threads. In particular, it will be necessary to identify the starting indexfrom which each thread is to begin sorting. Refer to the instructions in Project1 for details on passing parameters to a thread.The parentthread will output the sorted array once all sorting threads haveexited.b.Solve the previous problemwithout using threads
/ tex