Sie sind auf Seite 1von 2

Thomas Kleffel CSCI 610 Winter 2006 Amdahls Law Tutorial Make the common case faster; dont

spend time on improving a piece of code that is only used once. It is not here you will gain any great performance improvements, on the other hand if a loop is being used a 100 times or a 1000 times in the program, then you want to improve that piece of code to gain a optimal amount of performance. Two reasons for making the common case fast 1. It helps performance 2. It is simpler and faster to do. Amdahls law can be used for this principle. Amdahl's law states that the performance improvement to be gained from using some faster mode of execution is limited by the fraction of the time the faster mode can be used. Also known as speedup, which can be defined as the maximum expected improvement to an overall system when only part of the system, is improved.

Speedup =

Execution time for task without enhancement Execution time for task with enhancement

Execution time using the enhancement can be thought of as the amount of time the unenhanced fraction takes (which is 1 Fractionenhanced) plus the length of time the enhanced fraction takes.

Speedup =

Execution time old = Execution time new

1 (1 Fractionenhanced ) + Fractionenhanced Speedupenhanced

Example 1: We are considering an enhancement to the processor of a web server. The new CPU is 20 times faster on search queries than the old processor. The old processor is busy with search queries 70% of the time, what is the speedup gained by integrating the enhanced CPU?

Speedup =

1 ( 1 Fractionenhanced ) Fractionenhanced Speedupenhanced


1 = 2.985 0.335

Fractionenhanced = 70 % = 0.70 Speedupenhanced = 20

Speedup =

1 ( 1 0.70 ) + 0.70 20

Example 2: Booths algorithm, used to perform binary multiplication of X * Y using addition, subtraction and arithmetic right shift, is given below: 1. 2. A 0, Q X, Q-1 0, M Y For I = 1 to n do a. If Q0Q-1 = 01 then A A + M b. If Q0Q-1 = 10 then A A M c. Arithmetic Right Shift (A || Q) The answer is stored in the combination of (A || Q) Given that 5% of all instructions in a given benchmark are 32-bit binary multiplications (no other multiplications take place), how much faster is the machine with the hardware multiplication circuit over a machine that must perform the multiplication using Booths algorithm? Assume that each instruction (line) in the algorithm takes 1 clock cycle to perform (including the for-loop mechanisms and each if-then statement). Assume that a machine which can calculate binary multiplication using a hardware circuit has a multiply instruction with a CPI of 15. The frequency of the enhancement (the multiplication circuit) is 5% The machine that uses Booths algorithm to perform multiplication executes 1 + 4 * 32 instructions (at one cycle each) or has a 129 cycle multiply The machine with the hardware multiplier takes 15 cycles per multiple The speedup in the enhanced mode is then 129 / 15 = 8.6

Speedup =

1 ( 1 0.05 ) + 0.05 8.6

1 = 1.047 or a 4.7% speedup 0.955

Key idea: Amdahls law quantifies the general notion of diminishing returns. It applies to any activity, not just computer programs.

Source:

1. Computer Architecture, A Quantitative Approach, 3 edition, J.L. Hennessy and D.A. Patterson 2. Wikipedia, the free encyclopedia, http://www.wikipedia.com 3. Northern Kentucky University, CSC462, http://www.nku.edu/~foxr/CSC462/NOTES/ch1.ppt

rd

Das könnte Ihnen auch gefallen