Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1: Runtime measurements with timing measurements Open the file MatrixMatrixMultiplication.py. It is a functioning script that multiplies two square matrices of the same size

Part 1: Runtime measurements with timing measurements

  • Open the file MatrixMatrixMultiplication.py. It is a functioning script that multiplies two square matrices of the same size after the user enters the size of the matrices
  • Add the appropriate documentation at the top of the file
  • Add commands to measure the elapsed time at the indicated locations in the file, as well as statements to print the results as indicated
  • Run the code for multiple matrix sizes (a good starting range to think about is 10 to 500, but this will vary for different computers) and observe what happens with the time needed for the computation, per element.
  • Add a short description (100 to 150 words) to your code file (at the top, in the documentation section) indicating what happens with the runtimes for Part 1

Part 2: Runtime measurements with addition of profiler

  • Add the following: @profile right above the function definition. This will start profiling the code
  • Repeat the steps above, for the lower half of the range you used for Part 1 and observe what happens with the time needed for the computation, per element. You will also see some output from the profiler that shows the memory requirements of your code. Why do you think the runtimes behave like that now that you have enabled profiling?
  • Add a short description to your code file (at the top, in the documentation section) indicating what happens with the runtimes for Part 1. Why do you think the runtimes are now different? (100 to 150 words)
  • Here's the python code

#INSERT DOCUMENTATION HERE

import random import time from memory_profiler import profile

def multiply(): for i in range(size): for j in range(size): for k in range(size): P[i][j]=P[i][j]+(A[i][k]*B[k][j]) #multiplication

size=int(input("Enter size: "))

r1=size c1=size r2=size c2=size

A=[[0 for i in range(c1)] for j in range(r1)] #initialize matrix A

#input matrix A for i in range(r1): for j in range(c1): x=random.randint(1,100) A[i][j]=x

B=[[0 for i in range(c2)] for j in range(r2)] #initialize matrix B

#input matrix B for i in range(r2): for j in range(c2): x=random.randint(1,100) B[i][j]=x

P=[[0 for i in range(c2)] for j in range(r1)] #initialize product matrix #INSERT CODE TO START TIMER multiply() #INSERT CODE TO STOP TIMER #INSERT CODE TO COMPUTE ELAPSED TIME #INSERT CODE TO PRINT OVERALL TIME (IN s, NUMBER OF ELEMENTS IN THE RESULT MATRIX, AND TIME PER ELEMENT(IN ms)

PLS IN PYTHON

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

Combinatorial Testing In Cloud Computing

Authors: Wei-Tek Tsai ,Guanqiu Qi

1st Edition

9811044805, 978-9811044809

More Books

Students also viewed these Programming questions

Question

Name two tests used to measure impact energy.

Answered: 1 week ago