Parallel iterators and streams¶
Category: Parallelism · Status: stub · Lessons: chapter 07, Parallelism
One line: A library that spreads an iterator's work over a thread pool with one method call — Rayon's par_iter, Java's parallelStream.
Also called: rayon, parallel streams, PLINQ.
How it connects¶
flowchart LR
n_data_parallelism["Data parallelism"]
n_parallel_iterators["Parallel iterators and streams"]
n_thread_pool["Thread pool and executor"]
n_work_stealing["Work stealing"]
n_parallel_iterators -->|is a| n_data_parallelism
n_parallel_iterators -->|uses| n_thread_pool
n_parallel_iterators -->|uses| n_work_stealing
classDef center stroke-width:3px
class n_parallel_iterators center
classDef outside stroke-dasharray: 4 3
class n_data_parallelism,n_thread_pool,n_work_stealing outside
- Is a kind of: Data parallelism
- Is built on: Thread pool and executor, Work stealing
In each language¶
| Rust | Rayon's par_iter ↗ gives parallel versions of iterator methods such as map, filter and fold |
| C++ | Standard algorithms take an execution policy ↗ rather than a parallel iterator |
| Java | Collection.parallelStream ↗, or parallel() on a stream |
| Python | Executor.map ↗ on a thread or process pool |
| C# | PLINQ ↗: AsParallel() on a LINQ query |
| Erlang and Elixir | Task.async_stream ↗ runs a function on each element in its own task, by default as many at once as there are schedulers online |
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: Concurrency in .NET, Riccardo Terrell — ch. 5, 'PLINQ and MapReduce: data parallelism, part 2'
- In the books: Parallel Loops in Python, Jason Brownlee — ch. 2, 'Parallel Loop with the Thread Class'
- In the books: Concurrency in C# Cookbook, Stephen Cleary — ch. 4, 'Parallel Basics' → 'Parallel LINQ'
- In the books: Parallel Programming and Concurrency with C# 10 and .NET 6, Alvin Ashcraft — ch. 6, 'Parallel Programming Concepts' → 'Parallel loops in .NET'
- In the books: Modern Java in Action, Raoul-Gabriel Urma, Mario Fusco, Alan Mycroft — ch. 7, 'Parallel data processing and performance'
- In the books: C# 10 in a Nutshell, Joseph Albahari — ch. 22, 'Parallel Programming' → 'PLINQ'