Question: In this assignment you will investigate how multiprocessing in Python can speedup matrix multiplication. Recall if A is an m n matrix and B is

In this assignment you will investigate how multiprocessing in Python can speedup matrix multiplication. Recall if
A is an mn matrix and B is an np matrix, given by
A=[a11a12cdotsa1na21a22cdotsa2nvdotsvdotsddotsvdotsam1am2cdotsamn],B=[b11b12cdotsb1pb21b22cdotsb2pvdotsvdotsddotsvdotsbn1bn2cdotsbnp]
then the matrix product C is the mp matrix
C=[c11c12cdotsc1pc21c22cdotsc2pvdotsvdotsddotsvdotscm1cm2cdotscmp]
where each element of C is the inner product
cij=ai1b1j+ai2b2j+cdots+ainbnj=k=1naikbkj
for i=1,dots,m and j=1,dots,p.
The computational complexity of the classic algorithm is therefore O(n3),
c=np*zeros((m,p))
for iin range(m):
for jin range (p) :
sum =0.0
for kin range(n):
sum +=A[i,k]**B[k,j]
c[i,j]= sum
Based on the
mp.py code demonstrated in class, develop a Python code .py file using Sublime Text (or other
editor) to serially multiply two matrices using the classic algorithm and report elapsed runtime. Then implement a
parallel approach using the Python multiprocessing Pool.map() facility. Observe each entry ci,j is an inner
product that can be computed independently by a separate thread. Report elapsed runtime of your parallel
implementation. Do not include the pool construction in the timing (i.e., do not include time to execute
statement pool = mp.Pool(processes=threads)).
Choose your own values for m,n, and p. Initialize matrices A and B with random values using
A=np*r andom * rand (m,n)
B=np*r andom. rand (n,p)
Add an assert statement to verify the serially computed C matrix is equal to the parallelly computed C matrix.
Finally, answer the question: for what value of mp does your parallel implementation outperform your
serial?
Code In Python
 In this assignment you will investigate how multiprocessing in Python can

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!