KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
parallel_environment.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main author: Jordi Cotela
11 //
12 
13 #pragma once
14 
15 // System includes
16 #include <string>
17 #include <iostream>
18 #include <unordered_map>
19 
20 // External includes
21 
22 // Project includes
23 #include "includes/define.h"
26 
27 namespace Kratos
28 {
31 
34 
35 class KRATOS_API(KRATOS_CORE) EnvironmentManager
36 {
37  public:
38  typedef std::unique_ptr<EnvironmentManager> Pointer;
39 
41 
42  virtual ~EnvironmentManager() = default;
43 
44  virtual bool IsInitialized() const = 0;
45 
46  virtual bool IsFinalized() const = 0;
47 
48  protected:
49  EnvironmentManager() = default;
50 };
51 
53 
56 class KRATOS_API(KRATOS_CORE) ParallelEnvironment
57 {
58  public:
61 
62  constexpr static bool MakeDefault = true;
63  constexpr static bool DoNotMakeDefault = false;
64 
68 
70 
71  static DataCommunicator& GetDataCommunicator(const std::string& rName);
72 
75 
77 
78  static void SetDefaultDataCommunicator(const std::string& rName);
79 
81  static int GetDefaultRank();
82 
84  static int GetDefaultSize();
85 
87  static std::string RetrieveRegisteredName(const DataCommunicator& rComm);
88 
92 
93  static void SetUpMPIEnvironment(EnvironmentManager::Pointer pEnvironmentManager);
94 
100  template<class TDataCommunicatorInputType>
101  static void RegisterFillCommunicatorFactory(std::function<FillCommunicator::Pointer(ModelPart&, TDataCommunicatorInputType&)> FillCommunicatorFactory);
102 
108  template<class TDataCommunicatorInputType>
109  static void RegisterCommunicatorFactory(std::function<Communicator::UniquePointer(ModelPart&, TDataCommunicatorInputType&)> CommunicatorFactory);
110 
117  KRATOS_DEPRECATED_MESSAGE("This function is deprecated, please use \"CreateFillCommunicatorFromGlobalParallelism\" instead")
118  static FillCommunicator::Pointer CreateFillCommunicator(ModelPart& rModelPart);
119 
127  static FillCommunicator::Pointer CreateFillCommunicatorFromGlobalParallelism(
128  ModelPart& rModelPart,
129  const std::string& rDataCommunicatorName);
130 
138  static FillCommunicator::Pointer CreateFillCommunicatorFromGlobalParallelism(
139  ModelPart& rModelPart,
140  const DataCommunicator& rDataCommunicator);
141 
149  static Communicator::UniquePointer CreateCommunicatorFromGlobalParallelism(
150  ModelPart& rModelPart,
151  const std::string& rDataCommunicatorName);
152 
160  static Communicator::UniquePointer CreateCommunicatorFromGlobalParallelism(
161  ModelPart& rModelPart,
162  const DataCommunicator& rDataCommunicator);
163 
165 
169  static void RegisterDataCommunicator(
170  const std::string& rName,
171  DataCommunicator::UniquePointer pPrototype,
172  const bool Default = DoNotMakeDefault);
173 
175 
177  static void UnregisterDataCommunicator(
178  const std::string& rName);
179 
183 
185  static bool HasDataCommunicator(const std::string& rName);
186 
188 
189  static std::string GetDefaultDataCommunicatorName();
190 
191  static bool MPIIsInitialized();
192 
193  static bool MPIIsFinalized();
194 
198 
200  static std::string Info();
201 
203  static void PrintInfo(std::ostream &rOStream);
204 
206  static void PrintData(std::ostream &rOStream);
207 
209 
210  private:
211 
214 
217 
220 
224 
225  static void Create();
226 
227  void SetUpMPIEnvironmentDetail(EnvironmentManager::Pointer pEnvironmentManager);
228 
229  template<class TDataCommunicatorInputType>
230  void RegisterFillCommunicatorFactoryDetail(std::function<FillCommunicator::Pointer(ModelPart&, TDataCommunicatorInputType&)> FillCommunicatorFactory);
231 
232  template<class TDataCommunicatorInputType>
233  void RegisterCommunicatorFactoryDetail(std::function<Communicator::UniquePointer(ModelPart&, TDataCommunicatorInputType&)> CommunicatorFactory);
234 
235  void RegisterDataCommunicatorDetail(
236  const std::string& Name,
237  DataCommunicator::UniquePointer pPrototype,
238  const bool Default = DoNotMakeDefault);
239 
240  void UnregisterDataCommunicatorDetail(const std::string& Name);
241 
242  DataCommunicator& GetDataCommunicatorDetail(const std::string& rName) const;
243 
244  DataCommunicator& GetDefaultDataCommunicatorDetail() const;
245 
246  void SetDefaultDataCommunicatorDetail(const std::string& rName);
247 
251 
252  bool HasDataCommunicatorDetail(const std::string& rName) const;
253 
254  bool MPIIsInitializedDetail() const;
255 
256  bool MPIIsFinalizedDetail() const;
257 
261 
262  static ParallelEnvironment& GetInstance();
263 
264  void SetAsDefault(std::unordered_map<std::string, DataCommunicator::UniquePointer>::iterator& rThisCommunicator);
265 
269 
271  std::string InfoDetail() const;
272 
274  void PrintInfoDetail(std::ostream &rOStream) const;
275 
277  void PrintDataDetail(std::ostream &rOStream) const;
278 
282 
283  std::unordered_map<std::string, DataCommunicator::UniquePointer> mDataCommunicators;
284 
285  std::unordered_map<std::string, DataCommunicator::UniquePointer>::iterator mDefaultCommunicator;
286 
287  std::function<FillCommunicator::Pointer(ModelPart&, const std::string&)> mFillCommunicatorStringFactory;
288 
289  std::function<FillCommunicator::Pointer(ModelPart&, const DataCommunicator&)> mFillCommunicatorReferenceFactory;
290 
291  std::function<Communicator::UniquePointer(ModelPart&, const std::string&)> mCommunicatorStringFactory;
292 
293  std::function<Communicator::UniquePointer(ModelPart&, const DataCommunicator&)> mCommunicatorReferenceFactory;
294 
295  int mDefaultRank;
296  int mDefaultSize;
297 
298  EnvironmentManager::Pointer mpEnvironmentManager;
299 
300  static ParallelEnvironment* mpInstance;
301  static bool mDestroyed;
302 
306 
309 
312 
314 
315 }; // Class ParallelEnvironment
316 
318 
320 
321 } // namespace Kratos.
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
The Commmunicator class manages communication for distributed ModelPart instances.
Definition: communicator.h:67
Serial (do-nothing) version of a wrapper class for MPI communication.
Definition: data_communicator.h:318
Definition: parallel_environment.h:36
EnvironmentManager(EnvironmentManager &rOther)=delete
virtual bool IsFinalized() const =0
virtual ~EnvironmentManager()=default
virtual bool IsInitialized() const =0
std::unique_ptr< EnvironmentManager > Pointer
Definition: parallel_environment.h:38
Base class defining the API for the fill communicator utilities.
Definition: fill_communicator.h:52
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Holder for general data related to MPI (or suitable serial equivalents for non-MPI runs).
Definition: parallel_environment.h:57
Modeler::Pointer Create(const std::string &ModelerName, Model &rModel, const Parameters ModelParameters)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:30
DataCommunicator & GetDefaultDataCommunicator()
Definition: testing.cpp:24
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Kratos::PeriodicInterfaceProcess Process operator(std::istream &rIStream, PeriodicInterfaceProcess &rThis)
input stream function
namespace KRATOS_DEPRECATED_MESSAGE("Please use std::filesystem directly") filesystem
Definition: kratos_filesystem.h:33
tuple const
Definition: ode_solve.py:403
namespace
Definition: array_1d.h:793