11 #ifndef _BLOCKWRITEI_H_ 12 #define _BLOCKWRITEI_H_ 29 template <
class T>
void 32 long long & a_localTotalSize,
38 if (!(T::preAllocatable()==0))
40 MayDay::Error(
"non static preallocatable data not covered yet.");
46 unsigned int curIndex = 0;
50 a_localSizes.
resize(it.size());
51 a_localBoxes.
resize(it.size());
52 for (it.reset(); it.ok(); ++it)
54 long long curSize = 0;
55 const Box& curBox = layout[it()];
57 region.
grow(a_outputGhost);
58 dataSize(dummy, thisSize, region, a_comps);
60 curSize = thisSize[0];
61 a_localSizes[curIndex] = curSize;
62 a_localBoxes[curIndex] = curBox;
64 a_localTotalSize += thisSize[0];
69 template <
class T>
void 76 int* curPtr = (
int*)(a_buffer);
81 const T& data = a_data[it()];
84 box.
grow(a_outputGhost);
85 write(data, buffers, box, a_comps);
87 curPtr += a_sizes[curIndex];
95 long long& a_allProcSize,
100 const long long& a_localAllBoxSize)
107 gather(allBoxes, a_localBoxes, iprocdest);
108 gather(allBoxSizes, a_localBoxSizes, iprocdest);
109 gather(allSizes, a_localAllBoxSize, iprocdest);
111 if (
procID() == iprocdest)
114 long long numBoxes = 0;
115 for (
int iproc = 0; iproc <
numProc(); iproc++)
117 a_allProcSize += allSizes[iproc];
118 numBoxes += allBoxes[iproc].
size();
120 a_globalBoxes. resize(numBoxes);
121 a_globalOffsets.
resize(numBoxes+1);
123 long long curOffset = 0;
125 for (
int iproc = 0; iproc <
numProc(); iproc++)
127 for (
int ivec = 0; ivec < allBoxSizes[iproc].
size(); ivec++)
131 offsetsProcs[iproc] = curOffset;
133 long long boxSize = allBoxSizes[iproc][ivec];
134 Box curBox = allBoxes[iproc][ivec];
136 a_globalBoxes [curIndex] = curBox;
137 a_globalOffsets[curIndex] = curOffset;
140 curOffset += boxSize;
143 if (curOffset != a_allProcSize)
147 a_globalOffsets[curIndex] = curOffset;
150 a_offsetThisProc = offsetsProcs[
procID()];
160 const std::string& a_name,
165 const long long& a_thisprocsize)
170 long long offsetthisproc, sumprocsize;
175 int ret =
gatherBoxesAndOffsets(offsetthisproc, sumprocsize, globalOffsets, globalBoxes, a_sizes, a_boxes, a_thisprocsize);
181 if (globalBoxes.
size() != a_layout.
size())
187 char offsetname[1024];
188 sprintf(offsetname,
"%s:offsets=0",a_name.c_str());
191 flatdims[0] = globalOffsets.
size();
192 hid_t offsetspace = H5Screate_simple(1, flatdims, NULL);
193 hid_t offsetdata = H5Dcreate(a_handle.
groupID(), offsetname,
194 H5T_NATIVE_LLONG, offsetspace, H5P_DEFAULT);
198 hid_t memdataspace = H5Screate_simple(1, flatdims, NULL);
199 err = H5Dwrite(offsetdata, H5T_NATIVE_LLONG, memdataspace, offsetspace,
200 H5P_DEFAULT, &(globalOffsets[0]));
201 if (err < 0)
return err;
202 H5Sclose(memdataspace);
205 H5Sclose(offsetspace);
206 H5Dclose(offsetdata);
209 hsize_t hs_procsize[1];
210 hsize_t hs_allprocsize[1];
213 ch_offset[0] = offsetthisproc;
214 hs_procsize[0] = a_thisprocsize;
215 hs_allprocsize[0] = sumprocsize;
218 sprintf(dataname,
"%s:datatype=0",a_name.c_str());
220 hid_t dataspace = H5Screate_simple(1, hs_allprocsize, NULL);
221 hid_t memdataspace = H5Screate_simple(1, hs_procsize, NULL);
223 hid_t dataset = H5Dcreate(a_handle.
groupID(), dataname,
224 a_types[0], dataspace, H5P_DEFAULT);
227 err = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET,
230 if (err < 0)
return err;
232 err = H5Dwrite(dataset, a_types[0], memdataspace, dataspace,
233 H5P_DEFAULT, a_buffer);
234 if (err < 0)
return err;
236 H5Sclose(memdataspace);
246 const std::string& a_name,
255 std::string group = a_handle.
getGroup();
256 a_handle.
setGroup(group+
"/"+a_name+
"_attributes");
263 template <
class T>
int 266 const std::string& a_name,
278 if (types.
size() != 1)
280 MayDay::Error(
"premature generality, I only deal with types of size 1");
293 size_t type_size = H5Tget_size(types[0]);
296 void* buffer =
mallocMT(totalsize*type_size);
305 std::string group = a_handle.
getGroup();
307 a_handle.
setGroup(group+
"/"+a_name+
"_attributes");
334 template <
class T>
int 342 const int& a_refRatio,
348 std::string currentGroup = a_handle.
getGroup();
349 sprintf(levelName,
"/level_%i",a_level);
350 error = a_handle.
setGroup(currentGroup + levelName);
351 if (error != 0)
return 1;
356 meta.
m_real[
"time"] = a_time;
357 meta.
m_box[
"prob_domain"] = a_domain;
358 meta.
m_int[
"ref_ratio"] = a_refRatio;
361 if (error != 0)
return 2;
364 if (error != 0)
return 3;
366 error =
blockWrite(a_handle, a_data, std::string(
"data"), a_outputGhost, a_comps);
367 if (error != 0)
return 4;
374 template <
class T>
int 393 std::string currentGroup = a_handle.
getGroup();
394 sprintf(levelName,
"/level_%i",a_level);
395 error = a_handle.
setGroup(currentGroup + levelName);
396 if (error != 0)
return 1;
400 if (error != 0)
return 2;
403 a_time = meta.
m_real[
"time"];
404 a_domain = meta.
m_box[
"prob_domain"];
405 a_refRatio = meta.
m_int[
"ref_ratio"];
409 error =
read(a_handle, boxes);
417 if (error != 0)
return 3;
419 error =
blockRead(a_handle, a_data,
"data", layout, a_comps);
421 if (error != 0)
return 4;
430 template <
class T>
int 437 std::string group = a_handle.
getGroup();
438 if (a_handle.
setGroup(group+
"/"+a_name+
"_attributes"))
440 std::string message =
"error opening " 441 +a_handle.
getGroup()+
"/"+a_name+
"_attributes" ;
447 int ncomp = info.
m_int[
"comps"];
449 if (a_comps.
end() > 0 && ncomp < a_comps.
end())
451 MayDay::Error(
"attempt to read component interval that is not available");
453 if (a_comps.
size() == 0)
454 a_data.
define(a_layout, ncomp, ghost);
456 a_data.
define(a_layout, a_comps.
size(), ghost);
468 int ret =
read(a_handle, a_data, a_name, a_layout, a_comps, a_redefineData);
int blockWriteBufferToFile(HDF5Handle &a_handle, void *a_buffer, const std::string &a_name, Vector< Box > &a_boxes, Vector< long long > &a_sizes, const Vector< hid_t > &a_types, const BoxLayout &a_layout, const long long &a_thisprocsize)
Definition: BlockWriteI.H:158
IntVect & min(const IntVect &p)
Definition: IntVect.H:1124
#define freeMT(a_a)
Definition: memtrack.H:160
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:145
int size() const
Definition: Interval.H:75
#define mallocMT(a_a)
Definition: memtrack.H:159
unsigned int size() const
Returns the total number of boxes in the BoxLayout.
const BoxLayout & boxLayout() const
Definition: LayoutData.H:107
DataIterator dataIterator() const
Definition: LayoutDataI.H:78
void blockLocalOffsets(Vector< long long > &a_localSizes, long long &a_localTotalSize, Vector< Box > &a_localBoxes, const BoxLayoutData< T > &a_data, const Interval &a_comps, const IntVect &a_outputGhost)
Definition: BlockWriteI.H:30
Box box(const DataIndex &a_index) const
Definition: LayoutDataI.H:66
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:117
int gatherBoxesAndOffsets(long long &a_offsetThisProc, long long &a_allProcSize, Vector< long long > &a_globalOffsets, Vector< Box > &a_globalBoxes, const Vector< long long > &a_localBoxSizes, const Vector< Box > &a_localBoxes, const long long &a_localAllBoxSize)
Definition: BlockWriteI.H:94
Definition: DataIterator.H:190
int LoadBalance(Vector< Vector< int > > &a_procAssignments, Real &a_effRatio, const Vector< Vector< Box > > &a_Grids, const Vector< Vector< long > > &a_ComputeLoads, const Vector< int > &a_RefRatios, int a_nProc=numProc())
unsigned int numProc()
number of parallel processes
void dataTypes(Vector< hid_t > &a_types, const BaseFab< int > &dummy)
Definition: CH_HDF5.H:801
void dataSize(const BaseFab< int > &item, Vector< int > &a_sizes, const Box &box, const Interval &comps)
Definition: CH_HDF5.H:847
int blockWriteLevel(HDF5Handle &a_handle, const int &a_level, const LevelData< T > &a_data, const Real &a_dx, const Real &a_dt, const Real &a_time, const Box &a_domain, const int &a_refRatio, const IntVect &a_outputGhost, const Interval &a_comps)
Definition: BlockWriteI.H:335
Definition: EBInterface.H:45
void resize(unsigned int isize)
Definition: Vector.H:346
const std::string & getGroup() const
void gather(Vector< T > &a_outVec, const T &a_input, int a_dest)
Definition: SPMDI.H:197
#define CH_TIME(name)
Definition: CH_Timer.H:82
Structure for passing component ranges in code.
Definition: Interval.H:23
const char * name(const FArrayBox &a_dummySpecializationArg)
Definition: CH_HDF5.H:907
new code
Definition: BoxLayoutData.H:170
Data on a BoxLayout.
Definition: BoxLayoutData.H:97
double Real
Definition: REAL.H:33
virtual void define(const DisjointBoxLayout &dp, int comps, const IntVect &ghost=IntVect::Zero, const DataFactory< T > &a_factory=DefaultDataFactory< T >())
Definition: LevelDataI.H:93
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:30
size_t size() const
Definition: Vector.H:192
const IntVect & ghostVect() const
Definition: LevelData.H:186
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.
int write(HDF5Handle &a_handle, const BoxLayout &a_layout, const std::string &name="boxes")
writes BoxLayout to HDF5 file.
int blockWrite(HDF5Handle &a_handle, const LevelData< T > &a_data, const std::string &a_name, const IntVect &a_outputGhost, const Interval &a_in_comps)
Definition: BlockWriteI.H:244
hssize_t ch_offset_t
Definition: CH_HDF5.H:695
static void Warning(const char *const a_msg=m_nullString)
Print out message to cerr and continue.
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
void blockWriteToBuffer(void *a_buffer, const Vector< long long > &a_sizes, const BoxLayoutData< T > &a_data, const Interval &a_comps, const IntVect &a_outputGhost)
Definition: BlockWriteI.H:70
Handle to a particular group in an HDF file.
Definition: CH_HDF5.H:294
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Box & grow(int i)
grow functions
Definition: Box.H:2247
int setGroup(const std::string &groupAbsPath)
void broadcast(T &a_inAndOut, int a_src)
broadcast to every process
Definition: SPMDI.H:207
int end() const
Definition: Interval.H:102
int blockReadLevel(HDF5Handle &a_handle, const int &a_level, LevelData< T > &a_data, Real &a_dx, Real &a_dt, Real &a_time, Box &a_domain, int &a_refRatio, const Interval &a_comps, bool a_setGhost)
Definition: BlockWriteI.H:375
DataIterator dataIterator() const
Parallel iterator.
int procID()
local process ID
void read(T &item, Vector< Vector< char > > &a_allocatedBuffers, const Box &box, const Interval &comps)
Definition: CH_HDF5.H:51
const hid_t & groupID() const
int blockRead(HDF5Handle &a_handle, LevelData< T > &a_data, const std::string &a_name, const DisjointBoxLayout &a_layout, const Interval &a_comps, bool a_redefineData)
read LevelData named a_name from location specified by a_handle.
Definition: BlockWriteI.H:431