1
$\begingroup$

I have a program that has a nested loop, together with its parent running at $O(n^2)$ complexity performing floating point arithmetic.

I see that the performance of the code when compiled with icc is comparable to that of g++ -ffast-math.

Does this mean that icc is switching on an equivalent of the -ffast-math implicitly?

$\endgroup$
5
$\begingroup$

To first order approximation, icc does use -ffast-math by default.

If you run icc --help, it will show you its options. One of the sections is Floating Point, which begins like this:

Floating Point
--------------

-fp-model <name>
          enable <name> floating point model variation
            [no-]except - enable/disable floating point semantics
            fast[=1|2]  - enables more aggressive floating point optimizations
            precise     - allows value-safe optimizations
            source      - enables intermediates in source precision
            strict      - enables -fp-model precise -fp-model except, disables
                          contractions and enables pragma stdc fenv_access
            double      - rounds intermediates in 53-bit (double) precision
            extended    - rounds intermediates in 64-bit (extended) precision

It doesn't say it here, but in icc documentation here, it says that fast=1 is the default.

The other options similar to -ffast-math are:

-[no-]prec-sqrt
          determine if certain square root optimizations are enabled
-[no-]prec-div
          improve precision of FP divides (some speed impact)
-[no-]fast-transcendentals
          generate a faster version of the transcendental functions
...
-[no-]ftz
          enable/disable flush denormal results to zero
-[no-]fma
          enable/disable the combining of floating point multiplies and
          add/subtract operations

E.g., fused multiply-adds are on by default, and precise square root is off by default.

But the correspondence between -ffast-math and -fp-model fast=1 is probably not very precise - it could well be that some other specific options are included in fast-math (which can be seen here) but excluded in fp-model fast=1 or vice versa. It looks to me like among other things -ffast-math would disable non-finite floating-point arithmetic (inf, nan), which icc doesn't do by default.

$\endgroup$
  • $\begingroup$ So does icc prioritise speed over accuracy ? $\endgroup$ – kesari Sep 27 '15 at 20:51
  • $\begingroup$ @kesari Yes, but it is a choice of defaults - it is easy to pick -fp-model that suits you best. Given how common the flag -ffast-math is for gcc projects, I don't think it represents any kind of real difference between the two compilers. $\endgroup$ – Kirill Sep 28 '15 at 18:12
1
$\begingroup$

You can find out by asking icc and g++ to print out all the optimization switches that are actually enabled. Look at the verbosity options for each.

$\endgroup$
  • $\begingroup$ How do I do that ? $\endgroup$ – kesari Sep 24 '15 at 17:36
  • $\begingroup$ The '-v' option to both seems to give what you need for both compilers. You may have to work backwards from some switches to know if they are implied by a higher-level one. $\endgroup$ – Bill Barth Sep 24 '15 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.