Strange Problem

T

twizansky

Hi,

I'm sorry about the vagueness of this post but I don't really know how
to present the problem.

I am writing a numerical integrator and currently the program gets
stuck and I am forced to abort it. When I attempt to add debug code
such as cout << ..., The problem goes away. I can't even pinpoint the
section of code which is causing the problem (this is why I haven't
included any code). I can't understand how the addition of a cout
command could affect the program in this way and I'm going crazy. Does
anyone have any advice?

Thanks
 
P

Phil Endecott

I am writing a numerical integrator and currently the program gets
stuck and I am forced to abort it. When I attempt to add debug code
such as cout << ..., The problem goes away.

Probably adding the debugging has caused things to move around in
memory. Something is going wrong and corrupting a bit of memory;
without the debugging, it hits something that matters. With the
debugging, by chance it hits something that doesn't matter.

So... Use a debugger. Unlike putting explicit debugging in the code,
running under a debugger should preserve the same memory layout.

Or, since the problem is likely to be something memory-related, try a
memory access tracing tool like Purify or Valgrind.

--Phil.
 
V

Victor Bazarov

I'm sorry about the vagueness of this post but I don't really know how
to present the problem.

I am writing a numerical integrator and currently the program gets
stuck and I am forced to abort it. When I attempt to add debug code
such as cout << ..., The problem goes away. I can't even pinpoint the
section of code which is causing the problem (this is why I haven't
included any code). I can't understand how the addition of a cout
command could affect the program in this way and I'm going crazy. Does
anyone have any advice?

I've seen it happen and it _can_ be a compiler bug related to the way
the code is generated. It is rather rare. I've had a case where some
variable wouldn't get updated with the result of evaluating of some
expression unless there was a 'cout' thing inserted in the vicinity
of the assignment operator. Awful. I could only find it by making
a release build with debug information (optimisations turned on and
the debug symbols created in a separate file) and actually looking at
the assembly code while stepping through the program. I don't wish
anybody would have to do the same, although sometimes one has to reach
far to get it. I eventually fixed it by declaring that variable as
'volatile'.

What advice to give? Try adding debugging info and run it under the
debugger. Force the debugger to stop (interrupt) your application when
it reached the sticking point. See where it gets stuck. Try to narrow
it down to one function or a block of code. Proceed from that point.

V
 
T

twizansky

Thanks a lot.

The problem turned out to be a function that returned a value that was
too small and was converted to NaN. I still have no idea why this
would be affected by cout statements.

Tommer
 
P

Pete Becker

Thanks a lot.

The problem turned out to be a function that returned a value that was
too small and was converted to NaN.

Floating-point values that are too close to zero to represent are either
turned into subnormal values or coverted to zero. They don't become
NaN's. You get NaN's for things like 0.0/0.0, which has no meaningful value.
I still have no idea why this
would be affected by cout statements.

Probably because you're looking at corrupted memory, caused by writing
though a bad pointer. That's consistent with all the symptoms you
described initially, and corrupted floating-point values often look like
NaNs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,298
Messages
2,571,542
Members
48,283
Latest member
RitaVui655

Latest Threads

Top