I want to run some code in parallel and populate a global variable with the results in Python. I have written an example code to check the behavior of joblib, but I don't know how to get the results back. The example code is:
import numpy as np
import multiprocessing
from joblib import Parallel, delayed
global_var = np.zeros(10)
def populate(idx):
print('I am core',idx,'\')
global_var[idx] = idx
num_cores = multiprocessing.cpu_count()
Parallel(n_jobs=num_cores)(delayed(populate)(idx) for idx in range(len(global_var))`
if I check global_var before running anything else, it is an array of zeros; when I run the code, the array is full of "None" values.
How can I return the values from the function and populate the global array?
Thank you very much in advance! =)