MATLAB: Can chunk caching be used with the high-level NetCDF functions

cachechunkfilehigh-levellow-levelMATLABncreadnetcdfnetcdf.setchunkcacheperformancesetchunkcache

I am using the high-level NetCDF interface to read a NetCDF file. My code might have to access the same data multiple times. In order to increase performance, I want to use chunk caching. The low-level interface includes the function "netcdf.setChunkCache" that is used to configure the default chunk cache size. If I use this low-level function to configure the chunk cache, can I expect a performance increase when I call functions in the high-level interface like "ncread"?

Best Answer

When the default chunk cache is configured with the low-level interface, those settings will be respected by the high-level functions such as "ncread". However, if you intend on using multiple calls to "ncread" to access the same data, the performance improvement from caching may not be fully realized. This is because the "ncread" function always closes the file before it returns. This action of closing the file will clear the chunk cache, and subsequent calls to "ncread" will start with an empty cache.
To fully realize the performance improvements offered by the chunk cache, you may wish to exclusively use the low-level interface. This interface offers much more control over when the file is opened and closed, and therefore enables greater persistence of the chunk cache. For more information regarding the low-level NetCDF interface, please consult the functions described under the section "NetCDF Library Package" at the documentation link below.