C++ mpi module for stochmagnet_main Package
MPI_GraphGridEnvironment.h
1 #ifndef MPI_GraphGridEnvironment_H
2 #define MPI_GraphGridEnvironment_H
3 
4 //inherited class object
5 #include "MPI_DirectionalGridEnvironment.h"
6 
7 //MPI File IO Header
8 #include "MPI_IOFile.h"
9 
10 //array function headers
11 #include "functions_array.h"
12 
34 template<tUCInt N,tUCInt D=1>
36 
37  //attributes
38 private :
39 
40  MPI_Group *mGroup,*mParentGroup;
41 
42 
45 protected:
46  // CONSTRUCTORS
47 
51  mGroup=null;
52  mParentGroup=null;
53  this->getWorld()=MPI_COMM_NULL;
54 
55  }
56 
57 
58 
59  // DESTRUCTORS
62  virtual ~MPI_GraphGridEnvironment(void) {
63  if (mGroup!=null) {
64  MPI_Group_free(mGroup);
65  delete mGroup;
66  }
67  if (mParentGroup!=null) {
68  MPI_Group_free(mParentGroup);
69  delete mParentGroup;
70  }
71 
72 
73  }
74 
75 public:
76 
77 
78 
79  //New methods
80  //===========
81 
87  inline static CORE_UniquePointer<MPI_GraphGridEnvironment<N>> New(const MPI_Environment& parent,
88  const tString& fileDescriptor) {
89 
90 
91 
92  std::array<tInteger,N> gridsNumber;
93  std::array<tInteger,N> coreIndices;
94  std::map<tUCInt,tMPICoreId> dirNeighbors;
95 
96  tBoolean isInGraphGridEnv=false;
97  tMPICoreId nCores;
98  //std::cout<<"load the grid cart file for process "<<parent.getCoreId()<<"\n";
100  nCores,
101  gridsNumber,coreIndices,dirNeighbors,
102  isInGraphGridEnv);
103  //std::cout<<"return a Graph Grid environment if available of "<<parent.getCoreId()<<"\n";
104  return New(parent,nCores,gridsNumber,coreIndices,dirNeighbors);
105  }
106 
115  inline static CORE_UniquePointer<MPI_GraphGridEnvironment<N>> New(const MPI_Environment& parent,
116  const tMPICoreId& nCores,
117  const std::array<tInteger,N>& gridsNumber,
118  const std::array<tInteger,N>& coreIndices,
119  const std::map<tUCInt,tMPICoreId>& dirNeighbors) {
120 
121 
122 
123  CORE_UniquePointer<MPI_GraphGridEnvironment<N>> p(new MPI_GraphGridEnvironment<N>(),
125 
126 
127 
128 
129  //get the group under it parent
130  //std::cout<<"create a group for process : "<<parent.getCoreId()<<"\n";
131  p->mParentGroup=new MPI_Group();
132  MPI_Comm_group(parent.getWorld(),p->mParentGroup);
133 
134  //create the grid group
135  std::valarray<tMPICoreId> processRanks(nCores);
136  tMPICoreId i=0;
137  for(auto& Pk:processRanks) {Pk=i;i++;}
138 
139  p->mGroup=new MPI_Group();
140  MPI_Group_incl(*p->mParentGroup,nCores,&processRanks[0],p->mGroup);
141 
142  //create the communicator of the group
143  MPI_Comm_create(parent.getWorld(),*p->mGroup,&p->getWorld());
144 
145  //erify the group is well done
146  if (p->getWorld()==MPI_COMM_NULL) {
147  //process can not be added in the grid environement
148  p.reset();
149  } else {
150 
151  //iniitialize the communicator
152  p->initialize();
153 
154  //initialize the data of the communicator
155  p->setGridSize(gridsNumber);
156  p->setIndices(coreIndices);
157  p->setDirectionalNeighbors(dirNeighbors);
158  }
159 
160  return p;
161  };
162 
165  virtual void initialize() {
166 
168  }
169 
170 
171 
172 
173  //accessor methods
174  //================
175 
176 
177 public:
178 
179 
180 
191  static tBoolean LoadGridCartFile(const tString& fileName,
192  const MPI_Environment& env,
193  tMPICoreId& nCores,
194  std::array<tInteger,N>& gridsNumber,
195  std::array<tInteger,N>& coreIndices,
196  std::map<tUCInt,tMPICoreId>& dirNeighbors,
197  tBoolean& isCoreInGrid);
198 
210  template<typename Q>
211  static tBoolean SaveGridCartFile(const MPI_DirectionalGridEnvironment<N,D>& env,
212  const tInteger& nFullCores,
213  const tInteger& fullId,
214  const std::map<tUCInt,Q>& isDirNeighborFull,
215  const tString& fileName);
216 
217 
218 
219 
220 };
221 
222 #include "MPI_GraphGridEnvironment.hpp"
223 
224 #endif
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
This class is a grid Environment of templated dimension N=1,2,3.
Definition: MPI_DirectionalGridEnvironment.h:30
virtual void initialize()
initialize the environment
Definition: MPI_DirectionalGridEnvironment.h:303
This class is a Environment class to define MPI world.
Definition: MPI_Environment.h:36
const tMPIComm & getWorld() const
get the world of the environment for reading
Definition: MPI_Environment.h:165
This class is a cart Environment of templated dimension N.
Definition: MPI_GraphGridEnvironment.h:35
MPI_GraphGridEnvironment()
create a root environment
Definition: MPI_GraphGridEnvironment.h:50
virtual ~MPI_GraphGridEnvironment(void)
destroy
Definition: MPI_GraphGridEnvironment.h:62
static tBoolean SaveGridCartFile(const MPI_DirectionalGridEnvironment< N, D > &env, const tInteger &nFullCores, const tInteger &fullId, const std::map< tUCInt, Q > &isDirNeighborFull, const tString &fileName)
save the grid cart file
Definition: MPI_GraphGridEnvironment.hpp:170
static CORE_UniquePointer< MPI_GraphGridEnvironment< N > > New(const MPI_Environment &parent, const tMPICoreId &nCores, const std::array< tInteger, N > &gridsNumber, const std::array< tInteger, N > &coreIndices, const std::map< tUCInt, tMPICoreId > &dirNeighbors)
create a new cart environment
Definition: MPI_GraphGridEnvironment.h:115
static CORE_UniquePointer< MPI_GraphGridEnvironment< N > > New(const MPI_Environment &parent, const tString &fileDescriptor)
create a new cart environment
Definition: MPI_GraphGridEnvironment.h:87
static tBoolean LoadGridCartFile(const tString &fileName, const MPI_Environment &env, tMPICoreId &nCores, std::array< tInteger, N > &gridsNumber, std::array< tInteger, N > &coreIndices, std::map< tUCInt, tMPICoreId > &dirNeighbors, tBoolean &isCoreInGrid)
save the grid cart file
Definition: MPI_GraphGridEnvironment.hpp:5
virtual void initialize()
initialize the environment
Definition: MPI_GraphGridEnvironment.h:165