C++ mpi module for stochmagnet_main Package
SMOMPI_Network.h
1 #ifndef SMOMPI_Network_H
2 #define SMOMPI_Network_H
3 
4 //define a real field
5 #include "SM_Network.h"
6 
7 
8 //mpi header
9 #include "MPI_Run.h"
10 
11 
37 class SMOMPI_Network : public SM_Network {
38 
39 
40 private :
41 
42  //class names
43  typedef SMOMPI_Network SelfClass;
44  typedef SM_Network SuperClass;
45 
46  //attributes
47  //C0:(0,1,2) -> (0,1,2) local
48  //C1:(3,4,5) -> (0,1,2)
49  //C2:(6,7,8) -> (0,1,2)
50  //halo connections: (0,3) (1,5) (2,8) (5,6)
51 
52  //C0:nParticles=3
53  //C1:nParticles=3
54  //C2:nParticles=3
55 
56  //index of the core connected core
57  //C0:mConnectedCores={1,2}
58  //C1:mConnectedCores={0,2}
59  //C2:mConnectedCores={1,0}
60  std::valarray<tMPICoreId> mConnectedCores;
61 
62  //halo particles of the core packed by connected cores
63  //-------------------------------------------------------
64  //mHaloParticles={{local halo particles in Co},...,{local halo particles in C_{nc-1}}
65  //C0: mHaloParticles={{3,5},8} -> {{0,2},{2}} haloParticleIndex={3,4,5}
66  //C1: mHaloParticles={{1},{6}} -> {{1},{0}} haloParticleIndex=[3,4}
67  //C2: mHaloParticles={{5},{2}} -> {{2},{2}} haloParticleIndex={3,4}
68  //std::valarray<tIndex> mHaloParticles;
69 
70 
71  //index in mHaloParticles of first halo particle of the core c_i of size nc
72  //C0:mHaloParticlesOffset={0,2,3}
73  //C1:mHaloParticlesOffset={0,1,2}
74  //C2:mHaloParticlesOffset={0,1,2}
75  std::valarray<tMPIInteger> mHaloParticlesOffset;
76 
77  //bound particles of this core which are bounds of the connected core
78  //--------------------------------------------------------------------
79  //mBoundParticles={{local bound particles needed by Co},...,{local bound particles needed by C_{nc-1}}
80  //C0:mBoundParticles={{1},{2}} -> {{1},{2}}
81  //C1:mBoundParticles={{3,5},{5}} -> {{0,2},{2}}
82  //C2:mBoundParticles={{6},{8}} -> {{0},{2}}
83  std::valarray<tIndex> mBoundParticles;
84 
85 
86  //index in mBoundParticles of first bound particle of the core c_i of size nc
87  //C0:mBoundParticlesOffset={0,1,2}
88  //C1:mBoundParticlesOffset={0,2,3}
89  //C2:mBoundParticlesOffset={0,1,2}
90  std::valarray<tMPIInteger> mBoundParticlesOffset;
91 
92  //halo connection id
93  std::vector<tMPITag> mHaloConnectionsTag;
94 
95  //echange field
96  //C0:
97  // - receive from C1 to C0 into {F[3],F[4]}
98  // - send from C0 to C1 {F[1]}
99  // - receive from C2 to C0 in {F[5]}
100  // - send from C0 to C2 {F[2]}
101  //C1:
102  // - receive from C0 to C1 into {F[3]}
103  // - send from C1 to C0 {F[0],F[2]}
104  // - receive from C2 to C1 in {F[4]}
105  // - send from C1 to C2 {F[2]}
106  //C2:
107  // - receive from C1 to C2 into {F[3]}
108  // - send from C2 to C1 {F[0]}
109  // - receive from C0 to C2 in {F[4]}
110  // - send from C2 to C0 {F[2]}
111 
112  std::valarray<tReal> mBoundFieldValues;
113  std::valarray<tMPIRequest> mRequests;
114 
115 
116 
117 protected:
118  // CONSTRUCTORS
122 
123 
124 
125  }
126 
127  // DESTRUCTORS
130  virtual ~SMOMPI_Network(void) {
131  }
132 
133 public :
134 
135  //Instance building
136  //=================
137 
138 
139 
140 
141  //MEMORY
142 
156  virtual tMemSize getMemorySize() const {
157  return sizeof(*this)+getContentsMemorySize();
158  }
159 
168  virtual tMemSize getContentsMemorySize() const {
169  tMemSize mem=SuperClass::getContentsMemorySize();
170  mem+=sizeof(tMPIInteger)*mConnectedCores.size();
171  //mem+=sizeof(tIndex)*mHaloParticles.size();
172  mem+=sizeof(tMPIInteger)*mHaloParticlesOffset.size();
173  mem+=sizeof(tIndex)*mBoundParticles.size();
174  mem+=sizeof(tMPIInteger)*mBoundParticlesOffset.size();
175  mem+=sizeof(tMPITag)*mHaloConnectionsTag.capacity();
176  mem+=sizeof(tReal)*mBoundFieldValues.size();
177  mem+=sizeof(tMPIRequest)*mRequests.size();
178 
179  return mem;
180  }
181 
182 
183  //NEW
184 
188  inline static CORE_UniquePointer<SelfClass> New() {
189  return CORE_UniquePointer<SelfClass>(new SelfClass(),
191  }
192 
193  //SET & GET methods
194 
195 
198  inline void setConnectedCoresNumber(const tMPIInteger& nConnectedCores) {
199 
200  mConnectedCores.resize(nConnectedCores);
201  mHaloParticlesOffset.resize(nConnectedCores+1);
202  mBoundParticlesOffset.resize(nConnectedCores+1);
203  mRequests.resize(2*nConnectedCores);
204 
205  functions_array::reset(mHaloParticlesOffset);
206  functions_array::reset(mBoundParticlesOffset);
207  }
210  inline const std::valarray<tMPICoreId>& getConnectedCores() const {
211  return mConnectedCores;
212  }
215  inline std::valarray<tMPICoreId>& getConnectedCores() {
216  return mConnectedCores;
217  }
218 
221  inline void setBoundParticlesNumber(const tIndex& n) {
222  mBoundParticles.resize(n);
223  mBoundFieldValues.resize(SM_Constants::DIM*n);
224  }
225 
228  inline const std::valarray<tIndex>& getBoundParticles() const {
229  return mBoundParticles;
230  }
233  inline std::valarray<tIndex>& getBoundParticles() {
234  return mBoundParticles;
235  }
236 
239  inline const std::valarray<tMPIInteger>& getBoundParticlesOffset() const {
240  return mBoundParticlesOffset;
241  }
244  inline std::valarray<tMPIInteger>& getBoundParticlesOffset() {
245  return mBoundParticlesOffset;
246  }
249  inline const std::valarray<tMPIInteger>& getHaloParticlesOffset() const {
250  return mHaloParticlesOffset;
251  }
254  inline std::valarray<tMPIInteger>& getHaloParticlesOffset() {
255  return mHaloParticlesOffset;
256  }
259  inline const std::vector<tMPIInteger>& getHaloConnectionsTag() const {
260  return mHaloConnectionsTag;
261  }
264  inline std::vector<tMPIInteger>& getHaloConnectionsTag() {
265  return mHaloConnectionsTag;
266  }
267 
268 
269 protected:
270 
271 
276  virtual void computeBoundingBox(std::array<tReal,SM_Constants::DIM>& bbMinPoint,
277  std::array<tReal,SM_Constants::DIM>& bbSize) const final;
278 
279 
280 
281 
282  //exchange data field on network
283  //--------------------------------
284 public:
305 
306 
307 
308  //IO methods
309  //=========
310 protected:
313  virtual void saveStatesToFile(std::ofstream& file) const override ;
314 
317  virtual void loadStatesFromFile(std::ifstream& file,tInteger& version,tDimension& d) override;
318 
323  virtual void updateState() override;
324 
325 
332  virtual void updateConnectionValues(const tReal& noiseRate,
334  const tReal& J,
335  const std::function<void(const tReal&,const tReal& ,const tReal&,tReal& )>& F) final;
336 public:
343  static inline void ComputeConnectionTag(const tIndex& p,const tIndex& q,tMPITag& tag) {
344  if (p<q) {
345  tag=q;
346  tag--;
347  tag*=q;
348  tag/=2;
349  tag+=p;
350  } else {
351  ComputeConnectionTag(q,p,tag);
352  }
353  }
354 public:
355 
358  virtual tString toString() const override;
359 
360 };
361 
362 #endif
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
This class describes an MPI implementation of interface class SM_Network . It implements the abstract...
Definition: SMOMPI_Network.h:37
const std::valarray< tMPIInteger > & getBoundParticlesOffset() const
get bound particles list offset
Definition: SMOMPI_Network.h:239
const std::valarray< tIndex > & getBoundParticles() const
get bound particles list
Definition: SMOMPI_Network.h:228
void setConnectedCoresNumber(const tMPIInteger &nConnectedCores)
set connected cores number
Definition: SMOMPI_Network.h:198
void setBoundParticlesNumber(const tIndex &n)
set the bound particles number
Definition: SMOMPI_Network.h:221
virtual void saveStatesToFile(std::ofstream &file) const override
save the state of the network
Definition: SMOMPI_Network.cpp:352
virtual void loadStatesFromFile(std::ifstream &file, tInteger &version, tDimension &d) override
load the state of the network
Definition: SMOMPI_Network.cpp:434
virtual ~SMOMPI_Network(void)
destroy
Definition: SMOMPI_Network.h:130
virtual tString toString() const override
return the string representation of the class
Definition: SMOMPI_Network.cpp:630
std::vector< tMPIInteger > & getHaloConnectionsTag()
get halo connections tag
Definition: SMOMPI_Network.h:264
virtual void updateState() override
compute the network stae
Definition: SMOMPI_Network.cpp:227
std::valarray< tMPICoreId > & getConnectedCores()
get the connected cores
Definition: SMOMPI_Network.h:215
tBoolean mpiExchangeFieldValues(SM_RealField &F)
exchange the data of F between connected cores
Definition: SMOMPI_Network.cpp:87
virtual void computeBoundingBox(std::array< tReal, SM_Constants::DIM > &bbMinPoint, std::array< tReal, SM_Constants::DIM > &bbSize) const final
get the min point and size of the bunding box depend on X
Definition: SMOMPI_Network.cpp:19
const std::valarray< tMPICoreId > & getConnectedCores() const
get the connected cores
Definition: SMOMPI_Network.h:210
std::valarray< tMPIInteger > & getBoundParticlesOffset()
get bound particles list offset
Definition: SMOMPI_Network.h:244
std::valarray< tMPIInteger > & getHaloParticlesOffset()
get halo particles list offset
Definition: SMOMPI_Network.h:254
static CORE_UniquePointer< SelfClass > New()
build a new instance of a BCC structure
Definition: SMOMPI_Network.h:188
const std::vector< tMPIInteger > & getHaloConnectionsTag() const
get halo connections tag
Definition: SMOMPI_Network.h:259
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SMOMPI_Network.h:156
std::valarray< tIndex > & getBoundParticles()
get bound particles list
Definition: SMOMPI_Network.h:233
const std::valarray< tMPIInteger > & getHaloParticlesOffset() const
get halo particles list offset
Definition: SMOMPI_Network.h:249
static void ComputeConnectionTag(const tIndex &p, const tIndex &q, tMPITag &tag)
compute the connection tag between particle (p,q)
Definition: SMOMPI_Network.h:343
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SMOMPI_Network.h:168
virtual void updateConnectionValues(const tReal &noiseRate, SM_StochasticFunctionsInterface &randomF, const tReal &J, const std::function< void(const tReal &, const tReal &, const tReal &, tReal &)> &F) final
compute the connection values of the particles
Definition: SMOMPI_Network.cpp:238
SMOMPI_Network(void)
create a network class
Definition: SMOMPI_Network.h:121
static constexpr tDimension DIM
space dimension
Definition: SM_Constants.h:80
This class is describes a network composed by.
Definition: SM_Network.h:66
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_Network.h:181
This class describes a stochastic functions based on same random number generator which implement ran...
Definition: SM_StochasticFunctionsInterface.h:18