我正在尝试使用性能分析来优化一个相当复杂的C++项目(多个源文件,链接到Boost库、GSL和OpenCV)。使用CMake,我首先使用
set(CMAKE_CXX_FLAGS " -O3 -ffast-math -fprofile-generate=profiling -pg -fopenmp ")
在使用典型输入运行生成的可执行文件之后,我使用以下命令进行编译
set(CMAKE_CXX_FLAGS " -O3 -ffast-math -fprofile-use=profiling -fopenmp ")
编译失败,出现大量错误,如下所示:
/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
我使用的是GNU编译器的4.8.0版本。从编译器标志可以看出,我的项目使用了OpenMP。
是什么导致了个人资料信息的损坏?
发布于 2014-12-31 13:26:51
我怀疑是多线程导致了这个问题,因为您使用的是-fopenmp
。
在较高的级别上,-fprofile-generate
使编译器使用计数器增量来检测您的程序。这些增量不是线程安全的,因此您的测试运行可能会产生损坏的分析数据。
您可以通过将-fprofile-correction
传递给编译器1来解决此问题。或者,您可以在尝试PGO时禁用-fopenmp
/multithreading。我已经成功地使用了第一种方法。
https://stackoverflow.com/questions/16868235
复制相似问题