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 C & c);
46 struct GenericGuardCommunicator
47 :
public GuardCommunicator
51 struct GenericGuardCommunicator< CollectiveCommunication<T> >
52 :
public GuardCommunicator
54 const CollectiveCommunication<T> comm;
55 GenericGuardCommunicator(
const CollectiveCommunication<T> & c) :
57 virtual int rank() {
return comm.rank(); };
58 virtual int size() {
return comm.size(); };
59 virtual int sum(
int i) {
return comm.sum(i); }
65 struct GenericGuardCommunicator<MPI_Comm>
66 :
public GenericGuardCommunicator< CollectiveCommunication<MPI_Comm> >
68 GenericGuardCommunicator(
const MPI_Comm & c) :
69 GenericGuardCommunicator< CollectiveCommunication<MPI_Comm> >(
70 CollectiveCommunication<MPI_Comm>(c)) {}
76 GuardCommunicator * GuardCommunicator::create(
const C & comm)
78 return new GenericGuardCommunicator<C>(comm);
121 GuardCommunicator * comm_;
133 comm_(GuardCommunicator::create(
134 MPIHelper::getCollectiveCommunication())),
144 comm_(GuardCommunicator::create(
145 m.getCollectiveCommunication())),
161 comm_(GuardCommunicator::create(comm)),
199 int result = success ? 0 : 1;
200 bool was_active = active_;
202 result = comm_->sum(result);
203 if (result>0 && was_active)
206 << comm_->rank() <<
" due to "
207 << result <<
" remote error(s)");
This exception is thrown if the MPIGuard detects an error on a remote process.
Definition: mpiguard.hh:85
detects a thrown exception and communicates to all other processes
Definition: mpiguard.hh:120
void reactivate()
reactivate the guard.
Definition: mpiguard.hh:181
void finalize(bool success=true)
stop the guard.
Definition: mpiguard.hh:197
~MPIGuard()
destroy the guard and check for undetected exceptions
Definition: mpiguard.hh:167
MPIGuard(const C &comm, bool active=true)
create an MPIGuard operating on an arbitrary communicator.
Definition: mpiguard.hh:160
MPIGuard(bool active=true)
create an MPIGuard operating on the Communicator of the global Dune::MPIHelper
Definition: mpiguard.hh:132
MPIGuard(MPIHelper &m, bool active=true)
create an MPIGuard operating on the Communicator of a special Dune::MPIHelper m
Definition: mpiguard.hh:143
A real mpi helper.
Definition: mpihelper.hh:160
Default exception if an error in the parallel communication of the programm occured.
Definition: exceptions.hh:312
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:243
Implements an utility class that provides MPI's collective communication methods.
Helpers for dealing with MPI.
Dune namespace.
Definition: alignment.hh:10