Parallel Distributed Computing Assignment 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Assignment#2

Q.1 In this question, you have to write a multithreaded program using ‘Pthreads’. You will perform
Data Decomposition as well as task decomposition. Your program should provide the following
functionality.

a) Take a matrix of size (m x n) where ‘m’ and ‘n’ values are taken as input from user. Initialize
the matrix by some random values or user input.

b) Then

a. if the last digit of your student ID is (0 or 1 or 2) then create number of threads equal to
number of columns ‘n’ and each thread will sort a column using Quick Sort in Ascending
order.

b. if the last digit of your student ID is (4 or 5) then create number of threads equal to
number of columns ‘n’ and each thread will sort a column using Quick Sort in
Descending order.
c. if the last digit of your student ID is (6 or 7) then create number of threads equal to
number of rows ‘m’ and each thread will sort a row using Quick Sort in Ascending
order.
d. if the last digit of your student ID is (8 or 9) then create number of threads equal to
number of rows ‘m’ and each thread will sort a row using Quick Sort in Descending
order.

c) Quicksort should be implemented using recursive decomposition. Each subtask will be done
by a new thread.

d) At the end each thread should add all values of the column/row that is being sorted and the
resultant figure will be added to Matrix addition which is the sum of all values of the matrix.

Let’s take the scenario of (4 x4) matrix.

Input Matrix Output Matrix

3 5 32 80 3 5 2 7

23 11 9 15 4 7 9 15

20 7 14 26 20 11 14 26

4 17 2 7 23 17 32 80

Matrix Addition = 275


Q.2 The following code performs a linear search on an array A (size n) to find the first occurrence
of a value target, how might cache locality be affected in this linear search, and how could it
be potentially improved?

You might also like