In [1]:
import os
In a terminal you can type:
ipcluster start --profile=default --n=4
You can also use the IPython web client.
In [2]:
from IPython.parallel import Client
c = Client(profile='default')
c
Out[2]:
In [3]:
direct = c[:]
balanced = c.load_balanced_view()
In [4]:
direct.targets
Out[4]:
In [5]:
parallel_result = direct.apply_sync(os.getpid)
parallel_result
Out[5]:
In [6]:
parallel_result = direct.apply(os.getpid)
parallel_result
Out[6]:
AsyncResult: A class for representing results of non-blocking calls.
In [7]:
parallel_result.ready()
Out[7]:
In [8]:
parallel_result.result
Out[8]:
In [9]:
serial_result = list(map(lambda x:x**10, range(4)))
serial_result
Out[9]:
In [10]:
parallel_result = list(direct.map(lambda x:x**10, range(4)))
parallel_result
Out[10]:
In [11]:
parallel_result = direct.map_async(lambda x:x**10, range(4))
parallel_result
Out[11]:
AsyncMapResult: A class for representing results of non-blocking gathers.
In [12]:
parallel_result.ready()
Out[12]:
In [13]:
parallel_result.result
Out[13]:
In [16]:
def power(a, power=10):
return a**power
In [17]:
[power(x) for x in range(4)]
Out[17]:
In [19]:
@balanced.remote()
def power(a, power=10):
return a**power
In [20]:
[power(x) for x in range(4)]
Out[20]:
In [21]:
[power(x).result for x in range(4)]
Out[21]:
In [ ]: