且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我无法理解的fortran计时问题

更新时间:2023-02-01 18:47:23

这是很典型的观察.人们在创建只能测试性能而无法产生有用结果的人工计算时会遇到这种情况.当不打印结果时,编译器可以识别出它不需要该结果作为程序输出,并且可以完全省略计算.

This is quite a typical thing to observe. People hit this when they create artificial computations which only test performance and do not create a useful result. When the result is not printed, the compiler can recognize that it does not need the result for the program output and may completely omit the computation.

要对其进行检查,可以添加-fdump-tree-optimized标志以获得称为GIMPLE的特殊源格式,并且可以比较源代码的这两个变体的输出.它将输出写入名为yourfilename.f90.something.optimized的文件.我确实可以看到很大一部分缺失.基本上,整个r2数组及其操作都经过优化.如果您更了解,也可以比较生成的程序集.

To examine it you can add the -fdump-tree-optimized flag to get a special source form called GIMPLE and you can compare the output for those two variants of the source code. It writes the output to a file called yourfilename.f90.something.optimized. I can indeed see a big part missing. Basically the whole r2 array and the operations with it are optimized out. You can also compare the generated assembly if you know that better.