|
| 1 | +/************************************************************************************* |
| 2 | +
|
| 3 | +Grid physics library, www.github.com/paboyle/Grid |
| 4 | +
|
| 5 | +Source file: ./lib/qcd/hmc/ScidacCheckpointer.h |
| 6 | +
|
| 7 | +Copyright (C) 2018 |
| 8 | +
|
| 9 | +Author: Guido Cossu <guido.cossu@ed.ac.uk> |
| 10 | +
|
| 11 | +This program is free software; you can redistribute it and/or modify |
| 12 | +it under the terms of the GNU General Public License as published by |
| 13 | +the Free Software Foundation; either version 2 of the License, or |
| 14 | +(at your option) any later version. |
| 15 | +
|
| 16 | +This program is distributed in the hope that it will be useful, |
| 17 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | +GNU General Public License for more details. |
| 20 | +
|
| 21 | +You should have received a copy of the GNU General Public License along |
| 22 | +with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 24 | +
|
| 25 | +See the full license in the file "LICENSE" in the top level distribution |
| 26 | +directory |
| 27 | +*************************************************************************************/ |
| 28 | +/* END LEGAL */ |
| 29 | +#ifndef SCIDAC_CHECKPOINTER |
| 30 | +#define SCIDAC_CHECKPOINTER |
| 31 | + |
| 32 | +#ifdef HAVE_LIME |
| 33 | + |
| 34 | +#include <iostream> |
| 35 | +#include <sstream> |
| 36 | +#include <string> |
| 37 | + |
| 38 | +namespace Grid { |
| 39 | +namespace QCD { |
| 40 | + |
| 41 | +// For generic fields |
| 42 | +template <class Implementation, class Metadata> |
| 43 | +class ScidacHmcCheckpointer : public BaseHmcCheckpointer<Implementation> { |
| 44 | + private: |
| 45 | + CheckpointerParameters Params; |
| 46 | + Metadata MData; |
| 47 | + |
| 48 | + typedef typename Implementation::Field Field; |
| 49 | + |
| 50 | + public: |
| 51 | + //INHERIT_GIMPL_TYPES(Implementation); |
| 52 | + |
| 53 | + ScidacHmcCheckpointer(const CheckpointerParameters &Params_) { initialize(Params_); } |
| 54 | + ScidacHmcCheckpointer(const CheckpointerParameters &Params_, const Metadata& M_):MData(M_) { initialize(Params_); } |
| 55 | + |
| 56 | + void initialize(const CheckpointerParameters &Params_) { |
| 57 | + Params = Params_; |
| 58 | + |
| 59 | + // check here that the format is valid |
| 60 | + int ieee32big = (Params.format == std::string("IEEE32BIG")); |
| 61 | + int ieee32 = (Params.format == std::string("IEEE32")); |
| 62 | + int ieee64big = (Params.format == std::string("IEEE64BIG")); |
| 63 | + int ieee64 = (Params.format == std::string("IEEE64")); |
| 64 | + |
| 65 | + if (!(ieee64big || ieee32 || ieee32big || ieee64)) { |
| 66 | + std::cout << GridLogError << "Unrecognized file format " << Params.format |
| 67 | + << std::endl; |
| 68 | + std::cout << GridLogError |
| 69 | + << "Allowed: IEEE32BIG | IEEE32 | IEEE64BIG | IEEE64" |
| 70 | + << std::endl; |
| 71 | + |
| 72 | + exit(1); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + void TrajectoryComplete(int traj, Field &U, GridSerialRNG &sRNG, |
| 77 | + GridParallelRNG &pRNG) { |
| 78 | + if ((traj % Params.saveInterval) == 0) { |
| 79 | + std::string config, rng; |
| 80 | + this->build_filenames(traj, Params, config, rng); |
| 81 | + GridBase *grid = U._grid; |
| 82 | + uint32_t nersc_csum,scidac_csuma,scidac_csumb; |
| 83 | + BinaryIO::writeRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb); |
| 84 | + ScidacWriter _ScidacWriter(grid->IsBoss()); |
| 85 | + _ScidacWriter.open(config); |
| 86 | + _ScidacWriter.writeScidacFieldRecord(U, MData); |
| 87 | + _ScidacWriter.close(); |
| 88 | + |
| 89 | + std::cout << GridLogMessage << "Written Scidac Configuration on " << config |
| 90 | + << " checksum " << std::hex << nersc_csum<<"/" |
| 91 | + << scidac_csuma<<"/" << scidac_csumb |
| 92 | + << std::dec << std::endl; |
| 93 | + } |
| 94 | + }; |
| 95 | + |
| 96 | + void CheckpointRestore(int traj, Field &U, GridSerialRNG &sRNG, |
| 97 | + GridParallelRNG &pRNG) { |
| 98 | + std::string config, rng; |
| 99 | + this->build_filenames(traj, Params, config, rng); |
| 100 | + this->check_filename(rng); |
| 101 | + this->check_filename(config); |
| 102 | + |
| 103 | + |
| 104 | + uint32_t nersc_csum,scidac_csuma,scidac_csumb; |
| 105 | + BinaryIO::readRNG(sRNG, pRNG, rng, 0,nersc_csum,scidac_csuma,scidac_csumb); |
| 106 | + |
| 107 | + Metadata md_content; |
| 108 | + ScidacReader _ScidacReader; |
| 109 | + _ScidacReader.open(config); |
| 110 | + _ScidacReader.readScidacFieldRecord(U,md_content); // format from the header |
| 111 | + _ScidacReader.close(); |
| 112 | + |
| 113 | + std::cout << GridLogMessage << "Read Scidac Configuration from " << config |
| 114 | + << " checksum " << std::hex |
| 115 | + << nersc_csum<<"/" |
| 116 | + << scidac_csuma<<"/" |
| 117 | + << scidac_csumb |
| 118 | + << std::dec << std::endl; |
| 119 | + }; |
| 120 | +}; |
| 121 | +} |
| 122 | +} |
| 123 | + |
| 124 | +#endif // HAVE_LIME |
| 125 | +#endif // ILDG_CHECKPOINTER |
0 commit comments