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);
39 static GuardCommunicator * create(
const MPI_Comm & c);
49 struct GenericGuardCommunicator
50 :
public GuardCommunicator
54 struct GenericGuardCommunicator< Communication<T> >
55 :
public GuardCommunicator
57 const Communication<T> comm;
58 GenericGuardCommunicator(
const Communication<T> & c) :
60 int rank()
override {
return comm.rank(); };
61 int size()
override {
return comm.size(); };
62 int sum(
int i)
override {
return comm.sum(i); }
68 struct GenericGuardCommunicator<MPI_Comm>
69 :
public GenericGuardCommunicator< Communication<MPI_Comm> >
71 GenericGuardCommunicator(
const MPI_Comm & c) :
72 GenericGuardCommunicator< Communication<MPI_Comm> >(
73 Communication<MPI_Comm>(c)) {}
79 GuardCommunicator * GuardCommunicator::create(
const CollectiveCommunication<C> & comm)
81 return new GenericGuardCommunicator< CollectiveCommunication<C> >(comm);
85 GuardCommunicator * GuardCommunicator::create(
const MPI_Comm & comm)
87 return new GenericGuardCommunicator< CollectiveCommunication<MPI_Comm> >(comm);
132 GuardCommunicator * comm_;
144 comm_(GuardCommunicator::create(
155 comm_(GuardCommunicator::create(
156 m.getCommunication())),
172 comm_(GuardCommunicator::create(comm)),
177 MPIGuard (
const MPI_Comm & comm,
bool active=
true) :
178 comm_(GuardCommunicator::create(comm)),
217 int result = success ? 0 : 1;
218 bool was_active = active_;
220 result = comm_->sum(result);
221 if (result>0 && was_active)
224 << comm_->rank() <<
" due to "
225 << result <<
" remote error(s)");
This exception is thrown if the MPIGuard detects an error on a remote process.
Definition: mpiguard.hh:96
detects a thrown exception and communicates to all other processes
Definition: mpiguard.hh:131
void reactivate()
reactivate the guard.
Definition: mpiguard.hh:199
void finalize(bool success=true)
stop the guard.
Definition: mpiguard.hh:215
~MPIGuard()
destroy the guard and check for undetected exceptions
Definition: mpiguard.hh:185
MPIGuard(const C &comm, bool active=true)
create an MPIGuard operating on an arbitrary communicator.
Definition: mpiguard.hh:171
MPIGuard(bool active=true)
create an MPIGuard operating on the Communicator of the global Dune::MPIHelper
Definition: mpiguard.hh:143
MPIGuard(MPIHelper &m, bool active=true)
create an MPIGuard operating on the Communicator of a special Dune::MPIHelper m
Definition: mpiguard.hh:154
A real mpi helper.
Definition: mpihelper.hh:169
Default exception if an error in the parallel communication of the program occurred.
Definition: exceptions.hh:285
Implements an utility class that provides collective communication methods for sequential programs.
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Implements an utility class that provides MPI's collective communication methods.
Helpers for dealing with MPI.
Dune namespace.
Definition: alignedallocator.hh:14