Dendro  5.01
Dendro in Greek language means tree. The Dendro library is a large scale (262K cores on ORNL's Titan) distributed memory adaptive octree framework. The main goal of Dendro is to perform large scale multiphysics simulations efficeiently in mordern supercomputers. Dendro consists of efficient parallel data structures and algorithms to perform variational ( finite element) methods and finite difference mthods on 2:1 balanced arbitary adaptive octrees which enables the users to perform simulations raning from black holes (binary black hole mergers) to blood flow in human body, where applications ranging from relativity, astrophysics to biomedical engineering.
checkPoint.h
1 //
2 // Created by milinda on 7/12/17.
8 //
9 
10 #ifndef SFCSORTBENCH_CHECKPOINT_H
11 #define SFCSORTBENCH_CHECKPOINT_H
12 
13 #include "TreeNode.h"
14 #include "mesh.h"
15 #include "json.hpp"
16 #include <iostream>
17 #include <fstream>
18 using json = nlohmann::json;
19 namespace io
20 {
21 
22  namespace checkpoint
23  {
24 
35  int writeOctToFile(const char * fName,const ot::TreeNode* pNodes,const unsigned int num);
36 
43  int readOctFromFile(const char * fName,std::vector<ot::TreeNode> & pNodes);
44 
45 
55  template <typename T>
56  int writeVecToFile(const char * fName, const ot::Mesh* pMesh,const T* vec);
57 
68  template <typename T>
69  int writeVecToFile(const char * fName, const ot::Mesh* pMesh,const T** vec,const unsigned int numVars);
70 
77  template <typename T>
78  int readVecFromFile(const char * fName, const ot::Mesh* pMesh, T* vec);
79 
80 
88  template <typename T>
89  int readVecFromFile(const char * fName, const ot::Mesh* pMesh, T** vec, const unsigned int numVars);
90 
91 
92 
93 
94 
95  } // end of namespace checkpoint.
96 
97 }// end of namespace io
98 
99 
100 
101 
102 // templated implementations
103 namespace io
104 {
105  namespace checkpoint
106  {
107  template <typename T>
108  int writeVecToFile(const char * fName, const ot::Mesh* pMesh,const T* vec)
109  {
110  unsigned int numNodes=pMesh->getNumLocalMeshNodes()+pMesh->getNumPreMeshNodes()+pMesh->getNumPostMeshNodes();
111  unsigned int nLocalBegin=pMesh->getNodeLocalBegin();
112  unsigned int nLocalEnd=pMesh->getNodeLocalEnd();
113 
114  FILE * outfile=fopen(fName,"w");
115  if(outfile==NULL){std::cout<<fName<<" file open failed "<<std::endl; return 1;}
116 
117  fwrite(&numNodes,sizeof(unsigned int ),1,outfile);
118  fwrite(&nLocalBegin,sizeof(unsigned int ),1,outfile);
119  fwrite(&nLocalEnd,sizeof(unsigned int ),1,outfile);
120  if(numNodes>0)
121  fwrite((vec+nLocalBegin),sizeof(T),pMesh->getNumLocalMeshNodes(),outfile);
122 
123  fclose(outfile);
124  return 0;
125 
126  }
127 
128 
129  template <typename T>
130  int writeVecToFile(const char * fName, const ot::Mesh* pMesh,const T** vec,const unsigned int numVars)
131  {
132  unsigned int numNodes=pMesh->getNumLocalMeshNodes()+pMesh->getNumPreMeshNodes()+pMesh->getNumPostMeshNodes();
133  unsigned int nLocalBegin=pMesh->getNodeLocalBegin();
134  unsigned int nLocalEnd=pMesh->getNodeLocalEnd();
135 
136  FILE * outfile=fopen(fName,"w");
137  if(outfile==NULL){std::cout<<fName<<" file open failed "<<std::endl; return 1;}
138 
139  fwrite(&numNodes,sizeof(unsigned int ),1,outfile);
140  fwrite(&nLocalBegin,sizeof(unsigned int ),1,outfile);
141  fwrite(&nLocalEnd,sizeof(unsigned int ),1,outfile);
142  if(numNodes>0)
143  for(unsigned int i=0;i<numVars;i++)
144  fwrite((vec[i]+nLocalBegin),sizeof(T),pMesh->getNumLocalMeshNodes(),outfile);
145 
146  fclose(outfile);
147  return 0;
148 
149  }
150 
151 
152  template <typename T>
153  int readVecFromFile(const char * fName, const ot::Mesh* pMesh,T* vec)
154  {
155 
156  unsigned int numNodes,nLocalBegin,nLocalEnd;
157 
158  FILE * infile = fopen(fName,"r");
159  if(infile==NULL){std::cout<<fName<<" file open failed "<<std::endl; return 1;}
160  fread(&numNodes,sizeof(unsigned int ),1,infile);
161  fread(&nLocalBegin,sizeof(unsigned int ),1,infile);
162  fread(&nLocalEnd,sizeof(unsigned int ),1,infile);
163 
164  if(numNodes!=(pMesh->getNumPreMeshNodes()+pMesh->getNumLocalMeshNodes()+pMesh->getNumPostMeshNodes())) {std::cout<<fName<<" file number of total node mismatched with the mesh. "<<std::endl; return 1;}
165  if(nLocalBegin!=pMesh->getNodeLocalBegin()) {std::cout<<fName<<" file local node begin location mismatched with the mesh. "<<std::endl; return 1;}
166  if(nLocalEnd!=pMesh->getNodeLocalEnd()) {std::cout<<fName<<" file local node end location mismatched with the mesh. "<<std::endl; return 1;}
167 
168  if(numNodes>0)
169  fread((vec+nLocalBegin),sizeof(T),pMesh->getNumLocalMeshNodes(),infile);
170 
171  fclose(infile);
172  return 0;
173  }
174 
175  template <typename T>
176  int readVecFromFile(const char * fName, const ot::Mesh* pMesh, T** vec, const unsigned int numVars)
177  {
178  unsigned int numNodes,nLocalBegin,nLocalEnd;
179 
180  FILE * infile = fopen(fName,"r");
181  if(infile==NULL){std::cout<<fName<<" file open failed "<<std::endl; return 1;}
182  fread(&numNodes,sizeof(unsigned int ),1,infile);
183  fread(&nLocalBegin,sizeof(unsigned int ),1,infile);
184  fread(&nLocalEnd,sizeof(unsigned int ),1,infile);
185 
186  if(numNodes!=(pMesh->getNumPreMeshNodes()+pMesh->getNumLocalMeshNodes()+pMesh->getNumPostMeshNodes())) {std::cout<<fName<<" file number of total node mismatched with the mesh. "<<std::endl; return 1;}
187  if(nLocalBegin!=pMesh->getNodeLocalBegin()) {std::cout<<fName<<" file local node begin location mismatched with the mesh. "<<std::endl; return 1;}
188  if(nLocalEnd!=pMesh->getNodeLocalEnd()) {std::cout<<fName<<" file local node end location mismatched with the mesh. "<<std::endl; return 1;}
189 
190  if(numNodes>0)
191  for(unsigned int i=0;i<numVars;i++)
192  fread((vec[i]+nLocalBegin),sizeof(T),pMesh->getNumLocalMeshNodes(),infile);
193 
194  fclose(infile);
195  return 0;
196  }
197 
198 
199  } // end of namespace checkpoint
200 
201 } // end of namespace io
202 
203 
204 
205 
206 #endif //SFCSORTBENCH_CHECKPOINT_H
unsigned int getNumPostMeshNodes() const
return the number of post ghost mesh nodes
Definition: mesh.h:1024
a class to store JSON values
Definition: json.hpp:85
A class to manage octants.
Definition: TreeNode.h:35
Definition: mesh.h:179
basic_json<> json
default JSON class
Definition: json.hpp:109
unsigned int getNodeLocalBegin() const
return the location of local node begin
Definition: mesh.h:1043
contains functions to dump out raw data asci/binary. Can be useful for debugging purposes.
Definition: rawIO.h:19
unsigned int getNumPreMeshNodes() const
return the number of pre ghost mesh nodes
Definition: mesh.h:1022
unsigned int getNumLocalMeshNodes() const
return the number of nodes local to the mesh
Definition: mesh.h:1020
unsigned int getNodeLocalEnd() const
return the location of local node end
Definition: mesh.h:1045