13 #ifndef _PARTICLEIOI_H_ 14 #define _PARTICLEIOI_H_ 18 #include "NamespaceHeader.H" 21 #define _CHUNK (1024*1024) 27 const vector<T>& a_vect,
28 const hid_t& H5T_type,
29 const std::string& a_dataname)
32 hsize_t length = a_vect.size();
33 hid_t dataspace= H5Screate_simple(1, &length, NULL);
36 hid_t dataset = H5Dcreate(a_handle.
groupID(), a_dataname.c_str(),
40 hid_t dataset = H5Dcreate2(a_handle.
groupID(), a_dataname.c_str(),
42 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
49 hid_t memdataspace = H5Screate_simple(1, &length, NULL);
51 int err = H5Dwrite(dataset, H5T_type, memdataspace,
52 dataspace, H5P_DEFAULT, &a_vect[0]);
54 H5Sclose(memdataspace);
64 const hid_t& H5T_type,
65 const std::string& a_dataname)
69 hsize_t length = a_vect.size();
71 hid_t dataspace= H5Screate_simple(1, &length, NULL);
73 hid_t dataset = H5Dopen(a_handle.
groupID(), a_dataname.c_str());
75 hid_t dataset = H5Dopen2(a_handle.
groupID(), a_dataname.c_str(), H5P_DEFAULT);
80 hid_t memdataspace = H5Screate_simple(1, &length, NULL);
82 int err = H5Dread(dataset, H5T_type, memdataspace,
83 dataspace, H5P_DEFAULT, &a_vect[0]);
86 H5Sclose(memdataspace);
92 template<
class P>
void 95 const std::string& a_dataType)
104 vector<unsigned long long> locParticlesPerBox(grids.
size(),0);
107 unsigned long long numLocalParticles = 0;
112 const size_t numItems=a_particles[di].numItems();
113 numLocalParticles += (
unsigned long long)numItems;
114 locParticlesPerBox[grids.
index(di())] = (
unsigned long long)numItems;
117 vector<unsigned long long> particlesPerBox(grids.
size());
120 int result = MPI_Allreduce(&locParticlesPerBox[0], &particlesPerBox[0], locParticlesPerBox.size(),
121 MPI_UNSIGNED_LONG_LONG, MPI_SUM, Chombo_MPI::comm);
122 if (result != MPI_SUCCESS)
129 for (
int i=0; i<grids.
size(); i++)
131 particlesPerBox[i]=(
unsigned long long)locParticlesPerBox[i];
139 size_t objSize = P().size();
142 size_t numComps = objSize /
sizeof(
Real);
145 vector<unsigned long long> offsets;
146 unsigned long long totNumParticles = 0;
147 for (
int i=0; i<grids.
size(); i++)
149 offsets.push_back(numComps * totNumParticles);
150 totNumParticles += particlesPerBox[i];
154 if (totNumParticles==0)
159 CH_TIMER(
"writeParticlesToHDF::checkpoint",t_cp);
163 hsize_t
dataSize = totNumParticles * numComps;
166 hid_t dataspace = H5Screate_simple(1, &dataSize, NULL);
169 hid_t H5T_type = H5T_NATIVE_DOUBLE;
172 std::string dataname = a_dataType+
":data";
176 hid_t dataset = H5Dcreate(a_handle.
groupID(), dataname.c_str(),
180 hid_t dataset = H5Dcreate2(a_handle.
groupID(), dataname.c_str(),
182 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
185 if (numLocalParticles > 0)
188 const size_t chunkSize = objSize*
_CHUNK;
189 char* chunk =
new char[chunkSize];
192 MayDay::Error(
"WritePart::Error: new returned NULL pointer ");
197 size_t offset = offsets[ grids.
index(di()) ];
203 const List<P>& pList = a_particles[di].listItems();
207 pList[li].linearOut((
void*)chunk);
210 if (++ip % _CHUNK == 0)
215 chunkSize /
sizeof(
Real),chunk);
224 chunk -= (nResidual*objSize);
226 nResidual*objSize /
sizeof(
Real),chunk);
231 delete[] chunk; chunk=NULL;
246 const std::string& a_dataType)
252 vector<unsigned long long> particlesPerBox;
266 size_t objSize = P().
size();
269 size_t numComps = objSize /
sizeof(
Real);
272 vector<unsigned long long> offsets;
273 unsigned long long totNumParticles = 0;
274 for (
int i=0; i<grids.
size(); i++)
276 offsets.push_back(numComps * totNumParticles);
277 totNumParticles += particlesPerBox[i];
281 if (totNumParticles==0)
286 CH_TIMER(
"readParticlesFromHDF::checkpoint",t_cp);
293 hid_t H5T_type = H5T_NATIVE_DOUBLE;
296 std::string dataname = a_dataType+
":data";
300 hid_t dataset = H5Dopen(a_handle.
groupID(), dataname.c_str());
302 hid_t dataset = H5Dopen2(a_handle.
groupID(), dataname.c_str(), H5P_DEFAULT);
305 hid_t dataspace= H5Dget_space(dataset);
308 const size_t chunkSize = objSize*
_CHUNK;
311 char* chunk =
new char[chunkSize];
315 size_t boxData= numComps * particlesPerBox[ bl.index(di()) ];
316 size_t offset = offsets[ bl.index(di()) ];
318 List<P>& items= a_particles[di].listItems();
321 while (dataIn < boxData)
324 int size = ((boxData-dataIn) >= (chunkSize /
sizeof(
Real))) ? chunkSize /
sizeof(
Real) : boxData - dataIn;
325 readDataChunk(offset, dataspace, dataset, H5T_type, size, chunk);
328 for (
int ip=0; ip<size/numComps; ip++)
337 chunk -= size*
sizeof(
Real);
342 delete[] chunk; chunk=NULL;
353 template<
class P>
void 357 const std::string& a_dataType)
369 unsigned long long totNumParticles = a_particles.
size();
372 vector<unsigned long long> particlesPerBox;
373 particlesPerBox.push_back(totNumParticles);
378 size_t objSize = P().size();
381 size_t numComps = objSize /
sizeof(
Real);
384 if (totNumParticles==0)
390 hsize_t
dataSize = totNumParticles * numComps;
393 hid_t dataspace = H5Screate_simple(1, &dataSize, NULL);
396 hid_t H5T_type = H5T_NATIVE_DOUBLE;
399 std::string dataname = a_dataType+
":data";
404 hid_t dataset = H5Dcreate(a_handle.
groupID(), dataname.c_str(),
408 hid_t dataset = H5Dcreate2(a_handle.
groupID(), dataname.c_str(),
410 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
414 const size_t bufferSize = objSize*totNumParticles;
415 char* buffer =
new char[bufferSize];
418 if (buffer == NULL) {
419 MayDay::Error(
"WritePart::Error: new returned NULL pointer ");
426 for (
int ip = 0; ip < totNumParticles; ip++)
428 a_particles[ip].linearOut((
void*)buffer);
433 buffer -= bufferSize;
437 bufferSize /
sizeof(
Real), buffer);
450 #include "NamespaceFooter.H" #define CH_TIMERS(name)
Definition: CH_Timer.H:133
void writeDataChunk(size_t &offset, const hid_t &dataspace, const hid_t &dataset, const hid_t &H5T_type, const unsigned long dataLength, const void *const data)
Write chunk of data and upgrade offset. Not meant to be a user-facing function.
void readParticlesFromHDF(HDF5Handle &a_handle, ParticleData< P > &a_particles, const std::string &a_dataType)
Definition: ParticleIOI.H:244
void readDataChunk(size_t &offset, const hid_t &dataspace, const hid_t &dataset, const hid_t &H5T_type, const unsigned long dataLength, void *const data, const size_t stride=1, const size_t block=1)
Read chunk of data and upgrade offset. Not meant to be a user-facing function.
#define CH_assert(cond)
Definition: CHArray.H:37
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:145
#define CH_START(tpointer)
Definition: CH_Timer.H:145
unsigned int size() const
Returns the total number of boxes in the BoxLayout.
void read_vect_from_header(HDF5Handle &a_handle, vector< T > &a_vect, const hid_t &H5T_type, const std::string &a_dataname)
A helper function that reads a vector of 'T's to the HDF5 file under a_dataname.
Definition: ParticleIOI.H:62
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:117
Definition: DataIterator.H:190
void dataSize(const BaseFab< int > &item, Vector< int > &a_sizes, const Box &box, const Interval &comps)
Definition: CH_HDF5.H:847
#define CH_TIMER(name, tpointer)
Definition: CH_Timer.H:63
const std::string & getGroup() const
bool ok() const
Return true if the iterator is not past the end of the list.
Definition: List.H:465
unsigned int index(const LayoutIndex &index) const
Definition: BoxLayout.H:748
void push_back(const T &in)
Definition: Vector.H:295
void writeParticlesToHDF(HDF5Handle &a_handle, const ParticleData< P > &a_particles, const std::string &a_dataType)
Definition: ParticleIOI.H:93
Iterator over a List.
Definition: List.H:20
void add(const T &value)
Adds a copy of the value to the end of the List<T>.
Definition: ListImplem.H:49
double Real
Definition: REAL.H:33
size_t size() const
Definition: Vector.H:192
static void Error(const char *const a_msg=m_nullString, int m_exitCode=CH_DEFAULT_ERROR_CODE)
Print out message to cerr and exit with the specified exit code.
void read_hdf_part_header(HDF5Handle &a_handle, Vector< Box > &a_grids, vector< unsigned long long > &a_particlesPerBox, const std::string &a_dataType, const std::string &a_path)
Read the particle header from the HDF5 file. Not meant to be a user-facing function.
void write_vect_to_header(HDF5Handle &a_handle, const vector< T > &a_vect, const hid_t &H5T_type, const std::string &a_dataname)
A helper function that writes a vector of 'T's to the HDF5 file under a_dataname. ...
Definition: ParticleIOI.H:26
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
const BoxLayout & getBoxes() const
Get the BoxLayout on which this ParticleData.
Definition: ParticleDataI.H:193
void write_hdf_part_header(HDF5Handle &a_handle, const BoxLayout &a_grids, const vector< unsigned long long > &a_partPerBox, const std::string &a_dataType)
Write the particle header to the HDF5 file. Not meant to be a user-facing function.
int length() const
Returns the number of objects in the List<T>.
Definition: ListImplem.H:56
#define CH_STOP(tpointer)
Definition: CH_Timer.H:150
Handle to a particular group in an HDF file.
Definition: CH_HDF5.H:294
#define _CHUNK
Definition: ParticleIOI.H:21
int procID()
local process ID
Definition: ParticleData.H:67
const hid_t & groupID() const