4

I'm trying to optimize a fairly complex C++ project (multiple source files, linked to Boost libraries, GSL and OpenCV) using profiling. Using CMake, I first compile with

set(CMAKE_CXX_FLAGS " -O3 -ffast-math -fprofile-generate=profiling -pg -fopenmp ")

After running the resulting executable with typical inputs, I compile with

set(CMAKE_CXX_FLAGS " -O3 -ffast-math -fprofile-use=profiling -fopenmp ")

Compilation fails with a large number of errors like this:

/n/user/projects/project_name/src/foo.cpp: In member function ‘double TLinearInterp::operator()(double) const’:
/n/user/projects/project_name/src/foo.cpp:86:1: error: corrupted profile info: profile data is not flow-consistent
 }
 ^
/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/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/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/user/projects/project_name/src/foo.cpp:86:1: error: corrupted profile info: number of executions for edge 3-4 thought to be 21024686

I'm using version 4.8.0 of the GNU compilers. As one can see from the compiler flags, my project uses OpenMP.

What could be causing the corruption of the profile info?

4

1 回答 1

4

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

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

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

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

于 2014-12-31T05:26:51.043 回答