In [1]:
from IPython.parallel import Client
rc=Client()
view = rc[:]
print rc.ids
Use the %px magic to import methods on the nodes
In [2]:
%px from pylab import arccos, rand
from numpy import array
Next, use the %%px magic to define a function on the nodes
In [3]:
%%px
def f(N):
y=arccos(1.0-2*rand(N))
return 2.0*y.sum()/N
In [4]:
x = view.map(lambda N: f(N), 10*[1000000]).result
x
Out[4]:
In [5]:
array(x).sum()/len(x)
Out[5]:
In [ ]: