import numpy as np from ipyparallel import Client # IPython.parallel before IPython 4.0 rc = Client() rc.ids %px import os, time %px print(os.getpid()) %%px --targets :-1 print(os.getpid()) view = rc[:-1] view v = rc.load_balanced_view() def sample(n): import numpy as np # Random coordinates. x, y = np.random.rand(2, n) # Square distances to the origin. r_square = x ** 2 + y ** 2 # Number of points in the quarter disc. return (r_square <= 1).sum() def pi(n_in, n): return 4. * float(n_in) / n n = 100000000 pi(sample(n), n) %timeit pi(sample(n), n) args = [n // 100] * 100 ar = v.map(sample, args) ar.ready(), ar.progress ar.elapsed, ar.serial_time pi(np.sum(ar.result()), n)