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 FoTAreReady function for simple actions #5513

Merged
merged 2 commits into from
Oct 2, 2023

Conversation

knelli2
Copy link
Contributor

@knelli2 knelli2 commented Sep 28, 2023

Proposed changes

The previous version of functions_of_time_are_ready() only used a PerformAlgorithmCallback. But sometimes we want to use a SimpleActionCallback. This generalizes functions_of_time_are_ready() to allow both.

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

@knelli2 knelli2 requested a review from wthrowe September 28, 2023 21:12
@knelli2 knelli2 force-pushed the simple_action_fot_ready branch 2 times, most recently from a763611 to 1f3c8da Compare September 28, 2023 21:38
Copy link
Member

@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.

You also have some clang-tidy warnings. The gcc9 failures appear to be unrelated and will hopefully work after a new push.

/// are moved into the callback.
template <typename CacheTag, typename SimpleAction, typename Metavariables,
typename ArrayIndex, typename Component, typename... Args>
bool functions_of_time_are_ready(
Copy link
Member

Choose a reason for hiding this comment

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

Not sure I'm a fan of distinguishing the two overloads only by the existence of a template parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any suggestions? I did it like this because the different callbacks have different template parameters. Didn't make a lot of sense to have to specify an extra template for the perform algorithm callback that would never be used.

Copy link
Member

Choose a reason for hiding this comment

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

Give them different names, maybe.

Parallel::GlobalCache<Metavariables>& cache, const ArrayIndex& array_index,
const Component* component_p, const double time,
const std::optional<std::unordered_set<std::string>>& functions_to_check,
Args... args) {
Copy link
Member

Choose a reason for hiding this comment

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

Args&& and forward below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this first, but ran into build errors in SimpleActionCallback due to the const &ness of some of the args that were passed in. I wasn't sure how to get around that because SimpleActionCallback needs to actually store the data locally (not references to it which may go out of scope). That's why I chose a copy initially and then std::move from then on.

Copy link
Member

Choose a reason for hiding this comment

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

That's a bug in SimpleActionCallback. It shouldn't be taking it's arguments by reference, but by value and then moving.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok added a new commit that fixes SimpleActionCallback

Parallel::GlobalCache<Metavariables>& cache, const ArrayIndex& array_index,
const Component* /*meta*/, const double time,
const std::optional<std::unordered_set<std::string>>& functions_to_check,
Args... args) {
Copy link
Member

Choose a reason for hiding this comment

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

Args&& and forward below.

@knelli2 knelli2 force-pushed the simple_action_fot_ready branch 2 times, most recently from 41cb954 to e5c4c68 Compare September 29, 2023 08:05
@@ -37,9 +37,10 @@ class SimpleActionCallback : public Callback {
public:
WRAPPED_PUPable_decl_template(SimpleActionCallback); // NOLINT
SimpleActionCallback() = default;
SimpleActionCallback(Proxy proxy, Args&&... args)
// NOLINTNEXTLINE(google-explicit-constructor)
SimpleActionCallback(Proxy proxy, std::decay_t<Args>... args)
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need decay_t all over the place in this class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well Args... keeps all the const & so I had to remove those for the declaration of the member tuple so it wasn't a tuple of references, but I left everything else as Args.... However, my test failed with that because a DataVector I was using to test actually got moved into this callback instead of copied (not std::move from the calling code, but from the std::move one line below) and this caused subsequent tests to fail. When I did std::decay_t<Args>... in the constructor, everything worked fine.

Copy link
Member

Choose a reason for hiding this comment

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

I see. I think you're right and this is the correct way to do it here.

Optionally, you might want to add decay_t to the calling code as well, just to keep the number of equivalent types the compiler has to deal with down. Probably not many instantiations of this class though, so not very important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other than the test, the calling code (in the FoT are ready functions) is usually std::forward<Args>(args).... So I'll leave that as is.

: proxy_(proxy),
args_(std::make_tuple<Args...>(std::forward<Args>(args)...)) {}
args_(std::make_tuple<std::decay_t<Args>...>(std::move(args)...)) {}
Copy link
Member

Choose a reason for hiding this comment

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

[optional] make_tuple doesn't do anything here. It can be removed.

Copy link
Member

@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.

That leaves only optional things. Let me know if you want to do any or if this is ready.

@@ -37,9 +37,10 @@ class SimpleActionCallback : public Callback {
public:
WRAPPED_PUPable_decl_template(SimpleActionCallback); // NOLINT
SimpleActionCallback() = default;
SimpleActionCallback(Proxy proxy, Args&&... args)
// NOLINTNEXTLINE(google-explicit-constructor)
SimpleActionCallback(Proxy proxy, std::decay_t<Args>... args)
Copy link
Member

Choose a reason for hiding this comment

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

I see. I think you're right and this is the correct way to do it here.

Optionally, you might want to add decay_t to the calling code as well, just to keep the number of equivalent types the compiler has to deal with down. Probably not many instantiations of this class though, so not very important.

@knelli2 knelli2 force-pushed the simple_action_fot_ready branch from e5c4c68 to d8969fb Compare September 29, 2023 18:30
@knelli2
Copy link
Contributor Author

knelli2 commented Sep 29, 2023

Squashed in the optional remove of std::make_tuple

@wthrowe wthrowe merged commit 626e0da into sxs-collaboration:develop Oct 2, 2023
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