-
Notifications
You must be signed in to change notification settings - Fork 150
WalkerLogXXX should provide move constructors #5567
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
Changes from 5 commits
2c71ebd
e7e824a
7275164
c6757f3
fd410a9
ceec7cd
99b589b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| ////////////////////////////////////////////////////////////////////////////////////// | ||
| // This file is distributed under the University of Illinois/NCSA Open Source License. | ||
| // See LICENSE file in top directory for details. | ||
| // | ||
| // Copyright (c) 2025 QMCPACK developers. | ||
| // | ||
| // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory | ||
| ////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #ifndef QMCPLUSPLUS_VALIDWALKERLOGINPUT_H | ||
| #define QMCPLUSPLUS_VALIDWALKERLOGINPUT_H | ||
|
|
||
| #include <array> | ||
| #include <string_view> | ||
| namespace qmcplusplus::testing | ||
| { | ||
| class WalkerLogInputSections | ||
| { | ||
| public: | ||
| enum class valid | ||
| { | ||
| DEFAULT = 0 | ||
| }; | ||
|
|
||
| static std::string_view getXml(valid val) { return xml[static_cast<std::size_t>(val)]; } | ||
| auto begin() { return xml.begin(); } | ||
| auto end() { return xml.end(); } | ||
|
|
||
| private: | ||
| static constexpr std::array<std::string_view, 1> xml{ | ||
| R"XML( | ||
| <walkerlogs/> | ||
| )XML"}; | ||
| }; | ||
|
|
||
| } // namespace qmcplusplus::testing | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| ////////////////////////////////////////////////////////////////////////////////////// | ||
| // This file is distributed under the University of Illinois/NCSA Open Source | ||
| // License. See LICENSE file in top directory for details. | ||
| // | ||
| // Copyright (c) 2025 QMCPACK developers. | ||
| // | ||
| // File developed by: Peter W. Doak, doakpw@ornl.gov, Oak Ridge National | ||
| // Laboratory | ||
| ////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #include "OhmmsData/Libxml2Doc.h" | ||
| #include "QMCDrivers/WalkerLogManager.h" | ||
| #include "catch.hpp" | ||
|
|
||
| #include "Message/Communicate.h" | ||
| #include <MockGoldWalkerElements.h> | ||
|
|
||
| #include "ValidWalkerLogInput.h" | ||
| #include "WalkerLogInput.h" | ||
|
|
||
| namespace qmcplusplus | ||
| { | ||
| class CollectorHolder | ||
| { | ||
| public: | ||
| void setWalkerLogCollector(UPtr<WalkerLogCollector>&& wlc) { walker_collector_ = std::move(wlc); } | ||
| void startBlock() { walker_collector_->startBlock(); } | ||
|
|
||
| private: | ||
| UPtr<WalkerLogCollector> walker_collector_; | ||
| }; | ||
|
|
||
| struct LogAndStuff | ||
| { | ||
| WalkerLogManager wlm; | ||
| CollectorHolder ch; | ||
| }; | ||
|
|
||
| TEST_CASE("WalkerLogManager::move", "[drivers]") | ||
| { | ||
| Communicate* comm = OHMMS::Controller; | ||
| RuntimeOptions run_time_options; | ||
|
|
||
| auto mgwe = testing::makeGoldWalkerElementsWithEEEI(comm, run_time_options); | ||
| using WLInput = testing::WalkerLogInputSections; | ||
| Libxml2Document doc; | ||
| bool okay = doc.parseFromString(WLInput::getXml(WLInput::valid::DEFAULT)); | ||
| REQUIRE(okay); | ||
| xmlNodePtr node = doc.getRoot(); | ||
| WalkerLogInput walker_log_input{node}; | ||
| auto make_stuff = [comm](WalkerLogInput& walker_log_input) -> LogAndStuff { | ||
| WalkerLogManager wlm{walker_log_input, true, "root_name", comm}; | ||
| CollectorHolder ch; | ||
| ch.setWalkerLogCollector(wlm.makeCollector()); | ||
| return {std::move(wlm), std::move(ch)}; | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This factory function shows the tight connection between the manager and collectors as it returns them as a whole structure. We can write the code as In this way, the hassle of move constructors can be avoided and also reduce the number copy operations. The intention of introducing move constructor and operator is to bring real benefit. It is not worth maintaining move constructor and operators rigorously in every class but only places we benefit. Hopefully everyone agrees with that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above was my opinion. This is not a request for change.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a point in blocking this other than making the refactoring I need to do to implement effective testing for a requested feature harder? I think ease of testing refactoring trumps weasling out of providing sane threaded design and basic constructors. I'm correcting a design issue that should have never gotten through review the reference used as a back door state update and fixing the lack of clear declaration of constructors.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably you missed my other comment, I'm not making a request for change in this area of code. The blocking reason is missing CMake changes in this PR. Your added code is not compiled and tested. To be honest, the name state made me feel it may carry variable like step counters. If that was the case, I wanted it to be a const ref in collectors and let the manager to operate it. |
||
| auto l_and_s = make_stuff(walker_log_input); | ||
|
|
||
| // In the past this has resulted in a AddressSanitizer: | ||
| // stack-use-after-return | ||
| // due to access to a dead reference to | ||
| // a state object made back in moved from WalkerLogManager in | ||
| // the factory function. Seemed to work in release, caught by llvm | ||
| // asan. | ||
| l_and_s.ch.startBlock(); | ||
| } | ||
|
|
||
|
|
||
| } // namespace qmcplusplus | ||
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.
IIRC.
WalkerLogManagerowns and manipulates thestate_andWalkerLogStateonly reads it. In this way, per crowdWalkerLogStatewon't go out of sync. For that reason, keeping it a const ref seems fine to me. What is your motivation to make it a copy especially a non-const copy?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.
Sent out review before my laptop died. Continue reading the added test.
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 cannot move a ref.
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.
Can you make it at least a
const?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.
So multiple threads spectate on a single memory location to stay "synchronized"? examining the source shows no evidence this anti feature is used and no crowd level resources state should be getting controlled in this manner. If this needs to be updated then a call can be made to change the behavior of the per crowd loggers.