Parallelism¶
Category: Foundations · Status: stub · Lessons: chapter 07, Parallelism
One line: Running several computations at the same instant on separate processing units so the whole finishes sooner; it needs more than one core, and concurrency does not.
Also called: parallel computing, parallel execution.
How it connects¶
flowchart LR
n_asynchrony["Asynchrony"]
n_concurrency["Concurrency"]
n_data_parallelism["Data parallelism"]
n_parallelism["Parallelism"]
n_task_parallelism["Task parallelism"]
n_asynchrony ---|vs| n_parallelism
n_concurrency ---|vs| n_parallelism
n_data_parallelism -->|is a| n_parallelism
n_task_parallelism -->|is a| n_parallelism
classDef center stroke-width:3px
class n_parallelism center
classDef outside stroke-dasharray: 4 3
class n_asynchrony,n_concurrency,n_data_parallelism,n_task_parallelism outside
- Kinds: Data parallelism, Task parallelism
- Often confused with: Asynchrony, Concurrency
- See also: I/O-bound and CPU-bound work, Speedup and Amdahl's law
In each language¶
| Rust | std::thread::scope ↗ runs threads that borrow local data; parallel iterators come from the Rayon ↗ crate, not the standard library |
| Go | Goroutines run in parallel on as many CPUs as runtime.GOMAXPROCS ↗ allows |
| C++ | Execution policies ↗ (C++17) let standard algorithms such as std::sort and std::reduce run in parallel |
| Java | Parallel streams ↗, and ForkJoinPool ↗ for tasks that spawn subtasks |
| Python | Threads do not run Python code in parallel under the GIL ↗; use multiprocessing ↗ or the free-threaded build |
| C# | Parallel programming in .NET ↗: the Task Parallel Library and PLINQ |
| JavaScript | Each worker ↗ runs in a background thread; memory is shared between them with a SharedArrayBuffer ↗ |
| Erlang and Elixir | The VM starts one scheduler thread ↗ per logical processor by default, so processes run in parallel without any change to the code |
| Haskell | par and pseq ↗ in the parallel package mark pure expressions that may be worth evaluating in parallel |
Where to read more¶
- In the books: Hands-On Concurrency with Rust, Brian L. Troutwine — ch. 8, 'High-Level Parallelism – Threadpools, Parallel Iterators and Processes'
- In the books: Parallel Programming with Intel Parallel Studio XE, Stephen Blair-Chappell, Andrew Stokes — ch. 1, 'Parallelism Today'
- In the books: Parallel and Concurrent Programming in Haskell, Simon Marlow — ch. 2, 'Basic Parallelism: The Eval Monad'
- In the books: Pro Asynchronous Programming with .NET, Richard Blewett, Andrew Clymer — ch. 11, 'Parallel Programming'
- In the books: Python Parallel Programming Cookbook, Giancarlo Zaccone — ch. 1, 'Getting Started with Parallel Computing and Python'
- In the books: Grokking Concurrency, Kirill Bobrov — ch. 2, 'Serial and parallel execution' → 'Parallel computing requirements'
- Notes: parallelism - general ↗
- Notes: parallelism - rust ↗
- Reference: Wikipedia: Parallel computing ↗