On 3/24/23 11:04, Simon wrote:
>
> Having all that said, is there any reasonable argument as to what could
> cause the program output to be different by just adding ...<<... statement?
There is no reasonable argument why that should be the case. The
function you are calling looks like this:
template <int rank_, int dim, typename Number>
inline std::ostream &
operator<<(std::ostream &out, const Tensor<rank_, dim, Number> &p)
{
for (unsigned int i = 0; i < dim; ++i)
{
out << p[i];
if (i != dim - 1)
out << ' ';
}
return out;
}
It *should* have no side effects. If it does, there is something funny
going on in your program.
That leaves a philosophical question:
> Admittedly, I do not know how to debug this further, because there is in
> theory
> nothing to debug if I can trace the differences back to the ...<<...
> statement.
Approach A is to say "Well, let me just remove the output statement
then; I know that my program works in that case". Approach B is to say
"This situation illustrates that I don't understand something
fundamental about my program. Let me use the occasion to investigate".
Everyone who has been following this mailing list for a while will
suspect that I lean quite heavily towards Approach B. If the state of
the program changes in ways I do not understand, and that make no sense
to me, it is not unreasonable to suspect that there is a conceptual bug
somewhere, however unpleasant it may be to search for it, and that not
investigating the cause for the issue is really just closing one's eyes
towards a problem that is clearly there.
In your case, I would start by outputting vastly more intermediate
results (up to machine precision) to see where the first time is that
something is different between the program with and the one without the
<< statement. Maybe you can identify which variable it is that first
changes, and if you know that, it may be easier to also see *why* it
changes. You could wrap the operator<< statement in some kind of
if-condition that you can control from outside the program, and then run
your program twice every time, once with and without the output
statement. Pipe the output of each run into two files that you can then
run 'diff' on.
From experience, this is not likely going to be a bug that is fun to
chase down. But it might make for a good learning opportunity. It would
be quite interesting to hear back here if you find out what caused the
issue!
Best
W.
--
------------------------------------------------------------------------
Wolfgang Bangerth email:
bang...@colostate.edu
www:
http://www.math.colostate.edu/~bangerth/