Next: , Previous: nc_set_default_format, Up: Datasets


2.20 Set HDF5 Chunk Cache for Future File Opens/Creates: nc_set_chunk_cache

This function changes the default chunk cache settings in the HDF5 library for all variables in the file. The settings apply for subsequent file opens/creates. This function does not change the chunk cache settings of already open files.

For more information, see the documentation for the H5Pset_cache() function in the HDF5 library at the HDF5 website: http://hdfgroup.org/HDF5/.

Usage

     int nc_set_chunk_cache(size_t size, size_t nelems, float preemption);
size
The total size of the raw data chunk cache, in bytes. This should be big enough to hold multiple chunks of data.
nelems
The number of chunk slots in the raw data chunk cache hash table. This should be a prime number larger than the number of chunks that will be in the cache.
preemption
The preemtion value must be between 0 and 1 inclusive and indicates how much chunks that have been fully read are favored for preemption. A value of zero means fully read chunks are treated no differently than other chunks (the preemption is strictly LRU) while a value of one means fully read chunks are always preempted before other chunks.

Return Codes

NC_NOERR
No error.
NC_EINVAL
Preemption must be between zero and one (inclusive).

Example

This example is from libsrc4/tst_files.c:

     #include <netcdf.h>
        ...
     #define NEW_CACHE_SIZE 32000000
     #define NEW_CACHE_NELEMS 2000
     #define NEW_CACHE_PREEMPTION .75
     
        /* Change chunk cache. */
        if (nc_set_chunk_cache(NEW_CACHE_SIZE, NEW_CACHE_NELEMS,
     			  NEW_CACHE_PREEMPTION)) ERR;
     
        /* Create a file with two dims, two vars, and two atts. */
        if (nc_create(FILE_NAME, cflags|NC_CLOBBER, &ncid)) ERR;
     
        ...