MPI memory leak

I write code that uses MPI and I continued to notice memory leaks when starting with valgrind. Trying to determine what the problem is, I ended up with this simple (and completely useless) core:

#include "/usr/include/mpi/mpi.h" int main(int argc,char** argv) { MPI_Init(&argc, &argv); MPI_Finalize(); return 0; } 

As you can see, this code does nothing and should not cause any problems. However, when I run the code with valgrind (in both serial and parallel cases), I get the following summary:

== 28271 == HEAP SUMMARY:

== 28271 == used on exit: 190 826 bytes in 2745 blocks

== 28271 == total heap usage: 11,214 allocs, 8,469 frees, 16,487,977 bytes allocated

== 28271 ==

== 28271 == CONTENTS:

== 28271 == definitely lost: 5,950 bytes in 55 blocks

== 28271 == indirectly lost: 3,562 bytes in 32 blocks

== 28271 == possibly lost: 0 bytes in 0 blocks

== 28271 == still available: 181.314 bytes in 2.658 blocks

== 28271 == suppressed: 0 bytes in 0 blocks

I do not understand why there are these leaks. Maybe I just couldn't read the output of valgrind or use MPI initialization / termination correctly ...

I am using OMPI 1.4.1-3 under ubuntu in 64bit architecture if this can help.

Thanks so much for your time!

+4
source share
2 answers

You are not doing anything wrong. Memcheck false alarms with valgrind are common, the best you can do is to suppress them.

This manual page talks more about these false positives. Quote near the end:

Wrappers should reduce the frequency of false Memcheck errors on MPI Applications. Since the wrapper runs on the MPI interface, there will still potentially be a large number of errors that are reported in the MPI implementation below the interface. The best you can do is try to suppress them.

+8
source

OpenMPI FAQs solve this problem: http://www.open-mpi.org/faq/?category=debugging#valgrind_clean

There are many situations where Open MPI does not intentionally initialize and subsequently report memory, for example, by calling writev. In addition, there are several cases where memory is not correctly freed from MPI_Finalize.

This, of course, does not help distinguish real errors from false positives. Valgrind provides functionality to suppress errors and warnings from specific function contexts.

In an attempt to facilitate debugging with Valgrind, starting with version 1.5, Open MPI provides a so-called Valgrind suppression file, which can be passed on the command line:

 mpirun -np 2 valgrind --suppressions=$PREFIX/share/openmpi/openmpi-valgrind.supp 
+6
source

Source: https://habr.com/ru/post/1385851/


All Articles