In [22]:
import os
In a terminal you can type:
ipcluster start --profile=default --n=4
You can also use the IPython web client.
In [23]:
from IPython.parallel import Client
c = Client(profile='default')
c
Out[23]:
In [24]:
direct = c[:]
balanced = c.load_balanced_view()
In [25]:
direct.targets
Out[25]:
In [26]:
parallel_result = direct.apply_sync(os.getpid)
parallel_result
Out[26]:
In [27]:
parallel_result = direct.apply(os.getpid)
parallel_result
Out[27]:
AsyncResult: A class for representing results of non-blocking calls.
In [28]:
parallel_result.ready()
Out[28]:
In [29]:
parallel_result.result
Out[29]:
In [30]:
serial_result = list(map(lambda x:x**10, range(4)))
serial_result
Out[30]:
In [31]:
parallel_result = list(direct.map(lambda x:x**10, range(4)))
parallel_result
Out[31]:
In [32]:
parallel_result = direct.map_async(lambda x:x**10, range(4))
parallel_result
Out[32]:
AsyncMapResult: A class for representing results of non-blocking gathers.
In [33]:
parallel_result.ready()
Out[33]:
In [34]:
parallel_result.result
Out[34]:
In [35]:
def power(a, power=10):
return a**power
In [36]:
[power(x) for x in range(4)]
Out[36]:
In [37]:
@balanced.remote()
def power(a, power=10):
return a**power
In [38]:
[power(x) for x in range(4)]
Out[38]:
In [39]:
[power(x).result for x in range(4)]
Out[39]:
In [39]: