13 #ifndef DUNE_COMMON_PARALLEL_MPIGUARD_HH 14 #define DUNE_COMMON_PARALLEL_MPIGUARD_HH 33 struct GuardCommunicator
36 virtual ~GuardCommunicator() {};
38 virtual int rank() = 0;
39 virtual int size() = 0;
40 virtual int sum(
int i) = 0;
43 static GuardCommunicator * create(
const Communication<C> & c);
46 static GuardCommunicator * create(
const MPI_Comm & c);
56 struct GenericGuardCommunicator
57 :
public GuardCommunicator
61 struct GenericGuardCommunicator< Communication<T> >
62 :
public GuardCommunicator
64 const Communication<T> comm;
65 GenericGuardCommunicator(
const Communication<T> & c) :
67 int rank()
override {
return comm.rank(); };
68 int size()
override {
return comm.size(); };
69 int sum(
int i)
override {
return comm.sum(
i); }
75 struct GenericGuardCommunicator<MPI_Comm>
76 :
public GenericGuardCommunicator< Communication<MPI_Comm> >
78 GenericGuardCommunicator(
const MPI_Comm & c) :
79 GenericGuardCommunicator< Communication<MPI_Comm> >(
80 Communication<MPI_Comm>(c)) {}
86 GuardCommunicator * GuardCommunicator::create(
const Communication<C> & comm)
88 return new GenericGuardCommunicator< Communication<C> >(comm);
92 GuardCommunicator * GuardCommunicator::create(
const MPI_Comm & comm)
94 return new GenericGuardCommunicator< Communication<MPI_Comm> >(comm);
139 GuardCommunicator * comm_;
151 comm_(GuardCommunicator::create(
162 comm_(GuardCommunicator::create(
163 m.getCommunication())),
179 comm_(GuardCommunicator::create(comm)),
184 MPIGuard (
const MPI_Comm & comm,
bool active=
true) :
185 comm_(GuardCommunicator::create(comm)),
224 int result = success ? 0 : 1;
225 bool was_active = active_;
227 result = comm_->sum(result);
228 if (result>0 && was_active)
231 << comm_->rank() <<
" due to " 232 << result <<
" remote error(s)");
239 #endif // DUNE_COMMON_PARALLEL_MPIGUARD_HH void finalize(bool success=true)
stop the guard.
Definition: mpiguard.hh:222
Default exception if an error in the parallel communication of the program occurred.
Definition: exceptions.hh:381
Helpers for dealing with MPI.
Implements an utility class that provides MPI's collective communication methods. ...
MPIGuard(MPIHelper &m, bool active=true)
create an MPIGuard operating on the Communicator of a special Dune::MPIHelper m
Definition: mpiguard.hh:161
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
MPIGuard(bool active=true)
create an MPIGuard operating on the Communicator of the global Dune::MPIHelper
Definition: mpiguard.hh:150
I i
Definition: hybridmultiindex.hh:328
detects a thrown exception and communicates to all other processes
Definition: mpiguard.hh:137
Dune namespace
Definition: alignedallocator.hh:12
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
A real mpi helper.This helper should be used for parallel programs.
Definition: mpihelper.hh:168
void reactivate()
reactivate the guard.
Definition: mpiguard.hh:206
A few common exception classes.
~MPIGuard()
destroy the guard and check for undetected exceptions
Definition: mpiguard.hh:192
This exception is thrown if the MPIGuard detects an error on a remote process.
Definition: mpiguard.hh:103
MPIGuard(const C &comm, bool active=true)
create an MPIGuard operating on an arbitrary communicator.
Definition: mpiguard.hh:178
Implements an utility class that provides collective communication methods for sequential programs...
MPIGuard(const MPI_Comm &comm, bool active=true)
Definition: mpiguard.hh:184