In [1]:
import sys
sys.path.append('..')
In [2]:
import utils
import imp
imp.reload(utils)
Out[2]:
In [3]:
import numpy as np
from joblib import Parallel, delayed
from itertools import product
from time import sleep
In [8]:
def power_it(number, n=2):
# We add a sleep in here to simulate heavy work that
# needs the parallelizing:
sleep(0.1)
return number ** n
In [9]:
my_array = np.arange(100).reshape(10, 10)
In [10]:
in_list = list(my_array.ravel())
In [12]:
results = utils.parfor(power_it, in_list)
In [15]:
results_array = np.array(results).reshape(my_array.shape)
In [18]:
i, j = np.random.randint(0, 9, 2)
assert results_array[i, j] == power_it(my_array[i, j])
In [21]:
%timeit power_it(my_array[i, j])
In [22]:
%timeit utils.parfor(power_it, in_list, n=3, n_jobs=1)
In [23]:
%timeit utils.parfor(power_it, in_list, n=3, n_jobs=2)
In [24]:
%timeit utils.parfor(power_it, in_list, n=3, n_jobs=8)
In [25]:
import multiprocessing
In [26]:
multiprocessing.cpu_count()
Out[26]:
In [ ]: