title: How to use multiprocessing for grid search (parameter optimization) in Python
body: <p>I'm trying to figure out how I can speed up a grid search for a function that takes 2 input (a lower threshold value and an upper threshold value) in Python by using multiprocessing. I checked <a href="http://pymotw.com/2/multiprocessing/basics.html" rel="nofollow">http://pymotw.com/2/multiprocessing/basics.html</a> and tried using the following:</p>
  
  <pre><code>import multiprocessing
  
  lower_threshold = range(0,100)
  upper_threshold = range(100,200)
  
  def worker():
      bestAccuracy = 0
      bestLowerThreshold = 0
      bestUpperThreshold = 0    
      for lowerThreshold in lower_threshold:
          for upperThreshold in upper_threshold:
              accuracy = someOtherFunction(lower_threshold,upper_threshold)
              if accuracy &gt; bestAccuracy:
                  bestAccuracy = accuracy
                  bestLowerTheshold = lowerThreshold
                  bestUpperThreshold = upperThreshold
      return bestAccuracy, bestLowerThreshold, bestUpperThreshold
  
  if __name__ == '__main__':
      jobs = []
      for i in range(8):
          p = multiprocessing.Process(target=worker)
          jobs.append(p)
          p.start()
  </code></pre>
  
  <p>When I run this code, then I end up having my 8 core processes that run the same parameters/input for my function. Is there some way that I can specify that the the cores processes should use different parameters? In advance, thanks for your help. </p>