What are the general strategies to start debugging numerical code, when:
- code compiled with aggressive optimization flags, produces occational NaN's and Inf's in the output
- code compiled with
-g
(which implies-O0
) for running with debugger, does not produce NaN's and Inf's anymore?
In this case I was working with the Portland Group C++ compiler, pgCC, and used optimization options
-w -fast -O3 -Mipa=fast -Mfprelaxed -Minline=levels:10
and then just
-w -g
for the debugging version. But I am sure a similar situation could happen with g++
as well.
EDIT: Adding print statements is not a very alluring option, as the code is not written by me, it's several thousands of lines large, and I have no idea to narrow the search; the NaN's might originate pretty much from anywhere.