|
23 | 23 | "cell_type": "markdown", |
24 | 24 | "metadata": {}, |
25 | 25 | "source": [ |
26 | | - "First, let's start Ray…" |
| 26 | + "First, let's start Ray… \n", |
| 27 | + "\n", |
| 28 | + "This will start Ray on the local host, with headnode and workers for each core or CPU available.\n", |
| 29 | + "You can check the resources being used." |
27 | 30 | ] |
28 | 31 | }, |
29 | 32 | { |
|
38 | 41 | "ray.init(\n", |
39 | 42 | " ignore_reinit_error=True, # Don't print error messages if a Ray instance is already running. Attach to it\n", |
40 | 43 | " logging_level=logging.ERROR, \n", |
41 | | - ")" |
| 44 | + ")\n", |
| 45 | + "ray.cluster_resources() # get the cluster resources" |
| 46 | + ] |
| 47 | + }, |
| 48 | + { |
| 49 | + "cell_type": "markdown", |
| 50 | + "metadata": {}, |
| 51 | + "source": [ |
| 52 | + "Ray Dashboard accessible at URI: [http://127.0.0.1:8265](http://127.0.0.1:8265)" |
42 | 53 | ] |
43 | 54 | }, |
44 | 55 | { |
|
129 | 140 | "cell_type": "markdown", |
130 | 141 | "metadata": {}, |
131 | 142 | "source": [ |
132 | | - "The result can be retrieved with `ray.get`" |
| 143 | + "The result can be retrieved with `ray.get`, which is a blocking call if the task is still not finished" |
133 | 144 | ] |
134 | 145 | }, |
135 | 146 | { |
|
147 | 158 | "cell_type": "markdown", |
148 | 159 | "metadata": {}, |
149 | 160 | "source": [ |
150 | | - "Invocations of Ray *remote functions* happen in parallel, and all computation gets performed in the background, driven by Ray's internal event loop.\n", |
| 161 | + "Invocations of Ray *remote functions* happen in parallel, and all computation gets performed in the background, driven by Ray's internal event loop. Remote calls return immediately, with a Python Future Object reference.\n", |
151 | 162 | "\n", |
152 | 163 | "To illustrate this, first let's define a relatively \"slow\" function, by adding a 10 second delay..." |
153 | 164 | ] |
|
187 | 198 | "for i in range(4):\n", |
188 | 199 | " future = slow_function.remote()\n", |
189 | 200 | " futures_list.append(future)\n", |
190 | | - " print(i)\n", |
191 | 201 | "print(futures_list)" |
192 | 202 | ] |
193 | 203 | }, |
|
210 | 220 | "Note the difference between CPU times and wall clock?" |
211 | 221 | ] |
212 | 222 | }, |
| 223 | + { |
| 224 | + "cell_type": "markdown", |
| 225 | + "metadata": {}, |
| 226 | + "source": [ |
| 227 | + "## Another way to do this is using list comprehension" |
| 228 | + ] |
| 229 | + }, |
| 230 | + { |
| 231 | + "cell_type": "code", |
| 232 | + "execution_count": null, |
| 233 | + "metadata": {}, |
| 234 | + "outputs": [], |
| 235 | + "source": [ |
| 236 | + "%%time\n", |
| 237 | + "\n", |
| 238 | + "futures_list = [slow_function.remote() for _ in range(4)]\n", |
| 239 | + "futures_list" |
| 240 | + ] |
| 241 | + }, |
| 242 | + { |
| 243 | + "cell_type": "code", |
| 244 | + "execution_count": null, |
| 245 | + "metadata": {}, |
| 246 | + "outputs": [], |
| 247 | + "source": [ |
| 248 | + "%%time\n", |
| 249 | + "\n", |
| 250 | + "values_list = [ray.get(future) for future in futures_list]\n", |
| 251 | + "values_list" |
| 252 | + ] |
| 253 | + }, |
| 254 | + { |
| 255 | + "cell_type": "markdown", |
| 256 | + "metadata": {}, |
| 257 | + "source": [ |
| 258 | + "Note the difference between CPU times and wall clock in comprehensions? \n", |
| 259 | + "Comprehensions seems faster." |
| 260 | + ] |
| 261 | + }, |
213 | 262 | { |
214 | 263 | "cell_type": "markdown", |
215 | 264 | "metadata": {}, |
|
240 | 289 | "source": [ |
241 | 290 | "[*Patterns for Parallel Programming*](https://www.goodreads.com/book/show/85053.Patterns_for_Parallel_Programming) \n", |
242 | 291 | "Timothy G. Mattson, Beverly A. Sanders, Berna L. Massingill \n", |
243 | | - "Addison-Wesley (2004)" |
| 292 | + "Addison-Wesley (2004)\n", |
| 293 | + "\n", |
| 294 | + "[Ray Core Walkthrough](https://docs.ray.io/en/latest/walkthrough.html)\n", |
| 295 | + "Ray Documentation and Gettting started materials" |
244 | 296 | ] |
245 | 297 | } |
246 | 298 | ], |
247 | 299 | "metadata": { |
248 | 300 | "kernelspec": { |
249 | | - "display_name": "Python 3", |
| 301 | + "display_name": "Python 3 (ipykernel)", |
250 | 302 | "language": "python", |
251 | 303 | "name": "python3" |
252 | 304 | }, |
|
260 | 312 | "name": "python", |
261 | 313 | "nbconvert_exporter": "python", |
262 | 314 | "pygments_lexer": "ipython3", |
263 | | - "version": "3.8.8" |
| 315 | + "version": "3.7.11" |
264 | 316 | } |
265 | 317 | }, |
266 | 318 | "nbformat": 4, |
|
0 commit comments