Amdahl's law¶

In this notebook, we illustrate Amdahl's law, which provides a hard upper limit on the speedup of a code based on the serial content.

P = Fraction of code that can be parallelized
S = Fraction of code that must be run sequentially (S = 1 - P)
N = Number of processors

$speedup(N) = \frac{1}{(1-P) + P/N}$

In [3]:
%matplotlib inline
import matplotlib as mpl
mpl.get_backend()

import matplotlib.pyplot as plt
import numpy as np

Amdahl's law - 50-95% parallel content¶

In [5]:
cores = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]
speedup_50 = [1/((1-0.50) + 0.50/x) for x in cores]
speedup_75 = [1/((1-0.75) + 0.75/x) for x in cores]
speedup_90 = [1/((1-0.90) + 0.90/x) for x in cores]
speedup_95 = [1/((1-0.95) + 0.95/x) for x in cores]
speedup_99 = [1/((1-0.99) + 0.99/x) for x in cores]
In [7]:
f, ax = plt.subplots()
ax.set_xlabel('Cores', fontsize=14)
ax.set_ylabel('speedup', fontsize=14)
ax.set_title('Amdahl\'s Law', fontsize=16)
ax.set_xscale('log')
ax.plot(cores, speedup_95, 'y-', label='P=95%')
ax.plot(cores, speedup_90, 'b-', label='P=90%')
ax.plot(cores, speedup_75, 'g-', label='P=75%')
ax.plot(cores, speedup_50, 'r-', label='P=50%')
ax.legend(loc='upper left', frameon=False)

plt.savefig("amdahl1.png", dpi=300)
plt.show()
No description has been provided for this image

Amdahl's law - 50-99% parallel content¶

In [9]:
f, ax = plt.subplots()
ax.set_xlabel('Cores', fontsize=14)
ax.set_ylabel('speedup', fontsize=14)
ax.set_title('Amdahl\'s Law', fontsize=16)
ax.set_xscale('log')
ax.plot(cores, speedup_99, 'c-', label='P=99%')
ax.plot(cores, speedup_95, 'y-', label='P=95%')
ax.plot(cores, speedup_90, 'b-', label='P=90%')
ax.plot(cores, speedup_75, 'g-', label='P=75%')
ax.plot(cores, speedup_50, 'r-', label='P=50%')
ax.legend(loc='upper left', frameon=False)

plt.savefig("amdahl2.png", dpi=300)
plt.show()
No description has been provided for this image
In [ ]: