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)");
A few common exception classes.
Helpers for dealing with MPI.
Implements an utility class that provides MPI's collective communication methods.
Implements an utility class that provides collective communication methods for sequential programs.
#define DUNE_THROW(E, m)
Definition exceptions.hh:218
Dune namespace.
Definition alignedallocator.hh:13
Default exception if an error in the parallel communication of the program occurred.
Definition exceptions.hh:287
This exception is thrown if the MPIGuard detects an error on a remote process.
Definition mpiguard.hh:103
detects a thrown exception and communicates to all other processes
Definition mpiguard.hh:138
void reactivate()
reactivate the guard.
Definition mpiguard.hh:206
void finalize(bool success=true)
stop the guard.
Definition mpiguard.hh:222
~MPIGuard()
destroy the guard and check for undetected exceptions
Definition mpiguard.hh:192
MPIGuard(const C &comm, bool active=true)
create an MPIGuard operating on an arbitrary communicator.
Definition mpiguard.hh:178
MPIGuard(const MPI_Comm &comm, bool active=true)
Definition mpiguard.hh:184
MPIGuard(bool active=true)
create an MPIGuard operating on the Communicator of the global Dune::MPIHelper
Definition mpiguard.hh:150
MPIGuard(MPIHelper &m, bool active=true)
create an MPIGuard operating on the Communicator of a special Dune::MPIHelper m
Definition mpiguard.hh:161
A real mpi helper.
Definition mpihelper.hh:181