添加/删除PRINT语句会更改变量 [英] Adding/removing a PRINT statement changes variables

查看:182
本文介绍了添加/删除PRINT语句会更改变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些编写fortran代码的经验,但我从未见过类似的东西。

我正在使用一个大型的HPC代码(约10K行),我正在修改一个子程序。我使用打印语句来验证一切正确,并在必要时进行调试。当我用我使用的最后一个 PRINT 语句运行我的代码时,代码在任何地方都给出了实际的数字。一旦我评论这最后一个 PRINT 语句,代码给我 NaN 是我的一些变量。由于我的代码太大,我显然无法在这里发布,但我会发布 PRINT 语句:

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

其中 up 是某个速度数组。



问题:

这怎么可能? PRINT 语句如何影响任何变量?

我认为 这代表了代码中的一些其他错误(例如内存损坏)。我不确定你使用了哪些调试标志。但是,请尝试使用编译标志-check all(对于intel fortran编译器)。该标志检查多个可能的错误。有关更多详情,请参阅 https://software.intel.com/sites/default/files/m/f/8/5/8/0/6366-ifort.txt


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?

解决方案

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

这篇关于添加/删除PRINT语句会更改变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆