Grid 0.7.0
ScidacCheckpointer.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/hmc/ScidacCheckpointer.h
6
7Copyright (C) 2018
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#pragma once
30
31#ifdef HAVE_LIME
32
33#include <iostream>
34#include <sstream>
35#include <string>
36
38// For generic fields
39template <class Implementation, class Metadata>
40class ScidacHmcCheckpointer : public BaseHmcCheckpointer<Implementation> {
41 private:
42 CheckpointerParameters Params;
43 Metadata MData;
44
45 typedef typename Implementation::Field Field;
46
47 public:
48 //INHERIT_GIMPL_TYPES(Implementation);
49
50 ScidacHmcCheckpointer(const CheckpointerParameters &Params_) { initialize(Params_); }
51 ScidacHmcCheckpointer(const CheckpointerParameters &Params_, const Metadata& M_):MData(M_) { 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 ieee32 = (Params.format == std::string("IEEE32"));
59 int ieee64big = (Params.format == std::string("IEEE64BIG"));
60 int ieee64 = (Params.format == std::string("IEEE64"));
61
62 if (!(ieee64big || ieee32 || ieee32big || ieee64)) {
63 std::cout << GridLogError << "Unrecognized file format " << Params.format
64 << std::endl;
65 std::cout << GridLogError
66 << "Allowed: IEEE32BIG | IEEE32 | IEEE64BIG | IEEE64"
67 << std::endl;
68
69 exit(1);
70 }
71 }
72
73 void TrajectoryComplete(int traj,
74 ConfigurationBase<Field> &SmartConfig,
75 GridSerialRNG &sRNG,
76 GridParallelRNG &pRNG) {
77 if ((traj % Params.saveInterval) == 0) {
78 std::string config, rng,smr;
79 this->build_filenames(traj, Params, config, smr, rng);
80 GridBase *grid = SmartConfig.get_U(false).Grid();
81 uint32_t nersc_csum,scidac_csuma,scidac_csumb;
82 BinaryIO::writeRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
83 std::cout << GridLogMessage << "Written Binary RNG " << rng
84 << " checksum " << std::hex
85 << nersc_csum <<"/"
86 << scidac_csuma <<"/"
87 << scidac_csumb
88 << std::dec << std::endl;
89
90
91 {
92 ScidacWriter _ScidacWriter(grid->IsBoss());
93 _ScidacWriter.open(config);
94 _ScidacWriter.writeScidacFieldRecord(SmartConfig.get_U(false), MData);
95 _ScidacWriter.close();
96 }
97
98 if ( Params.saveSmeared ) {
99 ScidacWriter _ScidacWriter(grid->IsBoss());
100 _ScidacWriter.open(smr);
101 _ScidacWriter.writeScidacFieldRecord(SmartConfig.get_U(true), MData);
102 _ScidacWriter.close();
103 }
104 std::cout << GridLogMessage << "Written Scidac Configuration on " << config << std::endl;
105 }
106 };
107
108 void CheckpointRestore(int traj, Field &U, GridSerialRNG &sRNG,
109 GridParallelRNG &pRNG) {
110 std::string config, rng, smr;
111 this->build_filenames(traj, Params, config, smr, rng);
112 this->check_filename(rng);
113 this->check_filename(config);
114
115
116 uint32_t nersc_csum,scidac_csuma,scidac_csumb;
117 BinaryIO::readRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
118
119 Metadata md_content;
120 ScidacReader _ScidacReader;
121 _ScidacReader.open(config);
122 _ScidacReader.readScidacFieldRecord(U,md_content); // format from the header
123 _ScidacReader.close();
124
125 std::cout << GridLogMessage << "Read Scidac Configuration from " << config
126 << " checksum " << std::hex
127 << nersc_csum<<"/"
128 << scidac_csuma<<"/"
129 << scidac_csumb
130 << std::dec << std::endl;
131 };
132};
134
135
136#endif // HAVE_LIME
137
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 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