【问题标题】:Calculate performance gains using Amdahl's Law使用阿姆达尔定律计算性能增益
【发布时间】:2012-02-11 18:53:57
【问题描述】:

我对确定性能增益和串行应用程序部分的阿姆达尔定律感到困惑,但未能弄清楚这一点。

已知如下:

S(N) = Speedup factor for (N) CPU's
N = Number of CPU's
f = The part of the program which is executed sequential
S(N) = N / ( 1 + f * ( N - 1 ) ) 

如果我有 4 个 CPU 和 3 倍的加速因子(性能增益)。 f 会是什么?

我的猜测:

S(N) = 3 (that's our performance gain using 4 CPU's)
N = 4

所以在公式中输入这些值:

3 = 4 / ( 1 + f * ( 4 - 1 ) )

我说 f = 0,11 是否正确?还是我需要将 S(N) 设置为 1(所以除以 3)?还是我做错了什么?

【问题讨论】:

    标签: algorithm parallel-processing distributed-computing parallelism-amdahl


    【解决方案1】:

    我的一个同学对此给出了(到目前为止工作/正确的)答案。

    我做了以下课程: 移除以消除混乱。

    这应该可以解决。

    编辑:

    好的,之前的答案是错误的,但我找到了解决方案。

    你首先计算可以并行完成的部分(它在维基百科上,但我花了一段时间才理解)然后你计算串行部分。

    所以最后的类变成了这样:

    /**
    * @param s - The maximum performance profit. 
    * @param n - The amount of processors that are usable..
    * @return f - The sequential part of the program.
    */
    public final double sequentialCalculation(final double s, final double n) {
        double p = 0; //the part that can be executed in parallel
        double f = 0;
    
        if (s <= 0) {
            throw new IllegalArgumentException("S > 0");
        }
    
        if (n <= 0) {
            throw new IllegalArgumentException("N > 0");
        }
    
        p = ((1 / s) - 1) / ((1 / n) - 1);
    
        f = 1 - p;
    
        return f;
    }
    

    不客气。

    【讨论】:

      【解决方案2】:

      如果这是你应该使用的方程式,我认为你的想法有点错误,所以让我试着解释一下。

      f 是您的程序在单核实现中未并行化的部分代码所花费的时间百分比(也称为 0

      // this takes 15 seconds
      init();
      
      for (int i = 0; i < 10; i++) {
          // this takes 10 seconds, and will be split
          // between threads when in parallel
          calculate();
      }
      
      // this takes 5 seconds
      finalize();
      

      这将在 15+(10*10)+5=120 秒内运行(串行)。但是,如果并行实施,则有 20 秒的执行时间不能在多个内核之间拆分。这意味着即使并行部分被加速到只需要 10 秒来执行所有 10 次迭代,整个程序仍然需要 30 秒。这就是 f 有助于告诉我们的 - 有多少问题可以从并行化中受益。在此示例中,由于总共 120 秒中的 20 秒必须连续完成,因此 f = 20/120 = 1/6。

      使用这个新的 f 值,您可以根据 Amdahl 获得加速。一项免责声明 - 这远不是衡量速度的唯一方法,不同的方法各有优缺点。

      【讨论】:

      • 谢谢泰勒,我基本明白你的回答。在我的示例中,我想计算连续完成的部分。在完成剩下的作业之前,我需要弄清楚这一点;-)
      猜你喜欢
      • 2013-04-25
      • 2017-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-27
      • 1970-01-01
      • 1970-01-01
      • 2016-04-26
      相关资源
      最近更新 更多