[newchem-cpp] Introduce Multi1dView#561
Open
mabruzzo wants to merge 5 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This introduces the
Multi1DView<T>class template. This construct internally tracks an array of pointers and it provides 2 ways to access the underlying data.Essentially, this type makes an array of pointers act more like a
View<T**>(our type for representing a 2D array).Motivation
The motivation is to use this as an alternative to
grackle_field_data*for accessing field data. Let's sketch out an example. Suppose that we want have a function that needs to access the proton density and neutral Hydrogen density at each index in a providedIndexRange. We'll sketch out out what this looks like right now, and the 2 ways to do it withMulti1DView. For the purpose of this discussion, let's assume that we've taken advantage of the ability to store an internal pointer offset to account for thej,koffsets in anidx_range.1. Variant with
grackle_field_data*The following logic is representative of the coding idioms currently in use throughout the code base
2. Variant using
Multi1DView::contig1d_ptrmethodThe following logic should have comparable (maybe marginally better performance than variant 1). The idea would to transition to this style of code throughout the codebase.
Note: I'm open to suggestions for better names for this method.
3. Variant using mulit-dimensional indexing
The performance of this approach will generally be comparable or slightly worse than variant 2. I sketch out the reasons for why this is the case in in the docstring for
Multi1DView::contig1d_ptr(but I'm happy to provide more details).Note
The fact the order of indices in
rho_sp(i, SpLUT::HI), rather thanrho_sp(SpLUT::HI, i)is a consequence of the fact that we our regular View object inherit the Fortran multi-dimensional array layouts in the . If we want to change this, now would probably be the time to do so (I may open an issue to discuss this if I have time).Reviewing Considerations
I suspect that you may want to wait to merge this until you see the followup PR that actually starts using this machinery. We currently don't use this new machinery outside of a few new unit-tests.
The actual code changes in this PR are quite minimal -- a lot of this is docstrings explaining how things work.