How to write to a shared variable in python joblib : <p>The following code parallelizes a for-loop.</p>

<pre><code>import networkx as nx;
import numpy as np;
from joblib import Parallel, delayed;
import multiprocessing;

def core_func(repeat_index, G, numpy_arrary_2D):
  for u in G.nodes():
    numpy_arrary_2D[repeat_index][u] = 2;
  return;

if __name__ == "__main__":
  G = nx.erdos_renyi_graph(100000,0.99);
  nRepeat = 5000;
  numpy_array = np.zeros([nRepeat,G.number_of_nodes()]);
  Parallel(n_jobs=4)(delayed(core_func)(repeat_index, G, numpy_array) for repeat_index in range(nRepeat));
  print(np.mean(numpy_array));
</code></pre>

<p>As can be seen, the expected value to be printed is 2. However, when I run my code on a cluster (multi-core, shared memory), it returns 0.0. </p>

<p>I think the problem is that each worker creates its own copy of the <code>numpy_array</code> object, and the one created in the main function is not updated. How can I modify the code such that the numpy array <code>numpy_array</code> can be updated?</p>
