Question: Write a multithreaded program to compute the product of two matrices. The multiplier matrix has M rows and P columns and the multiplicand matrix has

Write a multithreaded program to compute the product of two matrices. The multiplier matrix has M rows and P columns and the multiplicand matrix has P rows and N columns. The product matrix has M rows and N columns. Create a thread for each row of the product matrix. This thread computes all inner products for row i of the product matrix.

Use the following matrices to compute the product (AB).

M = 4, P = 3, and N = 4

A[M, P] = {(2, -3, 1), (1, 0, 4), (5, 2, -1), (0, 3, 6)};

B[P, N] = {(5, 1, -1, 0), (-4, 6, 2, 7), (5, 1, 0, 3)};

C[M, N] = Product matrix.

For the two matrices A and B, their product (AB) is given by:

P

(AB)ij = AikBkj

K=1

Using the given matrices, row 1 of the product matrix has the values:

C[1] = {(2*5 + -3*-4 + 1*5), (2*1 + -3*6 + 1), (2*-1 + -3*2 + 1*0),

(2*0 + -3*7 + 1*3)}

C[1] = {27, -15, -8, -18}

Each thread executes a function matMult() which is passed a row number as a parameter. This function computes all inner products for that row.

The main thread waits for the threads to complete before displaying the product matrix C.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!