Helgrind(Valgrind的)和OpenMP(C):避免误报? [英] Helgrind (Valgrind) and OpenMP (C): avoiding false positives?

查看:574
本文介绍了Helgrind(Valgrind的)和OpenMP(C):避免误报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Valgrind的线程错误检测工具Helgrind的文档,发现 href=\"http://valgrind.org/docs/manual/hg-manual.html\">

The documentation for the Valgrind thread error detection tool Helgrind, found here

警告说,如果使用GCC编译您的OpenMP code,GCC的OpenMP运行时库( libgomp.so )会导致因数据种族的假阳性报告的混乱,其使用原子机器指令和Linux系统futex的调用,而不是POSIX的pthreads元。它告诉你,你可以解决这个问题,但是,通过重新编译与海湾合作委员会的 - 禁用 - Linux的futex的配置选项

warns that, if you use GCC to compile your OpenMP code, GCC's OpenMP runtime library (libgomp.so) will cause a chaos of false positive reports of data races, because of its use of atomic machine instructions and Linux futex system calls instead of POSIX pthreads primitives. It tells you that you can solve this problem, however, by recompiling GCC with the --disable-linux-futex configuration option.

所以,我想这一点。我编译和安装到本地目录(〜/ GCC_Valgrind / gcc_install )的新版本的GCC 4.7.0(最新发布截至记者发稿)与 - 禁止 - Linux的futex的配置选项。然后,我创建了一个小型的OpenMP测试程序( test1.c )没有可见的数据竞争:

So I tried this. I compiled and installed to a local directory (~/GCC_Valgrind/gcc_install) a new GCC version 4.7.0 (the latest release as of this writing) with the --disable-linux-futex configuration option. I then created a small OpenMP test program (test1.c) that has no visible data races:

/* test1.c */

#include <omp.h>
#include <stdio.h>
#include <stdlib.h>

#define NUM_THREADS 2

int a[NUM_THREADS];

int main(void) {
        int i;
#pragma omp parallel num_threads(NUM_THREADS)
        {
                int tid = omp_get_thread_num();
                a[tid] = tid + 1;
        }
        for (i = 0; i < NUM_THREADS; i++)
                printf("%d ", a[i]);
        printf("\n");
        return EXIT_SUCCESS;
}

我编这个程序如下:

I compiled this program as follows

~/GCC_Valgrind/gcc_install/bin/gcc -Wall -fopenmp  -static -L~/GCC_Valgrind/gcc_install/lib64 -L~/GCC_Valgrind/gcc_install/lib -o test1 test1.c

不过,我得到了30误报数据争报道 - 在 libgomp code所有发生。然后,我编的 test1.c 没有 -static 标记,并再次运行Helgrind就可以了。这一次,我只拿到了9误报数据争的报道,但仍然太多了 - 而且,没有 -static 标志,我找不到在假想的种族 libgomp code。

However, I got 30 false positive data race reports!--all occurring in libgomp code. I then compiled test1.c without the -static flag, and ran Helgrind on it again. This time, I got only 9 false positive data race reports, but that is still too many--and, without the -static flag, I cannot trace the supposed race in the libgomp code.

有没有人找到了一种方法来减少,如果不消除,适用于使用GCC编译OpenMP程序从Helgrind误报数据争的报告数量?谢谢!

Has anybody found a way to reduce, if not eliminate, the number of false positive data race reports from Helgrind applied to an OpenMP program compiled with GCC? Thanks!

推荐答案

很抱歉把这个作为一个答案,因为它更是一个评论,但它是太长,不适合作为一个评论,所以这里有云:

Sorry to put this in as an answer since it's more of a comment, but it's too long to fit in as a comment, so here goes:

从网站引用你

有关GNU的OpenMP(GCC的一部分),至少对于GCC运行支持库
  4.2和4.3的版本。 GNU的OpenMP运行时库(libgomp.so)
  通过构建组合自己的同步原语
  原子存储器中的指令和futex的系统调用,这会导致总
  乱因为Helgrind因为它不能看到的。

Runtime support library for GNU OpenMP (part of GCC), at least for GCC versions 4.2 and 4.3. The GNU OpenMP runtime library (libgomp.so) constructs its own synchronisation primitives using combinations of atomic memory instructions and the futex syscall, which causes total chaos since in Helgrind since it cannot "see" those.

幸运的是,这可以使用配置时间选项(解决
  GCC)。从源代码重建GCC,以及使用配置
  --disable-Linux的futex的。这使得libgomp.so使用标准POSIX线程,而不是原语。请注意,这是使用GCC测试
  4.2.3和未被使用最近版本的GCC重新测试。我们会AP preciate听到任何成功或失败更
  最新版本的。

Fortunately, this can be solved using a configuration-time option (for GCC). Rebuild GCC from source, and configure using --disable-linux-futex. This makes libgomp.so use the standard POSIX threading primitives instead. Note that this was tested using GCC 4.2.3 and has not been re-tested using more recent GCC versions. We would appreciate hearing about any successes or failures with more recent versions.

如您在您的文章中提到,这与 libgomp.so 做的,但是这是一个共享的对象,所以我看不出你如何通过 - 静态标志,并仍然使用该库。我只是误传?

as you mentioned in your post, this has to do with libgomp.so, but that's a shared object, so I don't see how you can pass the -static flag and still use that library. Am I just misinformed?

这篇关于Helgrind(Valgrind的)和OpenMP(C):避免误报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆