这真的是我的时间。我找不到一种简单的方法来估算以下代码(循环),单个循环迭代多少拖鞋:

float func(float * atominfo, float energygridItem, int xindex, int yindex)
{
   ...
   for (atomid=0; atomid<numatoms*4; atomid+=4) 
   {
       float dy = coory - atominfo[atomid+2];
       float dysqpdzsq = (dy * dy) + atominfo[atomid+3];
       float dx1 = coorx1 - atominfo[atomid+1];

       float s, y, t;
       s = atominfo[atomid] * (1.0f / sqrtf(dx1*dx1 + dysqpdzsq));
       y = s - energycomp1;
       t = energyvalx1 + y;
       energycomp1 = (t - energyvalx1)  - y;
       energyvalx1 = t;
    }
    ...
}

它看起来很简单,但我与之前给出的其他一些数字感到困惑,因此,如果有人可以给出确切的数字,那就太好了。

谢谢。

有帮助吗?

解决方案

我看到(按复杂性增加的顺序):

  • 8个加法(INC。减法)
  • 3个乘法
  • 1个相互平方根

这些如何相互关系在很大程度上取决于CPU家族。

其他提示

尝试使用中间装配代码或反编译EXE。

然后计算所有浮点操作(在x86汇编代码中,他们以 F 前缀喜欢 FSIN).

我计算12加上一个SQRT(可能使用牛顿的方法,这是一个循环),但这取决于您未指定的某些变量的数据类型,以及汇编的结果(可能会添加更多或优化,一些操作)。

我正在计算每个 +, /, - 或 *,其中表达式包含至少一个浮点变量,因此数组索引和循环不变不计数,而这些是整数操作。

尝试使用诸如Papi之类的性能测量库,它们为硬件计数器提供抽象,这将是您最佳测量拖鞋的最佳选择。 papi_flops。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top