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 15 #ifndef OHMMS_RANDOMNUMBERCONTROL_H__ 16 #define OHMMS_RANDOMNUMBERCONTROL_H__ 17 #include <libxml/xpath.h> 18 #include "OhmmsData/OhmmsElementBase.h" 19 #include "Utilities/RandomGenerator.h" 20 #include "Utilities/PrimeNumberSet.h" 21 #include "hdf/hdf_archive.h" 22 23 class Communicate; 24 25 namespace qmcplusplus 26 { 27 /**class RandomNumberControl 28 *\brief Encapsulate data to initialize and save the status of the random number generator 29 * 30 * Default: myName = "random" 31 * 2007-12-01 32 * Use PrimeNumbers to generate random seeds. 33 */ 34 class RandomNumberControl : public OhmmsElementBase 35 { 36 public: 37 typedef RandomGenerator_t::uint_type uint_type; 38 static PrimeNumberSet<uint_type> PrimeNumbers; 39 //children random number generator 40 static std::vector<RandomGenerator_t*> Children; 41 42 /// constructors and destructors 43 RandomNumberControl(const char* aname = "random"); 44 45 bool get(std::ostream& os) const; 46 bool put(std::istream& is); 47 bool put(xmlNodePtr cur); 48 void reset(); 49 static void test(); 50 51 static void make_seeds(); 52 static void make_children(); 53 54 xmlNodePtr initialize(xmlXPathContextPtr); 55 56 /** read in parallel or serial 57 * @param fname file name 58 * @param comm communicator 59 */ 60 static void read(const std::string& fname, Communicate* comm); 61 /** write in parallel or serial 62 * @param fname file name 63 * @param comm communicator 64 */ 65 static void write(const std::string& fname, Communicate* comm); 66 /** read random state from a hdf file in parallel 67 * @param hin hdf_archive set to parallel 68 * @param comm communicator 69 */ 70 static void read_parallel(hdf_archive& hin, Communicate* comm); 71 /** write random state to a hdf file in parallel 72 * @param hdf_archive set to parallel 73 * @param comm communicator 74 */ 75 static void write_parallel(hdf_archive& hout, Communicate* comm); 76 /** rank 0 reads random states from a hdf file 77 * and distributes them to all the other ranks 78 * @param hin hdf_archive set to serial 79 * @param comm communicator 80 */ 81 static void read_rank_0(hdf_archive& hin, Communicate* comm); 82 /** rank 0 gathers the random states from all the other ranks 83 * and write them to a hdf file 84 * @param hin hdf_archive object set to serial 85 * @param comm communicator 86 */ 87 static void write_rank_0(hdf_archive& hout, Communicate* comm); 88 /** read random state from a xml file 89 * @param fname file name 90 * @param comm communicator 91 */ 92 static void read_old(const std::string& fname, Communicate* comm); 93 /** write random state to a xml file 94 * @param fname file name 95 * @param comm communicator 96 */ 97 static void write_old(const std::string& fname, Communicate* comm); 98 99 private: 100 bool NeverBeenInitialized; 101 xmlNodePtr myCur; 102 static uint_type Offset; 103 }; 104 } // namespace qmcplusplus 105 106 #endif 107