5

I have some experience writing fortran codes but I have never seen something like this.

I am using a large HPC code (~10K lines) in which I am modifying a subroutine. I used print statements to verify that everything was done correctly and debug if necessary. When I run my code with the last PRINT statement I used, the code is giving me real numbers everywhere. Once I comment this last PRINT statement, the code is giving me NaN is some of my variables. Since my code is too big, I obviously can't post it here, but I'll post the PRINT statement:

PRINT*, "outletBC up1    ", SUM(ABS(up(nptsx,:,:)))

where up is some velocity array.

QUESTION:

How is that possible? How can a PRINT statement possibly affect any variable?

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
solalito
  • 1,189
  • 4
  • 19
  • 34
  • 3
    this is indicative of a bug elsewhere in the code, likely related to accesing an array out of bounds. try turning on bounds checking – agentp Jan 13 '15 at 12:44
  • Like @agentp says. Also check procedure calls match dummy and actual arguments correctly. – High Performance Mark Jan 13 '15 at 12:53
  • 1
    @HighPerformanceMark I ran my code with the multiple debug flags ifort has available. I fixed all errors (some were out of bounds array access), but the error persists. I'll keep debugging the code but I was honestly more interested about understanding how can a print statement have any effect on anything else in the code. – solalito Jan 13 '15 at 14:43
  • 2
    What agentp and Mark said. Also check uninitialized variables. I've had this happen before. If things are shady somewhere else in the code, a print statement may push things around in memory leading to unexpected behavior. Also see http://en.wikipedia.org/wiki/Heisenbug – milancurcic Jan 13 '15 at 14:58
  • Similar post on [tag:c++] about an [inifinte loop heisenbug](https://stackoverflow.com/questions/28722647/infinite-loop-heisenbug-it-exits-if-i-add-a-printout) – kvantour Jan 31 '18 at 18:10
  • @kvantour We have plenty of Fortran examples here. Just on the right to **Related**. (I hope they all don't need the heisenbug tag now...) – Vladimir F Героям слава Feb 01 '18 at 09:37

1 Answers1

1

I think this is indicative of some other errors in the code (e.g. memory corruption). I am not sure what debug flags you used. However, try compilation flag "-check all" (for intel fortran compiler). This flag checks for multiple possible errors. For more details, you can refer to https://software.intel.com/sites/default/files/m/f/8/5/8/0/6366-ifort.txt

Ahmad S
  • 68
  • 6