C++ mpi module for stochmagnet_main Package
SMOMPI_OneMasterMacroCellsNetwork.h
1 #ifndef SMOMPI_OneMasterMacroCellsNetwork_H
2 #define SMOMPI_OneMasterMacroCellsNetwork_H
3 
4 //base classes
5 #include "SM_MacroCellsNetwork.h"
6 
7 //MPI header
8 #include "MPI_Run.h"
9 #include "MPI_WorldToWorldMessage.h"
10 
20 
21 
22 public:
23 private :
24 
25  //type class
28 
29  //master core id
30  tMPICoreId mMasterCoreId;
31 
32  // indices converter from index of macro cell in the not empty macro cells list of this core
33  // to index of macro cell in not empty maco cells list of the bounding box grid
34  std::valarray<tInteger> mBoundingBoxMacroCellsIndex;
35 
36  //C defined on not empty macro cell of the whole domain only for the master core id
37  SM_RealField mDomainC;
38  //volume of macro cells defined on not empty macro cell of the whole domain only for the master core id
39  std::valarray<tReal> mDomainVolumes;
40 
41  //work array for mpi communication
42  std::valarray<tInteger> mCoreBBMacroCellsIndex;
43  std::valarray<tReal> mCorePC;
44  std::valarray<tInteger> mCorePW;
45 
46  //MPI tags
47  static const tMPITag TAG_IS;
48  static const tMPITag TAG_IB;
49  static const tMPITag TAG_IR;
50 
51  static const tMPITag TAG_CREDUCE;
52  static const tMPITag TAG_CSCATTER;
53 
54 
55 
56 protected:
57  // CONSTRUCTORS
61  mMasterCoreId=0;
62  }
63 
64  // DESTRUCTORS
68  }
69 
70 
71 public :
72 
73  //Instance building
74  //=================
75 
79  inline static CORE_UniquePointer<SelfClass> New() {
80  return CORE_UniquePointer<SelfClass>(new SelfClass(),SelfClass::Delete());
81  }
82 
86  virtual CORE_UniquePointer<SM_MacroCellsNetwork> newInstance() const override {
87  return New();
88  }
102  virtual tMemSize getMemorySize() const {
103  return sizeof(*this)+this->getContentsMemorySize();
104  }
105 
114  virtual tMemSize getContentsMemorySize() const {
115  tMemSize mem=SuperClass::getContentsMemorySize();
116  mem+=mDomainC.getSize()*sizeof(tReal);
117  mem+=mDomainVolumes.size()*sizeof(tReal);
118  mem+=mBoundingBoxMacroCellsIndex.size()*sizeof(tInteger);
119  //work array
120  mem+=sizeof(tInteger)*mCoreBBMacroCellsIndex.size();
121  mem+=sizeof(tReal)*mCorePC.size();
122  mem+=sizeof(tInteger)*mCorePW.size();
123  return mem;
124  }
125 public:
126 
127 
128 public:
129 
130 
131 
132 
133 
134  //Macro cells methods
135  //======================
136 public:
137 
140  inline const tMPICoreId& getMasterCoreId() const {
141  return mMasterCoreId;
142  }
146  inline void setMasterCoreId(const tMPICoreId& coreId) {
147  mMasterCoreId=coreId;
148  }
149 
153  inline const std::valarray<tInteger>& getBoundingBoxMacroCellsIndex() const {
154  return mBoundingBoxMacroCellsIndex;
155  }
156 
160  inline tInteger getBoundingBoxMacroCellsNumber() const {
161  return mDomainC.getElementsNumber();
162  }
163 
168  return mDomainC;
169  }
170 
174  inline const std::valarray<tReal>& getBoundingBoxMacroCellsVolume() const {
175  return mDomainVolumes;
176  }
177  //discretize the network
178  //======================
179 public:
180 
181 public:
186  virtual void computeMacroCells(const SM_Material& material,
187  const SM_Network& network) override;
188 
193  virtual void computeMacroCellsMassCenter(const SM_Material& material,
194  const SM_Network& network) override;
195 
196 protected:
203  virtual void computeBoundingBoxMacroCells(const SM_Material& material,
204  const SM_Network& network,
205  const std::array<tReal,SM_Constants::DIM>& P,
206  const std::array<tReal,SM_Constants::DIM>& Q) override;
207 
208 public:
209 
221  static tBoolean WaitForBoundingBoxMacroCellsIndexFromNeighborCore(const MPI_Environment& mpiEnv,tMPICoreId& c,
222  const tMPITag& tag,tMPICount& nValues,
223  std::valarray<tInteger>& boundingBoxMacroCellsIndex,
224  tMPIBoolean& isAvaliable,tMPIStatus& status,
225  std::map<tMPICoreId,tBoolean>& isDataReceivedFromCore) ;
226 
227 
246  static tBoolean WaitForWeightFieldFromNeighborCore(const MPI_Environment& mpiEnv,tMPICoreId& c,
247  const tMPITag& tagIndices,tMPICount& nIndices,
248  std::valarray<tInteger>& boundingBoxMacroCellsIndex,
249  const tMPITag& tagX,tMPICount& sX, std::valarray<tReal>& X,
250  const tMPITag& tagW,tMPICount& nW, std::valarray<tInteger>& W,
251  tMPIBoolean& isAvaliable,tMPIStatus& status,std::array<tMPIRequest,3>& requests,
252  std::map<tMPICoreId,tBoolean>& isDataReceivedFromCore);
268  static tBoolean WaitForFieldFromNeighborCore(const MPI_Environment& mpiEnv,tMPICoreId& c,
269  const tMPITag& tagIndices,tMPICount& nIndices,
270  std::valarray<tInteger>& boundingBoxMacroCellsIndex,
271  const tMPITag& tagX,tMPICount& sX, std::valarray<tReal>& X,
272  tMPIBoolean& isAvaliable,tMPIStatus& status,std::array<tMPIRequest,2>& requests,
273  std::map<tMPICoreId,tBoolean>& isDataReceivedFromCore);
288  static void SumReduceField(const MPI_Environment& mpiEnv,const tMPICoreId& masterCoreId,const tMPITag& tagX,
289  const std::valarray<tInteger>& BBMacroCellsIndexMap,const SM_RealField& Xc,const std::valarray<tInteger>& Wc,
290  SM_RealField& X,std::valarray<tInteger>& W,
291  std::valarray<tInteger>& coreBBMacroCellsIndex,std::valarray<tReal>& corePX,std::valarray<tInteger>& corePW);
292 
305  static void SumReduceField(const MPI_Environment& mpiEnv,const tMPICoreId& masterCoreId,const tMPITag& tagX,
306  const std::valarray<tInteger>& BBMacroCellsIndexMap,const SM_RealField& Xc,
307  SM_RealField& X,
308  std::valarray<tInteger>& coreBBMacroCellsIndex,std::valarray<tReal>& corePX);
309 
322  static void ScatterField(const MPI_Environment& mpiEnv,const tMPICoreId& masterCoreId,
323  const tMPITag& tagX,const SM_RealField& X,
324  const std::valarray<tInteger>& BBMacroCellsIndexMap,SM_RealField& Xc,
325  std::valarray<tInteger>& coreBBMacroCellsIndex,
326  std::valarray<tReal>& coreX);
327 
338  static void ISendFieldToCore(const MPI_Environment& mpiEnv,const tMPICoreId& c,
339  const tMPICount& nMCs,
340  const tInteger* BBMacroCellsIndexMap,
341  const SM_RealField& X,
342  const tMPITag& tagX,tMPIRequest& request,
343  tReal *vXc);
344 
351  static void SelectFieldValues(const tMPICount& nMCs,
352  const tInteger* BBMacroCellsIndexMap,
353  const SM_RealField& X,
354  tReal *Xs);
355  // String representation
356  // =======================
357 public:
358 
359 
362  virtual tString toString() const override {
363  std::stringstream ret;
364  ret<<SuperClass::toString()<<"\n";
365  return ret.str();
366  }
367 
368 
369 };
370 
371 
372 #endif
tIndex getElementsNumber() const
return the number values of the container
Definition: CORE_Field.h:135
tIndex getSize() const
return the number values of the container
Definition: CORE_Field.h:161
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
This class is a Environment class to define MPI world.
Definition: MPI_Environment.h:36
This class describes a macro cell network for one master core implementation.
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:19
virtual void computeBoundingBoxMacroCells(const SM_Material &material, const SM_Network &network, const std::array< tReal, SM_Constants::DIM > &P, const std::array< tReal, SM_Constants::DIM > &Q) override
compute the macro cells of the network
Definition: SMOMPI_OneMasterMacroCellsNetwork.cpp:43
static CORE_UniquePointer< SelfClass > New()
return a new unique instnace of class This
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:79
virtual tString toString() const override
return string representaton of the operator
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:362
static tBoolean WaitForWeightFieldFromNeighborCore(const MPI_Environment &mpiEnv, tMPICoreId &c, const tMPITag &tagIndices, tMPICount &nIndices, std::valarray< tInteger > &boundingBoxMacroCellsIndex, const tMPITag &tagX, tMPICount &sX, std::valarray< tReal > &X, const tMPITag &tagW, tMPICount &nW, std::valarray< tInteger > &W, tMPIBoolean &isAvaliable, tMPIStatus &status, std::array< tMPIRequest, 3 > &requests, std::map< tMPICoreId, tBoolean > &isDataReceivedFromCore)
wait for receiving the map boundingBoxMacroCellsIndex [0,nMCs[ -> [0,nBBMCs[ and fields (W,...
Definition: SMOMPI_OneMasterMacroCellsNetwork.cpp:395
static void ScatterField(const MPI_Environment &mpiEnv, const tMPICoreId &masterCoreId, const tMPITag &tagX, const SM_RealField &X, const std::valarray< tInteger > &BBMacroCellsIndexMap, SM_RealField &Xc, std::valarray< tInteger > &coreBBMacroCellsIndex, std::valarray< tReal > &coreX)
scatter he field X into Xc with the map BBMacroCellsIndexMap
Definition: SMOMPI_OneMasterMacroCellsNetwork.cpp:845
virtual CORE_UniquePointer< SM_MacroCellsNetwork > newInstance() const override
create a New instance of this
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:86
const std::valarray< tInteger > & getBoundingBoxMacroCellsIndex() const
return the index of the macro cell within the not empty macro cells list of the boundig box
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:153
void setMasterCoreId(const tMPICoreId &coreId)
set the master core id
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:146
const SM_RealField & getBoundingBoxMacroCellsMassCenter() const
get the mass center on all not empty macro cells of the bouding box of macro cells
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:167
static tBoolean WaitForBoundingBoxMacroCellsIndexFromNeighborCore(const MPI_Environment &mpiEnv, tMPICoreId &c, const tMPITag &tag, tMPICount &nValues, std::valarray< tInteger > &boundingBoxMacroCellsIndex, tMPIBoolean &isAvaliable, tMPIStatus &status, std::map< tMPICoreId, tBoolean > &isDataReceivedFromCore)
wait for receiveing the map boundingBoxMacroCellsIndex [0,nMCs[ -> [0,nBBMCs[ from the core c with ta...
Definition: SMOMPI_OneMasterMacroCellsNetwork.cpp:373
virtual void computeMacroCells(const SM_Material &material, const SM_Network &network) override
compute the macro cells of the network
Definition: SMOMPI_OneMasterMacroCellsNetwork.cpp:16
SMOMPI_OneMasterMacroCellsNetwork(void)
create a network class
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:60
static void SelectFieldValues(const tMPICount &nMCs, const tInteger *BBMacroCellsIndexMap, const SM_RealField &X, tReal *Xs)
selected value from X with map BBMacroCellsIndex,
Definition: SMOMPI_OneMasterMacroCellsNetwork.cpp:973
static void ISendFieldToCore(const MPI_Environment &mpiEnv, const tMPICoreId &c, const tMPICount &nMCs, const tInteger *BBMacroCellsIndexMap, const SM_RealField &X, const tMPITag &tagX, tMPIRequest &request, tReal *vXc)
non blocking end message to send selected values of X with the map BMacroCellsIndexMap to values of X...
Definition: SMOMPI_OneMasterMacroCellsNetwork.cpp:948
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:102
tInteger getBoundingBoxMacroCellsNumber() const
return the number of not empty macro cells of the bouning box
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:160
virtual ~SMOMPI_OneMasterMacroCellsNetwork(void)
destroy
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:67
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:114
const std::valarray< tReal > & getBoundingBoxMacroCellsVolume() const
get the volume on all not empty macro cells of the bouding box of macro cells
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:174
virtual void computeMacroCellsMassCenter(const SM_Material &material, const SM_Network &network) override
compute the macro cells of the network
Definition: SMOMPI_OneMasterMacroCellsNetwork.cpp:292
const tMPICoreId & getMasterCoreId() const
get the master core id
Definition: SMOMPI_OneMasterMacroCellsNetwork.h:140
static tBoolean WaitForFieldFromNeighborCore(const MPI_Environment &mpiEnv, tMPICoreId &c, const tMPITag &tagIndices, tMPICount &nIndices, std::valarray< tInteger > &boundingBoxMacroCellsIndex, const tMPITag &tagX, tMPICount &sX, std::valarray< tReal > &X, tMPIBoolean &isAvaliable, tMPIStatus &status, std::array< tMPIRequest, 2 > &requests, std::map< tMPICoreId, tBoolean > &isDataReceivedFromCore)
wait for receiving the map boundingBoxMacroCellsIndex [0,nMCs[ -> [0,nBBMCs[ and fields X from the co...
Definition: SMOMPI_OneMasterMacroCellsNetwork.cpp:442
static void SumReduceField(const MPI_Environment &mpiEnv, const tMPICoreId &masterCoreId, const tMPITag &tagX, const std::valarray< tInteger > &BBMacroCellsIndexMap, const SM_RealField &Xc, const std::valarray< tInteger > &Wc, SM_RealField &X, std::valarray< tInteger > &W, std::valarray< tInteger > &coreBBMacroCellsIndex, std::valarray< tReal > &corePX, std::valarray< tInteger > &corePW)
make the sum reduction of the field Xc into X (Wc into W) with the map BBMacroCellsIndexMap
Definition: SMOMPI_OneMasterMacroCellsNetwork.cpp:481
This class is describes a macro cell network.
Definition: SM_MacroCellsNetwork.h:25
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_MacroCellsNetwork.h:117
virtual tString toString() const override
return string representaton of the operator
Definition: SM_MacroCellsNetwork.h:440
This class describes a materials defined by state attributes:
Definition: SM_Material.h:61
This class is describes a network composed by.
Definition: SM_Network.h:66