我为Fortran提供了一个开放的MPI代码,它在没有使用优化标志的情况下编译和运行没有错误。当我使用-O1标志时,在执行时会出现分段错误。导致此问题的唯一优化标志是-ftoplevel-reorder。您能直观地解释这个标志的作用以及在代码中发现错误的最佳策略(如果有的话)吗?
发布于 2017-07-21 04:24:41
来自https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
-fno-toplevel-reorder
Do not reorder top-level functions, variables, and asm statements. Output them in the same order that they appear in the input file. When this option is used, unreferenced static variables are not removed. This option is intended to support existing code that relies on a particular ordering. For new code, it is better to use attributes when possible.
Enabled at level -O0. When disabled explicitly, it also implies -fno-section-anchors, which is otherwise enabled at -O0 on some targets.
您可能正在访问超出界限的数组,并且根据局部变量在堆栈中的放置方式,其后果范围从不明显到致命的崩溃。
https://stackoverflow.com/questions/45221752
复制相似问题