dune-common  2.2.0
Public Member Functions
Dune::MPIGuard Class Reference

detects a thrown exception and communicates to all other processes More...

#include <dune/common/mpiguard.hh>

List of all members.

Public Member Functions

 MPIGuard (bool active=true)
 create an MPIGuard operating on the Communicator of the global Dune::MPIHelper
 MPIGuard (MPIHelper &m, bool active=true)
 create an MPIGuard operating on the Communicator of a special Dune::MPIHelper m
template<class C >
 MPIGuard (const C &comm, bool active=true)
 create an MPIGuard operating on an arbitrary communicator.
 ~MPIGuard ()
 destroy the guard and check for undetected exceptions
void reactivate ()
 reactivate the guard.
void finalize (bool success=true)
 stop the guard.

Detailed Description

detects a thrown exception and communicates to all other processes

      {
         MPIGuard guard(...);
         
         do_something();

         // tell the guard that you successfully passed a critical operation
         guard.finalize();
         // reactivate the guard for the next critical operation
         guard.reactivate();
         
         int result = do_something_else();

         // tell the guard the result of your operation
         guard.finalize(result == success);
      }

You create a MPIGuard object. If an exception is risen on a process the MPIGuard detects the exception, because the finalize method was not called. when reaching the finalize call all other processes are informed that an error occured and the MPIGuard throws an exception of type MPIGuardError.

Note:
You can initialize the MPIGuard from different types of communication objects:

Constructor & Destructor Documentation

Dune::MPIGuard::MPIGuard ( bool  active = true) [inline]

create an MPIGuard operating on the Communicator of the global Dune::MPIHelper

Parameters:
activeshould the MPIGuard be active upon creation?
Dune::MPIGuard::MPIGuard ( MPIHelper m,
bool  active = true 
) [inline]

create an MPIGuard operating on the Communicator of a special Dune::MPIHelper m

Parameters:
ma reference to an MPIHelper
activeshould the MPIGuard be active upon creation?
template<class C >
Dune::MPIGuard::MPIGuard ( const C &  comm,
bool  active = true 
) [inline]

create an MPIGuard operating on an arbitrary communicator.

Supported types for the communication object are:

Parameters:
commreference to a communication object
activeshould the MPIGuard be active upon creation?

destroy the guard and check for undetected exceptions

References finalize().


Member Function Documentation

void Dune::MPIGuard::finalize ( bool  success = true) [inline]

stop the guard.

If no success parameter is passed, the guard assumes that everything worked as planned. All errors are communicated and an exception of type MPIGuardError is thrown if an error (or exception) occured on any of the processors in the communicator.

Parameters:
successinform the guard about possible errors

References DUNE_THROW.

Referenced by reactivate(), and ~MPIGuard().

void Dune::MPIGuard::reactivate ( ) [inline]

reactivate the guard.

If the guard is still active finalize(true) is called first.

References finalize().


The documentation for this class was generated from the following file: