Grid 0.7.0
CheckPointerModules.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/action/gauge/WilsonGaugeAction.h
6
7Copyright (C) 2016
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
30#ifndef CP_MODULES_H
31#define CP_MODULES_H
32
34
36// Checkpoint module, owns the Checkpointer
38
39template <class ImplementationPolicy>
40class CheckPointerModule: public Parametrized<CheckpointerParameters>, public HMCModuleBase< BaseHmcCheckpointer<ImplementationPolicy> > {
41public:
42 /* In addition to the virtual method initialize() below,
43 subclasses of CheckPointerModule must define a public attribute
44 constexpr static const char* const Name
45 such that the LoadCheckpointer template method can report which checkpointer it has loaded.
46 Once Grid supports C++20, this may be enforced via concepts. */
47
48 std::unique_ptr<BaseHmcCheckpointer<ImplementationPolicy> > CheckPointPtr;
51 typedef typename Base::Product Product;
52
54 template <class ReaderClass>
55 CheckPointerModule(Reader<ReaderClass>& Reader) : Parametrized<APar>(Reader){};
56
57 virtual void print_parameters(){
58 std::cout << this->Par_ << std::endl;
59 }
60
63
64 return CheckPointPtr.get();
65 }
66
67private:
68 /* Implementations of initialize() must set CheckPointPtr to an instance of the relevant checkpointer
69 (i.e. child class of BaseHmcCheckpointer). */
70 virtual void initialize() = 0;
71
72};
73
74template <char const *str, class ImplementationPolicy, class ReaderClass >
76 : public Factory < HMCModuleBase< BaseHmcCheckpointer<ImplementationPolicy> > , Reader<ReaderClass> > {
77public:
78 typedef Reader<ReaderClass> TheReader;
79 // use SINGLETON FUNCTOR MACRO HERE
81 void operator=(const HMC_CPModuleFactory& e) = delete;
83 static HMC_CPModuleFactory e;
84 return e;
85 }
86
87private:
88 HMC_CPModuleFactory(void) = default;
89 std::string obj_type() const {
90 return std::string(str);
91 }
92};
93
95// Concrete classes
97
98template<class ImplementationPolicy>
99class BinaryCPModule: public CheckPointerModule< ImplementationPolicy> {
101 using CPBase::CPBase; // for constructors
102
103 // acquire resource
104 virtual void initialize(){
106 }
107public:
108 constexpr static const char* const Name = "Binary";
109};
110
111
112template<class ImplementationPolicy>
113class NerscCPModule: public CheckPointerModule< ImplementationPolicy> {
115 using CPBase::CPBase; // for constructors inheritance
116
117 // acquire resource
118 virtual void initialize(){
120 }
121public:
122 constexpr static const char* const Name = "Nersc";
123};
124
125
126#ifdef HAVE_LIME
127
128template<class ImplementationPolicy>
129class ILDGCPModule: public CheckPointerModule< ImplementationPolicy> {
131 using CPBase::CPBase; // for constructors
132
133 // acquire resource
134 virtual void initialize(){
135 this->CheckPointPtr.reset(new ILDGHmcCheckpointer<ImplementationPolicy>(this->Par_));
136 }
137public:
138 constexpr static const char* const Name = "ILDG";
139};
140
141template<class ImplementationPolicy, class Metadata>
142class ScidacCPModule: public CheckPointerModule< ImplementationPolicy> {
143 typedef CheckPointerModule< ImplementationPolicy> CPBase;
144 Metadata M;
145
146 // acquire resource
147 virtual void initialize(){
148 this->CheckPointPtr.reset(new ScidacHmcCheckpointer<ImplementationPolicy, Metadata>(this->Par_, M));
149 }
150public:
151 ScidacCPModule(typename CPBase::APar Par, Metadata M_):M(M_), CPBase(Par) {}
152 template <class ReaderClass>
153 ScidacCPModule(Reader<ReaderClass>& Reader) : Parametrized<typename CPBase::APar>(Reader), M(Reader){};
154public:
155 constexpr static const char* const Name = "Scidac";
156};
157#endif
158
159extern char cp_string[];
160
161/*
162// use macros?
163static Registrar<BinaryCPModule<PeriodicGimplR>, HMC_CPModuleFactory<cp_string, PeriodicGimplR, XmlReader> > __CPBinarymodXMLInit("Binary");
164static Registrar<NerscCPModule<PeriodicGimplR> , HMC_CPModuleFactory<cp_string, PeriodicGimplR, XmlReader> > __CPNerscmodXMLInit("Nersc");
165
166#ifdef HAVE_LIME
167static Registrar<ILDGCPModule<PeriodicGimplR> , HMC_CPModuleFactory<cp_string, PeriodicGimplR, XmlReader> > __CPILDGmodXMLInit("ILDG");
168#endif
169*/
170
172
173#endif //CP_MODULES_H
char cp_string[]
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
CheckPointerModule< ImplementationPolicy > CPBase
virtual void initialize()
static constexpr const char *const Name
virtual void initialize()=0
CheckPointerModule(Reader< ReaderClass > &Reader)
virtual void print_parameters()
std::unique_ptr< BaseHmcCheckpointer< ImplementationPolicy > > CheckPointPtr
HMCModuleBase< BaseHmcCheckpointer< ImplementationPolicy > > Base
CheckpointerParameters APar
BaseHmcCheckpointer< ImplementationPolicy > Product
Definition Modules.h:97
Reader< ReaderClass > TheReader
HMC_CPModuleFactory(const HMC_CPModuleFactory &e)=delete
HMC_CPModuleFactory(void)=default
void operator=(const HMC_CPModuleFactory &e)=delete
std::string obj_type() const
static HMC_CPModuleFactory & getInstance(void)
CheckPointerModule< ImplementationPolicy > CPBase
static constexpr const char *const Name
virtual void initialize()