Skip to main content

Module 2: Parallel and Distributed Computing

Overview

Big data frameworks such as Apache Spark are built on functional programming, because pure functions on immutable data are easy to run in parallel. This module covers the functional programming you need in Python (first-class functions, lambda, and higher-order functions such as map, filter and reduce), then speeds up real programs on a single machine by optimising pandas and using the built-in multiprocessing library.

Estimated time: about 3 hours (1 hour lecture, 2 hours hands-on)

Learning objectives

By the end of this module, you should be able to:

  • Explain what functional programming is, and why pure functions and immutable data make code easy to parallelise.
  • Use Python functions as first-class objects: assign them to variables, pass them as arguments and return them from other functions.
  • Write anonymous functions with lambda, and use map, filter and reduce to transform and aggregate data.
  • Load large files efficiently with pandas by reading selected columns, a subset of rows, or chunks.
  • Speed up CPU-bound and I/O-bound tasks with multiprocessing, choose a sensible number of processes for your machine, and measure the speed-up.

Before class

Prerequisites: Module 0 or equivalent Python (functions, lists, dictionaries, basic pandas), and the concepts from Module 1, especially CPU-bound vs I/O-bound programs.

Install the course environment by following the Python environment setup.

Lecture slides

Open the slides (Google Slides) Version française

Hands-on

Functional Programming

Functions as first-class citizens, anonymous functions, and map, filter and reduce.

View Open in Colab Download

Parallel Processing in Python

Reading large files in chunks, and parallelising work with multiprocessing.

View Open in Colab Download

Scripts (run from a terminal):

Exercises

To be added.

Further reading