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)");
214 #endif // DUNE_COMMON_MPIGUARD_HH
MPIGuard(bool active=true)
create an MPIGuard operating on the Communicator of the global Dune::MPIHelper
Definition: parallel/mpiguard.hh:132
char c
Definition: alignment.hh:37
Implements an utility class that provides collective communication methods for sequential programs...
A few common exception classes.
A real mpi helper.This helper should be used for parallel programs.
Definition: parallel/mpihelper.hh:160
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: parallel/mpiguard.hh:143
This exception is thrown if the MPIGuard detects an error on a remote process.
Definition: parallel/mpiguard.hh:85
~MPIGuard()
destroy the guard and check for undetected exceptions
Definition: parallel/mpiguard.hh:167
MPIGuard(const C &comm, bool active=true)
create an MPIGuard operating on an arbitrary communicator.
Definition: parallel/mpiguard.hh:160
Helpers for dealing with MPI.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
void reactivate()
reactivate the guard.
Definition: parallel/mpiguard.hh:181
Default exception if an error in the parallel communication of the programm occured.
Definition: exceptions.hh:313
detects a thrown exception and communicates to all other processes
Definition: parallel/mpiguard.hh:119
void finalize(bool success=true)
stop the guard.
Definition: parallel/mpiguard.hh:197