Grid 0.7.0
ILDGCheckpointer.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/hmc/ILDGCheckpointer.h
6
7Copyright (C) 2016, 2026
8
9Author: Guido Cossu <guido.cossu@ed.ac.uk>
10Author: Gaurav Ray <gaurav.sinharay@swansea.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 ILDG_CHECKPOINTER
31#define ILDG_CHECKPOINTER
32
33#ifdef HAVE_LIME
34
35#include <iostream>
36#include <sstream>
37#include <string>
38
40
41// Only for Gauge fields
42template <class Implementation>
43class ILDGHmcCheckpointer : public BaseHmcCheckpointer<Implementation> {
44private:
45 CheckpointerParameters Params;
46
47public:
48 INHERIT_GIMPL_TYPES(Implementation);
49 typedef GaugeStatistics<Implementation> GaugeStats;
50
51 ILDGHmcCheckpointer(const CheckpointerParameters &Params_) { initialize(Params_); }
52
53 void initialize(const CheckpointerParameters &Params_) {
54 Params = Params_;
55
56 // check here that the format is valid
57 int ieee32big = (Params.format == std::string("IEEE32BIG"));
58 int ieee64big = (Params.format == std::string("IEEE64BIG"));
59
60 if (!(ieee64big || ieee32big)) {
61 std::cout << GridLogError << "Unrecognized file format " << Params.format
62 << std::endl;
63 std::cout << GridLogError
64 << "Allowed: IEEE32BIG | IEEE64BIG"
65 << std::endl;
66 exit(1);
67 }
68
69 if ( !((Params.group == std::string("su")) || (Params.group == std::string("sp"))) ) {
70 std::cout << GridLogError << "Unrecognized gauge group " << Params.group << std::endl;
71 std::cout << GridLogError << "Allowed: su | sp" << std::endl;
72 exit(1);
73 }
74
75 if ( Params.group == std::string("sp") && Nc%2!=0 ) {
76 std::cout << GridLogError << "Nc=" << Nc;
77 std::cout << ", Sp fields require even Nc" << std::endl;
78 exit(1);
79 }
80
81 }
82
83 // choose appropriate template instantiation here since the
84 // non-const checkpointer parameters cannot be used directly as
85 // template arguments to IldgWriter
86 void chooseIldgWriter( std::string format, std::string group, bool reduced_matrix,
87 std::string lat_obj, int traj,
88 ConfigurationBase<GaugeField> &SmartConfig) {
89
90 GridBase *grid = SmartConfig.get_U(false).Grid();
91
92 IldgWriter _IldgWriter(grid->IsBoss());
93 _IldgWriter.open(lat_obj);
94
95 if(format=="IEEE64BIG") {
96 if(group=="su" && reduced_matrix) {
97 _IldgWriter.writeConfiguration<GaugeStats, GroupName::SU, MatrixFormat::REDUCED, FloatingPointFormat::IEEE64BIG>(SmartConfig.get_U(false), traj, lat_obj, lat_obj);
98 }
99 else if (group=="su" && !reduced_matrix) {
100 _IldgWriter.writeConfiguration<GaugeStats, GroupName::SU, MatrixFormat::FULL, FloatingPointFormat::IEEE64BIG>(SmartConfig.get_U(false), traj, lat_obj, lat_obj);
101 }
102 else if (group=="sp" && reduced_matrix) {
103 _IldgWriter.writeConfiguration<GaugeStats, GroupName::Sp, MatrixFormat::REDUCED, FloatingPointFormat::IEEE64BIG>(SmartConfig.get_U(false), traj, lat_obj, lat_obj);
104 }
105 else if (group=="sp" && !reduced_matrix) {
106 _IldgWriter.writeConfiguration<GaugeStats, GroupName::Sp, MatrixFormat::FULL, FloatingPointFormat::IEEE64BIG>(SmartConfig.get_U(false), traj, lat_obj, lat_obj);
107 }
108 }
109 else if (format=="IEEE32BIG") {
110 if(group=="su" && reduced_matrix) {
111 _IldgWriter.writeConfiguration<GaugeStats, GroupName::SU, MatrixFormat::REDUCED, FloatingPointFormat::IEEE32BIG>(SmartConfig.get_U(false), traj, lat_obj, lat_obj);
112 }
113 else if (group=="su" && !reduced_matrix) {
114 _IldgWriter.writeConfiguration<GaugeStats, GroupName::SU, MatrixFormat::FULL, FloatingPointFormat::IEEE32BIG>(SmartConfig.get_U(false), traj, lat_obj, lat_obj);
115 }
116 else if (group=="sp" && reduced_matrix) {
117 _IldgWriter.writeConfiguration<GaugeStats, GroupName::Sp, MatrixFormat::REDUCED, FloatingPointFormat::IEEE32BIG>(SmartConfig.get_U(false), traj, lat_obj, lat_obj);
118 }
119 else if (group=="sp" && !reduced_matrix) {
120 _IldgWriter.writeConfiguration<GaugeStats, GroupName::Sp, MatrixFormat::FULL, FloatingPointFormat::IEEE32BIG>(SmartConfig.get_U(false), traj, lat_obj, lat_obj);
121 }
122 }
123
124 _IldgWriter.close();
125 }
126
127
128 void TrajectoryComplete(int traj,
129 ConfigurationBase<GaugeField> &SmartConfig,
130 GridSerialRNG &sRNG,
131 GridParallelRNG &pRNG) {
132 if ((traj % Params.saveInterval) == 0) {
133 std::string config, rng, smr;
134 this->build_filenames(traj, Params, config, smr, rng);
135 uint32_t nersc_csum,scidac_csuma,scidac_csumb;
136 BinaryIO::writeRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
137 std::cout << GridLogMessage << "Written BINARY RNG " << rng
138 << " checksum " << std::hex
139 << nersc_csum<<"/"
140 << scidac_csuma<<"/"
141 << scidac_csumb
142 << std::dec << std::endl;
143
144 chooseIldgWriter( Params.format, Params.group, Params.reduced_matrix, config, traj,
145 SmartConfig );
146
147 std::cout << GridLogMessage << "Written ILDG Configuration on " << config
148 << " checksum " << std::hex
149 << nersc_csum<<"/"
150 << scidac_csuma<<"/"
151 << scidac_csumb
152 << std::dec << std::endl;
153
154 if ( Params.saveSmeared ) {
155 chooseIldgWriter( Params.format, Params.group, Params.reduced_matrix, smr, traj,
156 SmartConfig );
157
158 std::cout << GridLogMessage << "Written ILDG Configuration on " << smr
159 << " checksum " << std::hex
160 << nersc_csum<<"/"
161 << scidac_csuma<<"/"
162 << scidac_csumb
163 << std::dec << std::endl;
164 }
165
166 }
167 };
168
169 void CheckpointRestore(int traj, GaugeField &U, GridSerialRNG &sRNG,
170 GridParallelRNG &pRNG) {
171 std::string config, rng, smr;
172 this->build_filenames(traj, Params, config, smr, rng);
173 this->check_filename(rng);
174 this->check_filename(config);
175
176 uint32_t nersc_csum,scidac_csuma,scidac_csumb;
177 BinaryIO::readRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
178
179 FieldMetaData header;
180 IldgReader _IldgReader;
181 _IldgReader.open(config);
182
183 if(Params.unique_su) {
184 _IldgReader.readConfiguration<GaugeStats, true>(U,header);// format from the header
185 }
186 else { _IldgReader.readConfiguration<GaugeStats, false>(U,header); }
187
188 _IldgReader.close();
189
190 std::cout << GridLogMessage << "Read ILDG Configuration from " << config
191 << " checksum " << std::hex
192 << nersc_csum<<"/"
193 << scidac_csuma<<"/"
194 << scidac_csumb
195 << std::dec << std::endl;
196 };
197};
198
200
201#endif // HAVE_LIME
202#endif // ILDG_CHECKPOINTER
#define INHERIT_GIMPL_TYPES(GImpl)
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
static constexpr int Nc
Definition QCD.h:50
#define header
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
static void readRNG(GridSerialRNG &serial_rng, GridParallelRNG &parallel_rng, std::string file, uint64_t offset, uint32_t &nersc_csum, uint32_t &scidac_csuma, uint32_t &scidac_csumb)
Definition BinaryIO.h:647
static void writeRNG(GridSerialRNG &serial_rng, GridParallelRNG &parallel_rng, std::string file, uint64_t offset, uint32_t &nersc_csum, uint32_t &scidac_csuma, uint32_t &scidac_csumb)
Definition BinaryIO.h:714
virtual Field & get_U(bool smeared=false)=0