31#ifndef GRID_NERSC_IO_H
32#define GRID_NERSC_IO_H
51 std::ofstream fout(file,std::ios::out);
56 std::ofstream fout(file,std::ios::out|std::ios::in);
57 fout.seekp(0,std::ios::beg);
59 field.data_start = fout.tellp();
60 return field.data_start;
66 std::map<std::string,std::string>
header;
72 std::ifstream fin(file);
79 assert(line==std::string(
"BEGIN_HEADER"));
84 int eq = line.find(
"=");
86 std::string key=line.substr(0,eq);
87 std::string val=line.substr(eq+1);
93 }
while( line.find(
"END_HEADER") == std::string::npos );
95 field.data_start = fin.tellg();
100 field.hdr_version =
header[
"HDR_VERSION"];
101 field.data_type =
header[
"DATATYPE"];
102 field.storage_format =
header[
"STORAGE_FORMAT"];
104 field.dimension[0] = std::stol(
header[
"DIMENSION_1"]);
105 field.dimension[1] = std::stol(
header[
"DIMENSION_2"]);
106 field.dimension[2] = std::stol(
header[
"DIMENSION_3"]);
107 field.dimension[3] = std::stol(
header[
"DIMENSION_4"]);
110 for(
int d=0;d<4;d++){
114 field.link_trace = std::stod(
header[
"LINK_TRACE"]);
115 field.plaquette = std::stod(
header[
"PLAQUETTE"]);
117 field.boundary[0] =
header[
"BOUNDARY_1"];
118 field.boundary[1] =
header[
"BOUNDARY_2"];
119 field.boundary[2] =
header[
"BOUNDARY_3"];
120 field.boundary[3] =
header[
"BOUNDARY_4"];
122 field.checksum = std::stoul(
header[
"CHECKSUM"],0,16);
123 field.ensemble_id =
header[
"ENSEMBLE_ID"];
124 field.ensemble_label =
header[
"ENSEMBLE_LABEL"];
125 field.sequence_number = std::stol(
header[
"SEQUENCE_NUMBER"]);
126 field.creator =
header[
"CREATOR"];
127 field.creator_hardware =
header[
"CREATOR_HARDWARE"];
128 field.creation_date =
header[
"CREATION_DATE"];
129 field.archive_date =
header[
"ARCHIVE_DATE"];
130 field.floating_point =
header[
"FLOATING_POINT"];
132 return field.data_start;
139 template<
class GaugeStats=PeriodicGaugeStatistics>
143 GaugeStats GaugeStatisticsCalculator=GaugeStats())
151 std::string format(
header.floating_point);
153 const int ieee32big = (format == std::string(
"IEEE32BIG"));
154 const int ieee32 = (format == std::string(
"IEEE32"));
155 const int ieee64big = (format == std::string(
"IEEE64BIG"));
156 const int ieee64 = (format == std::string(
"IEEE64") || \
157 format == std::string(
"IEEE64LITTLE"));
159 uint32_t nersc_csum,scidac_csuma,scidac_csumb;
162 const std::string stNC = std::to_string(
Nc ) ;
163 if (
header.data_type == std::string(
"4D_SU"+stNC+
"_GAUGE") ) {
164 if ( ieee32 || ieee32big ) {
167 nersc_csum,scidac_csuma,scidac_csumb);
169 if ( ieee64 || ieee64big ) {
172 nersc_csum,scidac_csuma,scidac_csumb);
174 }
else if (
header.data_type == std::string(
"4D_SU"+stNC+
"_GAUGE_"+stNC+
"x"+stNC) ) {
175 if ( ieee32 || ieee32big ) {
178 nersc_csum,scidac_csuma,scidac_csumb);
180 if ( ieee64 || ieee64big ) {
183 nersc_csum,scidac_csuma,scidac_csumb);
189 GaugeStats Stats; Stats(Umu,clone);
191 std::cout<<
GridLogMessage <<
"NERSC Configuration "<<file<<
" checksum "<<std::hex<<nersc_csum<< std::dec
192 <<
" header "<<std::hex<<
header.checksum<<std::dec <<std::endl;
193 std::cout<<
GridLogMessage <<
"NERSC Configuration "<<file<<
" plaquette "<<clone.plaquette
194 <<
" header "<<
header.plaquette<<std::endl;
195 std::cout<<
GridLogMessage <<
"NERSC Configuration "<<file<<
" link_trace "<<clone.link_trace
196 <<
" header "<<
header.link_trace<<std::endl;
198 if ( fabs(clone.plaquette -
header.plaquette ) >= 1.0e-5 ) {
199 std::cout <<
" Plaquette mismatch "<<std::endl;
201 if ( nersc_csum !=
header.checksum ) {
202 std::cerr <<
" checksum mismatch " << std::endl;
203 std::cerr <<
" plaqs " << clone.plaquette <<
" " <<
header.plaquette << std::endl;
204 std::cerr <<
" trace " << clone.link_trace<<
" " <<
header.link_trace<< std::endl;
205 std::cerr <<
" nersc_csum " <<std::hex<< nersc_csum <<
" " <<
header.checksum<< std::dec<< std::endl;
209 assert(fabs(clone.link_trace-
header.link_trace) < 1.0e-6 );
210 assert(nersc_csum ==
header.checksum );
212 std::cout<<
GridLogMessage <<
"NERSC Configuration "<<file<<
" and plaquette, link trace, and checksum agree"<<std::endl;
216 template<
class GaugeStats=PeriodicGaugeStatistics>
219 std::string ens_label = std::string(
"DWF"),
220 std::string ens_id = std::string(
"UKQCD"),
221 unsigned int sequence_number = 1)
225 template<
class GaugeStats=PeriodicGaugeStatistics>
230 std::string ens_label = std::string(
"DWF"),
231 std::string ens_id = std::string(
"UKQCD"),
232 unsigned int sequence_number = 1)
235 typedef typename vobj::scalar_object sobj;
238 header.sequence_number = sequence_number;
239 header.ensemble_id = ens_id;
240 header.ensemble_label = ens_label;
241 header.hdr_version =
"1.0" ;
250 GaugeStats Stats; Stats(Umu,
header);
256 header.floating_point = std::string(
"IEEE64BIG");
257 const std::string stNC = std::to_string(
Nc ) ;
259 header.data_type = std::string(
"4D_SU" + stNC +
"_GAUGE" );
261 header.data_type = std::string(
"4D_SU" + stNC +
"_GAUGE_" + stNC +
"x" + stNC );
267 grid->
Broadcast(0,(
void *)&offset,
sizeof(offset));
269 uint32_t nersc_csum,scidac_csuma,scidac_csumb;
273 nersc_csum,scidac_csuma,scidac_csumb);
277 nersc_csum,scidac_csuma,scidac_csumb);
279 header.checksum = nersc_csum;
284 std::cout<<
GridLogMessage <<
"Written NERSC Configuration on "<< file <<
" checksum "
285 <<std::hex<<
header.checksum
286 <<std::dec<<
" plaq "<<
header.plaquette <<std::endl;
294 typedef typename GridParallelRNG::RngStateType RngStateType;
298 header.sequence_number = 1;
299 header.ensemble_id =
"UKQCD";
300 header.ensemble_label =
"DWF";
312 header.floating_point = std::string(
"UINT64");
313 header.data_type = std::string(
"RANLUX48");
316 header.floating_point = std::string(
"UINT32");
317 header.data_type = std::string(
"MT19937");
320 header.floating_point = std::string(
"UINT64");
321 header.data_type = std::string(
"SITMO");
328 grid->
Broadcast(0,(
void *)&offset,
sizeof(offset));
330 uint32_t nersc_csum,scidac_csuma,scidac_csumb;
332 header.checksum = nersc_csum;
338 <<
"Written NERSC RNG STATE "<<file<<
" checksum "
339 <<std::hex<<
header.checksum
340 <<std::dec<<std::endl;
346 typedef typename GridParallelRNG::RngStateType RngStateType;
354 std::string format(
header.floating_point);
355 std::string data_type(
header.data_type);
358 assert(format == std::string(
"UINT64"));
359 assert(data_type == std::string(
"RANLUX48"));
362 assert(format == std::string(
"UINT32"));
363 assert(data_type == std::string(
"MT19937"));
366 assert(format == std::string(
"UINT64"));
367 assert(data_type == std::string(
"SITMO"));
372 uint32_t nersc_csum,scidac_csuma,scidac_csumb;
373 BinaryIO::readRNG(serial,parallel,file,offset,nersc_csum,scidac_csuma,scidac_csumb);
375 if ( nersc_csum !=
header.checksum ) {
376 std::cerr <<
"checksum mismatch "<<std::hex<< nersc_csum <<
" "<<
header.checksum<<std::dec<<std::endl;
379 assert(nersc_csum ==
header.checksum );
381 std::cout<<
GridLogMessage <<
"Read NERSC RNG file "<<file<<
" format "<< data_type <<std::endl;
GridLogger GridLogMessage(1, "Message", GridLogColours, "NORMAL")
#define NAMESPACE_BEGIN(A)
iLorentzColourMatrix< vComplexD > vLorentzColourMatrixD
iLorentzColourMatrix< ComplexD > LorentzColourMatrixD
static void readRNG(GridSerialRNG &serial_rng, GridParallelRNG ¶llel_rng, std::string file, uint64_t offset, uint32_t &nersc_csum, uint32_t &scidac_csuma, uint32_t &scidac_csumb)
static void writeRNG(GridSerialRNG &serial_rng, GridParallelRNG ¶llel_rng, std::string file, uint64_t offset, uint32_t &nersc_csum, uint32_t &scidac_csuma, uint32_t &scidac_csumb)
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)
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)
void Broadcast(int root, void *data, int bytes)
unsigned long _ndimension
GridBase * Grid(void) const
GridBase * Grid(void) const
Lattice< vLorentzColourMatrixD > GaugeField
static void readRNGState(GridSerialRNG &serial, GridParallelRNG ¶llel, FieldMetaData &header, std::string file)
static void readConfiguration(GaugeField &Umu, FieldMetaData &header, std::string file, GaugeStats GaugeStatisticsCalculator=GaugeStats())
static void writeConfiguration(Lattice< vLorentzColourMatrixD > &Umu, std::string file, int two_row, int bits32, std::string ens_label=std::string("DWF"), std::string ens_id=std::string("UKQCD"), unsigned int sequence_number=1)
static void writeRNGState(GridSerialRNG &serial, GridParallelRNG ¶llel, std::string file)
static bool & exitOnReadPlaquetteMismatch()
static void writeConfiguration(Lattice< vLorentzColourMatrixD > &Umu, std::string file, std::string ens_label=std::string("DWF"), std::string ens_id=std::string("UKQCD"), unsigned int sequence_number=1)
static int readHeader(std::string file, GridBase *grid, FieldMetaData &field)
static unsigned int writeHeader(FieldMetaData &field, std::string file)
static void truncate(std::string file)
void removeWhitespace(std::string &key)