问题描述
我正在编写一些使用MPI的代码,并且一直在用valgrind运行它时注意到一些内存泄漏.在尝试确定问题出在哪里时,我最终得到了一个简单(完全没用)的主程序:
I am writing some code that uses MPI and I was keeping noticing some memory leaks when running it with valgrind. While trying to identify where the problem was, I ended up with this simple (and totally useless) main:
#include "/usr/include/mpi/mpi.h"
int main(int argc,char** argv)
{
MPI_Init(&argc, &argv);
MPI_Finalize();
return 0;
}
如您所见,此代码不执行任何操作,也不应该造成任何问题.但是,当我使用valgrind(在串行和并行情况下)运行代码时,会得到以下摘要:
As you can see, this code doesn't do anything and shouldn't create any problem. However, when I run the code with valgrind (both in the serial and parallel case), I get the following summary:
== 28271 ==在出口使用:2,745个块中的190,826字节
==28271== in use at exit: 190,826 bytes in 2,745 blocks
== 28271 ==堆总使用量:11,214个分配,8,469个空闲,16,487,977个字节分配
==28271== total heap usage: 11,214 allocs, 8,469 frees, 16,487,977 bytes allocated
== 28271 ==
==28271==
== 28271 ==泄漏摘要:
==28271== LEAK SUMMARY:
== 28271 ==绝对丢失:55个块中的5,950字节
==28271== definitely lost: 5,950 bytes in 55 blocks
== 28271 ==间接丢失:32个块中的3,562字节
==28271== indirectly lost: 3,562 bytes in 32 blocks
== 28271 ==可能丢失:0字节,位于0块中
==28271== possibly lost: 0 bytes in 0 blocks
== 28271 ==仍然可以访问:2,658个块中的181,314字节
==28271== still reachable: 181,314 bytes in 2,658 blocks
== 28271 ==已抑制:0字节,分为0个块
==28271== suppressed: 0 bytes in 0 blocks
我不明白为什么会有这些泄漏.也许只是我无法读取valgrind输出或无法正确使用MPI初始化/完成...
I don't understand why there are these leaks. Maybe it's just me not able to read the valgrind output or to use MPI initialization/finalization correctly...
如果有帮助,我正在ubuntu下的64位架构上使用OMPI 1.4.1-3.
I am using OMPI 1.4.1-3 under ubuntu on a 64 bit architecture, if this can help.
非常感谢您的时间!
推荐答案
您没有做错任何事情.带有valgrind的Memcheck误报很常见,最好的办法就是抑制它们.
You're not doing anything wrong. Memcheck false positives with valgrind are common, the best you can do is suppress them.
手册的本页详细介绍这些误报.末尾的报价:
This page of the manual speaks more about these false positives. A quote near the end:
这篇关于MPI内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!