When compiling the following code against the Eigen version 3.3-beta1
with the Intel compiler icc version 13.1.3, the code hangs on the call to BDCSVD. The same code compiled with g++ 4.4.7 runs fine. Optimization levels -O1 to -O3 have been tried.
Additionally, during the compilation with icc several screens of warnings are issued (apparetnly not related to the problem, but annoying):
Eigen/src/Core/ProductEvaluators.h(543): warning #2536: type qualifiers are meaningless here
Indeed, by default icc performs numerous unsafe floating point optimizations breaking any D&C SVD implementation. You need to disable them by compiling with "-fp-model precise".
I'm not sure what we could do on our side (beyond adding such a note in the documentation).
Thanks, with this flag it works fine, although is a bit slower than the code produced by gcc (~20%).
Most of the time, an up-to-date gcc is the best choice for Eigen code.
Regarding a work-around for icc: Are there ways to prohibit certain optimizations locally (e.g., via #pragma)? Or could/should we protect some assignments with inline-assembler instructions (in case icc is detected).
Also, wouldn't this bug occur with `g++ -ffast-math` as well?
> Also, wouldn't this bug occur with `g++ -ffast-math` as well?
In fact yes, tried gcc 4.4.7 and 4.9.3, both produce a code that hangs.
Thus it would be better to somehow trick compilers into skipping the unsafe optimizations even if compiled with this flag. For my project, icc (with this flag on by default) produces code that is sometimes twice as fast as the one from gcc (which has it off by default), which is quite a big difference - not sure how much is gained by this flag though.
I tried with:
#pragma float_control(precise, on, push)
but that only works if I put it at the beginning of the .cpp file and pop it after the function doing the instantiation/calls to BDCSVD.
Actually, it seems that compiling with -no-ftz is enough (ftz = flush denormals to zero). So the issue might be fixed through a careful analysis...
sorry, with -no-ftz it does not hang, but it lacks accuracy...
Summary: Bug 1214: consider denormals as zero in D&C SVD. This also workaround infinite binary search when compiling with ICC's unsafe optimizations.
Remains to add a note in the doc.