11 #ifndef DUNE_COMMON_MPIGUARD_HH
12 #define DUNE_COMMON_MPIGUARD_HH
27 struct GuardCommunicator
30 virtual ~GuardCommunicator() {};
32 virtual int rank() = 0;
33 virtual int size() = 0;
34 virtual int sum(
int i) = 0;
37 static GuardCommunicator * create(
const CollectiveCommunication<C> & c);
40 static GuardCommunicator * create(
const MPI_Comm & c);
50 struct GenericGuardCommunicator
51 :
public GuardCommunicator
55 struct GenericGuardCommunicator< Communication<T> >
56 :
public GuardCommunicator
58 const Communication<T> comm;
59 GenericGuardCommunicator(
const Communication<T> & c) :
61 int rank()
override {
return comm.rank(); };
62 int size()
override {
return comm.size(); };
63 int sum(
int i)
override {
return comm.sum(i); }
69 struct GenericGuardCommunicator<MPI_Comm>
70 :
public GenericGuardCommunicator< Communication<MPI_Comm> >
72 GenericGuardCommunicator(
const MPI_Comm & c) :
73 GenericGuardCommunicator< Communication<MPI_Comm> >(
74 Communication<MPI_Comm>(c)) {}
80 GuardCommunicator * GuardCommunicator::create(
const CollectiveCommunication<C> & comm)
82 return new GenericGuardCommunicator< CollectiveCommunication<C> >(comm);
86 GuardCommunicator * GuardCommunicator::create(
const MPI_Comm & comm)
88 return new GenericGuardCommunicator< CollectiveCommunication<MPI_Comm> >(comm);
133 GuardCommunicator * comm_;
145 comm_(GuardCommunicator::create(
156 comm_(GuardCommunicator::create(
157 m.getCommunication())),
173 comm_(GuardCommunicator::create(comm)),
178 MPIGuard (
const MPI_Comm & comm,
bool active=
true) :
179 comm_(GuardCommunicator::create(comm)),
218 int result = success ? 0 : 1;
219 bool was_active = active_;
221 result = comm_->sum(result);
222 if (result>0 && was_active)
225 << comm_->rank() <<
" due to "
226 << result <<
" remote error(s)");
A few common exception classes.
Implements an utility class that provides collective communication methods for sequential programs.
Implements an utility class that provides MPI's collective communication methods.
Helpers for dealing with MPI.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:14
Default exception if an error in the parallel communication of the program occurred.
Definition: exceptions.hh:285
This exception is thrown if the MPIGuard detects an error on a remote process.
Definition: mpiguard.hh:97
detects a thrown exception and communicates to all other processes
Definition: mpiguard.hh:132
void reactivate()
reactivate the guard.
Definition: mpiguard.hh:200
void finalize(bool success=true)
stop the guard.
Definition: mpiguard.hh:216
~MPIGuard()
destroy the guard and check for undetected exceptions
Definition: mpiguard.hh:186
MPIGuard(const C &comm, bool active=true)
create an MPIGuard operating on an arbitrary communicator.
Definition: mpiguard.hh:172
MPIGuard(const MPI_Comm &comm, bool active=true)
Definition: mpiguard.hh:178
MPIGuard(bool active=true)
create an MPIGuard operating on the Communicator of the global Dune::MPIHelper
Definition: mpiguard.hh:144
MPIGuard(MPIHelper &m, bool active=true)
create an MPIGuard operating on the Communicator of a special Dune::MPIHelper m
Definition: mpiguard.hh:155
A real mpi helper.
Definition: mpihelper.hh:169