Valgrind汇总意味着什么?

时间:2015-12-27 16:04:17

标签: segmentation-fault fortran openmp valgrind

我用Valgrind运行我的fortran代码,这是摘要:

==7966== HEAP SUMMARY:
==7966==     in use at exit: 13,254 bytes in 19 blocks
==7966==   total heap usage: 340 allocs, 321 frees, 75,007 bytes allocated
==7966== 
==7966== LEAK SUMMARY:
==7966==    definitely lost: 0 bytes in 0 blocks
==7966==    indirectly lost: 0 bytes in 0 blocks
==7966==      possibly lost: 0 bytes in 0 blocks
==7966==    still reachable: 13,254 bytes in 19 blocks
==7966==         suppressed: 0 bytes in 0 blocks
==7966== Reachable blocks (those to which a pointer was found) are not shown.
==7966== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==7966== 
==7966== For counts of detected and suppressed errors, rerun with: -v
==7966== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

1。一切都好吗?

  1. ==7966== total heap usage: 340 allocs, 321 frees, 75,007 bytes allocated
  2. 这意味着一些记忆没有被解除分配?我的所有变量都是静态的。

    1. 我的串行代码运行良好,但是当我使其与OpenMP并行时,对于大数据,segmentation fault会发生。这些记忆可能导致这个问题吗?
    2. 编辑:我用

      运行代码
      valgrind --leak-check=yes ./a.out
      

      这是摘要:

      ==9825== Conditional jump or move depends on uninitialised value(s)
      ==9825==    at 0x41630D9: log (w_log.c:28)
      ==9825==    by 0x804D052: MAIN__ (main.f90:225)
      ==9825==    by 0x804D128: main (main.f90:231)
      ==9825== 
      ==9825== Conditional jump or move depends on uninitialised value(s)
      ==9825==    at 0x4158E88: __ieee754_log (e_log.S:16)
      ==9825==    by 0x41630EF: log (w_log.c:42)
      ==9825==    by 0x804D052: MAIN__ (main.f90:225)
      ==9825==    by 0x804D128: main (main.f90:231)
      ==9825== 
      ==9825== HEAP SUMMARY:
      ==9825==     in use at exit: 0 bytes in 0 blocks
      ==9825==   total heap usage: 12,023 allocs, 12,023 frees, 96,007,152 bytes allocated
      ==9825== 
      ==9825== All heap blocks were freed -- no leaks are possible
      ==9825== 
      ==9825== For counts of detected and suppressed errors, rerun with: -v
      ==9825== Use --track-origins=yes to see where uninitialised values come from
      ==9825== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
      

      我找不到问题,这就是第225行

             free_energy(d) = -log(abs(correlation_fun(d)))
      

2 个答案:

答案 0 :(得分:5)

问题是未初始化变量的用法。你必须找出它是哪一个,并确保它有一个有意义的价值。 如果没有完整的代码,就无法再说了。很可能d的值没有被正确定义。

仍然可以访问的内存通常正常。那是泄漏。通常,这些是您可以解除分配的可分配变量。它们可能位于模块中或主程序中,也可能在其他任何地方声明为save。程序完成后,它们不会自动解除分配,通常不会出现问题。

导致问题的真正的内存泄漏是当你丢失指向某个内存的指针然后你无法解除分配它。如果反复这样做,可能会浪费大量内存。然而,在valgrind看起来不同。然后,您会看到definitely lostindirectly lostpossibly lost

答案 1 :(得分:2)

  1. 你正在根据这一行泄漏内存:== 7966 ==仍然可以访问:19个块中的13,254个字节

  2. 尝试使用--leak-check = full --show-leak-kinds =全部按照建议重新运行,并使用编译标志进行编译以跟踪哪些变量被泄露。即使变量是静态的,如果它们是堆分配的,它们仍会泄漏内存。

  3. 分段错误最好用gdb调试,但这种内存泄漏可能会导致错误。