1 #ifndef MPI_GraphGridEnvironment_HPP
2 #define MPI_GraphGridEnvironment_HPP
4 template<tUCInt N,tUCInt D>
8 std::array<tInteger,N>& gridsNumber,
9 std::array<tInteger,N>& coreIndices,
10 std::map<tUCInt,tMPICoreId>& dirNeighborCores,
11 tBoolean& isCoreInGrid) {
16 memset(gridsNumber.data(),0,N*
sizeof(tInteger));
17 memset(coreIndices.data(),0,N*
sizeof(tInteger));
36 std::cout<<
"file "<<cartFile<<
" does not exists\n";
46 MPI_Type::GetSize<tRelativeInteger>(mpiRIntSize);
50 std::valarray<tRelativeInteger> gridValues(s);
51 ok=ok && file.
allRead(gridValues,status);
52 ok=ok && file.
close();
54 std::cout<<
" error in reading "<<cartFile<<
"\n";
64 tIndex nThValues=3+gridsNumber.size()+coreIndices.size()+P;
65 nThValues*=functions_array::product<tRelativeInteger,tRelativeInteger,N>(&gridValues[3]);
68 if (nThValues!=gridValues.size()) {
69 std::cout<<
" bad number of values in "<<cartFile<<
" : "<<gridValues.size()<<
" !="<<nThValues<<
" gridValues:"<<functions_array::toString(gridValues)<<
"\n";
76 const tRelativeInteger *iValues=&gridValues[0];
79 const tRelativeInteger *eValues=iValues+gridValues.size();
87 tRelativeInteger fullIndicator;
90 std::array<tInteger,N> nGrids;
93 std::array<tInteger,N> indices;
96 std::map<tUCInt,tMPICoreId> dirNeighbors;
99 std::map<tMPICoreId,tMPICoreId> coresMap;
102 coreId=(*iValues);iValues++;
104 nCores=(*iValues);iValues++;
106 fullIndicator=(*iValues);iValues++;
108 for(
auto& Nd:nGrids) {
109 Nd=(*iValues);iValues++;
112 for(
auto& Id:indices) {
113 Id=(*iValues);iValues++;
117 dirNeighbors.clear();
118 for(index=0;index<P;index++) {
119 if ((*iValues)!=NULL_CORE) dirNeighbors[index]=(*iValues);
129 if (fullIndicator>0) {
136 dirNeighborCores=dirNeighbors;
139 coresMap[coreId]=iCore;
142 }
while ((iValues!=eValues)&&(iCore<nCores));
146 std::map<tMPICoreId,tMPICoreId>::const_iterator iGridCoreId;
147 std::map<tUCInt,tMPICoreId>::iterator iDirNeighbor=dirNeighborCores.begin();
148 while (iDirNeighbor!=dirNeighborCores.end()) {
149 iGridCoreId=coresMap.find(iDirNeighbor->second);
150 if (iGridCoreId!=coresMap.end()) {
151 iDirNeighbor->second=iGridCoreId->second;
154 dirNeighborCores.erase(iDirNeighbor);
155 iDirNeighbor=dirNeighborCores.begin();
168 template<tUCInt N,tUCInt D>
171 const tInteger& nFullCores,
172 const tInteger& fullId,
173 const std::map<tUCInt,Q>& fullDirNeighbor,
174 const tString& fileName) {
177 const std::array<tMPICoreId,N>& nGrids=env.
getGridSize();
179 const std::array<tMPICoreId,N>& indices=env.
getIndices();
189 tInteger nGridValues=3+nGrids.size()+indices.size()+P;
192 std::valarray<tRelativeInteger> gridValues(nGridValues);
195 tRelativeInteger *iGridValues=&gridValues[0];
198 *iGridValues=env.
getCoreId();iGridValues++;
199 *iGridValues=nFullCores;iGridValues++;
200 *iGridValues=fullId;iGridValues++;
201 for(
const auto& i:nGrids) {*iGridValues=i;iGridValues++;}
202 for(
const auto& i:indices) {*iGridValues=i;iGridValues++;}
205 typename std::map<tUCInt,Q>::const_iterator iFullDirNeighbor;
206 std::map<tUCInt,tMPICoreId>::const_iterator iDirNeighbors;
207 for(index=0;index<P;index++) {
208 iFullDirNeighbor=fullDirNeighbor.find(index);
209 iDirNeighbors=dirNeighbors.find(index);
213 (iDirNeighbors==dirNeighbors.end()) ||
214 ((iFullDirNeighbor!=fullDirNeighbor.end())&&
215 (iFullDirNeighbor->second==(Q)
false)) ||
216 (iFullDirNeighbor==fullDirNeighbor.end())
217 )?NULL_CORE:iDirNeighbors->second;
229 ok=ok && file.
close();
This class is a grid Environment of templated dimension N=1,2,3.
Definition: MPI_DirectionalGridEnvironment.h:30
static tUCInt GetMaximumDirectionalNeighborsNumber()
get the maximum direction number : (2*D+1)^N when D is the neighbor Depth (D=0,1,2)
Definition: MPI_DirectionalGridEnvironment.h:191
const std::map< tUCInt, tMPICoreId > & getDirectionalNeighbors() const
get the neighbor cores in all directions
Definition: MPI_DirectionalGridEnvironment.h:259
This class is a Environment class to define MPI world.
Definition: MPI_Environment.h:36
const tMPICoreId & getCoreId() const
get the id of the current process of this environment
Definition: MPI_Environment.h:200
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 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
const std::array< tMPICoreId, N > & getGridSize() const
get the grids number
Definition: MPI_GridEnvironment.h:200
const std::array< tMPICoreId, N > & getIndices() const
get the indices of the current core within the grid environment
Definition: MPI_GridEnvironment.h:219
This class manges the reading & writing in one file.
Definition: MPI_IOFile.h:72
tBoolean allRead(const tMPICount &n, T *values, tMPIStatus &status)
read the value at implicit shared position with blocking action
Definition: MPI_IOFile.h:421
tBoolean close()
close the file
Definition: MPI_IOFile.h:215
tBoolean open(const MPI_Environment &env, const tMPIIOMode &mode)
open the file for the environment
Definition: MPI_IOFile.h:187
tBoolean getSize(tMPIIOIndex &s) const
get the size of the file
Definition: MPI_IOFile.h:602
static const tMPIIOMode READ_ONLY
read only mode
Definition: MPI_IOFile.h:78
static const tMPIIOMode CREATE
file creation tag
Definition: MPI_IOFile.h:87
void setFileName(const tString &fn)
set the file name
Definition: MPI_IOFile.h:150
tBoolean writeOrdered(const tString &str)
write the value at shared core by explicit file cursor position with blocking action
Definition: MPI_IOFile.h:271
static const tMPIIOMode WRITE_ONLY
write only mode
Definition: MPI_IOFile.h:81