-
Notifications
You must be signed in to change notification settings - Fork 192
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
Add FoTAreReady function for simple actions #5513
Conversation
a763611
to
1f3c8da
Compare
There was a problem hiding this 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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Args&&
and forward below.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Args&&
and forward below.
41cb954
to
e5c4c68
Compare
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/Parallel/Callback.hpp
Outdated
: proxy_(proxy), | ||
args_(std::make_tuple<Args...>(std::forward<Args>(args)...)) {} | ||
args_(std::make_tuple<std::decay_t<Args>...>(std::move(args)...)) {} |
There was a problem hiding this comment.
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.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
e5c4c68
to
d8969fb
Compare
Squashed in the optional remove of |
Proposed changes
The previous version of
functions_of_time_are_ready()
only used aPerformAlgorithmCallback
. But sometimes we want to use aSimpleActionCallback
. This generalizesfunctions_of_time_are_ready()
to allow both.Upgrade instructions
Code review checklist
make doc
to generate the documentation locally intoBUILD_DIR/docs/html
.Then open
index.html
.code review guide.
bugfix
ornew feature
if appropriate.Further comments