Improve buoyancy_gradients
design
#2367
Merged
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.
This PR does two things:
EnvBuoyGrad
toEnvBuoyGradVars
and definesEnvBuoyGrad
as a singleton for dispatching. This is a bit simpler of a pattern being that, in the existing design,EnvBuoyGrad
contains all of the variables for allAbstractEnvBuoyGradClosure
specializations. This does mean that we need to pass an extra variable around, but that one is solely used for dispatch. Being that we currently have only one concrete subtype ofAbstractEnvBuoyGradClosure
, we could just do away with the extra parameter and duplicate structs, but I thought that adding the additional parameter wasn't too painful so that we can easily extend / dispatch.EnvBuoyGradVars
to take a thermo state. This should hopefully improve the memory loads, since the thermo function calls can all occur in registers after the thermo state is loaded. Alternatively, we could makeEnvBuoyGradVars
simply hold the thermo state ( or just bypass that altogether ), but then those thermo call would need to be sprinkled inbuoyancy_gradients
andbuoyancy_gradient_chain_rule
, and it's not clear to me that that is worth the additional compute, not to mention it may just make the code look a bit more complicated.