[Dune] MPI Handling in dgfparser

Markus Blatt mblatt at hal.iwr.uni-heidelberg.de
Sun Jul 16 16:19:04 CEST 2006


On Sun, Jul 16, 2006 at 08:29:40AM +0200, Peter Bastian wrote:
> Andreas Dedner wrote:
> >
> >Thimo Neubauer wrote:
> >>How about wrapping the MPI-startup in a helper class? This would allow
> >>for something as easy to write as the first pattern (and without any
> >>defines):
> >>
> >>  MPIHelper mpihelper;
> >>
> >>  grid("name", mpihelper::MPI_COMM_WORLD);
> >>  // or grid("name", mpihelper)
> >>  
> >

I think your are missing some important thing here:

We have to call MPI_Init with the arguments int argc and char** argv
to initialize mpi. So the user has to write:

MPIHelper mpihelper(argc, argv);

This is not very much different from initializing MPI the normal way,
but should still be convenient enough I guess.

> This is a nice solution! Some questions:
> 
> - Is there a different helper class for each grid then? (It should be).
> 

Why should there be a different class for each grid? IMHO there should
be no difference in initializing MPI for the grids. Or are there
different requirements?

> - Why can't these be singletons, this would remove the burden of MPI 
> initialization from the user altogether. On the other hand several grids 
> might use MPI, then only one needs to initialize it (Which is also a 
> problem of the solution above, BTW).

Regarding having only one MPIHelper, this should be a singleton, of
course. The user would have to call

MPIHelper helper = MPIHelper::instance(argc, argv);

as pointed out above before using any MPI. 

Still this can lead to funny situations in a program, as the variable
might go out off scope (and MPI_Finalize might be called). Or a funny
user might think of using the MPIHelper in to different nonoverlapping
blocks then MPI_Init might be called again after MPI_Finalize:

int main(int argc, char** argv){
    {
      MPIHelper h = MPIHelper::instance(argc, argv);
      // Maybe use YaspGrid here
    }
    // MPI_Finalize was called, so the next block will never run!
    {
      MPIHelper h = MPIHelper::instance(argc, argv);
      // Maybe use AluGrid here
    }
}

Or maybe the user just calls MPIHelper::instance without storing
it. Then the programm does nothing.

It still seems not to lift all the parallel burden from the users
shoulders.

Still it is a nice trick to use a parallel grid sequentially in a
parallel programm (Which might usefull for calculating an inverse
problem by calculating one realization on each process.

Markus





More information about the Dune mailing list