Grid 0.7.0
HMCModules.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/hmc/GenericHmcRunner.h
6
7Copyright (C) 2015
8Copyright (C) 2016
9
10Author: Guido Cossu <guido.cossu@ed.ac.uk>
11
12This program is free software; you can redistribute it and/or modify
13it under the terms of the GNU General Public License as published by
14the Free Software Foundation; either version 2 of the License, or
15(at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License along
23with this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26See the full license in the file "LICENSE" in the top level distribution
27directory
28*************************************************************************************/
29 /* END LEGAL */
30#ifndef GRID_HMC_MODULES
31#define GRID_HMC_MODULES
32
33#include "HMC_GridModules.h"
34
36
38struct RNGModuleParameters: Serializable {
40 std::string, serial_seeds,
41 std::string, parallel_seeds,);
42
43 std::vector<int> getSerialSeeds(){return strToVec<int>(serial_seeds);}
44 std::vector<int> getParallelSeeds(){return strToVec<int>(parallel_seeds);}
45
46 RNGModuleParameters(): serial_seeds("1"), parallel_seeds("1"){}
47
48 template <class ReaderClass >
49 RNGModuleParameters(Reader<ReaderClass>& Reader){
50 read(Reader, "RandomNumberGenerator", *this);
51 }
52
53};
54
55// Random number generators module
58 std::unique_ptr<GridParallelRNG> pRNG_;
60
61public:
62
64
66 pRNG_.reset(pRNG);
67 }
68
70 Params_ = Params;
71 }
72
74 GridParallelRNG& get_pRNG() { return *pRNG_.get(); }
75
76 void seed() {
77 auto SerialSeeds = Params_.getSerialSeeds();
78 auto ParallelSeeds = Params_.getParallelSeeds();
79 if (SerialSeeds.size() == 0 && ParallelSeeds.size() == 0) {
80 std::cout << GridLogError << "Seeds not initialized" << std::endl;
81 exit(1);
82 }
83 std::cout << GridLogMessage << "Reseeding serial RNG with seed vector " << SerialSeeds << std::endl;
84 sRNG_.SeedFixedIntegers(SerialSeeds);
85 std::cout << GridLogMessage << "Reseeding parallel RNG with seed vector " << ParallelSeeds << std::endl;
86 pRNG_->SeedFixedIntegers(ParallelSeeds);
87 }
88};
89
90
91/*
94template <class ImplementationPolicy>
95class SmearingModule{
96virtual void get_smearing();
97};
98
99template <class ImplementationPolicy>
100class StoutSmearingModule: public SmearingModule<ImplementationPolicy>{
101SmearedConfiguration<ImplementationPolicy> SmearingPolicy;
102};
103
104*/
105
107
108#endif // GRID_HMC_MODULES
GridLogger GridLogError(1, "Error", GridLogColours, "RED")
GridLogger GridLogMessage(1, "Message", GridLogColours, "NORMAL")
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
GridSerialRNG & get_sRNG()
Definition HMCModules.h:73
std::unique_ptr< GridParallelRNG > pRNG_
Definition HMCModules.h:58
void seed()
Definition HMCModules.h:76
RNGModuleParameters Params_
Definition HMCModules.h:59
void set_pRNG(GridParallelRNG *pRNG)
Definition HMCModules.h:65
GridParallelRNG & get_pRNG()
Definition HMCModules.h:74
GridSerialRNG sRNG_
Definition HMCModules.h:57
void set_RNGSeeds(RNGModuleParameters &Params)
Definition HMCModules.h:69
std::vector< int > getSerialSeeds()
Definition HMCModules.h:43
RNGModuleParameters(Reader< ReaderClass > &Reader)
Definition HMCModules.h:49
std::vector< int > getParallelSeeds()
Definition HMCModules.h:44
GRID_SERIALIZABLE_CLASS_MEMBERS(RNGModuleParameters, std::string, serial_seeds, std::string, parallel_seeds,)