3 ms·
Question 4 points at a huge surprise. With a scientific computing project, I got (if I recall correctly), correct and expected output at no optimization and -O1
by ISL 14y ago
Question 4 points at a huge surprise. With a scientific computing project, I got (if I recall correctly), correct and expected output at no optimization and -O1, and patently incorrect output at -O2 and -O3.
Cost: one sleepless night in college."What do you mean, optimization doesn't just make it faster?!?"
- widdershins 14y agoReally? Wow, I thought optimisations had to provably avoid affecting the correctness of your program. Hence: "This need to avoid imprecise intermediate results often prevents compilers from exploiting mathematical properties like associativity when optimizing FP arithmetic." from the explanation under Q4.
- haberman 14y agoIt's possible that both were "correct" but that -O2 and -O3 gave different results due to x86 extended precision. For some interesting reading, see: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323 (a centi-bug of back and forth between "it's broken!" and "no it's not, and we're not going to change the compiler.") http://gcc.gnu.org/ml/gcc/2003-08/msg01183.html http://gcc.gnu.org/ml/gcc/2003-08/msg01183.html (a really informative thread about the issue)