Valgrind报告了不同数量的分配和释放,但所有块均已释放

时间:2019-07-18 14:18:12

标签: c fortran mpi valgrind heap-memory

我使用valgrind运行可执行文件。该可执行文件是用C编写的,并调用了一个大型数字C库,其中包括Fortran代码并使用MPI(MPICH)。

$ 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

1 个答案:

答案 0 :(得分:0)

怀疑,这似乎是MPI实现MPICH的问题,provides custom logic to valgrind使用的是非标准堆分配过程。

特别是,可以使用简单的MPI程序重现该问题。

#include <mpi.h>
int main(int argc, char **argv)
{
    MPI_Init(&argc,&argv);
    MPI_Finalize();
}
==7291== Memcheck, a memory error detector
==7291== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==7291== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==7291== Command: ./a.out
==7291==
==7291==
==7291== HEAP SUMMARY:
==7291==     in use at exit: 0 bytes in 0 blocks
==7291==   total heap usage: 1,979 allocs, 1,974 frees, 4,720,483 bytes allocated
==7291==
==7291== All heap blocks were freed -- no leaks are possible
==7291==
==7291== For counts of detected and suppressed errors, rerun with: -v
==7291== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

这是使用配置为

的MPICH 3.1b1
$ ./configure --prefix=[REMOVED] MAKE=/usr/bin/make --libdir=[REMOVED] CC=gcc CFLAGS=-fPIC -fstack-protector -g -O3 AR=/usr/bin/ar ARFLAGS=cr CXX=g++ CXXFLAGS=-fstack-protector -g -O3 -fPIC F77=gfortran FFLAGS=-fPIC -ffree-line-length-0 -g -O3 FC=gfortran FCFLAGS=-fPIC -ffree-line-length-0 -g -O3 --enable-shared --with-device=ch3:sock --with-pm=hydra --enable-g=meminit