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

Rajeev Thakur thakur at mcs.anl.gov
Sun May 27 14:15:59 CDT 2007


MPI_Finalize does not deallocate user-created objects. 

MPI_Finalized is an MPI-2 function. There is no equivalent in MPI-1.2. But
in practice, this may not be a problem as most implementation support at
least some MPI-2 functions, and hence may support MPI_Finalized.

Rajeev
 

> -----Original Message-----
> From: owner-mpich-discuss at mcs.anl.gov 
> [mailto:owner-mpich-discuss at mcs.anl.gov] On Behalf Of Martin 
> Schwinzerl
> Sent: Sunday, May 27, 2007 3:51 AM
> To: mpich-discuss at mcs.anl.gov
> Subject: [MPICH] Freeing Userdefined resources (Datatypes, 
> Communicators, ... ) properly with C++
> 
> 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