3

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

已知如下:

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)?还是我做错了什么?

4

2 回答 2

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;
}

不客气。

于 2014-02-14T09:21:17.677 回答
0

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

f 是您的程序在单核实现中未并行化的部分代码所花费的时间百分比(也称为 0 <= f <= 1)。例如,如果您有这样的程序:

// 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 获得加速。一项免责声明——这远不是衡量速度的唯一方法,不同的方法各有优缺点。

于 2012-02-11T19:30:17.293 回答