Hi, one of our projects recently exposed severe memory leakage when using ROMIO to write a complex derived datatype (a struct made of other structs) to a file. From our code we distilled the attached short program to reproduce the leak.
After some Valgrind sessions, it appears as if the memcpy in ompi_ddt_duplicate() is a bit overhasty, as it does copy the old type's reference counter, too. I don't know if this is the right way to fix it, but if I apply the patch below to ompi the leak is fixed. Cheers! -Andreas diff -ru openmpi-1.1.1/ompi/datatype/dt_create_dup.c openmpi-1.1.1-fixed/ompi/datatype/dt_create_dup.c --- openmpi-1.1.1/ompi/datatype/dt_create_dup.c 2006-06-14 21:56:41.000000000 +0200 +++ openmpi-1.1.1-fixed/ompi/datatype/dt_create_dup.c 2006-11-13 00:35:03.000000000 +0100 @@ -33,6 +33,7 @@ int32_t old_index = pdt->d_f_to_c_index; memcpy( pdt, oldType, sizeof(ompi_datatype_t) ); + ((opal_object_t *)pdt)->obj_reference_count = 1; pdt->desc.desc = temp; pdt->flags &= (~DT_FLAG_PREDEFINED); /* ompi_ddt_create() creates a new f_to_c index that was saved
#include <mpi.h> int main(int argc, char* argv[]) { MPI::Init(); MPI::File file; char buf[1024]; file = MPI::File::Open(MPI::COMM_WORLD, "/tmp/memleak", MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI::INFO_NULL); // create a struct consisting of a derived datatype MPI::Aint displacementsAlpha[] = {0}; MPI::Datatype memberTypesAlpha[] = {MPI::INT}; int lengthsAlpha[] = {1}; MPI::Datatype structAlpha = MPI::Datatype::Create_struct(1, lengthsAlpha, displacementsAlpha, memberTypesAlpha); structAlpha.Commit(); MPI::Aint displacementsBravo[] = {0}; MPI::Datatype memberTypesBravo[] = {structAlpha}; int lengthsBravo[] = {1}; MPI::Datatype structBravo = MPI::Datatype::Create_struct(1, lengthsBravo, displacementsBravo, memberTypesBravo); structBravo.Commit(); // this will leak like hell for (;;) file.Write(buf, 1, structBravo); file.Close(); MPI::Finalize(); }
pgpY_HC0Jh6nI.pgp
Description: PGP signature