Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StaticDeque #4658

Merged
merged 3 commits into from Feb 7, 2023
Merged

Add StaticDeque #4658

merged 3 commits into from Feb 7, 2023

Conversation

wthrowe
Copy link
Member

@wthrowe wthrowe commented Jan 27, 2023

Proposed changes

Upgrade instructions

Code review checklist

  • The code is documented and the documentation renders correctly. Run
    make doc to generate the documentation locally into BUILD_DIR/docs/html.
    Then open index.html.
  • The code follows the stylistic and code quality guidelines listed in the
    code review guide.
  • The PR lists upgrade instructions and is labeled bugfix or
    new feature if appropriate.

Further comments

@teukolsky
Copy link
Contributor

Hi Will,
What is the proposed use of this?

@wthrowe
Copy link
Member Author

wthrowe commented Jan 28, 2023

Yeah, probably should have mentioned that somewhere.

It's to store the past values for multistep time steppers. The usage pattern makes this naturally a deque, and knowing what time steppers we have we know the queue will never have more than 8 elements.

I'm pretty sure libstdc++'s implementation of std::deque will keep allocating blocks at one end and deallocating them at the other. (The libstdc++ code is a bit dense, so it is possible I'm not interpreting it correctly.) For something as large as the GH variables, I think each block will hold one step, so there will be one allocation per step.

I think libc++'s implementation is actually smart enough to keep and reuse its storage blocks, so it would be fine for the main history. It's not clear whether the initial allocation of space would be significant in the IMEX code, which creates a temporary History<double>. We can't rely on using this implementation anyway, so it's academic.

This idea was also mentioned in passing in some unrelated recent PR, but I don't remember which or how useful it would actually have been there.

@nilsdeppe
Copy link
Member

Ah, I think @kidder used a std::deque in some AMR code

Copy link
Member

@nilsdeppe nilsdeppe left a comment

Choose a reason for hiding this comment

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

This looks good, a couple requests for a bit more C++ comments that I think would make it clearer to readers in the future. Please squash them in directly :)

src/DataStructures/StaticDeque.hpp Show resolved Hide resolved
src/DataStructures/StaticDeque.hpp Show resolved Hide resolved
src/DataStructures/StaticDeque.hpp Show resolved Hide resolved
p | sz;
resize(sz);
for (auto& entry : *this) {
p | entry;
Copy link
Member

Choose a reason for hiding this comment

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

If we end up with this class holding a fundamental types (I currently don't see that we would get that a lot), then we would want this to use PUP_array that serializes a byte stream directly (might be more efficient). I don't think that's important now, but just want to mention it :)

Copy link
Member Author

Choose a reason for hiding this comment

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

For fundamentals (and I think any trivially copyable types), I'm pretty sure we can just serialize the byte stream and the other member variables and restore the exact state. For more complicated things, we have to be careful not to try to pup the unused memory as objects of type T, so the current version just accesses the objects through the public interface and doesn't try to restore the details of the internal representation. (The elements may be "rotated" in the internal circular buffer after deserializing.) Switching to the first implementation when allowed would certainly be possible, but let's put it off for now. I've added a comment summarizing this.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with you! Thanks for adding the nice comment!

Copy link
Member Author

@wthrowe wthrowe left a comment

Choose a reason for hiding this comment

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

I have expanded the comment explaining the meaning of the member variables and the logical treatment of the storage, and added some short comments for the other things.

p | sz;
resize(sz);
for (auto& entry : *this) {
p | entry;
Copy link
Member Author

Choose a reason for hiding this comment

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

For fundamentals (and I think any trivially copyable types), I'm pretty sure we can just serialize the byte stream and the other member variables and restore the exact state. For more complicated things, we have to be careful not to try to pup the unused memory as objects of type T, so the current version just accesses the objects through the public interface and doesn't try to restore the details of the internal representation. (The elements may be "rotated" in the internal circular buffer after deserializing.) Switching to the first implementation when allowed would certainly be possible, but let's put it off for now. I've added a comment summarizing this.

p | sz;
resize(sz);
for (auto& entry : *this) {
p | entry;
Copy link
Member

Choose a reason for hiding this comment

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

I agree with you! Thanks for adding the nice comment!

@nilsdeppe nilsdeppe added the auto-merge GitHub's auto-merge has been enabled for this PR. label Feb 6, 2023
@nilsdeppe nilsdeppe merged commit 960f8c5 into sxs-collaboration:develop Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge GitHub's auto-merge has been enabled for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants