13#ifndef DUNE_COMMON_MPIGUARD_HH
14#define DUNE_COMMON_MPIGUARD_HH
29 struct GuardCommunicator
32 virtual ~GuardCommunicator() {};
34 virtual int rank() = 0;
35 virtual int size() = 0;
36 virtual int sum(
int i) = 0;
39 static GuardCommunicator * create(
const Communication<C> & c);
42 static GuardCommunicator * create(
const MPI_Comm & c);
52 struct GenericGuardCommunicator
53 :
public GuardCommunicator
57 struct GenericGuardCommunicator< Communication<T> >
58 :
public GuardCommunicator
60 const Communication<T> comm;
61 GenericGuardCommunicator(
const Communication<T> & c) :
63 int rank()
override {
return comm.rank(); };
64 int size()
override {
return comm.size(); };
65 int sum(
int i)
override {
return comm.sum(i); }
71 struct GenericGuardCommunicator<MPI_Comm>
72 :
public GenericGuardCommunicator< Communication<MPI_Comm> >
74 GenericGuardCommunicator(
const MPI_Comm & c) :
75 GenericGuardCommunicator< Communication<MPI_Comm> >(
76 Communication<MPI_Comm>(c)) {}
82 GuardCommunicator * GuardCommunicator::create(
const Communication<C> & comm)
84 return new GenericGuardCommunicator< Communication<C> >(comm);
88 GuardCommunicator * GuardCommunicator::create(
const MPI_Comm & comm)
90 return new GenericGuardCommunicator< Communication<MPI_Comm> >(comm);
135 GuardCommunicator * comm_;
147 comm_(GuardCommunicator::create(
158 comm_(GuardCommunicator::create(
159 m.getCommunication())),
175 comm_(GuardCommunicator::create(comm)),
180 MPIGuard (
const MPI_Comm & comm,
bool active=
true) :
181 comm_(GuardCommunicator::create(comm)),
220 int result = success ? 0 : 1;
221 bool was_active = active_;
223 result = comm_->sum(result);
224 if (result>0 && was_active)
227 << comm_->rank() <<
" due to "
228 << result <<
" remote error(s)");
A few common exception classes.
Implements an utility class that provides collective communication methods for sequential programs.
Helpers for dealing with MPI.
Implements an utility class that provides MPI's collective communication methods.
#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:99
detects a thrown exception and communicates to all other processes
Definition mpiguard.hh:134
void reactivate()
reactivate the guard.
Definition mpiguard.hh:202
void finalize(bool success=true)
stop the guard.
Definition mpiguard.hh:218
~MPIGuard()
destroy the guard and check for undetected exceptions
Definition mpiguard.hh:188
MPIGuard(const C &comm, bool active=true)
create an MPIGuard operating on an arbitrary communicator.
Definition mpiguard.hh:174
MPIGuard(const MPI_Comm &comm, bool active=true)
Definition mpiguard.hh:180
MPIGuard(bool active=true)
create an MPIGuard operating on the Communicator of the global Dune::MPIHelper
Definition mpiguard.hh:146
MPIGuard(MPIHelper &m, bool active=true)
create an MPIGuard operating on the Communicator of a special Dune::MPIHelper m
Definition mpiguard.hh:157
A real mpi helper.
Definition mpihelper.hh:179