2. Develop a multithreaded program to sort an a
ay of integers.
Your program should run with 4 threads
o
Break the a
ay into four equally sized partitions
o
Sort the partitions separately in different threads
o
Merge the results back together. This is a 2 step process where two threads merge the
four partitions into two partitions and then with one thread merge the two partitions
into one.
o
Write a simple routine that checks the final a
ay is in sorted order. If the a
ay is
sorted print “Sort complete.” Otherwise print an e
or message.
Each of the worker threads should use a bu
le sort algorithm (intentionally slow, see the
pseudo code below).
Use an a
ay size of 64,000 elements that you randomly initialize using
and()
·
The final version of your program should
only print out the simple message generated by your simple checker.
·
Along with your code, turn in a comparison of how much time the multithread program takes
versus running the same problem using a 1 threaded bu
lesort algorithm. To determine how
much time is required, you might use the unix time program.
Simple bu
le routine:
for (x = 0 ; x < ( n - 1 ); x++)
{for (y = 0 ; y < n - x - 1; y++)
{if (a
ay[y] > a
ay[y+1])
{temp = a
ay[y];
a
ay[y] = a
ay[y+1];
a
ay[y+1] = temp;
}