In this recipe, we will show how to interact with asynchronous tasks running in parallel with IPython.
You need to start the IPython engines (see the previous recipe). The simplest option is to launch them from the Clusters tab in the notebook dashboard. In this recipe, we use four engines.
Let's import a few modules:
In [1]: import time import sys from IPython import parallel from IPython.display import clear_output, display from IPython.html import widgets
We create a
Client
:In [2]: rc = parallel.Client()
Now, we create a load-balanced view on the IPython engines:
In [3]: view = rc.load_balanced_view()
We define a simple function for our parallel tasks:
In [4]: def f(x): import time time.sleep(.1) return x*x
We will run this function on 100 integer numbers in parallel:
In [5]: numbers = list(range(100))