AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
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
66
68 static int mpiRank()
69 {
70 return Mpi::instance().rank();
71 }
72
74 static int mpiSize()
75 {
76 return Mpi::instance().size();
77 }
78
80 static Dune::MPIHelper& mpiHelper()
81 {
82 return Mpi::instance().mpiHelper();
83 }
84
86 static typename Dune::MPIHelper::MPICommunicator comm()
87 {
88 return Dune::MPIHelper::getCommunicator();
89 }
90
92 static int infoLevel();
93
95 static bool msgAllRanks();
96
97 private:
98#if AMDIS_HAS_PETSC
99 bool petscInitialized_ = false;
100#endif
101 };
102
103} // 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:86
static Dune::MPIHelper & mpiHelper()
Return a reference to the stored MPIHelper.
Definition: Environment.hpp:80
Environment(std::string const &initFileName="")
Create an environment without mpi initialization, with a fixed initfile given as string.
Definition: Environment.cpp:25
~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:74
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:68
static bool msgAllRanks()
Return whether all ranks print msg()
Definition: Environment.cpp:71