I have a program which iterates over an array, deterministically making new row-vectors which it then appends to the array.
At each iteration the norm of the vector is taken, to ensure it’s not a zero vector. If it is zero, the program stops.
There was a bug whereby the third iteration would cause the vector to go to zero.
In looking for this bug I filled the code with debugging print statements, print *,”here”,this_var etc. One of these print statements (which prints the norm of the latest vector) fixed the program.
I don’t like the print statement. I also don’t like that I don’t understand what’s going on.
Does anyone have any ideas about why a print statement would affect the thing it’s printing?
Code (~400 lines, lots of comments) available
As James pointed out in the comments, this could be caused by array indexing. You should try recompiling the code with array bounds checking turned on (the command to do this will vary depending on your compiler) and run the program.
And you’re absolutely correct – insidious errors like this are absolutely maddening.