Skip to content

Commit

Permalink
Convert external chunking documentation to doxygen (#5131)
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnHDF authored Nov 21, 2024
1 parent 258fa78 commit 7315776
Show file tree
Hide file tree
Showing 20 changed files with 547 additions and 10 deletions.
139 changes: 139 additions & 0 deletions doxygen/dox/DSChunkingIssues.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/** \page hdf5_chunk_issues Dataset Chunking Issues
*
* \section sec_hdf5_chunk_issues_intro Introduction
* <b>Chunking</b> refers to a storage layout where a dataset is partitioned into fixed-size multi-dimensional chunks.
* The chunks cover the dataset but the dataset need not be an integral number of chunks. If no data is ever written
* to a chunk then that chunk isn't allocated on disk. Figure 1 shows a 25x48 element dataset covered by nine 10x20 chunks
* and 11 data points written to the dataset. No data was written to the region of the dataset covered by three of the chunks
* so those chunks were never allocated in the file -- the other chunks are allocated at independent locations in the file
* and written in their entirety.
*
* <table>
* <tr>
* <td>
* \image html Chunk_f1.gif "Figure 1"
* </td>
* </tr>
* </table>
*
* The HDF5 library treats chunks as atomic objects -- disk I/O is always in terms of complete chunks (parallel versions
* of the library can access individual bytes of a chunk when the underlying file uses MPI-IO.). This allows data filters
* to be defined by the application to perform tasks such as compression, encryption, checksumming, etc. on entire chunks.
* As shown in Figure 2, if #H5Dwrite touches only a few bytes of the chunk, the entire chunk is read from the file, the
* data passes upward through the filter pipeline, the few bytes are modified, the data passes downward through the filter
* pipeline, and the entire chunk is written back to the file.
*
* <table>
* <tr>
* <td>
* \image html Chunk_f2.gif "Figure 2"
* </td>
* </tr>
* </table>
*
* \section sec_hdf5_chunk_issues_data The Raw Data Chunk Cache
* It's obvious from Figure 2 that calling #H5Dwrite many times from the application would result in poor performance even
* if the data being written all falls within a single chunk. A raw data chunk cache layer was added between the top of
* the filter stack and the bottom of the byte modification layer.
* By default, the chunk cache will store 521 chunks
* or 1MB of data (whichever is less) but these values can be modified with #H5Pset_cache.
*
* The preemption policy for the cache favors certain chunks and tries not to preempt them.
* \li Chunks that have been accessed frequently in the near past are favored.
* \li A chunk which has just entered the cache is favored.
* \li A chunk which has been completely read or completely written but not partially read or written is penalized according
* to some application specified weighting between zero and one.
* \li A chunk which is larger than the maximum cache size is not eligible for caching.
*
* \section sec_hdf5_chunk_issues_effic Cache Efficiency
* Now for some real numbers... A 2000x2000 element dataset is created and covered by a 20x20 array of chunks (each chunk is
* 100x100 elements). The raw data cache is adjusted to hold at most 25 chunks by setting the maximum number of bytes to 25
* times the chunk size in bytes. Then the application creates a square, two-dimensional memory buffer and uses it as a window
* into the dataset, first reading and then rewriting in row-major order by moving the window across the dataset (the read and
* write tests both start with a cold cache).
*
* The measure of efficiency in Figure 3 is the number of bytes requested by the application divided by the number of bytes
* transferred from the file. There are at least a couple ways to get an estimate of the cache performance: one way is to turn
* on cache debugging and look at the number of cache misses. A more accurate and specific way is to register a data filter whose
* sole purpose is to count the number of bytes that pass through it (that's the method used below).
*
* <table>
* <tr>
* <td>
* \image html Chunk_f3.gif "Figure 3"
* </td>
* </tr>
* </table>
*
* The read efficiency is less than one for two reasons: collisions in the cache are handled by preempting one of
* the colliding chunks, and the preemption algorithm occasionally preempts a chunk which hasn't been referenced for
* a long time but is about to be referenced in the near future.
*
* The write test results in lower efficiency for most window sizes because HDF5 is unaware that the application is about
* to overwrite the entire dataset and must read in most chunks before modifying parts of them.
*
* There is a simple way to improve efficiency for this example. It turns out that any chunk that has been completely
* read or written is a good candidate for preemption. If we increase the penalty for such chunks from the default 0.75
* to the maximum 1.00 then efficiency improves.
*
* <table>
* <tr>
* <td>
* \image html Chunk_f4.gif "Figure 4"
* </td>
* </tr>
* </table>
*
* The read efficiency is still less than one because of collisions in the cache. The number of collisions can often
* be reduced by increasing the number of slots in the cache. Figure 5 shows what happens when the maximum number of
* slots is increased by an order of magnitude from the default (this change has no major effect on memory used by
* the test since the byte limit was not increased for the cache).
*
* <table>
* <tr>
* <td>
* \image html Chunk_f5.gif "Figure 5"
* </td>
* </tr>
* </table>
*
* Although the application eventually overwrites every chunk completely the library has no way of knowing this
* beforehand since most calls to #H5Dwrite modify only a portion of any given chunk. Therefore, the first modification of a
* chunk will cause the chunk to be read from disk into the chunk buffer through the filter pipeline. Eventually HDF5 might
* contain a dataset transfer property that can turn off this read operation resulting in write efficiency which is equal
* to read efficiency.
*
* \section sec_hdf5_chunk_issues_frag Fragmentation
* Even if the application transfers the entire dataset contents with a single call to #H5Dread or #H5Dwrite it's
* possible the request will be broken into smaller, more manageable pieces by the library. This is almost certainly
* true if the data transfer includes a type conversion.
*
* <table>
* <tr>
* <td>
* \image html Chunk_f6.gif "Figure 6"
* </td>
* </tr>
* </table>
*
* By default the strip size is 1MB but it can be changed by calling #H5Pset_buffer.
*
* \section sec_hdf5_chunk_issues_store File Storage Overhead
* The chunks of the dataset are allocated at independent locations throughout the HDF5 file and a B-tree maps chunk
* N-dimensional addresses to file addresses. The more chunks that are allocated for a dataset the larger the B-tree.
*
* Large B-trees have two disadvantages:
* \li The file storage overhead is higher and more disk I/O is required to traverse the tree from root to leaves.
* \li The increased number of B-tree nodes will result in higher contention for the metadata cache.
* There are three ways to reduce the number of B-tree nodes. The obvious way is to reduce the number of chunks by
* choosing a larger chunk size (doubling the chunk size will cut the number of B-tree nodes in half). Another method
* is to adjust the split ratios for the B-tree by calling #H5Pset_btree_ratios, but this method typically results in only a
* slight improvement over the default settings. Finally, the out-degree of each node can be increased by calling
* #H5Pset_istore_k (increasing the out degree actually increases file overhead while decreasing the number of nodes).
*
* \section sec_hdf5_chunk_issues_comp Chunk Compression
* Dataset chunks can be compressed through the use of filters. See the chapter \ref subsec_dataset_filters in the \ref UG.
*
* Reading and rewriting compressed chunked data can result in holes in an HDF5 file. In time, enough such holes can increase
* the file size enough to impair application or library performance when working with that file. See @ref H5TOOL_RP_UG.
*/
2 changes: 1 addition & 1 deletion doxygen/dox/IntroParHDF5.dox
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The following shows the Parallel HDF5 implementation layers:
This tutorial assumes that you are somewhat familiar with parallel programming with MPI (Message Passing Interface).

If you are not familiar with parallel programming, here is a tutorial that may be of interest:
<a href="https://\DOCURL/hdf5_topics/2016_NERSC_Introduction_to_Scientific_IO.pdf">Tutorial on HDF5 I/O tuning at NERSC</a>.
<a href="https://\DOCURL/hdf5_topics/2016_NERSC_Introduction_to_Scientific_IO.pdf">Tutorial on HDF5 I/O tuning at NERSC (PDF)</a>.
(NOTE: As of 2024, the specific systems described in this tutorial are outdated.)

Some of the terms that you must understand in this tutorial are:
Expand Down
10 changes: 5 additions & 5 deletions doxygen/dox/LearnBasics3.dox
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ created the dataset layout cannot be changed. The h5repack utility can be used t
to a new with a new layout.

\section secLBDsetLayoutSource Sources of Information
<a href="https://\DOCURL/advanced_topics/chunking_in_hdf5.md">Chunking in HDF5</a>
(See the documentation on <a href="https://\DOCURL/advanced_topics_list.md">Advanced Topics in HDF5</a>)
\ref hdf5_chunking
\see \ref sec_plist in the HDF5 \ref UG.

<hr>
Expand All @@ -201,7 +200,7 @@ certain initial dimensions, then to later increase the size of any of the initia

HDF5 requires you to use chunking to define extendible datasets. This makes it possible to extend
datasets efficiently without having to excessively reorganize storage. (To use chunking efficiently,
be sure to see the advanced topic, <a href="https://\DOCURL/advanced_topics/chunking_in_hdf5.md">Chunking in HDF5</a>.)
be sure to see the advanced topic, \ref hdf5_chunking.)

The following operations are required in order to extend a dataset:
\li Declare the dataspace of the dataset to have unlimited dimensions for all dimensions that might eventually be extended.
Expand Down Expand Up @@ -243,15 +242,16 @@ Navigate back: \ref index "Main" / \ref GettingStarted / \ref LearnBasics

\section secLBComDsetCreate Creating a Compressed Dataset
HDF5 requires you to use chunking to create a compressed dataset. (To use chunking efficiently,
be sure to see the advanced topic, <a href="https://\DOCURL/advanced_topics/chunking_in_hdf5.md">Chunking in HDF5</a>.)
be sure to see the advanced topic, \ref hdf5_chunking.)

The following operations are required in order to create a compressed dataset:
\li Create a dataset creation property list.
\li Modify the dataset creation property list instance to enable chunking and to enable compression.
\li Create the dataset.
\li Close the dataset creation property list and dataset.

For more information on compression, see the FAQ question on <a href="https://\DOCURL/hdf5_topics/UsingCompressionInHDF5.md">Using Compression in HDF5</a>.
For more information on troubleshooting compression issues, see the
<a href="https://\DOCURL/hdf5_topics/HDF5CompressionTroubleshooting.pdf">HDF5 Compression Troubleshooting (PDF)</a>.

\section secLBComDsetProg Programming Example

Expand Down
3 changes: 1 addition & 2 deletions doxygen/dox/LearnHDFView.dox
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ dataset must be stored with a chunked dataset layout (as multiple <em>chunks</em
in the file).

Please note that the chunk sizes used in this topic are for demonstration purposes only. For
information on chunking and specifying an appropriate chunk size, see the
<a href="https://\DOCURL/advanced_topics/chunking_in_hdf5.md">Chunking in HDF5</a> documentation.
information on chunking and specifying an appropriate chunk size, see the \ref hdf5_chunking documentation.

Also see the HDF5 Tutorial topic on \ref secLBComDsetCreate.
<ul>
Expand Down
2 changes: 1 addition & 1 deletion doxygen/dox/UsersGuide.dox
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ These documents provide additional information for the use and tuning of specifi
</tr>
<tr style="height: 36.00pt;">
<td style="width: 234.000pt; border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #228a22; vertical-align: top;padding-left: 6.00pt; padding-top: 3.00pt; padding-right: 6.00pt; padding-bottom: 3.00pt;">
<p style="font-style: italic; color: #0000ff;"><span><a href="http://\ARCURL/Advanced/Chunking/index.html">Chunking in HDF5</a></span></p>
<p style="font-style: italic; color: #0000ff;"><span>@ref hdf5_chunking</span></p>
</td>
<td style="width: 198.000pt; border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #228a22; vertical-align: top;padding-left: 6.00pt; padding-top: 3.00pt; padding-right: 6.00pt; padding-bottom: 3.00pt;">
<p>Structuring the use of chunking and tuning it for performance.</p>
Expand Down
Loading

0 comments on commit 7315776

Please sign in to comment.