5#ifndef DUNE_COMMON_PARALLEL_MPIHELPER_HH
6#define DUNE_COMMON_PARALLEL_MPIHELPER_HH
135 [[maybe_unused]]
char** argv)
142 static FakeMPIHelper singleton;
149 int rank ()
const {
return 0; }
153 int size ()
const {
return 1; }
157 FakeMPIHelper(
const FakeMPIHelper&);
158 FakeMPIHelper& operator=(
const FakeMPIHelper);
190 return MPI_COMM_WORLD;
201 return MPI_COMM_SELF;
262 assert((argc ==
nullptr) == (argv ==
nullptr));
263 static MPIHelper
instance{argc, argv};
270 int rank ()
const {
return rank_; }
274 int size ()
const {
return size_; }
279 int wasFinalized = -1;
280 MPI_Finalized( &wasFinalized );
281 if(!wasFinalized && initializedHere_)
284 dverb <<
"Called MPI_Finalize on p=" << rank_ <<
"!" <<std::endl;
292 bool initializedHere_;
293 void prevent_warning(
int){}
296 MPIHelper(
int* argc,
char*** argv)
297 : initializedHere_(false)
299 int wasInitialized = -1;
300 MPI_Initialized( &wasInitialized );
305 static int is_initialized = MPI_Init(argc, argv);
306 prevent_warning(is_initialized);
307 initializedHere_ =
true;
310 MPI_Comm_rank(MPI_COMM_WORLD,&rank_);
311 MPI_Comm_size(MPI_COMM_WORLD,&size_);
313 assert( rank_ >= 0 );
314 assert( size_ >= 1 );
316 dverb <<
"Called MPI_Init on p=" << rank_ <<
"!" << std::endl;
319 MPIHelper(
const MPIHelper&);
320 MPIHelper& operator=(
const MPIHelper);
A few common exception classes.
Implements an utility class that provides collective communication methods for sequential programs.
Implements an utility class that provides MPI's collective communication methods.
Standard Dune debug streams.
Definition of macros controlling symbol visibility at the ABI level.
#define DUNE_EXPORT
Export a symbol as part of the public ABI.
Definition visibility.hh:20
DVerbType dverb(std::cout)
Singleton of verbose debug stream.
Definition stdstreams.hh:117
Dune namespace
Definition alignedallocator.hh:13
Definition communication.hh:46
Collective communication interface and sequential default implementation.
Definition communication.hh:100
A fake mpi helper.
Definition mpihelper.hh:76
static DUNE_EXPORT MPICommunicator getCommunicator()
get the default communicator
Definition mpihelper.hh:95
int size() const
return rank of process, i.e. one
Definition mpihelper.hh:153
static MPICommunicator getLocalCommunicator()
get a local communicator
Definition mpihelper.hh:107
No_Comm MPICommunicator
The type of the mpi communicator.
Definition mpihelper.hh:87
static DUNE_EXPORT FakeMPIHelper & instance(int argc, char **argv)
Get the singleton instance of the helper.
Definition mpihelper.hh:134
static DUNE_EXPORT FakeMPIHelper & instance()
Definition mpihelper.hh:140
static Communication< MPICommunicator > getCommunication()
Definition mpihelper.hh:114
static constexpr bool isFake
Are we fake (i.e. pretend to have MPI support but are compiled without.).
Definition mpihelper.hh:82
int rank() const
return rank of process, i.e. zero
Definition mpihelper.hh:149
A real mpi helper.
Definition mpihelper.hh:169
int size() const
return number of processes
Definition mpihelper.hh:274
static constexpr bool isFake
Are we fake (i. e. pretend to have MPI support but are compiled without.
Definition mpihelper.hh:175
static DUNE_EXPORT MPIHelper & instance(int *argc=nullptr, char ***argv=nullptr)
Get the singleton instance of the helper.
Definition mpihelper.hh:260
static DUNE_EXPORT MPIHelper & instance(int &argc, char **&argv)
Get the singleton instance of the helper.
Definition mpihelper.hh:228
static Communication< MPICommunicator > getCommunication()
Definition mpihelper.hh:205
~MPIHelper()
calls MPI_Finalize
Definition mpihelper.hh:277
int rank() const
return rank of process
Definition mpihelper.hh:270
MPI_Comm MPICommunicator
The type of the mpi communicator.
Definition mpihelper.hh:180
static MPICommunicator getCommunicator()
get the default communicator
Definition mpihelper.hh:188
static MPICommunicator getLocalCommunicator()
get a local communicator
Definition mpihelper.hh:199