[Dune] MPIHelper.

Markus Blatt Markus.Blatt at ipvs.uni-stuttgart.de
Wed Sep 27 15:27:53 CEST 2006


On Wed, Sep 27, 2006 at 11:53:42AM +0200, Christian Engwer wrote:
> 
> > I took another look at the MPI standard and I think we can even do it
> > without a singleton at all.
> > There is the function MPI_Initialized which can be called before
> > MPI_Init to see whether MPI is already inititialized. Instead of the
> > singleton one could just check the result of this function and call
> > MPI_Init to initialize MPI if it was not initialized already.
> > Once the scope of MPIHelper ends MPI_Finalized will be called.
> 
> If MPIHelper is not a singleton, then it is possible to instatiate
> several MPIHelper objects. You could destroy one object, ad keep the
> others, which would mean, that you call MPI_Finalize in the destroyed
> object and can still use the other objects afterwards, although MPI is
> not available anymore.
> 

This situation is possible if you use new to allocate the objects,
like this:

int main(int i, char** v)
    MPIHelper* env=new MPIHelper(&argv,&arc); //Calls MPI_Init
    MPIHelper* env1= new MPIHelper(&argv,&arc); // DOes not call
						//    MPI_Init

    // parallel code

    delete env; //calls MPI_Finalize
    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Invalid as MPI_Finalized
                                          // was already called.

}

Lets be honest: Nobody will use new here if the documentation does not
say so.

The only problem might be if somebody creates singletons who do mpi
calls in their destructor. That would be invalid in my scenario. 

But even with a singleton one would have to make sure that the custom
singleton gets deallocated before the MPIHelper singleton. Does one
have control over this?

Markus





More information about the Dune mailing list