Show More
@@ -175,13 +175,16 b' everything is working correctly, try the following commands:' | |||||
175 | Out[5]: {0: 'Hello, World', 1: 'Hello, World', 2: 'Hello, World', 3: |
|
175 | Out[5]: {0: 'Hello, World', 1: 'Hello, World', 2: 'Hello, World', 3: | |
176 | 'Hello, World'} |
|
176 | 'Hello, World'} | |
177 |
|
177 | |||
178 | Remember, a client needs to be able to see the Controller. So if the controller is on a different machine, and you have ssh access to that machine, then you would connect to it with:: |
|
178 | Remember, a client needs to be able to see the Controller. So if the | |
|
179 | controller is on a different machine, and you have ssh access to that machine, | |||
|
180 | then you would connect to it with:: | |||
179 |
|
181 | |||
180 | .. sourcecode:: ipython |
|
182 | .. sourcecode:: ipython | |
181 |
|
183 | |||
182 | In [2]: c = client.Client(sshserver='mycontroller.example.com') |
|
184 | In [2]: c = client.Client(sshserver='mycontroller.example.com') | |
183 |
|
185 | |||
184 |
Where 'mycontroller.example.com' is the url or IP address of the machine on |
|
186 | Where 'mycontroller.example.com' is the url or IP address of the machine on | |
|
187 | which the Controller is running. | |||
185 |
|
188 | |||
186 | You are now ready to learn more about the :ref:`MUX |
|
189 | You are now ready to learn more about the :ref:`MUX | |
187 | <parallelmultiengine>` and :ref:`Task <paralleltask>` interfaces to the |
|
190 | <parallelmultiengine>` and :ref:`Task <paralleltask>` interfaces to the |
@@ -71,7 +71,8 b' Parallel map' | |||||
71 |
|
71 | |||
72 | Python's builtin :func:`map` functions allows a function to be applied to a |
|
72 | Python's builtin :func:`map` functions allows a function to be applied to a | |
73 | sequence element-by-element. This type of code is typically trivial to |
|
73 | sequence element-by-element. This type of code is typically trivial to | |
74 |
parallelize. In fact, since IPython's interface is all about functions anyway, |
|
74 | parallelize. In fact, since IPython's interface is all about functions anyway, | |
|
75 | you can just use the builtin :func:`map`, or a client's :map: method: | |||
75 |
|
76 | |||
76 | .. sourcecode:: ipython |
|
77 | .. sourcecode:: ipython | |
77 |
|
78 | |||
@@ -124,6 +125,48 b' done in blocking or non-blocking mode (non-blocking is default) using the' | |||||
124 | :meth:`execute` method, and calling functions can be done via the |
|
125 | :meth:`execute` method, and calling functions can be done via the | |
125 | :meth:`.View.apply` method. |
|
126 | :meth:`.View.apply` method. | |
126 |
|
127 | |||
|
128 | apply | |||
|
129 | ----- | |||
|
130 | ||||
|
131 | The main method for doing remote execution (in fact, all methods that | |||
|
132 | communicate with the engines are built on top of it), is :meth:`Client.apply`. | |||
|
133 | Ideally, :meth:`apply` would have the signature :meth:`apply(f,*args,**kwargs)`, | |||
|
134 | which would call f(*args,**kwargs) remotely. However, since :class:`Clients` | |||
|
135 | require some more options, they cannot reasonably provide this interface. | |||
|
136 | Instead, they provide the signature:: | |||
|
137 | ||||
|
138 | c.apply(f, args=None, kwargs=None, bound=True, block=None, | |||
|
139 | targets=None, after=None, follow=None) | |||
|
140 | ||||
|
141 | In order to provide the nicer interface, we have :class:`View` classes, which wrap | |||
|
142 | :meth:`Client.apply` by using attributes and extra :meth:`apply_x` methods to determine | |||
|
143 | the extra arguments. For instance, performing index-access on a client creates a | |||
|
144 | :class:`.LoadBalancedView`. | |||
|
145 | ||||
|
146 | .. sourcecode:: ipython | |||
|
147 | ||||
|
148 | In [4]: view = rc[1:3] | |||
|
149 | Out[4]: <DirectView [1, 2]> | |||
|
150 | ||||
|
151 | In [5]: view.apply<tab> | |||
|
152 | view.apply view.apply_async view.apply_async_bound view.apply_bound view.apply_sync view.apply_sync_bound | |||
|
153 | ||||
|
154 | A :class:`DirectView` always uses its `targets` attribute, and it will use its `bound` | |||
|
155 | and `block` attributes in its :meth:`apply` method, but the suffixed :meth:`apply_x` | |||
|
156 | methods allow specifying `bound` and `block` via the different methods. | |||
|
157 | ||||
|
158 | ================== ========== ========== | |||
|
159 | method block bound | |||
|
160 | ================== ========== ========== | |||
|
161 | apply self.block self.bound | |||
|
162 | apply_sync True False | |||
|
163 | apply_async False False | |||
|
164 | apply_sync_bound True True | |||
|
165 | apply_async_bound False True | |||
|
166 | ================== ========== ========== | |||
|
167 | ||||
|
168 | For explanation of these values, read on. | |||
|
169 | ||||
127 | Blocking execution |
|
170 | Blocking execution | |
128 | ------------------ |
|
171 | ------------------ | |
129 |
|
172 | |||
@@ -154,7 +197,7 b' by index-access to the client:' | |||||
154 |
|
197 | |||
155 | In [7]: rc.execute('c=a-b',targets=[1,3]) |
|
198 | In [7]: rc.execute('c=a-b',targets=[1,3]) | |
156 |
|
199 | |||
157 | In [8]: rc[:]['c'] |
|
200 | In [8]: rc[:]['c'] # shorthand for rc.pull('c',targets='all') | |
158 | Out[8]: {0: 15, 1: -5, 2: 15, 3: -5} |
|
201 | Out[8]: {0: 15, 1: -5, 2: 15, 3: -5} | |
159 |
|
202 | |||
160 | .. note:: |
|
203 | .. note:: |
General Comments 0
You need to be logged in to leave comments.
Login now