g++ 和 CMake 损坏的配置文件信息

Thu*_*411 5 c++ profiling g++ compiler-optimization

我正在尝试使用分析来优化一个相当复杂的 C++ 项目(多个源文件,链接到 Boost 库、GSL 和 OpenCV)。使用 CMake,我首先编译

\n\n
set(CMAKE_CXX_FLAGS " -O3 -ffast-math -fprofile-generate=profiling -pg -fopenmp ")\n
Run Code Online (Sandbox Code Playgroud)\n\n

使用典型输入运行生成的可执行文件后,我使用以下命令进行编译

\n\n
set(CMAKE_CXX_FLAGS " -O3 -ffast-math -fprofile-use=profiling -fopenmp ")\n
Run Code Online (Sandbox Code Playgroud)\n\n

编译失败并出现大量错误,如下所示:

\n\n
/n/user/projects/project_name/src/foo.cpp: In member function \xe2\x80\x98double TLinearInterp::operator()(double) const\xe2\x80\x99:\n/n/user/projects/project_name/src/foo.cpp:86:1: error: corrupted profile info: profile data is not flow-consistent\n }\n ^\n/n/user/projects/project_name/src/foo.cpp:86:1: error: corrupted profile info: number of executions for edge 2-7 thought to be -7232\n/n/user/projects/project_name/src/foo.cpp:86:1: error: corrupted profile info: number of executions for edge 2-3 thought to be 20996551\n/n/user/projects/project_name/src/foo.cpp:86:1: error: corrupted profile info: number of executions for edge 3-7 thought to be -28135\n/n/user/projects/project_name/src/foo.cpp:86:1: error: corrupted profile info: number of executions for edge 3-4 thought to be 21024686\n
Run Code Online (Sandbox Code Playgroud)\n\n

我正在使用 4.8.0 版本的 GNU 编译器。从编译器标志可以看出,我的项目使用 OpenMP。

\n\n

什么可能导致个人资料信息损坏?

\n

ved*_*ntk 7

我怀疑多线程导致了问题,因为您正在使用-fopenmp.

在高水平上,-fprofile-generate使编译器使用计数器增量来检测您的程序。这些增量不是线程安全的,因此您的测试运行可能会产生损坏的分析数据。

您可以通过传递-fprofile-correction给编译器来解决这个问题[1]。或者,您可以禁用-fopenmp在尝试 PGO 时禁用/多线程。我用第一种方法取得了成功。

[1] https://bugs.launchpad.net/ubuntu/+source/gcc-4.4/+bug/598462