Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
randomNumbers_SFMT.h
Go to the documentation of this file.
1 
14 #ifndef RANDOMNUMBERS_SFMT_INCLUDED
15 #define RANDOMNUMBERS_SFMT_INCLUDED
16 
17 #ifdef USE_SFMTLIB
18 
19 // #define __STDC_CONSTANT_MACROS
20 
21 #include <string>
22 #include <cassert>
23 
24 #include "randomNumbers.h"
25 
26 #include <SFMT.h>
27 
28 #ifdef USE_NTLLIB
29 #define ENABLE_SFMT_JUMP
30 #include <SFMT-jump-alt.h>
31 #endif
32 
33 #include "IO/bridgeIO.h"
34 using Bridge::vout;
35 
36 class RandomNumbers_SFMT : public RandomNumbers
37 {
38  static const std::string class_name;
39 
40  public:
41  RandomNumbers_SFMT(const int s);
42  RandomNumbers_SFMT(const std::string& filename) { read_file(filename); }
43 
44  ~RandomNumbers_SFMT() {}
45 
46  double get();
47  void get_block(double *v, const size_t n);
48 
49  void write_file(const std::string& filename);
50  void read_file(const std::string& filename);
51 
52  void reset(unsigned long seed);
53 
54 #ifdef ENABLE_SFMT_JUMP
55  virtual void uniform_lex_global(Field&);
56  virtual void gauss_lex_global(Field&);
57 #endif
58 
59  private:
60 
61  template<typename T>
62  void generate_global_jump(Field& f);
63 
64  sfmt_t m_state;
65 
66 #ifdef USE_FACTORY
67  private:
68  static RandomNumbers *create_object_with_int(const int& iseed)
69  {
70  return new RandomNumbers_SFMT(iseed);
71  }
72 
73  static RandomNumbers *create_object_with_file(const std::string& filename)
74  {
75  return new RandomNumbers_SFMT(filename);
76  }
77 
78  public:
79  static bool register_factory()
80  {
81  bool init1 = RandomNumbers::Factory_int::Register("SFMT", create_object_with_int);
82  bool init2 = RandomNumbers::Factory_file::Register("SFMT", create_object_with_file);
83 
84  return init1 && init2;
85  }
86 #endif
87 };
88 #endif /* USE_SFMTLIB */
89 #endif /* RANDOMNUMBERS_SFMT_INCLUDED */
BridgeIO vout
Definition: bridgeIO.cpp:503
virtual void uniform_lex_global(Field &)
uniform random number defined on global lattice.
Container of Field-type object.
Definition: field.h:45
virtual void write_file(const std::string &)=0
static const std::string class_name
Definition: randomNumbers.h:46
virtual void gauss_lex_global(Field &)
gaussian random number defined on global lattice.
virtual void reset(unsigned long seed)=0
reset state with new seed.
virtual void read_file(const std::string &)=0
save and load random number status.
Base class of random number generators.
Definition: randomNumbers.h:43