#!/usr/bin/env python # -*- coding: utf-8 -*- # written by Christoph Federrath # define imports from cfpack.defaults import * import cfpack as cfp import numpy as np # === Amdahl's Law === def amdahl(ncores, parallel_fraction): serial_fraction = 1 - parallel_fraction speedup = 1 / (parallel_fraction / ncores + serial_fraction) return speedup # ===== the following applies in case we are running this in script mode ===== if __name__ == "__main__": # number of cores ncores = np.array([2**x for x in range(16)]) # parallel fractions parallel_fractions = [0.25, 0.5, 0.9, 0.95] # loop over parallel fraction cases for pf in parallel_fractions: # compute Amdahl's law speedup = amdahl(ncores, pf) # plot cfp.plot(x=ncores, y=speedup, label=r"$P="+cfp.round(pf, 2, True)+r"$") # create final plot cfp.plot(xlog=True, xlabel="Number of processor cores", ylabel="Speed-up factor", xlim=[0.5, 1e5], ylim=[0, 25], show=True, save="Amdahl.pdf")