Lab 4
Lab 4
Lab4
Pthreads
Objectives
Introducing threads concepts and POSIX threads library.
Implementing popular algorithms as multi-threaded ones.
Divide the unsorted list into two sub-lists of about half the size.
So you are required to implement it using pthreads. Each time the list is
divided; two threads are created to do merge-sort on each half
separately. This step is repeated recursively until each sub-list has only
one element.Given the code you will need to modify it to apply
multi threading merge sort in your lab.
The program should read two input lines from a file called input (create it in
your working directory where the .c file exist) in the following format:
[number of elements] 1
Array elements which are space separated.
example input
10
100 20 15 3 4 8 7 -1 0 33
When the program finishes, it should print out the sorted array.
For both variations, you have to compute the elapsed time for each of them, compare them
and justify your answer.
The program should read two input matrices from a file in the following format:
example input:
35
1 -2 3 4 5
2
1 2 -3 4 5
-1 2 3 4 5
54
-1 2 3 4
1 -2 3 4
1 2 -3 4
1 2 3 -4
-1 -2 -3 -4
output format:
Deliverables
Complete source code in for Part2 commented thoroughly and clearly.
You may talk together on the algorithms or functions being used but are NOT
allowed to look at anybody’s code.
Revise the academic integrity note found on the class web page.