title: multithreading optimization in python
body: <p>I am using <code>lmfit</code> to do some optimization and it is tediously slow. I have a large image and I am basically running least square minimization at every pixel. It seems to me that perhaps it is ideal for multithreading or other types of optimizations as it is painfully slow at the moment.</p>
  
  <p>So, my optimization code is as follows:</p>
  
  <p>I define the objective function as:</p>
  
  <pre><code>def objective(params, x, data):
      s0 = params['S0']
      t1 = params['T1']
      m = s0 * (1.0 - np.exp(-x / t1))
      return m - data
  </code></pre>
  
  <p>So, I am trying to minimise the difference between the model and observation. I think <strong>lmfit</strong> ensures that the absolute value is minimized but I am not sure and needs to check.</p>
  
  <p>The main loop is as follows:</p>
  
  <p>The parameters I need to estimate are as initialized as follows with some initial values:</p>
  
  <pre><code>p = Parameters()
  p.add('S0', value=1.0)
  p.add('T1', value=3.0)
  
  final_data = &lt;numpy image&gt;
  tis = np.asarray([1.0, 2.0, 3.0])
  
  for i in range(final_data.shape[0]):
      print "Processing pixel: ", i
      minner = Minimizer(objective, params=p, fcn_args=np.asarray(tis),
                         final_data[i, :]),
                         nan_policy='propagate')
      result = minner.minimize(method='least_squares')
      s0_data[i] = result.params['S0']
      t1_data[i] = result.params['T1']
  </code></pre>
  
  <p>This works fine but it is tediously slow. I was trying to figure out how to do multithreading in python and got thoroughly confused about posts regarding GIL locking and that multithreading in python does not really exist.</p>
  
  <p>My question is:
  1: Can this be scaled with multithreading in python easily?
  2: Is there any other optimizations that I can try?</p>