In [1]:
# Sequential code
from time import sleep
def slowinc(x):
sleep(1) # take a bit of time to simulate real work
return x + 1
In [ ]:
[slowinc(i) for i in range(10)] # this takes 10 seconds
In [ ]:
#from joblib import Parallel, delayed
#Parallel(n_jobs=4)(delayed(slowinc)(i) for i in range(10)) # this takes 3 seconds
In [2]:
from dask.distributed import Client
#client = Client() # set up local cluster on your laptop
client = Client('104.155.153.59:8786')
client
Out[2]:
In [ ]:
client.get_versions(check=True)
In [ ]:
In [5]:
import distributed.joblib
from joblib import Parallel, delayed
from joblib import parallel_backend
with parallel_backend('dask.distributed', scheduler_host='104.155.153.59:8786'):
print(Parallel()(delayed(slowinc)(i) for i in list(range(25))))