anonymous
  • anonymous
modyfing the code to get n threads that compute each row, instead of row and column in python
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
import numpy import random import threading class MatrixMult(threading.Thread): """A thread which computes the i,j entry of A * B""" def __init__(self, A, B, i): super(MatrixMult, self).__init__() self.A = A self.B = B self.i = i #self.j = j def run(self): print "Computing %i, %i" % (self.i, self.i) x = 0 result=[] for k in range(self.A.shape[0]): x += self.A[self.i,k] * self.B[k,self.j] self.result=x print "Completed %i, %i" % (self.i, self.j) def mult(n): """A function to randomly create two n x n matrices and multiply them""" # Create two random matrices A = numpy.zeros((n,n)) B = numpy.zeros((n,n)) for i in range(n): for j in range(n): A[i,j] = random.randrange(0, 100) B[i,j] = random.randrange(0, 100) # Create and start the threads threads = [] for i in range(n): for j in range(n): t = MatrixMult(A, B, i) threads.append(t) t.start() for t in threads: t.join() C = numpy.zeros((n,n)) for t in threads: C[t.i,t.j] = t.result return C

Looking for something else?

Not the answer you are looking for? Search for more explanations.