I was working with some paralization and that brought me looking into Amdahl’s law. I’ve read a number of posts on the topic;
Calculate performance gains using Amdahl's Law
How to calculate Amadahl's Law for threading effectiveness
http://en.wikipedia.org/wiki/Amdahl%27s_law
…but was hoping to find a C# example showing it in practice. Searching has proved no results. In theory it should be possible to make a serial application, time the parallelisable parts, run a parallelised version, recording the length it takes the parallel parts and compare the difference (knowing how many processors are being used) to the result of Amdahl’s function. Is this correct and is anyone aware of such an example existing?
Note: A complete working downloadable version of the program can be found on My Github Page
So with Amdahl’s Law, we split the work in to “Work that must run in serial” and “Work that can be parallelized“, so let’s represent those two workloads as
List<Action>:Where the
DoHeavyWorkdelegate is abstracted brilliantly as:As you can see I’ve made the parallelizable workload a bit heavier for fun and to make a decent example of it.
Next we have to run both workloads in Serial to get our baseline:
At this point we have how long it took each workload to run in serial. Now, let’s run it again, with the parallelizable portion parallelized.
Now that we have the baseline and the parallelized version, we can calculate the speedup and report our findings:
And as Amdahl’s Law tells you, it is hard to scale perfectly with the # of cores you have because of the serial-only work.