Remove BoostRandom

This commit is contained in:
Ye Luo 2022-01-06 22:18:20 -06:00
parent 1ca0abf8f4
commit f4d4fc3bc8
17 changed files with 13 additions and 412 deletions

View File

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

View File

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

View File

@ -147,9 +147,6 @@ struct TensorSoaContainer<T, 3>
}
};
//Incorrect: provide wrapper class
//BOOST_CLASS_TRACKING(Pos3DSoA<double,3>, boost::serialization::track_never)
//BOOST_CLASS_TRACKING(Pos3DSoA<float,3>, boost::serialization::track_never)
} // namespace qmcplusplus
#endif

View File

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

View File

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

View File

@ -25,8 +25,6 @@
#include "Message/CommOperators.h"
// #include "QMCDrivers/ForwardWalking/ForwardWalkingStructure.h"
//#include <boost/archive/binary_oarchive.hpp>
namespace qmcplusplus
{
namespace testing

View File

@ -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 <Configuration.h>
#include "Particle/ParticleSet.h"
#include "Particle/MCWalkerConfiguration.h"
#include "Utilities/PrimeNumberSet.h"
#include <random/random.hpp>
#include "Sandbox/graphite.hpp"
#include "Utilities/Timer.h"
#include "Sandbox/common.hpp"
#include <boost/mpi.hpp>
#include <getopt.h>
using namespace std;
namespace qmcplusplus
{
namespace mpi = boost::mpi;
/** dummy walker to show how boost::mpi and boost::serialization work
*/
template<typename T, unsigned D>
struct DummyWalker
{
using PosType = TinyVector<T, D>;
long ID;
ParticleAttrib<PosType> R;
Matrix<double> Properties;
DummyWalker() { Properties.resize(2, 8); }
DummyWalker(const DummyWalker&) = default;
inline void resize(size_t n) { R.resize(n); }
template<class Archive>
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<int, 3> 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<uint32_t> 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<int> 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<OHMMS_PRECISION, 3>;
vector<walker_t> 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;
}

View File

@ -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 <cmath>
uint32_t make_seed(int i, int n);
template<typename T, typename RNG>
void BoostRandom<T, RNG>::init(int iseed_in)
{
uint_type baseSeed = iseed_in;
uni.engine().seed(baseSeed);
}
template class BoostRandom<double>;

View File

@ -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 <sstream>
#include <limits>
#include <boost/config.hpp>
#ifdef BOOST_CLANG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-W#pragma-messages"
#endif
#include <boost/random.hpp>
#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<typename T, typename RNG = boost::mt19937>
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<generator_type, boost::uniform_real<T>> 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<T>(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<uint_type>& curstate) const
{
curstate.clear();
std::stringstream otemp;
otemp << uni.engine();
copy(std::istream_iterator<uint_type>(otemp), std::istream_iterator<uint_type>(), back_inserter(curstate));
}
inline void load(const std::vector<uint_type>& newstate)
{
std::stringstream otemp;
copy(newstate.begin(), newstate.end(), std::ostream_iterator<uint_type>(otemp, " "));
otemp >> uni.engine();
}
private:
///random number generator [0,1)
uniform_generator_type uni;
};
extern template class BoostRandom<float>;
extern template class BoostRandom<double>;
#endif

View File

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

View File

@ -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 <cstdint>
// 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 @@ public:
};
extern template class RNGThreadSafe<FakeRandom>;
#if defined(QMC_RNG_BOOST)
extern template class RNGThreadSafe<BoostRandom<double>>;
#else
extern template class RNGThreadSafe<StdRandom<double>>;
#endif
#if defined(USE_FAKE_RNG)
// fake RNG redirection
@ -68,11 +59,7 @@ extern RNGThreadSafe<RandomGenerator> fake_random_global;
#define Random fake_random_global
#else
// real RNG redirection
#if defined(QMC_RNG_BOOST)
using RandomGenerator = BoostRandom<OHMMS_PRECISION_FULL>;
#else
using RandomGenerator = StdRandom<OHMMS_PRECISION_FULL>;
#endif
extern RNGThreadSafe<RandomGenerator> random_global;
#define Random random_global
#endif

View File

@ -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 <random>
*
* 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

View File

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

View File

@ -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 <stdio.h>
#include <string>
#include <vector>
@ -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<OHMMS_PRECISION_FULL> our_rng(13);
std::vector<OHMMS_PRECISION_FULL> 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

View File

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

View File

@ -15,9 +15,6 @@
#include "type_traits/container_proxy.h"
#include "mpi/mpi_datatype.h"
//#if defined(HAVE_MPI)
//#include <boost/mpi/operations.hpp>
//#endif
namespace qmcplusplus
{

View File

@ -15,9 +15,6 @@
#include "type_traits/container_proxy.h"
#include "mpi/mpi_datatype.h"
//#if defined(HAVE_MPI)
//#include <boost/mpi/operations.hpp>
//#endif
namespace qmcplusplus
{