title: How to parallel sum a loop using multiprocessing in Python
body: <p>I am having difficulty understanding how to use Python's multiprocessing module.</p>
  
  <p>I have a sum from <code>1</code> to <code>n</code> where <code>n=10^10</code>, which is too large to fit into a list, which seems to be the thrust of many examples online using multiprocessing.</p>
  
  <p>Is there a way to "split up" the range into segments of a certain size and then perform the sum for each segment?</p>
  
  <p>For instance</p>
  
  <pre><code>def sum_nums(low,high):
      result = 0
      for i in range(low,high+1):
          result += i
      return result
  </code></pre>
  
  <p>And I want to compute <code>sum_nums(1,10**10)</code> by breaking it up into many <code>sum_nums(1,1000) + sum_nums(1001,2000) + sum_nums(2001,3000)...</code> and so on. I know there is a close-form <code>n(n+1)/2</code> but pretend we don't know that.</p>
  
  <p>Here is what I've tried</p>
  
  <pre><code>import multiprocessing
  
  def sum_nums(low,high):
      result = 0
      for i in range(low,high+1):
          result += i
      return result
  
  if __name__ == "__main__":
      n = 1000 
      procs = 2 
  
      sizeSegment = n/procs
  
      jobs = []
      for i in range(0, procs):
          process = multiprocessing.Process(target=sum_nums, args=(i*sizeSegment+1, (i+1)*sizeSegment))
          jobs.append(process)
  
      for j in jobs:
          j.start()
      for j in jobs:
          j.join()
  
      #where is the result?
  </code></pre>