import os,sys,time import numpy as np from IPython.core.display import display from IPython import parallel rc = parallel.Client() e0 = rc[0] engines = rc[:] even = rc[::2] odd = rc[1::2] # this is the one we are going to use: dview = engines dview.block = True for view in (e0, engines, even, odd): print view, view.apply_sync(os.getpid) engines['a'] = 5 engines['a'] dview.scatter('a',range(16)) dview['a'] dview.gather('a') dview.execute("asum = sum(a)") dview.gather('asum') dview.scatter('id',rc.ids) dview['id'] dview.scatter('id',rc.ids, flatten=True) dview['id'] A = np.random.randint(1,10,(16,4)) B = np.random.randint(1,10,(4,16)) display(A) display(B) dview.scatter('A', A) dview.scatter('B', B) display(e0['A']) display(e0['B']) %run ../hints mmhint() %load soln/matmul.py C_ref = A.dot(B) C1 = pdot(dview, A, B) # validation: (C1==C_ref).all() dview.block = True serial_result = map(lambda x:x**10, range(32)) parallel_result = dview.map(lambda x:x**10, range(32)) serial_result==parallel_result amr = dview.map_async(lambda x:x**10, range(32)) amr.msg_ids amr = dview.map_async(lambda x:x**10, range(3200)) amr.msg_ids from IPython.display import display, Image %run ../images_common pictures = get_pictures(os.path.join('..', 'images', 'castle')) %px cd {os.getcwd()} %%px import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from skimage.io import imread from skimage import measure engines.push(dict( plot_contours=plot_contours, find_contours=find_contours, )) ar = e0.apply_async(get_contours_image, pictures[0]) ar.wait_interactive() Image(data=ar.get()) amr = engines.map_async(get_contours_image, pictures[:len(engines)]) amr.wait_interactive() for pngdata in amr: display(Image(data=pngdata))