title: Perform a for-loop in parallel in Python 3.2
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/9786102/how-do-i-parallelize-a-simple-python-loop">how do I parallelize a simple python loop?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm quite new to Python (using Python 3.2) and I have a question concerning parallelisation. I have a for-loop that I wish to execute in parallel using "multiprocessing" in Python 3.2:</p>
  
  <pre><code>def computation:    
      global output
  
      for x in range(i,j):
          localResult = ... #perform some computation as a function of i and j
          output.append(localResult)
  </code></pre>
  
  <p>In total, I want to perform this computation for a range of i=0 to j=100. Thus I want to create a number of processes that each call the function "computation" with a subdomain of the total range. Any ideas of how do to this? Is there a better way than using multiprocessing?</p>
  
  <p>More specific, I want to perform a domain decomposition and I have the following code:</p>
  
  <pre><code>from multiprocessing import Pool
  
  class testModule:
  
      def __init__(self):
          self
  
      def computation(self, args):
          start, end = args
          print('start: ', start, ' end: ', end)
  
  testMod = testModule()
  length = 100
  np=4
  p = Pool(processes=np)
  p.map(yes tMod.computation, [(length, startPosition, length//np) for startPosition in    range(0, length, length//np)]) 
  </code></pre>
  
  <p>I get an error message mentioning PicklingError. Any ideas what could be the problem here?</p>