2

I want to make my coed run in Parallel, which is shown as below,

for j in range(nj):
    for i in range(ni):
        # assign matrix coefficient

This is a very large matrix, which results in very low execution time, how can I run this kind of code in Parallel?

Thanks in advance!

1
  • the multiprocessing module could be useful to you. If you're not married to python check out LAPACK and ScaLAPACK Commented Feb 3, 2015 at 23:57

1 Answer 1

1

You probably looking for multiprocessing module.

import multiprocessing
import random
import time

def f(x,y):
    print multiprocessing.current_process()
    time.sleep(random.random())
    return x*y

p = multiprocessing.Pool(10)
res= []
for i in xrange(1,10):
  for j in xrange(1,10):
    res.append(p.apply_async(f, [i,j]))

for r in res:
  print r.get()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.