QMCPACK
RandomNumberControl.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 #ifndef OHMMS_RANDOMNUMBERCONTROL_H__
15 #define OHMMS_RANDOMNUMBERCONTROL_H__
16 
17 #include "Configuration.h"
21 #include "hdf/hdf_archive.h"
23 
24 #include <libxml/xpath.h>
25 
26 #include <memory>
27 
28 class Communicate;
29 
30 namespace qmcplusplus
31 {
32 /**class RandomNumberControl
33  *\brief Encapsulate data to initialize and save the status of the random number generator
34  *
35  * Default: myName = "random"
36  * 2007-12-01
37  * Use PrimeNumbers to generate random seeds.
38  */
40 {
41 public:
45  //children random number generator
47 
48  /// constructors and destructors
49  RandomNumberControl(const char* aname = "random");
50 
51  bool get(std::ostream& os) const override;
52  bool put(std::istream& is) override;
53  bool put(xmlNodePtr cur) override;
54  void reset() override;
55  static void test();
56 
57  static void make_seeds();
58  static void make_children();
59 
60  xmlNodePtr initialize(xmlXPathContextPtr);
61 
62  /** read in parallel or serial
63  * @param fname file name
64  * @param comm communicator
65  */
66  static void read(const std::string& fname, Communicate* comm);
67  /** write in parallel or serial
68  * @param fname file name
69  * @param comm communicator
70  */
71  static void write(const std::string& fname, Communicate* comm);
72  /** write in parallel or serial
73  * @param rng random number generators
74  * @param fname file name
75  * @param comm communicator
76  */
77  static void write(const RefVector<RandomBase<FullPrecRealType>>& rng, const std::string& fname, Communicate* comm);
78  /** read random state from a hdf file in parallel
79  * @param hin hdf_archive set to parallel
80  * @param comm communicator
81  */
82  static void read_parallel(hdf_archive& hin, Communicate* comm);
83  /** write random state to a hdf file in parallel
84  * @param hdf_archive set to parallel
85  * @param comm communicator
86  */
88  /** rank 0 reads random states from a hdf file
89  * and distributes them to all the other ranks
90  * @param hin hdf_archive set to serial
91  * @param comm communicator
92  */
93  static void read_rank_0(hdf_archive& hin, Communicate* comm);
94  /** rank 0 gathers the random states from all the other ranks
95  * and write them to a hdf file
96  * @param hin hdf_archive object set to serial
97  * @param comm communicator
98  */
100 
101 private:
103  xmlNodePtr myCur;
105 };
106 } // namespace qmcplusplus
107 
108 #endif
static void read(const std::string &fname, Communicate *comm)
read in parallel or serial
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
static void read_parallel(hdf_archive &hin, Communicate *comm)
read random state from a hdf file in parallel
static PrimeNumberSet< uint_type > PrimeNumbers
initialize the static data members
class to handle hdf file
Definition: hdf_archive.h:51
std::vector< std::unique_ptr< T > > UPtrVector
static void write(const std::string &fname, Communicate *comm)
write in parallel or serial
xmlNodePtr initialize(xmlXPathContextPtr)
Declaration of OhmmsElementBase and define xml-related macros.
Wrapping information on parallelism.
Definition: Communicate.h:68
void reset() override
reset the generator
static void write_parallel(const RefVector< RandomBase< FullPrecRealType >> &rng, hdf_archive &hout, Communicate *comm)
write random state to a hdf file in parallel
Abstract class to provide xml-compatible I/O interfaces for the derived classes.
QMCTraits::FullPrecRealType FullPrecRealType
RandomBase< FullPrecRealType >::uint_type uint_type
class RandomNumberControl
static UPtrVector< RandomBase< FullPrecRealType > > Children
std::vector< std::reference_wrapper< T > > RefVector
bool put(std::istream &is) override
generic input
QTFull::RealType FullPrecRealType
Definition: Configuration.h:66
define a class to generate prime numbers for random number generators
static void write_rank_0(const RefVector< RandomBase< FullPrecRealType >> &rng, hdf_archive &hout, Communicate *comm)
rank 0 gathers the random states from all the other ranks and write them to a hdf file ...
static void make_seeds()
reset the generator
Declare a global Random Number Generator.
RandomNumberControl(const char *aname="random")
constructors and destructors
static void read_rank_0(hdf_archive &hin, Communicate *comm)
rank 0 reads random states from a hdf file and distributes them to all the other ranks ...