【发布时间】:2019-11-27 12:26:13
【问题描述】:
我使用valgrind 运行一个可执行文件。可执行文件是用 C 语言编写的,它调用一个包含 Fortran 代码并使用 MPI (MPICH) 的大型数字 C 库。
$ valgrind --leak-check=full --show-leak-kinds=all ./ex1
==13877== Memcheck, a memory error detector
==13877== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==13877== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==13877== Command: ./ex1
==13877==
==13877==
==13877== HEAP SUMMARY:
==13877== in use at exit: 0 bytes in 0 blocks
==13877== total heap usage: 2,057 allocs, 2,046 frees, 4,812,368 bytes allocated
==13877==
==13877== All heap blocks were freed -- no leaks are possible
==13877==
==13877== For counts of detected and suppressed errors, rerun with: -v
==13877== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
请注意,在堆摘要中,分配的次数多于释放的次数,但没有报告泄漏(甚至“仍然可访问”的泄漏)。我不明白这怎么可能。 这是不一致的输出,还是有合法的机制可以产生这种情况?
使用-v 运行会给出包含此警告的输出:
==14266== WARNING: new redirection conflicts with existing -- ignoring it
--14266-- old: 0x0401f2f0 (strlen ) R-> (0000.0) 0x58060901 ???
--14266-- new: 0x0401f2f0 (strlen ) R-> (2007.0) 0x04c32db0 strlen
【问题讨论】:
-
也许
realloc()算作一个分配(而您的运行有 11 个重新分配)? -
这不是我所期望的,天真。这显示了 2 个分配和 2 个释放:
printf "#include <stdlib.h>\n int main(){int* a = malloc(10); int* b = realloc(a,20); free(b);}" > t.c && gcc -O0 t.c && valgrind ./a.out -
这个问题与 MPI 有什么关系?
-
它正在运行一个依赖于 MPI 的代码,因此可以想象 MPI 实现可能涉及此行为。
标签: c fortran mpi valgrind heap-memory