C++ mac OS X El Capitan上的openmp,Valgrind错误(数据竞赛)
C++ openmp on mac OS X El Capitan, Valgrind error (data race)
我在 mac 上用 opnemp 库C++测试一个简单的 helloword,通过终端使用以下两个命令:
/usr/local/bin/clang++-omp -fopenmp helloworld.cpp -o test
/usr/local/bin/valgrind --tool=helgrind --log-file=a.log ./test
输出正确:
warning: no debug symbols in executable (-arch x86_64)
Hello World from thread = 0
Hello World from thread = 1
Hello World from thread = 3
Hello World from thread = 2
Number of threads = 4
但日志文件 (a.log) 包含:"来自 231 个上下文的174986错误"(作为错误摘要)
下面是日志文件的一部分:
==643== ---Thread-Announcement------------------------------------------
==643==
==643== Thread #1 is the program's root thread
==643==
==643== ----------------------------------------------------------------
==643==
==643== Possible data race during read of size 4 at 0x10057C118 by thread #3
==643== Locks held: none
==643== at 0x10055D1F4: spin_lock (in /usr/lib/system/libsystem_platform.dylib)
==643== by 0x10057092D: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib)
==643== by 0x10056E384: thread_start (in /usr/lib/system/libsystem_pthread.dylib)
==643==
==643== This conflicts with a previous write of size 4 by thread #1
==643== Locks held: none
==643== at 0x10055D200: spin_unlock (in /usr/lib/system/libsystem_platform.dylib)
==643== by 0x1000434B0: __kmp_create_worker (in /usr/local/Cellar/libiomp/20150701/lib/libiomp5.dylib)
==643== by 0x100031E3D: __kmp_allocate_thread (in /usr/local/Cellar/libiomp/20150701/lib/libiomp5.dylib)
==643== by 0x10002E7A1: __kmp_allocate_team (in /usr/local/Cellar/libiomp/20150701/lib/libiomp5.dylib)
==643== by 0x10002FA2D: __kmp_fork_call (in /usr/local/Cellar/libiomp/20150701/lib/libiomp5.dylib)
==643== by 0x100027F0D: __kmpc_fork_call (in /usr/local/Cellar/libiomp/20150701/lib/libiomp5.dylib)
==643== by 0x100000CE8: main (in ./test)
==643== Address 0x10057c118 is in the Data segment of /usr/lib/system/libsystem_pthread.dylib
"helloworld"的代码是:
#include <stdio.h>
#include <libiomp/omp.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
int nthreads=4, tid;
#pragma omp parallel num_threads(nthreads) private(tid)
{
//Obtain thread number
tid = omp_get_thread_num();
printf("Hello World from thread = %dn", tid);
// Only master thread does this
if (tid == 0)
{
printf("Number of threads = %dn", nthreads);
}
}
return 0;
}
有没有人知道这些错误(数据竞赛)?我在这些线程之间没有共享数据。
这很可能是误报。例如,请参阅有关libgomp的同一问题的类似讨论。这也可能是 libiomp/pthread 实现中的实际问题,但这似乎不太可能。
你似乎无能为力。通常,如果堆栈的顶部位于库中,则它要么是库中的误报或错误,要么是滥用它(例如,在多线程的缓冲区上运行memcpy
)。
如果您的二进制文件位于堆栈的顶部,则更明显的是代码存在问题。
你的代码很好,可以解决数据竞争问题。
相关文章:
- 如何修复valgrind启动时的致命错误(与libc6-dbg和libc6-dbg:i386连接)
- 重载 new 和 delete 会导致 valgrind 错误
- 使用valgrind跟踪段错误,并了解valgrind输出
- 我如何理解我的Valgrind错误消息
- STD :: FPCLASSIFY的错误结果使用Valgrind进行长时间的双重双重结果
- Valgrind 错误和内存泄漏与 Python/C API
- 将TopoDS_Face对象分配给其子对象编译没有错误,但我有 3 个 valgrind 错误
- Opencl ClgetPlatFormids给出了约230个Valgrind Memcheck错误
- 为什么我会因Valgrind遇到内存错误?(C ,抽象语法树评估)
- valgrind错误无效读数4
- Valgrind 检查简单多线程 C++11 得到 SIG11 错误
- Valgrind 显示无效的读/写错误,但我不使用 new 或 calloc,只使用向量和固定数组
- C++ mac OS X El Capitan上的openmp,Valgrind错误(数据竞赛)
- Valgrind 错误:系统调用参数 epoll_pwait(sigmask) 指向不可寻址的字节
- Valgrind中的一些错误
- 使用 valgrind 时获得 int 变量指针的无效读取大小错误
- 使用 valgrind 的地图中的读取大小错误无效
- Valgrind内存泄漏和错误
- Valgrind 在构建时出现由 G++5 内联的错误 - Valgrind 或 G++5 中的错误
- 双重免费或腐败错误- valgrind