From f4d4fc3bc832be1b26f2a1fcd095f6f24e27ff5e Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Thu, 6 Jan 2022 22:18:20 -0600 Subject: [PATCH] Remove BoostRandom --- CMakeLists.txt | 1 - external_codes/CMakeLists.txt | 1 + src/Containers/OhmmsSoA/TensorSoaContainer.h | 3 - src/Message/CMakeLists.txt | 2 +- src/QMCDrivers/WalkerControlBase.cpp | 2 - src/QMCDrivers/WalkerControlBase.h | 2 - src/Sandbox/exchange_walker.cpp | 214 ------------------- src/Utilities/BoostRandom.cpp | 25 --- src/Utilities/BoostRandom.h | 102 --------- src/Utilities/CMakeLists.txt | 4 +- src/Utilities/RandomGenerator.h | 23 +- src/Utilities/StdRandom.h | 8 +- src/Utilities/Timer.h | 4 +- src/Utilities/tests/test_rng.cpp | 25 +-- src/config.h.cmake.in | 3 - src/mpi/collectives.h | 3 - src/mpi/point2point.h | 3 - 17 files changed, 13 insertions(+), 412 deletions(-) delete mode 100644 src/Sandbox/exchange_walker.cpp delete mode 100644 src/Utilities/BoostRandom.cpp delete mode 100644 src/Utilities/BoostRandom.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 29ff673876..6cc4a4cbc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,7 +193,6 @@ cmake_dependent_option(USE_NVTX_API "Enable/disable NVTX regions in CUDA code." set(HAVE_EINSPLINE 1) # to be removed option(QMC_EXP_THREADING "Experimental non openmp threading models" OFF) mark_as_advanced(QMC_EXP_THREADING) -option(QMC_RNG_BOOST "Use random number generator from boost C++ libraries instead of C++ standard library" OFF) #-------------------------------------------------------------------- # Sanitizer options diff --git a/external_codes/CMakeLists.txt b/external_codes/CMakeLists.txt index 84dcdb94ce..eef9f5be55 100644 --- a/external_codes/CMakeLists.txt +++ b/external_codes/CMakeLists.txt @@ -12,6 +12,7 @@ add_library(qmc_external_mpi_wrapper INTERFACE) target_include_directories(qmc_external_mpi_wrapper INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/mpi_wrapper) +target_link_libraries(qmc_external_mpi_wrapper INTERFACE MPI::MPI_CXX Boost::boost) add_library(qmc_external_multi INTERFACE) target_include_directories(qmc_external_multi INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/boost_multi/multi/include) diff --git a/src/Containers/OhmmsSoA/TensorSoaContainer.h b/src/Containers/OhmmsSoA/TensorSoaContainer.h index 210bb0503e..3a0e53bd77 100644 --- a/src/Containers/OhmmsSoA/TensorSoaContainer.h +++ b/src/Containers/OhmmsSoA/TensorSoaContainer.h @@ -147,9 +147,6 @@ struct TensorSoaContainer } }; -//Incorrect: provide wrapper class -//BOOST_CLASS_TRACKING(Pos3DSoA, boost::serialization::track_never) -//BOOST_CLASS_TRACKING(Pos3DSoA, boost::serialization::track_never) } // namespace qmcplusplus #endif diff --git a/src/Message/CMakeLists.txt b/src/Message/CMakeLists.txt index a0ead8cf33..78a1bd7200 100644 --- a/src/Message/CMakeLists.txt +++ b/src/Message/CMakeLists.txt @@ -16,7 +16,7 @@ add_library(message ${COMM_SRCS}) target_link_libraries(message PUBLIC platform_host_runtime) if(HAVE_MPI) - target_link_libraries(message PUBLIC MPI::MPI_CXX Boost::boost qmc_external_mpi_wrapper) + target_link_libraries(message PUBLIC qmc_external_mpi_wrapper) endif() add_library(catch_main catch_main.cpp) diff --git a/src/QMCDrivers/WalkerControlBase.cpp b/src/QMCDrivers/WalkerControlBase.cpp index 045a9b49a1..ac0e7222b9 100644 --- a/src/QMCDrivers/WalkerControlBase.cpp +++ b/src/QMCDrivers/WalkerControlBase.cpp @@ -132,8 +132,6 @@ void WalkerControlBase::measureProperties(int iter) // If it is it shouldn't be in QMDrivers but QMCDrivers/DMC if (dmcStream) { - //boost::archive::text_oarchive oa(*dmcStream); - //(*oa) & iter & eavg_cur & wgt_cur & Etrial & pop_old; (*dmcStream) << std::setw(10) << iter << std::setw(20) << ensemble_property_.Energy << std::setw(20) << ensemble_property_.Variance << std::setw(20) << ensemble_property_.Weight << std::setw(20) << ensemble_property_.NumSamples << std::setw(20) diff --git a/src/QMCDrivers/WalkerControlBase.h b/src/QMCDrivers/WalkerControlBase.h index 929f08487a..55ac66f1f6 100644 --- a/src/QMCDrivers/WalkerControlBase.h +++ b/src/QMCDrivers/WalkerControlBase.h @@ -25,8 +25,6 @@ #include "Message/CommOperators.h" // #include "QMCDrivers/ForwardWalking/ForwardWalkingStructure.h" -//#include - namespace qmcplusplus { namespace testing diff --git a/src/Sandbox/exchange_walker.cpp b/src/Sandbox/exchange_walker.cpp deleted file mode 100644 index 69145b00b2..0000000000 --- a/src/Sandbox/exchange_walker.cpp +++ /dev/null @@ -1,214 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////////// -// This file is distributed under the University of Illinois/NCSA Open Source License. -// See LICENSE file in top directory for details. -// -// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers. -// -// File developed by: -// -// File created by: Jeongnim Kim, jeongnim.kim@intel.com, Intel Corp. -////////////////////////////////////////////////////////////////////////////////////// -// -*- C++ -*- -/** @file exchange_walker.cpp - * @brief Test boost::mpi - */ -#include -#include "Particle/ParticleSet.h" -#include "Particle/MCWalkerConfiguration.h" -#include "Utilities/PrimeNumberSet.h" -#include -#include "Sandbox/graphite.hpp" -#include "Utilities/Timer.h" -#include "Sandbox/common.hpp" -#include -#include - -using namespace std; - -namespace qmcplusplus -{ -namespace mpi = boost::mpi; - -/** dummy walker to show how boost::mpi and boost::serialization work - */ -template -struct DummyWalker -{ - using PosType = TinyVector; - long ID; - ParticleAttrib R; - Matrix Properties; - - DummyWalker() { Properties.resize(2, 8); } - - DummyWalker(const DummyWalker&) = default; - - inline void resize(size_t n) { R.resize(n); } - - template - inline void serialize(Archive& ar, const unsigned int version) - { - ar& ID; - ar& boost::serialization::make_array(&R[0][0], D * R.size()); - ar& boost::serialization::make_array(Properties.data(), Properties.size()); - } -}; - -} // namespace qmcplusplus - - -int main(int argc, char** argv) -{ - using namespace qmcplusplus; - - mpi::environment env(mpi::threading::funneled); - mpi::communicator world; - //create two MPI groups - mpi::communicator rows = world.split(world.rank() / 2); - - - typedef QMCTraits::RealType RealType; - typedef ParticleSet::ParticlePos_t ParticlePos_t; - typedef ParticleSet::ParticleLayout_t LatticeType; - typedef ParticleSet::TensorType TensorType; - typedef ParticleSet::PosType PosType; - - //use the global generator - - int na = 4; - int nb = 4; - int nc = 1; - int nsteps = 100; - int iseed = 11; - RealType Rmax(2.7); - - char* g_opt_arg; - int opt; - while ((opt = getopt(argc, argv, "hg:i:r:")) != -1) - { - switch (opt) - { - case 'h': - printf("[-g \"n0 n1 n2\"]\n"); - return 1; - case 'g': //tiling1 tiling2 tiling3 - sscanf(optarg, "%d %d %d", &na, &nb, &nc); - break; - case 'i': //number of MC steps - nsteps = atoi(optarg); - break; - case 's': //random seed - iseed = atoi(optarg); - break; - case 'r': //rmax - Rmax = atof(optarg); - break; - } - } - - // Random.init(iseed); - Tensor tmat(na, 0, 0, 0, nb, 0, 0, 0, nc); - - //turn off output - if (omp_get_max_threads() > 1) - { - outputManager.pause(); - } - - size_t nptcl = 0; - double t0 = 0.0, t1 = 0.0; - OHMMS_PRECISION ratio = 0.0; - - PrimeNumberSet myPrimes; - - { - ParticleSet ions; - MCWalkerConfiguration els; - OHMMS_PRECISION scale = 1.0; - - int np = omp_get_num_threads(); - int ip = omp_get_thread_num(); - - //create generator within the thread - RandomGenerator random_th(myPrimes[world.rank()]); - - tile_graphite(ions, tmat, scale); - ions.setCoordinates(ions.R); //fill the SoA - - const int nions = ions.getTotalNum(); - const int nels = count_electrons(ions); - const int nels3 = 3 * nels; - -#pragma omp master - nptcl = nels; - - { //create up/down electrons - els.Lattice.BoxBConds = 1; - els.Lattice.set(ions.Lattice); - vector ud(2); - ud[0] = nels / 2; - ud[1] = nels - ud[0]; - els.create(ud); - els.R.InUnit = PosUnit::Lattice; - random_th.generate_uniform(&els.R[0][0], nels3); - els.convert2Cart(els.R); // convert to Cartiesian - els.setCoordinates(els.R); - } - - size_t nw = 4; - using walker_t = DummyWalker; - vector walkers(nw); - for (size_t i = 0; i < nw; ++i) - { - walkers[i].resize(nptcl); - walkers[i].ID = world.rank(); - walkers[i].R = 0; - walkers[i].Properties = i * world.size() + world.rank(); - } - - walkers[0].R = els.R; - - char fname[128]; - sprintf(fname, "debug.p%d", world.rank()); - ofstream fout(fname); - - //bcast a string - string message("dummy"); - if (world.rank() == 0) - { - message = "exchange_walker"; - walkers[0].R = els.R; - } - broadcast(world, message, 0); - - fout << message << endl << endl; - fout << world.rank() << " " << rows.rank() << " " << rows.size() << endl; - - //send the skeleton - broadcast(world, mpi::skeleton(walkers[0]), 0); - - mpi::request reqs[2]; - if (rows.rank() == 1) - { - mpi::content c = mpi::get_content(walkers[1]); - reqs[0] = rows.irecv(0, 911, c); - } - else if (rows.rank() == 0) - { - mpi::content c = mpi::get_content(walkers[0]); - reqs[0] = rows.isend(1, 911, c); - } - mpi::wait_any(reqs, reqs + 1); - - fout << "Properties " << endl; - fout << walkers[0].Properties << endl; - fout << endl; - fout << walkers[1].Properties << endl; - fout << endl; - fout << "ID " << walkers[1].ID << endl; - for (size_t e = 0; e < 4; ++e) - fout << walkers[0].R[e] << walkers[1].R[e] << endl; - } //end of omp parallel - - return 0; -} diff --git a/src/Utilities/BoostRandom.cpp b/src/Utilities/BoostRandom.cpp deleted file mode 100644 index 8ca07daaac..0000000000 --- a/src/Utilities/BoostRandom.cpp +++ /dev/null @@ -1,25 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////////// -// This file is distributed under the University of Illinois/NCSA Open Source License. -// See LICENSE file in top directory for details. -// -// Copyright (c) 2020 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 "BoostRandom.h" -#include - -uint32_t make_seed(int i, int n); - -template -void BoostRandom::init(int iseed_in) -{ - uint_type baseSeed = iseed_in; - uni.engine().seed(baseSeed); -} - -template class BoostRandom; diff --git a/src/Utilities/BoostRandom.h b/src/Utilities/BoostRandom.h deleted file mode 100644 index 80f9fe86f0..0000000000 --- a/src/Utilities/BoostRandom.h +++ /dev/null @@ -1,102 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////////// -// This file is distributed under the University of Illinois/NCSA Open Source License. -// See LICENSE file in top directory for details. -// -// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers. -// -// File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign -// Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign -// Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory -// -// File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign -////////////////////////////////////////////////////////////////////////////////////// - - -#ifndef OHMMS_BOOSTRANDOM_H -#define OHMMS_BOOSTRANDOM_H - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include -#include -#include -#ifdef BOOST_CLANG -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-W#pragma-messages" -#endif -#include -#ifdef BOOST_CLANG -#pragma clang diagnostic pop -#endif - -/** random number generator using boost::random - * - * A wrapper of boost::random class to work with applicatoins. - */ -template -class BoostRandom -{ -public: - /// real result type - typedef T result_type; - /// randmon number generator [0,max) where max depends on the generator type - typedef RNG generator_type; - /// unsigned integer type - typedef typename generator_type::result_type uint_type; - /// real random generator [0,1) - typedef boost::variate_generator> uniform_generator_type; - - std::string ClassName; - std::string EngineName; - - ///default constructor - explicit BoostRandom(uint_type iseed = 911, const std::string& aname = "mt19937") - : ClassName("boost"), - EngineName(aname), - uni(generator_type(iseed), boost::uniform_real(0, 1)) - {} - - /** initialize the generator - * @param iseed_in input seed - * - * Initialize generator with the seed. - */ - void init(int iseed_in); - - ///assign seed - inline void seed(uint_type aseed) { uni.engine().seed(aseed); } - - /** return a random number [0,1) - */ - inline result_type operator()() { return uni(); } - - inline size_t state_size() const { return uni.engine().state_size; } - - inline void read(std::istream& rin) { rin >> uni.engine(); } - - inline void write(std::ostream& rout) const { rout << uni.engine(); } - - inline void save(std::vector& curstate) const - { - curstate.clear(); - std::stringstream otemp; - otemp << uni.engine(); - copy(std::istream_iterator(otemp), std::istream_iterator(), back_inserter(curstate)); - } - - inline void load(const std::vector& newstate) - { - std::stringstream otemp; - copy(newstate.begin(), newstate.end(), std::ostream_iterator(otemp, " ")); - otemp >> uni.engine(); - } - -private: - ///random number generator [0,1) - uniform_generator_type uni; -}; - -extern template class BoostRandom; -extern template class BoostRandom; -#endif diff --git a/src/Utilities/CMakeLists.txt b/src/Utilities/CMakeLists.txt index dcead75706..fa39a9aef7 100644 --- a/src/Utilities/CMakeLists.txt +++ b/src/Utilities/CMakeLists.txt @@ -11,10 +11,8 @@ add_library(cxx_helpers ModernStringUtils.cpp) target_include_directories(cxx_helpers PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") set(QMC_RNG FakeRandom.cpp - RandomGenerator.cpp - BoostRandom.cpp) + RandomGenerator.cpp) add_library(qmcrng ${QMC_RNG}) -target_link_libraries(qmcrng PUBLIC Boost::boost) set(UTILITIES qmc_common.cpp diff --git a/src/Utilities/RandomGenerator.h b/src/Utilities/RandomGenerator.h index 698887ea59..a5ad7ed696 100644 --- a/src/Utilities/RandomGenerator.h +++ b/src/Utilities/RandomGenerator.h @@ -2,12 +2,13 @@ // This file is distributed under the University of Illinois/NCSA Open Source License. // See LICENSE file in top directory for details. // -// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers. +// Copyright (c) 2022 QMCPACK developers. // // File developed by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign // Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign +// Ye Luo, yeluo@anl.gov, Argonne National Laboratory // // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign ////////////////////////////////////////////////////////////////////////////////////// @@ -17,9 +18,7 @@ * @brief Declare a global Random Number Generator * * Selected among - * - boost::random - * - sprng - * - math::random + * - std::mt19937 * qmcplusplus::Random() returns a random number [0,1) * For OpenMP is enabled, it is important to use thread-safe boost::random. Each * thread uses its own random number generator with a distinct seed. This prevents @@ -32,12 +31,8 @@ #endif #include // The definition of the fake RNG should always be available for unit testing -#include "Utilities/FakeRandom.h" -#if defined(QMC_RNG_BOOST) -#include "Utilities/BoostRandom.h" -#else -#include "Utilities/StdRandom.h" -#endif +#include "FakeRandom.h" +#include "StdRandom.h" uint32_t make_seed(int i, int n); @@ -55,11 +50,7 @@ class RNGThreadSafe : public RNG }; extern template class RNGThreadSafe; -#if defined(QMC_RNG_BOOST) -extern template class RNGThreadSafe>; -#else extern template class RNGThreadSafe>; -#endif #if defined(USE_FAKE_RNG) // fake RNG redirection @@ -68,11 +59,7 @@ extern RNGThreadSafe fake_random_global; #define Random fake_random_global #else // real RNG redirection -#if defined(QMC_RNG_BOOST) -using RandomGenerator = BoostRandom; -#else using RandomGenerator = StdRandom; -#endif extern RNGThreadSafe random_global; #define Random random_global #endif diff --git a/src/Utilities/StdRandom.h b/src/Utilities/StdRandom.h index 1235577cd9..ce37acf3ab 100644 --- a/src/Utilities/StdRandom.h +++ b/src/Utilities/StdRandom.h @@ -2,19 +2,15 @@ // This file is distributed under the University of Illinois/NCSA Open Source License. // See LICENSE file in top directory for details. // -// Copyright (c) 2020 QMCPACK developers. +// Copyright (c) 2022 QMCPACK developers. // // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory +// Ye Luo, yeluo@anl.gov, Argonne National Laboratory // ////////////////////////////////////////////////////////////////////////////////////// /** @file * A minimally functional wrapper for the since c++11 - * - * This supports what I saw as the minimal functionality a RandomGenerator type - * needed to abstract. Patterned on by radically cut down from BoostRandom.h - * - * only used by test code */ #ifndef QMCPLUSPLUS_STDRAND_H #define QMCPLUSPLUS_STDRAND_H diff --git a/src/Utilities/Timer.h b/src/Utilities/Timer.h index 3c6c87eecb..6bf3c2e988 100644 --- a/src/Utilities/Timer.h +++ b/src/Utilities/Timer.h @@ -2,7 +2,7 @@ // This file is distributed under the University of Illinois/NCSA Open Source License. // See LICENSE file in top directory for details. // -// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers. +// Copyright (c) 2022 QMCPACK developers. // // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign @@ -12,7 +12,7 @@ /** @file Timer.h - * @brief Timer class using boost::timer + * @brief Timer class */ #ifndef QMCPLUSPLUS_TIMER_H #define QMCPLUSPLUS_TIMER_H diff --git a/src/Utilities/tests/test_rng.cpp b/src/Utilities/tests/test_rng.cpp index f520d03072..ce4306300c 100644 --- a/src/Utilities/tests/test_rng.cpp +++ b/src/Utilities/tests/test_rng.cpp @@ -2,7 +2,7 @@ // This file is distributed under the University of Illinois/NCSA Open Source License. // See LICENSE file in top directory for details. // -// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers. +// Copyright (c) 2022 QMCPACK developers. // // File developed by: Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign // @@ -13,7 +13,6 @@ #include "catch.hpp" #include "Utilities/RandomGenerator.h" -#include "Utilities/BoostRandom.h" #include #include #include @@ -22,28 +21,6 @@ using std::string; using std::vector; namespace qmcplusplus { -#ifdef HAVE_LIBBOOST -TEST_CASE("boost", "[utilities]") -{ - double d = Random(); - REQUIRE(d >= 0.0); - REQUIRE(d < 1.0); -} - -TEST_CASE("boost_mt19937_determinism", "[utilities]") -{ - // Verify BoostRandom (MT19937 internally) generates a fixed sequence given an fixed initial seed - // This is not guaranteed by Boost but appears to be the case - BoostRandom our_rng(13); - std::vector expected = {0.7777024102, 0.6073413305, 0.237541216}; - for (auto i = 0; i < expected.size(); ++i) - { - REQUIRE(our_rng() == Approx(expected[i])); - } -} - -#endif - TEST_CASE("make_seed", "[utilities]") { // not sure what to test here - mostly that it doesn't crash diff --git a/src/config.h.cmake.in b/src/config.h.cmake.in index 65d5dbe785..b3a811f6ed 100644 --- a/src/config.h.cmake.in +++ b/src/config.h.cmake.in @@ -155,8 +155,5 @@ /* Enable NVTX regions in CUDA code. */ #cmakedefine USE_NVTX_API @USE_NVTX_API@ -/* Use random number generator from boost C++ libraries instead of C++ standard library */ -#cmakedefine QMC_RNG_BOOST @QMC_RNG_BOOST@ - #endif // QMCPLUSPLUS_CONFIGURATION_H diff --git a/src/mpi/collectives.h b/src/mpi/collectives.h index 92a65227a3..fc99773596 100644 --- a/src/mpi/collectives.h +++ b/src/mpi/collectives.h @@ -15,9 +15,6 @@ #include "type_traits/container_proxy.h" #include "mpi/mpi_datatype.h" -//#if defined(HAVE_MPI) -//#include -//#endif namespace qmcplusplus { diff --git a/src/mpi/point2point.h b/src/mpi/point2point.h index bab5cd2b71..3255f26b02 100644 --- a/src/mpi/point2point.h +++ b/src/mpi/point2point.h @@ -15,9 +15,6 @@ #include "type_traits/container_proxy.h" #include "mpi/mpi_datatype.h" -//#if defined(HAVE_MPI) -//#include -//#endif namespace qmcplusplus {