Summary: Parallel Algorithms
Everything on one page, to review the chapter before moving on.
Key ideas
- Processor frequencies stopped growing; performance now grows by adding cores (Concurrency and Parallelism).
- Concurrency means dealing with several tasks whose executions overlap; parallelism means executing them at the same time on several processors.
- Shared memory needs synchronisation; divide and conquer algorithms on independent parts of the data avoid most of the problems.
- The Fork/Join framework runs divide and conquer in parallel: below a sequential threshold, solve directly; otherwise divide, solve the parts in parallel and combine (The Fork/Join Framework).
- Parallelism does not change the asymptotic complexity, but it can divide the time by up to the number of processors (Performance of Parallel Algorithms).
- Prefer a better algorithm before adding cores.
Fork/Join in Java
| Element | Use |
|---|---|
RecursiveAction | Task that does not return a value |
RecursiveTask<V> | Task that returns a value of type V |
compute() | Where the algorithm is written |
fork() / join() | Launch a subtask / wait for its result |
invokeAll(...) | Run several tasks and wait for all of them |
ForkJoinPool | Pool of threads with work stealing |
Never join a task before starting the others.
Formulas
| Concept | Formula |
|---|---|
| Time of the parallel sum | |
| Work and span | |
| Speedup | |
| Efficiency | |
| Amdahl's law | , limit |
is the fraction of the time that can be parallelized.
Saved only in your browser
Questions, or something wrong?
Errors, suggestions and public questions open a form on GitHub, visible to everyone.