[MOAB-dev] HDF5 export of structured mesh

Jason Kraftcheck kraftche at cae.wisc.edu
Tue Jul 13 15:07:59 CDT 2010


hongjun at mcs.anl.gov wrote:
> Hi,
> 
> I'd like to ask a question about HDF5 export of structured mesh. 
> Currently, "WriteHDF5" uses "WriteUtil::get_element_connect" function to
> write element connectivities. However, the function is implemented just
> for unstructured mesh which copies connectivity buffer from element
> sequence. So, I am trying to add to it a code copying connectivities
> element by element for structured mesh case.
> 

This is OK.

> Is it the right way to solve the problem? Otherwise, I think I can make a
> buffer inside "StructuredElementSeq" and
> "StructuredElementSeq::get_connectivity_array()" function returns array
> pointer. It can be more modular but copies connectivities once more for
> HDF5 exporting in "WriteUtil::get_element_connect" function. Could anyone
> tell me which one is better or other advice for me? Thanks.

This is not OK.  The point of structured mesh is to *not* allocate memory
for explicit storage of the connectivity.  If you allocate a buffer in the
sequence and return a pointer to it then the sequence will never know when
the buffer is no longer needed.  Thus after the first write of a structured
mesh the memory use by MOAB from then on will be worse than if the mesh were
stored as unstructured.

The correct way is to do something like allow the caller of
WriteUtil::get_element_connect to pass in an optional pointer to an
std::vector.  If the mesh is unstructured then the passed vector is never
used.  If the mesh is structured and the vector pointer is null then it is
an error.  If the mesh is structured and the vector pointer is not null then
the function should allocate the required storage in the vector and return a
pointer to the vector contents (i.e. &vector[0]).  That way if a buffer does
need to be allocated then a) the caller is responsible for freeing it and b)
the caller doesn't really need to do anything special other than declare a
vector and pass a pointer to it to handle structured mesh.


As for which approach to use: your first approach would be best for the HDF5
writer because it would avoid allocating potentially large blocks of memory
during the write (it is really unpleasant to have an application fail at the
very end when trying to save the data because it ran out of memory.)
However, the latter method would allow all writers to be easily changed to
handle structured mesh.  In the long term, the correct solution is probably
to do both.

- jason


More information about the moab-dev mailing list