6

This is really taking my time. I could not find a simple way to estimate FLOPS for a following code (the loop), How much FLOPS are for a single iteration of the loop:

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

It looks simple but I got confused with some other numbers given earlier, so it would be great if someone can give an exact number.

Thanks.

usman
  • 1,285
  • 1
  • 14
  • 25
  • Is this homework? If so, please use the "homework" tag. – Lightness Races in Orbit Mar 16 '11 at 19:32
  • 1
    Are you looking for "FLOPS" or complexity (Big-O stuff)? Flops will change based on hardware (Floating point operations per second) the "per second" piece means that it is dependent on the abilities of the executing machine. – Brandon Mar 16 '11 at 19:34
  • FLOPS stands for FLoating point OPerations per Second. It is measure of performance, it can't be measure of amount of computations. What you mean is amount of FLOP or FLOPs (small s) – Andrey Mar 16 '11 at 19:35

4 Answers4

6

I see (in order of increasing complexity):

  • 8 additions (inc. subtractions)
  • 3 multiplications
  • 1 reciprocal-square-root

How these relate to each other depends strongly on the CPU family.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
5

Try to either take intermediate assembly code or decompile exe.

Then count all floating point operations (in x86 assembly code they start with F prefix like FSIN).

Andrey
  • 59,039
  • 12
  • 119
  • 163
1

I count 12 plus a sqrt (which is likely using Newton's method, which is a loop), but that depends on the data types of some variables that you did not specify, and the result of compilation (which may add more, or optimize out some operations).

I am counting each +, /, -, or * where the expression contains at least one floating point variable, so array indices and the loop invariant do not count, and those are integer operations.

Jonathan
  • 13,354
  • 4
  • 36
  • 32
0

Try using a performance measurement library like PAPI, they give abstractions to hardware counters which would be your best best to measure the FLOPS. PAPI_FLOPS.