Блог пользователя Leo_Pranav

Автор Leo_Pranav, история, 10 месяцев назад, По-английски

The problem which I had solved using the pre-processor directives #pragma GCC optimize("Ofast") #pragma GCC target("avx") slows down the code and when i comment them, the code got accepted!! Can anyone explain about this?

My accepted code 323201201 My failed code 323200976

  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by Leo_Pranav (previous revision, new revision, compare).

»
10 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Ofast: This is one of the more controversial flags. It turns on all optimizations that O3 offers, along with some other optimizations, some of which might not be standards compliant. For instance, it turns on the fast-math optimization, which assumes floating-point arithmetic is associative (among other things), and under this assumption, it is not unexpected to see your floating-point error analysis go to waste. Ofast may or may not make your code faster; only use this if you’re sure it does the right things.

So you're in fact allowing some compiler optimizations along with floating point associative which can make the code slower due to the way how computers deal with floats.

Further Reading