Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

Given File:

image text in transcribed

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 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? Submit the python code file, which includes your two explanations. #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: ")) rl=size cl=size r2=size c2=size A=[[O for i in range (cl)] for j in range (rl)] #initialize matrix A #input matrix A for i in range (rl): for j in range (cl): x=random.randint (1,100) A[i][j]=x B=[[0 for i in range (c2)] for j in range (12)] #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 (rl)] #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 3, NUMBER OF ELEMENTS IN THE RESULT MATRIX, AND TIME PER ELEMENT (IN ms)

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

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions

Question

=+ a. a family deciding whether to buy a new car

Answered: 1 week ago

Question

=+10. How are inflation and unemployment related in the short run?

Answered: 1 week ago