Instructor Notes

Testing this lesson


A lot of the code in this lesson can be tested using Entangled. You may tangle source files by running

entangled tangle -a

A set of source files will appear in <project-root>/src, including a Poetry environment for running the tests and benchmarks. You may also run entangled daemon if you want to debug the code, changes made to the files in src will then be merged back into the lesson material automatically.

TOML

[tool.poetry]
name = "parallel-python"
version = "0.1.0"
description = "Testing environment for Parallel Python workshop"
authors = ["Johan Hidding <j.hidding@esciencecenter.nl>"]
license = "Apache-2.0"

[tool.poetry.dependencies]
python = ">=3.9, <3.11"
numba = "^0.56.4"
dask = {extras = ["complete"], version = "^2022.12.1"}
richbench = "^1.0.3"
matplotlib = "^3.6.2"
numba-progress = "^0.0.4"
pandas = "^1.5.2"
plotnine = "^0.10.1"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

MAKEFILE

.RECIPEPREFIX = >

.PHONY: bench

bench: mandelbrot-timings.svg

mandelbrot-timings.svg:
> poetry run python -m mandelbrot.bench_all

introductionCommon problemsOverview and rationaleWhy Python?What is parallel computing?


BenchmarkingA first example with DaskMemory profilingUsing many cores


Computing $\pi$Parallelizing a Python applicationUsing Numba to accelerate Python code


Threads and processesThreadingMultiprocessing


Delayed evaluationDask Delayed


Map and reduce


Exercise with FractalsThe Mandelbrot and Julia fractals


AsyncioIntroduction to AsyncioA first programWorking with asyncio outside Jupyter


Instructor Note

This section goes rather in depth on coroutines. This is meant to grow the correct mental model about what’s going on with asyncio.



Instructor Note

It may be best to let participants copy paste this snippet from the collaborative document. You may want to explain what a context manager is, but don’t overdo it. This is advanced code and may scare off novices.



Calling external C and C++ libraries from PythonCalling C and C++ librariesCall the C library from multiple threads simultaneously.