我可以将Thread Sanitizer用于OpenMP程序吗?
请考虑以下示例:
#include int main () { int i = 0; #pragma omp parallel { #pragma omp critical { ++i; } } std::cout << i; }
使用g++ -fopenmp -fsanitize=thread
和运行yield进行编译
警告:ThreadSanitizer:数据竞争(pid = 9576)
通过线程T1读取大小4在0x7ffdc170f600:
#0 main._omp_fn.0(a.out + 0x000000400d20)
#1 gomp_thread_start /build/gcc/src/gcc-5.2.0/libgomp/team.c:118(libgomp.so.1 + 0x00000000f42d)先前通过线程T2在0x7ffdc170f600处写入大小4:
#0 main._omp_fn.0(a.out + 0x000000400d35)
#1 gomp_thread_start /build/gcc/src/gcc-5.2.0/libgomp/team.c:118(libgomp.so.1 + 0x00000000f42d)位置是主线程的堆栈。
线程T1(tid = 9578,正在运行)由主线程创建:
#0 pthread_create /build/gcc/src/gcc-5.2.0/libsanitizer/tsan/tsan_interceptors.cc:895(libtsan.so.0 + 0x000000027a37)
#1 gomp_team_start /build/gcc/src/gcc-5.2.0/libgomp/team.c:796(libgomp.so.1 + 0x00000000f98f)
#2 __libc_start_main(libc.so.6 + 0x00000002060f)线程T2(tid = 9579,正在运行)由主线程创建:
#0 pthread_create /build/gcc/src/gcc-5.2.0/libsanitizer/tsan/tsan_interceptors.cc:895(libtsan.so.0 + 0x000000027a37)
#1 gomp_team_start /build/gcc/src/gcc-5.2.0/libgomp/team.c:796(libgomp.so.1 + 0x00000000f98f)
#2 __libc_start_main(libc.so.6 + 0x00000002060f)摘要:ThreadSanitizer:数据竞争??:0 main._omp_fn.0
据我所知,这是误报。 有没有办法避免这种情况?
(使用clang和libomp的东西也可以。)
即使有了抑制,你仍然会在OpenMP运行时上得到误报,因为在运行时内有一些Tsan无法理解的同步机制。
我们在OpenMP运行时工作,让Tsan了解这个同步点并删除所有误报。
看看这个项目:
https://github.com/PRUNER/archer
如果您需要更多帮助,请告诉我。
最好,
西蒙娜