Reputation: 750
I am compiling some numerical code with gfortran using Code::Blocks. I have two versions of the executable: Debug and Release.
-Jobj\Debug\ -Wall -g -c
-Jobj\Release\ -Wall -O2 -c
-nx -fullname -quiet -args
When I run the code normally, both the Release and Debug executables produce the same output. However, when I run the code in gdb
, the output is different. This appears to be due to numerical calculations producing different results during execution.
For example, the result of one calculation when run in gdb is 7.93941842553643E-06 and when run normally is 1.71006041855278E-03. More oddly, some of the non-zero results are identical within double precision accuracy.
How can I ensure that the output is the same when I run using gdb
? Is a different type of numerical calculation or evaluation used by default when using gdb?
Upvotes: 1
Views: 375
Reputation: 213385
This appears to be due to numerical calculations producing different results during execution.
That is exceedingly unlikely: GDB doesn't participate in any numerical calculations your program executes.
Significantly more likely is that your program uses uninitialized memory, and that memory just happens to have different values when the program runs under GDB.
If you are on a platform that is supported by valgrind, your very first step should be to run your program under it, and fix all bugs it finds.
Upvotes: 1