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 bool smeared ) {
90
91 GridBase *grid = SmartConfig.get_U(smeared).Grid();
92
93 IldgWriter _IldgWriter(grid->IsBoss());
94 _IldgWriter.open(lat_obj);
95
96 if(format=="IEEE64BIG") {
97 if(group=="su" && reduced_matrix) {
98 _IldgWriter.writeConfiguration<GaugeStats, GroupName::SU, MatrixFormat::REDUCED, FloatingPointFormat::IEEE64BIG>(SmartConfig.get_U(smeared), traj, lat_obj, lat_obj);
99 }
100 else if (group=="su" && !reduced_matrix) {
101 _IldgWriter.writeConfiguration<GaugeStats, GroupName::SU, MatrixFormat::FULL, FloatingPointFormat::IEEE64BIG>(SmartConfig.get_U(smeared), traj, lat_obj, lat_obj);
102 }
103 else if (group=="sp" && reduced_matrix) {
104 _IldgWriter.writeConfiguration<GaugeStats, GroupName::Sp, MatrixFormat::REDUCED, FloatingPointFormat::IEEE64BIG>(SmartConfig.get_U(smeared), traj, lat_obj, lat_obj);
105 }
106 else if (group=="sp" && !reduced_matrix) {
107 _IldgWriter.writeConfiguration<GaugeStats, GroupName::Sp, MatrixFormat::FULL, FloatingPointFormat::IEEE64BIG>(SmartConfig.get_U(smeared), traj, lat_obj, lat_obj);
108 }
109 }
110 else if (format=="IEEE32BIG") {
111 if(group=="su" && reduced_matrix) {
112 _IldgWriter.writeConfiguration<GaugeStats, GroupName::SU, MatrixFormat::REDUCED, FloatingPointFormat::IEEE32BIG>(SmartConfig.get_U(smeared), traj, lat_obj, lat_obj);
113 }
114 else if (group=="su" && !reduced_matrix) {
115 _IldgWriter.writeConfiguration<GaugeStats, GroupName::SU, MatrixFormat::FULL, FloatingPointFormat::IEEE32BIG>(SmartConfig.get_U(smeared), traj, lat_obj, lat_obj);
116 }
117 else if (group=="sp" && reduced_matrix) {
118 _IldgWriter.writeConfiguration<GaugeStats, GroupName::Sp, MatrixFormat::REDUCED, FloatingPointFormat::IEEE32BIG>(SmartConfig.get_U(smeared), traj, lat_obj, lat_obj);
119 }
120 else if (group=="sp" && !reduced_matrix) {
121 _IldgWriter.writeConfiguration<GaugeStats, GroupName::Sp, MatrixFormat::FULL, FloatingPointFormat::IEEE32BIG>(SmartConfig.get_U(smeared), traj, lat_obj, lat_obj);
122 }
123 }
124
125 _IldgWriter.close();
126 }
127
128
129 void TrajectoryComplete(int traj,
130 ConfigurationBase<GaugeField> &SmartConfig,
131 GridSerialRNG &sRNG,
132 GridParallelRNG &pRNG) {
133 if ((traj % Params.saveInterval) == 0) {
134 std::string config, rng, smr;
135 this->build_filenames(traj, Params, config, smr, rng);
136 uint32_t nersc_csum,scidac_csuma,scidac_csumb;
137 BinaryIO::writeRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
138 std::cout << GridLogMessage << "Written BINARY RNG " << rng
139 << " checksum " << std::hex
140 << nersc_csum<<"/"
141 << scidac_csuma<<"/"
142 << scidac_csumb
143 << std::dec << std::endl;
144
145 chooseIldgWriter(Params.format, Params.group, Params.reduced_matrix, config, traj,
146 SmartConfig, false);
147
148 std::cout << GridLogMessage << "Written ILDG Configuration on " << config
149 << " checksum " << std::hex
150 << nersc_csum<<"/"
151 << scidac_csuma<<"/"
152 << scidac_csumb
153 << std::dec << std::endl;
154
155 if ( Params.saveSmeared ) {
156 chooseIldgWriter(Params.format, Params.group, Params.reduced_matrix, smr, traj,
157 SmartConfig, true);
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 void CheckpointRestore(int traj, GaugeField &U, GridSerialRNG &sRNG,
169 GridParallelRNG &pRNG) {
170 std::string config, rng, smr;
171 this->build_filenames(traj, Params, config, smr, rng);
172 this->check_filename(rng);
173 this->check_filename(config);
174
175 uint32_t nersc_csum,scidac_csuma,scidac_csumb;
176 BinaryIO::readRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
177
178 FieldMetaData header;
179 IldgReader _IldgReader;
180 _IldgReader.open(config);
181
182 if(Params.unique_su) {
183 _IldgReader.readConfiguration<GaugeStats, true>(U,header);// format from the header
184 }
185 else { _IldgReader.readConfiguration<GaugeStats, false>(U,header); }
186
187 _IldgReader.close();
188
189 std::cout << GridLogMessage << "Read ILDG Configuration from " << config
190 << " checksum " << std::hex
191 << nersc_csum<<"/"
192 << scidac_csuma<<"/"
193 << scidac_csumb
194 << std::dec << std::endl;
195 };
196};
197
199
200#endif // HAVE_LIME
201#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