Helgrind使用openmp在大多数简单的c ++代码上报告“可能的数据竞争”

时间:2014-06-26 10:43:05

标签: c++ openmp valgrind

我正在检查我的程序是否存在线程错误,并使用这个最简单的代码重现了我得到的helgrind错误:

int main() {

int num = 24;
#pragma omp parallel for firstprivate(num)
    for (int i= 0; i <num; ++i) {
        int test = 0;
    }
}

使用g++-4.7 -fopenmp -g test.cpp -o test

编译

这会产生300行错误&#34;可能的数据竞争&#34;。我在这里缺乏理解是什么?我做错了什么?

以下是错误日志的示例:

  1     ==11990== Helgrind, a thread error detector
  2     ==11990== Copyright (C) 2007-2013, and GNU GPL'd, by OpenWorks LLP et al.
  3     ==11990== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
  4     ==11990== Command: /home/windenergy/test
  5     ==11990== Parent PID: 10832
  6     ==11990==
  7
  8     parse_type_DIE: confused by:
  9      <2><197>: DW_TAG_typedef
 10          DW_AT_type        : <1f4>
 11
 12     --11990-- WARNING: Serious error when reading debug info
 13     --11990-- When reading debug info from /home/windenergy/test:
 14     --11990-- parse_type_DIE: confused by the above DIE
 15     ==11990== ---Thread-Announcement------------------------------------------
 16     ==11990==
 17     ==11990== Thread #1 is the program's root thread
 18     ==11990==
 19     ==11990== ---Thread-Announcement------------------------------------------
 20     ==11990==
 21     ==11990== Thread #24 was created
 22     ==11990==    at 0x5ACE05E: clone (in /lib64/libc-2.11.3.so)
 23     ==11990==    by 0x57DC990: do_clone (in /lib64/libpthread-2.11.3.so)
 24     ==11990==    by 0x57DCF77: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.11.3.so)
 25     ==11990==    by 0x4C2DB78: pthread_create_WRK (hg_intercepts.c:269)
 26     ==11990==    by 0x4C2DC89: pthread_create@* (hg_intercepts.c:300)
 27     ==11990==    by 0x53BA56D: ??? (in /usr/lib64/libgomp.so.1.0.0)
 28     ==11990==    by 0x400816: main (test.cpp:4)
 29     ==11990==
 30     ==11990== ----------------------------------------------------------------
 31     ==11990==
 32     ==11990== Possible data race during write of size 4 at 0x5F750C0 by thread #1
 33     ==11990== Locks held: none
 34     ==11990==    at 0x53BB85B: ??? (in /usr/lib64/libgomp.so.1.0.0)
 35     ==11990==    by 0x53BA5B0: ??? (in /usr/lib64/libgomp.so.1.0.0)
 36     ==11990==    by 0x400816: main (test.cpp:4)
 37     ==11990==
 38     ==11990== This conflicts with a previous read of size 4 by thread #24
 39     ==11990== Locks held: none
 40     ==11990==    at 0x53BB8C6: ??? (in /usr/lib64/libgomp.so.1.0.0)
 41     ==11990==    by 0x53BA0B8: ??? (in /usr/lib64/libgomp.so.1.0.0)
 42     ==11990==    by 0x4C2DD12: mythread_wrapper (hg_intercepts.c:233)
 43     ==11990==    by 0x57DD7F5: start_thread (in /lib64/libpthread-2.11.3.so)
 44     ==11990==    by 0x5ACE09C: clone (in /lib64/libc-2.11.3.so)
 45     ==11990==
 46     ==11990== Address 0x5F750C0 is 128 bytes inside a block of size 192 alloc'd
 47     ==11990==    at 0x4C2819E: malloc (vg_replace_malloc.c:291)
 48     ==11990==    by 0x53B6038: ??? (in /usr/lib64/libgomp.so.1.0.0)
 49     ==11990==    by 0x53BA7DF: ??? (in /usr/lib64/libgomp.so.1.0.0)
 50     ==11990==    by 0x400816: main (test.cpp:4)
 51     ==11990==
 52     ==11990== ----------------------------------------------------------------
 53     ==11990==
 54     ==11990== Possible data race during write of size 4 at 0x5F75084 by thread #1
 55     ==11990== Locks held: none
 56     ==11990==    at 0x53BB869: ??? (in /usr/lib64/libgomp.so.1.0.0)
 57     ==11990==    by 0x53BA5B0: ??? (in /usr/lib64/libgomp.so.1.0.0)
 58     ==11990==    by 0x400816: main (test.cpp:4)
 59     ==11990==
 60     ==11990== This conflicts with a previous read of size 4 by thread #24
 61     ==11990== Locks held: none
 62     ==11990==    at 0x53BB8C0: ??? (in /usr/lib64/libgomp.so.1.0.0)
 63     ==11990==    by 0x53BA0B8: ??? (in /usr/lib64/libgomp.so.1.0.0)
 64     ==11990==    by 0x4C2DD12: mythread_wrapper (hg_intercepts.c:233)
 65     ==11990==    by 0x57DD7F5: start_thread (in /lib64/libpthread-2.11.3.so)
 66     ==11990==    by 0x5ACE09C: clone (in /lib64/libc-2.11.3.so)
 67     ==11990==
 68     ==11990== Address 0x5F75084 is 68 bytes inside a block of size 192 alloc'd
 69     ==11990==    at 0x4C2819E: malloc (vg_replace_malloc.c:291)
 70     ==11990==    by 0x53B6038: ??? (in /usr/lib64/libgomp.so.1.0.0)
 71     ==11990==    by 0x53BA7DF: ??? (in /usr/lib64/libgomp.so.1.0.0)
 72     ==11990==    by 0x400816: main (test.cpp:4)
 73     ==11990==

0 个答案:

没有答案