Skip to content

Commit

Permalink
Merge branch 'develop' into available_supported
Browse files Browse the repository at this point in the history
  • Loading branch information
ye-luo authored Oct 5, 2021
2 parents 94b98f5 + 132b560 commit 309afa1
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/QMCDrivers/QMCDriverNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ void QMCDriverNew::checkNumCrowdsLTNumThreads(const int num_crowds)
* - initialize Estimators
* - initialize Walkers
*/
void QMCDriverNew::startup(xmlNodePtr cur, QMCDriverNew::AdjustedWalkerCounts awc)
void QMCDriverNew::startup(xmlNodePtr cur, const QMCDriverNew::AdjustedWalkerCounts& awc)
{
app_summary() << this->QMCType << " Driver running with target_walkers = " << awc.global_walkers << std::endl
<< " walkers_per_rank = " << awc.walkers_per_rank << std::endl
<< " num_crowds = " << awc.walkers_per_crowd.size() << std::endl
<< " on rank 0, walkers_per_crowd = " << awc.walkers_per_crowd << std::endl
app_summary() << QMCType << " Driver running with" << std::endl
<< " total_walkers = " << awc.global_walkers << std::endl
<< " walkers_per_rank = " << awc.walkers_per_rank << std::endl
<< " num_crowds = " << awc.walkers_per_crowd.size() << std::endl
<< " on rank 0, walkers_per_crowd = " << awc.walkers_per_crowd << std::endl
<< std::endl;

// set num_global_walkers explicitly and then make local walkers.
Expand Down
2 changes: 1 addition & 1 deletion src/QMCDrivers/QMCDriverNew.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase
* And these are the arguments to the branch_engine and estimator_manager
* Constructors or these objects should be created elsewhere.
*/
void startup(xmlNodePtr cur, QMCDriverNew::AdjustedWalkerCounts awc);
void startup(xmlNodePtr cur, const QMCDriverNew::AdjustedWalkerCounts& awc);

static void initialLogEvaluation(int crowd_id, UPtrVector<Crowd>& crowds, UPtrVector<ContextForSteps>& step_context);

Expand Down
24 changes: 18 additions & 6 deletions src/Utilities/StlPrettyPrint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,32 @@
namespace qmcplusplus
{

/** collapsed vector printout
* [3, 3, 2, 2] is printed as [3(x2), 2(x2)]
*/
template<typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& rhs)
{
out << "[";
if (!rhs.empty())
auto cursor = rhs.begin();
while (cursor != rhs.end())
{
auto last = rhs.end();
last--;
copy(rhs.begin(), last, std::ostream_iterator<T>(out, ", "));
out << *last;
// each iteration handles one unique value
const T ref_value = *cursor;
size_t count = 1;
while (++cursor != rhs.end() && *cursor == ref_value)
count++;
out << ref_value;
// identical elements are collapsed
if (count > 1)
out << "(x" << count << ")";
// if not the last element, add a separator
if (cursor != rhs.end())
out << ", ";
}
out << "]";
return out;
}

}
} // namespace qmcplusplus
#endif
1 change: 1 addition & 0 deletions src/Utilities/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ add_executable(
test_project_data.cpp
test_rng_control.cpp
test_output_manager.cpp
test_StlPrettyPrint.cpp
test_StdRandom.cpp)
target_link_libraries(${UTEST_EXE} catch_main qmcutil)

Expand Down
3 changes: 0 additions & 3 deletions src/Utilities/tests/for_testing/test_RandomForTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

#include "catch.hpp"
#include "RandomForTest.cpp"
#include "../StlPrettyPrint.hpp"
#include <iostream>
#include <string>

/** \file
*/
Expand Down
46 changes: 46 additions & 0 deletions src/Utilities/tests/test_StlPrettyPrint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//////////////////////////////////////////////////////////////////////////////////////
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2021 QMCPACK developers.
//
// File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
//
// File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
//////////////////////////////////////////////////////////////////////////////////////

#include "catch.hpp"
#include <sstream>
#include "StlPrettyPrint.hpp"

namespace qmcplusplus
{
TEST_CASE("StlPrettyPrint", "[utilities]")
{
std::ostringstream msg;
std::vector<int> vec;

msg << vec;
CHECK(msg.str() == "[]");

msg.str(std::string());
vec = {4, 4, 3, 3};
msg << vec;
CHECK(msg.str() == "[4(x2), 3(x2)]");

msg.str(std::string());
vec = {4, 4, 3};
msg << vec;
CHECK(msg.str() == "[4(x2), 3]");

msg.str(std::string());
vec = {4, 3, 3};
msg << vec;
CHECK(msg.str() == "[4, 3(x2)]");

msg.str(std::string());
vec = {4, 3, 2};
msg << vec;
CHECK(msg.str() == "[4, 3, 2]");
}
} // namespace qmcplusplus

0 comments on commit 309afa1

Please sign in to comment.