AMDiS 2.11-git
The Adaptive Multi-Dimensional Simulation Toolbox
 
Loading...
Searching...
No Matches
Environment.hpp
1#pragma once
2
3// std c++ headers
4#include <cassert>
5#include <string>
6
7#include <dune/common/parallel/mpihelper.hh>
8
9namespace AMDiS
10{
12
20 {
21 // internal static container holding a pointer to the Dune::MPIHelper.
22 struct Mpi
23 {
24 static Mpi& instance()
25 {
26 static Mpi mpi;
27 return mpi;
28 }
29
30 void registerMpiHelper(Dune::MPIHelper& mpiHelper)
31 {
32 mpiHelper_ = &mpiHelper;
33 }
34
35 int rank()
36 {
37 assert(mpiHelper_ != nullptr);
38 return mpiHelper_->rank();
39 }
40
41 int size()
42 {
43 assert(mpiHelper_ != nullptr);
44 return mpiHelper_->size();
45 }
46
47 Dune::MPIHelper& mpiHelper()
48 {
49 return *mpiHelper_;
50 }
51
52 private:
53 Dune::MPIHelper* mpiHelper_ = nullptr;
54 };
55
56 public:
58 Environment(std::string const& initFileName = "");
59
62 Environment(int& argc, char**& argv, std::string const& initFileName = "");
63
64 Environment(Environment const&) = delete;
65 Environment& operator=(Environment const&) = delete;
66
69
71 static int mpiRank()
72 {
73 return Mpi::instance().rank();
74 }
75
77 static int mpiSize()
78 {
79 return Mpi::instance().size();
80 }
81
83 static Dune::MPIHelper& mpiHelper()
84 {
85 return Mpi::instance().mpiHelper();
86 }
87
89 static typename Dune::MPIHelper::MPICommunicator comm()
90 {
91 return Dune::MPIHelper::getCommunicator();
92 }
93
95 static int infoLevel();
96
98 static bool msgAllRanks();
99
100 private:
101#if AMDIS_HAS_PETSC
102 bool petscInitialized_ = false;
103#endif
104 };
105
106} // end namespace AMDiS
Establishes an environment for sequential and parallel AMDiS programs.
Definition Environment.hpp:20
static Dune::MPIHelper::MPICommunicator comm()
Return the MPI_Comm object (or a fake communicator)
Definition Environment.hpp:89
static Dune::MPIHelper & mpiHelper()
Return a reference to the stored MPIHelper.
Definition Environment.hpp:83
~Environment()
Finishes MPI and PETSc.
Definition Environment.cpp:54
static int mpiSize()
Return the MPI_Size of the group created by Dune::MPIHelper.
Definition Environment.hpp:77
static int infoLevel()
Return the info level for messages in info()
Definition Environment.cpp:63
static int mpiRank()
Return the MPI_Rank of the current processor.
Definition Environment.hpp:71
static bool msgAllRanks()
Return whether all ranks print msg()
Definition Environment.cpp:71