title: python multiprocessing and joblib argument passing
body: <p>I have some confusions about Python multiprocessing, when it involves global numpy array.</p>
  
  <p>Consider the follow toy example, the argument passed is an integer that indicates the row to be summed. My questions are: </p>
  
  <ol>
  <li><p>Does each processor/worker has a copy of x? </p></li>
  <li><p>How does the performance change if I pass the actual row, for example, <code>pool.apply_async(sum, (x[i],))</code> and change the function sum() accordingly. My understanding is that the argument passed is a view of the numpy array, so it shouldn't affect anything in non-parallel program. But what about multiprocessing programs.</p></li>
  <li><p>If I rewrite the program with joblib package, <code>results = joblib.Parallel(n_jobs=-1, max_nbytes=1e6)(joblib.delayed(sum)(i) for i in xrange(len(x)))</code> does each processor/worker has its own copy of x? if it does, since x is read-only, what is the easiest way to share across the workers?</p></li>
  </ol>
  
  <p>the code:</p>
  
  <pre><code>import numpy as np
  from multiprocessing import Pool, cpu_count
  
  def sum(idx):
      """
      sum the idx row of global numpy array x
      :idx: indicate which row
      :returns: float sum 
      """
      return np.sum(x[idx])
  
  x = np.random.random((10, 100))
  pool = Pool(cpu_count())
  result = {} 
  for i in xrange(len(x)): 
      result[i] = pool.apply_async(sum, (i,))
  
  for k, v in result.iteritems():
      print k, v.get()
  </code></pre>
  
  <p>thank you </p>