OpenMP已经失去了#34;来自valgrind

时间:2017-05-09 12:14:09

标签: c++ memory-leaks openmp valgrind

我很难尝试纠正一个简单的OpenMP循环,以避免错过"肯定丢失"来自valgrind的内存泄漏。如果没有OpenMP,Valgrind在激活OpenMP pragma时不会返回有问题的内存泄漏。以下是泄漏的简单矩阵分配示例:

  void assign(const Matrix& src, Matrix& dest) {
  int nr = src.rows();
  int nc = src.cols();
#pragma omp parallel for num_threads(NUM_THREADS) firstprivate(nr, nc) schedule(dynamic, 1)
  for (int32 c = 0 ; c < nc ; ++c) {
    for (int32 r = 0 ;  r < nr ; ++r)
      mat(r,c) = src(r,c);
  }

以下是泄漏细节:

==19732== 304 bytes in 1 blocks are definitely lost in loss record 8 of 11
==19732==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==19732==    by 0x40136D4: allocate_dtv (dl-tls.c:322)
==19732==    by 0x40136D4: _dl_allocate_tls (dl-tls.c:539)
==19732==    by 0x68A926E: allocate_stack (allocatestack.c:588)
==19732==    by 0x68A926E: pthread_create@@GLIBC_2.2.5 (pthread_create.c:539)
==19732==    by 0x647899F: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==19732==    by 0x6474CB9: GOMP_parallel (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==19732==    by 0x43BF6D: void assign(Matrix const&, Matrix&) (assign.h:267)
==19732==    by 0x43BB30: Matrix::Matrix(Matrix const&) (matrix.h:1351)
==19732==    by 0x43A451: DistanceTest::read_matrix(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (test_distance.cpp:85)
==19732==    by 0x43A702: DistanceTest::read_data() (test_distance.cpp:106)
==19732==    by 0x43DE10: test::ABTest::Run(int) (ab_test.cpp:44)

这是一个巨大的交易,有一个&#34;绝对丢失&#34;因为OpenMP?是因为我的编写写作中的坏习惯,还是因为Valgrind研究OpenMP框架的困难?

0 个答案:

没有答案