Skip to main content

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​

ElementUse
RecursiveActionTask 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
ForkJoinPoolPool of threads with work stealing

Never join a task before starting the others.

Formulas​

ConceptFormula
Time of the parallel sumTp∈O(np+log⁡p)T_p \in O\left(\frac{n}{p} + \log p\right)
Work and spanTp≈Wp+ST_p \approx \frac{W}{p} + S
SpeedupS(p)=T1TpS(p) = \frac{T_1}{T_p}
EfficiencyE(p)=S(p)pE(p) = \frac{S(p)}{p}
Amdahl's lawS(p)=1(1−f)+f/pS(p) = \frac{1}{(1 - f) + f/p}, limit 11−f\frac{1}{1 - f}

ff is the fraction of the time that can be parallelized.

Saved only in your browser
Was this lesson helpful?
Questions, or something wrong?

Errors, suggestions and public questions open a form on GitHub, visible to everyone.