Grid 0.7.0
BaseCheckpointer.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/hmc/BaseCheckpointer.h
6
7Copyright (C) 2015
8
9Author: Guido Cossu <guido.cossu@ed.ac.uk>
10
11This program is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 2 of the License, or
14(at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along
22with this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25See the full license in the file "LICENSE" in the top level distribution
26directory
27*************************************************************************************/
28 /* END LEGAL */
29#ifndef BASE_CHECKPOINTER
30#define BASE_CHECKPOINTER
31
33
34class CheckpointerParameters : Serializable {
35public:
37 std::string, config_prefix,
38 std::string, smeared_prefix,
39 std::string, rng_prefix,
40 int, saveInterval,
41 bool, saveSmeared,
42 std::string, format,
43 std::string, group,
44 bool, reduced_matrix,
45 bool, unique_su, );
46
47 CheckpointerParameters(std::string cf = "cfg", std::string sf="cfg_smr" , std::string rn = "rng", int savemodulo = 1, bool save_smr = false, const std::string& f = "IEEE64BIG", std::string grp = "su", bool rdc_mat = false, bool unq_su = false)
48 : config_prefix(cf),
49 smeared_prefix(sf),
50 rng_prefix(rn),
51 saveInterval(savemodulo),
52 saveSmeared(save_smr),
53 format(f),
54 group(grp),
55 reduced_matrix(rdc_mat),
56 unique_su(unq_su) {};
57
58
59 template <class ReaderClass >
60 CheckpointerParameters(Reader<ReaderClass> &Reader) {
61 read(Reader, "Checkpointer", *this);
62 }
63
64
65};
66
68// Base class for checkpointers
69template <class Impl>
70class BaseHmcCheckpointer : public HmcObservable<typename Impl::Field> {
71public:
73 std::string &conf_file,
74 std::string &smear_file,
75 std::string &rng_file) {
76 {
77 std::ostringstream os;
78 os << Params.rng_prefix << "." << traj;
79 rng_file = os.str();
80 }
81
82 {
83 std::ostringstream os;
84 os << Params.smeared_prefix << "." << traj;
85 smear_file = os.str();
86 }
87
88 {
89 std::ostringstream os;
90 os << Params.config_prefix << "." << traj;
91 conf_file = os.str();
92 }
93 }
95 void check_filename(const std::string &filename){
96 std::ifstream f(filename.c_str());
97 if(!f.good()){
98 std::cout << GridLogError << "Filename " << filename << " not found. Aborting. " << std::endl;
99 abort();
100 };
101 }
102 virtual void initialize(const CheckpointerParameters &Params) = 0;
103
104 virtual void TrajectoryComplete(int traj,
105 typename Impl::Field &U,
106 GridSerialRNG &sRNG,
107 GridParallelRNG &pRNG) { assert(0); } ; // HMC should pass the smart config with smeared and unsmeared
108
109 virtual void CheckpointRestore(int traj, typename Impl::Field &U,
110 GridSerialRNG &sRNG,
111 GridParallelRNG &pRNG) = 0;
112
113}; // class BaseHmcCheckpointer
114
115
117
118#endif
GridLogger GridLogError(1, "Error", GridLogColours, "RED")
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
static INTERNAL_PRECISION U
Definition Zolotarev.cc:230
virtual void TrajectoryComplete(int traj, typename Impl::Field &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG)
virtual void CheckpointRestore(int traj, typename Impl::Field &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG)=0
void build_filenames(int traj, CheckpointerParameters &Params, std::string &conf_file, std::string &smear_file, std::string &rng_file)
void check_filename(const std::string &filename)
virtual void initialize(const CheckpointerParameters &Params)=0
CheckpointerParameters(std::string cf="cfg", std::string sf="cfg_smr", std::string rn="rng", int savemodulo=1, bool save_smr=false, const std::string &f="IEEE64BIG", std::string grp="su", bool rdc_mat=false, bool unq_su=false)
GRID_SERIALIZABLE_CLASS_MEMBERS(CheckpointerParameters, std::string, config_prefix, std::string, smeared_prefix, std::string, rng_prefix, int, saveInterval, bool, saveSmeared, std::string, format, std::string, group, bool, reduced_matrix, bool, unique_su,)
CheckpointerParameters(Reader< ReaderClass > &Reader)