[MPICH] Freeing Userdefined resources (Datatypes, Communicators, ... ) properly with C++

Martin Schwinzerl martin.schwinzerl at stud.uni-graz.at
Sun May 27 03:51:28 CDT 2007


Dear all!

I have a rather stupid question regarding the clean automated free-ing of
resources like Communicators, Datatypes, Groups, etc. in C++.

Currently, I manually Free() all allocated resources prior to calling
MPI::Finalize(), e.g.

MPI::Datatype someType = ...
MPI::Intracomm someComm = ....

// do something

someType.Free();
someComm.Free();
MPI::Finalize();


, since - if I have interpreted the MPI-2 standard correctly - the
destructors of the
intrinsic MPI classes are *not* called automatically, if the Resource
handle goes out
of scope. My first question is, whether the MPI-2 and
MPI-1.2 standards and/or the corresponding MPICH implementations
deallocate the
ressources automatically, once  MPI::Finalize() is called ( I have not
been able to
find this information in the official reports to this standards, in case
I overlooked it,
I would be very grateful for any pointers to this information).

I'm currently building a library from some of my programs and would like
to introduce
a RAII (Resource Allocation Is Initialisation) approach for
encapsulating the
resource management into my classes. At the moment, the best way of
automating
the deallocation of said resources I was able to come up with in MPI-2 is a

if( !MPI::Is_finalized() )
{
    this->m_resourceHandle.Free();
}

in the destructor. If it turns out, that MPI::Finalize() is not
responsible for cleaning up
all present resources, then this approach is prone to introduce resource
leaks.
If I - OTOH - call the .Free() method regardless of the
MPI::Is_finalized() result,
then I get an annoying error message, that tells me to not call MPI commands
after MPI::Finalize(). Moreover, if I'm not mistaken, then
MPI::Is_finalized() is
an exclusive MPI-2 commando. Are there any proven ways to fetch the status
in MPI-1.2 ?

Best Regards

Martin




More information about the mpich-discuss mailing list