11 #ifndef _BLOCKWRITEI_H_ 12 #define _BLOCKWRITEI_H_ 30 template <
class T>
void 33 long long & a_localTotalSize,
39 if (!(T::preAllocatable()==0))
41 MayDay::Error(
"non static preallocatable data not covered yet.");
47 unsigned int curIndex = 0;
51 a_localSizes.
resize(it.size());
52 a_localBoxes.
resize(it.size());
53 for (it.reset(); it.ok(); ++it)
55 long long curSize = 0;
56 const Box& curBox = layout[it()];
58 region.
grow(a_outputGhost);
59 dataSize(dummy, thisSize, region, a_comps);
61 curSize = thisSize[0];
62 a_localSizes[curIndex] = curSize;
63 a_localBoxes[curIndex] = curBox;
65 a_localTotalSize += thisSize[0];
70 template <
class T>
void 77 int* curPtr = (
int*)(a_buffer);
82 const T& data = a_data[it()];
85 box.
grow(a_outputGhost);
86 write(data, buffers, box, a_comps);
88 curPtr += a_sizes[curIndex];
96 long long& a_allProcSize,
101 const long long& a_localAllBoxSize)
108 gather(allBoxes, a_localBoxes, iprocdest);
109 gather(allBoxSizes, a_localBoxSizes, iprocdest);
110 gather(allSizes, a_localAllBoxSize, iprocdest);
112 if (
procID() == iprocdest)
115 long long numBoxes = 0;
116 for (
int iproc = 0; iproc <
numProc(); iproc++)
118 a_allProcSize += allSizes[iproc];
119 numBoxes += allBoxes[iproc].
size();
121 a_globalBoxes. resize(numBoxes);
122 a_globalOffsets.
resize(numBoxes+1);
124 long long curOffset = 0;
126 for (
int iproc = 0; iproc <
numProc(); iproc++)
128 for (
int ivec = 0; ivec < allBoxSizes[iproc].
size(); ivec++)
132 offsetsProcs[iproc] = curOffset;
134 long long boxSize = allBoxSizes[iproc][ivec];
135 Box curBox = allBoxes[iproc][ivec];
137 a_globalBoxes [curIndex] = curBox;
138 a_globalOffsets[curIndex] = curOffset;
141 curOffset += boxSize;
144 if (curOffset != a_allProcSize)
148 a_globalOffsets[curIndex] = curOffset;
151 a_offsetThisProc = offsetsProcs[
procID()];
161 const std::string& a_name,
166 const long long& a_thisprocsize)
171 long long offsetthisproc, sumprocsize;
176 int ret =
gatherBoxesAndOffsets(offsetthisproc, sumprocsize, globalOffsets, globalBoxes, a_sizes, a_boxes, a_thisprocsize);
182 if (globalBoxes.
size() != a_layout.
size())
188 char offsetname[1024];
189 sprintf(offsetname,
"%s:offsets=0",a_name.c_str());
192 flatdims[0] = globalOffsets.
size();
193 hid_t offsetspace = H5Screate_simple(1, flatdims, NULL);
194 hid_t offsetdata = H5Dcreate(a_handle.
groupID(), offsetname,
195 H5T_NATIVE_LLONG, offsetspace, H5P_DEFAULT);
199 hid_t memdataspace = H5Screate_simple(1, flatdims, NULL);
200 err = H5Dwrite(offsetdata, H5T_NATIVE_LLONG, memdataspace, offsetspace,
201 H5P_DEFAULT, &(globalOffsets[0]));
202 if (err < 0)
return err;
203 H5Sclose(memdataspace);
206 H5Sclose(offsetspace);
207 H5Dclose(offsetdata);
210 hsize_t hs_procsize[1];
211 hsize_t hs_allprocsize[1];
214 ch_offset[0] = offsetthisproc;
215 hs_procsize[0] = a_thisprocsize;
216 hs_allprocsize[0] = sumprocsize;
219 sprintf(dataname,
"%s:datatype=0",a_name.c_str());
222 hid_t dataspace = H5Screate_simple(1, hs_allprocsize, NULL);
223 hid_t memdataspace = H5Screate_simple(1, hs_procsize, NULL);
225 hid_t dataset = H5Dcreate(a_handle.
groupID(), dataname,
226 a_types[0], dataspace, H5P_DEFAULT);
230 err = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET,
233 if (err < 0)
return err;
235 err = H5Dwrite(dataset, a_types[0], memdataspace, dataspace,
236 H5P_DEFAULT, a_buffer);
237 if (err < 0)
return err;
240 H5Sclose(memdataspace);
250 const std::string& a_name,
259 std::string group = a_handle.
getGroup();
260 a_handle.
setGroup(group+
"/"+a_name+
"_attributes");
267 template <
class T>
int 270 const std::string& a_name,
283 if (types.
size() != 1)
285 MayDay::Error(
"premature generality, I only deal with types of size 1");
298 size_t type_size = H5Tget_size(types[0]);
301 void* buffer =
mallocMT(totalsize*type_size);
310 std::string group = a_handle.
getGroup();
312 a_handle.
setGroup(group+
"/"+a_name+
"_attributes");
339 template <
class T>
int 347 const int& a_refRatio,
353 std::string currentGroup = a_handle.
getGroup();
354 sprintf(levelName,
"/level_%i",a_level);
355 error = a_handle.
setGroup(currentGroup + levelName);
356 if (error != 0)
return 1;
361 meta.
m_real[
"time"] = a_time;
362 meta.
m_box[
"prob_domain"] = a_domain;
363 meta.
m_int[
"ref_ratio"] = a_refRatio;
366 if (error != 0)
return 2;
369 if (error != 0)
return 3;
371 error =
blockWrite(a_handle, a_data, std::string(
"data"), a_outputGhost, a_comps);
372 if (error != 0)
return 4;
379 template <
class T>
int 398 std::string currentGroup = a_handle.
getGroup();
399 sprintf(levelName,
"/level_%i",a_level);
400 error = a_handle.
setGroup(currentGroup + levelName);
401 if (error != 0)
return 1;
405 if (error != 0)
return 2;
408 a_time = meta.
m_real[
"time"];
409 a_domain = meta.
m_box[
"prob_domain"];
410 a_refRatio = meta.
m_int[
"ref_ratio"];
414 error =
read(a_handle, boxes);
422 if (error != 0)
return 3;
424 error =
blockRead(a_handle, a_data,
"data", layout, a_comps);
426 if (error != 0)
return 4;
435 template <
class T>
int 442 std::string group = a_handle.
getGroup();
443 if (a_handle.
setGroup(group+
"/"+a_name+
"_attributes"))
445 std::string message =
"error opening " 446 +a_handle.
getGroup()+
"/"+a_name+
"_attributes" ;
452 int ncomp = info.
m_int[
"comps"];
454 if (a_comps.
end() > 0 && ncomp < a_comps.
end())
456 MayDay::Error(
"attempt to read component interval that is not available");
458 if (a_comps.
size() == 0)
459 a_data.
define(a_layout, ncomp, ghost);
461 a_data.
define(a_layout, a_comps.
size(), ghost);
474 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:159
IntVect & min(const IntVect &p)
Definition: IntVect.H:1041
#define freeMT(a_a)
Definition: memtrack.H:159
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:146
int size() const
Definition: Interval.H:64
#define mallocMT(a_a)
Definition: memtrack.H:158
unsigned int size() const
Returns the total number of boxes in the BoxLayout.
const BoxLayout & boxLayout() const
Definition: LayoutData.H:108
DataIterator dataIterator() const
Definition: LayoutDataI.H:79
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:31
Box box(const DataIndex &a_index) const
Definition: LayoutDataI.H:67
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:110
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:95
Definition: DataIterator.H:140
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:676
void dataSize(const BaseFab< int > &item, Vector< int > &a_sizes, const Box &box, const Interval &comps)
Definition: CH_HDF5.H:707
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:340
Definition: EBInterface.H:45
void resize(unsigned int isize)
Definition: Vector.H:323
const std::string & getGroup() const
void gather(Vector< T > &a_outVec, const T &a_input, int a_dest)
Definition: SPMDI.H:194
#define CH_TIME(name)
Definition: CH_Timer.H:59
Structure for passing component ranges in code.
Definition: Interval.H:23
const char * name(const FArrayBox &a_dummySpecializationArg)
Definition: CH_HDF5.H:741
Definition: BoxLayoutData.H:136
Data on a BoxLayout.
Definition: BoxLayoutData.H:91
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:70
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:31
size_t size() const
Definition: Vector.H:177
const IntVect & ghostVect() const
Definition: LevelData.H:157
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:248
hssize_t ch_offset_t
Definition: CH_HDF5.H:566
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:71
Handle to a particular group in an HDF file.
Definition: CH_HDF5.H:267
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Box & grow(int i)
grow functions
Definition: Box.H:2268
int setGroup(const std::string &groupAbsPath)
void broadcast(T &a_inAndOut, int a_src)
broadcast to every process
Definition: SPMDI.H:204
int end() const
Definition: Interval.H:91
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:380
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:47
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:436