Amdahl's Law

本文介绍了软件优化中的80/20法则及Amdahl定律,探讨了程序热点区域的重要性及其对整体性能的影响,并通过数学模型展示了并行处理的局限性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The 80/20 Rule
In the profiling example, we see that most of the CPU time is spent in a fraction of the total program. This is sometimes called the 80/20 rule—that is, 80% of the CPU time is spent in 20% of the program. These places where the computer spends most of its time are also called hot spots, inner loops, and kernels. This is the code you want to optimize. 

Amdahl's Law
The fact that nearly all programs have hot spots is good news. This usually means that a little effort can have large payoffs. The bad news is that once you speed up the hot spots, you will face rapidly diminishing returns on your effort. Amdahl published a famous paper on the limits of parallel processing. He showed that if only part of a program can be sped up with parallel processing, then the sequential part of the program would determine and limit the possible speed up.

Suppose the program really spends 80% of its time in one spot, and suppose you can rewrite this spot to take a negligible amount of time. The program will now execute in 20% of its original time, meaning that it now runs 5 times as fast. So an infinite improvement in the hot spot only gives a 5-fold improvement overall. Getting additional speedup will then require many optimizations throughout the program, each improvement yielding only a small change in overall run time, and it is probable that these improvements won't be worth the effort.

Knowing how to optimize is an important skill. Knowing when to stop optimizing is also important. You can use profiling results to predict the best possible improvement you can get from any particular optimization. For example, if your program spends 20% of its time in one loop, optimizing that loop can speed up the program at most by 1/(1–0.2) = 1.25—that is, by 25%.


Given:

The time T \left(n \right) an algorithm takes to finish when being executed on n thread(s) of execution corresponds to:

T(n) = T(1)\left( B + \frac{1-B}{n}\right)


Therefore, the theoretical speedup that can be had by executing a given algorithm on a system capable of executing n threads of execution is:

S(n) = \frac{ T\left(1\right)}{T\left(n\right)} = \frac{T\left(1\right)}{T\left(1\right)\left(B + \frac{1-B}{n}\right) } =  \frac{1}{B + \frac{1-B}{n}}


http://en.wikipedia.org/wiki/Amdahl's_law

http://baike.baidu.com/view/1349114.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值