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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started