Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

What are the objectives of Human resource planning ?

Answered: 1 week ago

Question

Explain the process of Human Resource Planning.

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago