Concurrency · 7 / 15 Exercise Easy

Amdahl's law

Objective

Adding processors does not speed up a program indefinitely: the part that cannot be parallelized limits the improvement. Amdahl's law says that, if a fraction p of the work is parallelizable, with n processors the speedup is 1 / ((1 - p) + p / n).

Instructions

  • Read p (decimal between 0 and 1, not including 1) and an integer q. Then read q values of n (number of processors).
  • First show Limit: x: the maximum possible speedup, 1 / (1 - p), with 2 decimals.
  • For each n show n processors: a (efficiency e%). The efficiency is the speedup divided by n, as a percentage with 1 decimal.
Input
0.9
3
1
4
100
Output
Limit: 10.00
1 processors: 1.00 (efficiency 100.0%)
4 processors: 3.08 (efficiency 76.9%)
100 processors: 9.17 (efficiency 9.2%)

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise