Grid 0.7.0
BinaryCheckpointer.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/hmc/BinaryCheckpointer.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#ifndef BINARY_CHECKPOINTER
30#define BINARY_CHECKPOINTER
31
32#include <iostream>
33#include <sstream>
34#include <string>
35
37
38// Simple checkpointer, only binary file
39template <class Impl>
41private:
43
44public:
45 INHERIT_FIELD_TYPES(Impl); // Gets the Field type, a Lattice object
46
47 // Extract types from the Field
48 typedef typename Field::vector_object vobj;
49 typedef typename vobj::scalar_object sobj;
51 typedef typename sobj::DoublePrecision sobj_double;
52
54 initialize(Params_);
55 }
56
57 void initialize(const CheckpointerParameters &Params_) { Params = Params_; }
58
59 void truncate(std::string file) {
60 std::ofstream fout(file, std::ios::out);
61 fout.close();
62 }
63
64 void TrajectoryComplete(int traj,
65 ConfigurationBase<Field> &SmartConfig,
66 GridSerialRNG &sRNG, GridParallelRNG &pRNG)
67 {
68
69 if ((traj % Params.saveInterval) == 0) {
70 std::string config, rng, smr;
71 this->build_filenames(traj, Params, config, smr, rng);
72
73 uint32_t nersc_csum;
74 uint32_t scidac_csuma;
75 uint32_t scidac_csumb;
76
78 truncate(rng);
79 BinaryIO::writeRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
80 std::cout << GridLogMessage << "Written Binary RNG " << rng
81 << " checksum " << std::hex
82 << nersc_csum <<"/"
83 << scidac_csuma <<"/"
84 << scidac_csumb
85 << std::dec << std::endl;
86
87 truncate(config);
88 BinaryIO::writeLatticeObject<vobj, sobj_double>(SmartConfig.get_U(false), config, munge, 0, Params.format,
89 nersc_csum,scidac_csuma,scidac_csumb);
90
91 std::cout << GridLogMessage << "Written Binary Configuration " << config
92 << " checksum " << std::hex
93 << nersc_csum <<"/"
94 << scidac_csuma <<"/"
95 << scidac_csumb
96 << std::dec << std::endl;
97
98 if ( Params.saveSmeared ) {
99 truncate(smr);
100 BinaryIO::writeLatticeObject<vobj, sobj_double>(SmartConfig.get_U(true), smr, munge, 0, Params.format,
101 nersc_csum,scidac_csuma,scidac_csumb);
102 std::cout << GridLogMessage << "Written Binary Smeared Configuration " << smr
103 << " checksum " << std::hex
104 << nersc_csum <<"/"
105 << scidac_csuma <<"/"
106 << scidac_csumb
107 << std::dec << std::endl;
108 }
109 }
110
111 };
112
113 void CheckpointRestore(int traj, Field &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG) {
114 std::string config, rng, smr;
115 this->build_filenames(traj, Params, config, smr, rng);
116 this->check_filename(rng);
117 this->check_filename(config);
118
119
121
122 uint32_t nersc_csum;
123 uint32_t scidac_csuma;
124 uint32_t scidac_csumb;
125 BinaryIO::readRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb);
127 nersc_csum,scidac_csuma,scidac_csumb);
128
129 std::cout << GridLogMessage << "Read Binary Configuration " << config
130 << " checksums " << std::hex << nersc_csum<<"/"<<scidac_csuma<<"/"<<scidac_csumb
131 << std::dec << std::endl;
132 };
133};
134
136#endif
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
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)
vobj::scalar_object sobj
BinaryHmcCheckpointer(const CheckpointerParameters &Params_)
Field::vector_object vobj
CheckpointerParameters Params
void truncate(std::string file)
void TrajectoryComplete(int traj, ConfigurationBase< Field > &SmartConfig, GridSerialRNG &sRNG, GridParallelRNG &pRNG)
void CheckpointRestore(int traj, Field &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG)
getPrecision< sobj >::real_scalar_type sobj_stype
sobj::DoublePrecision sobj_double
void initialize(const CheckpointerParameters &Params_)
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
static void writeLatticeObject(Lattice< vobj > &Umu, std::string file, munger munge, uint64_t offset, const std::string &format, uint32_t &nersc_csum, uint32_t &scidac_csuma, uint32_t &scidac_csumb, int control=BINARYIO_LEXICOGRAPHIC)
Definition BinaryIO.h:580
static void readLatticeObject(Lattice< vobj > &Umu, std::string file, munger munge, uint64_t offset, const std::string &format, uint32_t &nersc_csum, uint32_t &scidac_csuma, uint32_t &scidac_csumb, int control=BINARYIO_LEXICOGRAPHIC)
Definition BinaryIO.h:541
Base class for "smart configuration", a container for a gauge configuration holding unsmeared and sme...
Definition ActionBase.h:51
virtual Field & get_U(bool smeared=false)=0
GridTypeMapper< scalar_type >::Realified real_scalar_type