Skip to content

refactor: netcdf cache offsetting and index manipulation logic#1000

Open
aaraney wants to merge 1 commit into
NOAA-OWP:masterfrom
aaraney:fix-nc-forcing-cache-indexing
Open

refactor: netcdf cache offsetting and index manipulation logic#1000
aaraney wants to merge 1 commit into
NOAA-OWP:masterfrom
aaraney:fix-nc-forcing-cache-indexing

Conversation

@aaraney

@aaraney aaraney commented Jul 8, 2026

Copy link
Copy Markdown
Member

Refactor the netcdf cache offsetting and index manipulation functions. This hopefully cleans up the logic a bit and makes it a little easier to follow and reason about (please be the judge of that :)). This also fixes a bug when the total forcing time steps are not divisible by the cache line size.

I still need to add tests, but a first review would be great! Thanks!

@aaraney
aaraney requested review from PhilMiller and hellkite500 July 8, 2026 21:36
Comment thread src/forcing/NetCDFPerFeatureDataProvider.cpp Outdated
This also fixes a bug when the total forcing timesteps is not divisible
by the cache line size.
@aaraney
aaraney force-pushed the fix-nc-forcing-cache-indexing branch from 2dff085 to 463b86b Compare July 9, 2026 21:13
@aaraney aaraney changed the title fix: account for nc cache line size change in the time dimension. refactor: netcdf cache offsetting and index manipulation logic Jul 9, 2026
@aaraney
aaraney requested a review from PhilMiller July 10, 2026 13:16
@aaraney

aaraney commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

for me: see #998 for testing inspiration

edit: and #922?

@PhilMiller

Copy link
Copy Markdown
Contributor

This all would be much easier to work with if we had mdspan available. Standardized in C++23, but implemented back to C++14.

@hellkite500 @robertbartel Do you think we'd be OK importing a dependency on that header-only library? Is it worth running this by Chris and Donald? Does it help that the reference implementation came from another US government agency, with strict provenance and review processes on their open-source releases?


std::size_t idx1_cache_slice_start = idx1 - (idx1 % cache_slice_t_size);
std::size_t time_idx = idx1 % cache_slice_t_size;
std::size_t cache_line_size = cache_slice_t_size;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may still be incorrect for the case of a single page. I.e. a very short run, in which there are fewer time steps than the chunking granularity that will determine cache_slice_t_size

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants