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?


2 Answers 2


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:

          determine if certain square root optimizations are enabled
          improve precision of FP divides (some speed impact)
          generate a faster version of the transcendental functions
          enable/disable flush denormal results to zero
          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.

  • $\begingroup$ So does icc prioritise speed over accuracy ? $\endgroup$
    – kesari
    Commented Sep 27, 2015 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
    Commented Sep 28, 2015 at 18:12

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.

  • $\begingroup$ How do I do that ? $\endgroup$
    – kesari
    Commented Sep 24, 2015 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
    Commented Sep 24, 2015 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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