Reputation: 7315
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?
Upvotes: 5
Views: 2441
Reputation: 386
I suspect that multithreading is causing the problem, since you are using -fopenmp
.
At a high level, -fprofile-generate
causes the compiler to instrument your program with counter increments. These increments are not thread-safe, so your test runs may yield corrupted profiling data.
You can solve this problem by passing -fprofile-correction
to the compiler [1]. Alternatively, you could disable -fopenmp
/multithreading when attempting PGO. I've had success with the first approach.
[1] https://bugs.launchpad.net/ubuntu/+source/gcc-4.4/+bug/598462
Upvotes: 7