From 086db7bd19c6f26ae75d5fc617a5906808260b9e Mon Sep 17 00:00:00 2001 From: paboyle Date: Sat, 13 Jan 2018 00:05:33 +0000 Subject: [PATCH] NAMESPACE and reformat --- lib/parallelIO/NerscIO.h | 491 +++++++++++++++++++-------------------- 1 file changed, 245 insertions(+), 246 deletions(-) diff --git a/lib/parallelIO/NerscIO.h b/lib/parallelIO/NerscIO.h index 786839f2..424cd232 100644 --- a/lib/parallelIO/NerscIO.h +++ b/lib/parallelIO/NerscIO.h @@ -30,324 +30,323 @@ #ifndef GRID_NERSC_IO_H #define GRID_NERSC_IO_H -namespace Grid { - namespace QCD { +NAMESPACE_BEGIN(Grid); - using namespace Grid; +using namespace Grid; - //////////////////////////////////////////////////////////////////////////////// - // Write and read from fstream; comput header offset for payload - //////////////////////////////////////////////////////////////////////////////// - class NerscIO : public BinaryIO { - public: +//////////////////////////////////////////////////////////////////////////////// +// Write and read from fstream; comput header offset for payload +//////////////////////////////////////////////////////////////////////////////// +class NerscIO : public BinaryIO { +public: - static inline void truncate(std::string file){ - std::ofstream fout(file,std::ios::out); - } + static inline void truncate(std::string file){ + std::ofstream fout(file,std::ios::out); + } - static inline unsigned int writeHeader(FieldMetaData &field,std::string file) - { - std::ofstream fout(file,std::ios::out|std::ios::in); - fout.seekp(0,std::ios::beg); - dump_meta_data(field, fout); - field.data_start = fout.tellp(); - return field.data_start; - } + static inline unsigned int writeHeader(FieldMetaData &field,std::string file) + { + std::ofstream fout(file,std::ios::out|std::ios::in); + fout.seekp(0,std::ios::beg); + dump_meta_data(field, fout); + field.data_start = fout.tellp(); + return field.data_start; + } - // for the header-reader - static inline int readHeader(std::string file,GridBase *grid, FieldMetaData &field) - { - int offset=0; - std::map header; - std::string line; + // for the header-reader + static inline int readHeader(std::string file,GridBase *grid, FieldMetaData &field) + { + int offset=0; + std::map header; + std::string line; - ////////////////////////////////////////////////// - // read the header - ////////////////////////////////////////////////// - std::ifstream fin(file); + ////////////////////////////////////////////////// + // read the header + ////////////////////////////////////////////////// + std::ifstream fin(file); - getline(fin,line); // read one line and insist is + getline(fin,line); // read one line and insist is - removeWhitespace(line); - std::cout << GridLogMessage << "* " << line << std::endl; + removeWhitespace(line); + std::cout << GridLogMessage << "* " << line << std::endl; - assert(line==std::string("BEGIN_HEADER")); + assert(line==std::string("BEGIN_HEADER")); - do { + do { getline(fin,line); // read one line std::cout << GridLogMessage << "* "<0) { - std::string key=line.substr(0,eq); - std::string val=line.substr(eq+1); - removeWhitespace(key); - removeWhitespace(val); + std::string key=line.substr(0,eq); + std::string val=line.substr(eq+1); + removeWhitespace(key); + removeWhitespace(val); - header[key] = val; - } + header[key] = val; + } } while( line.find("END_HEADER") == std::string::npos ); - field.data_start = fin.tellg(); + field.data_start = fin.tellg(); - ////////////////////////////////////////////////// - // chomp the values - ////////////////////////////////////////////////// - field.hdr_version = header["HDR_VERSION"]; - field.data_type = header["DATATYPE"]; - field.storage_format = header["STORAGE_FORMAT"]; + ////////////////////////////////////////////////// + // chomp the values + ////////////////////////////////////////////////// + field.hdr_version = header["HDR_VERSION"]; + field.data_type = header["DATATYPE"]; + field.storage_format = header["STORAGE_FORMAT"]; - field.dimension[0] = std::stol(header["DIMENSION_1"]); - field.dimension[1] = std::stol(header["DIMENSION_2"]); - field.dimension[2] = std::stol(header["DIMENSION_3"]); - field.dimension[3] = std::stol(header["DIMENSION_4"]); + field.dimension[0] = std::stol(header["DIMENSION_1"]); + field.dimension[1] = std::stol(header["DIMENSION_2"]); + field.dimension[2] = std::stol(header["DIMENSION_3"]); + field.dimension[3] = std::stol(header["DIMENSION_4"]); - assert(grid->_ndimension == 4); - for(int d=0;d<4;d++){ + assert(grid->_ndimension == 4); + for(int d=0;d<4;d++){ assert(grid->_fdimensions[d]==field.dimension[d]); } - field.link_trace = std::stod(header["LINK_TRACE"]); - field.plaquette = std::stod(header["PLAQUETTE"]); + field.link_trace = std::stod(header["LINK_TRACE"]); + field.plaquette = std::stod(header["PLAQUETTE"]); - field.boundary[0] = header["BOUNDARY_1"]; - field.boundary[1] = header["BOUNDARY_2"]; - field.boundary[2] = header["BOUNDARY_3"]; - field.boundary[3] = header["BOUNDARY_4"]; + field.boundary[0] = header["BOUNDARY_1"]; + field.boundary[1] = header["BOUNDARY_2"]; + field.boundary[2] = header["BOUNDARY_3"]; + field.boundary[3] = header["BOUNDARY_4"]; - field.checksum = std::stoul(header["CHECKSUM"],0,16); - field.ensemble_id = header["ENSEMBLE_ID"]; - field.ensemble_label = header["ENSEMBLE_LABEL"]; - field.sequence_number = std::stol(header["SEQUENCE_NUMBER"]); - field.creator = header["CREATOR"]; - field.creator_hardware = header["CREATOR_HARDWARE"]; - field.creation_date = header["CREATION_DATE"]; - field.archive_date = header["ARCHIVE_DATE"]; - field.floating_point = header["FLOATING_POINT"]; + field.checksum = std::stoul(header["CHECKSUM"],0,16); + field.ensemble_id = header["ENSEMBLE_ID"]; + field.ensemble_label = header["ENSEMBLE_LABEL"]; + field.sequence_number = std::stol(header["SEQUENCE_NUMBER"]); + field.creator = header["CREATOR"]; + field.creator_hardware = header["CREATOR_HARDWARE"]; + field.creation_date = header["CREATION_DATE"]; + field.archive_date = header["ARCHIVE_DATE"]; + field.floating_point = header["FLOATING_POINT"]; - return field.data_start; + return field.data_start; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Now the meat: the object readers + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + template + static inline void readConfiguration(Lattice > &Umu, + FieldMetaData& header, + std::string file) + { + typedef Lattice > GaugeField; + + GridBase *grid = Umu._grid; + int offset = readHeader(file,Umu._grid,header); + + FieldMetaData clone(header); + + std::string format(header.floating_point); + + int ieee32big = (format == std::string("IEEE32BIG")); + int ieee32 = (format == std::string("IEEE32")); + int ieee64big = (format == std::string("IEEE64BIG")); + int ieee64 = (format == std::string("IEEE64")); + + uint32_t nersc_csum,scidac_csuma,scidac_csumb; + // depending on datatype, set up munger; + // munger is a function of + if ( header.data_type == std::string("4D_SU3_GAUGE") ) { + if ( ieee32 || ieee32big ) { + BinaryIO::readLatticeObject, LorentzColour2x3F> + (Umu,file,Gauge3x2munger(), offset,format, + nersc_csum,scidac_csuma,scidac_csumb); + } + if ( ieee64 || ieee64big ) { + BinaryIO::readLatticeObject, LorentzColour2x3D> + (Umu,file,Gauge3x2munger(),offset,format, + nersc_csum,scidac_csuma,scidac_csumb); + } + } else if ( header.data_type == std::string("4D_SU3_GAUGE_3x3") ) { + if ( ieee32 || ieee32big ) { + BinaryIO::readLatticeObject,LorentzColourMatrixF> + (Umu,file,GaugeSimpleMunger(),offset,format, + nersc_csum,scidac_csuma,scidac_csumb); + } + if ( ieee64 || ieee64big ) { + BinaryIO::readLatticeObject,LorentzColourMatrixD> + (Umu,file,GaugeSimpleMunger(),offset,format, + nersc_csum,scidac_csuma,scidac_csumb); + } + } else { + assert(0); } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Now the meat: the object readers - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + GaugeStatistics(Umu,clone); - template - static inline void readConfiguration(Lattice > &Umu, - FieldMetaData& header, - std::string file) - { - typedef Lattice > GaugeField; + std::cout< - if ( header.data_type == std::string("4D_SU3_GAUGE") ) { - if ( ieee32 || ieee32big ) { - BinaryIO::readLatticeObject, LorentzColour2x3F> - (Umu,file,Gauge3x2munger(), offset,format, - nersc_csum,scidac_csuma,scidac_csumb); - } - if ( ieee64 || ieee64big ) { - BinaryIO::readLatticeObject, LorentzColour2x3D> - (Umu,file,Gauge3x2munger(),offset,format, - nersc_csum,scidac_csuma,scidac_csumb); - } - } else if ( header.data_type == std::string("4D_SU3_GAUGE_3x3") ) { - if ( ieee32 || ieee32big ) { - BinaryIO::readLatticeObject,LorentzColourMatrixF> - (Umu,file,GaugeSimpleMunger(),offset,format, - nersc_csum,scidac_csuma,scidac_csumb); - } - if ( ieee64 || ieee64big ) { - BinaryIO::readLatticeObject,LorentzColourMatrixD> - (Umu,file,GaugeSimpleMunger(),offset,format, - nersc_csum,scidac_csuma,scidac_csumb); - } - } else { - assert(0); - } - - GaugeStatistics(Umu,clone); - - std::cout<= 1.0e-5 ) { - std::cout << " Plaquette mismatch "<= 1.0e-5 ) { + std::cout << " Plaquette mismatch "< - static inline void writeConfiguration(Lattice > &Umu, - std::string file, - int two_row, - int bits32) - { - typedef Lattice > GaugeField; + template + static inline void writeConfiguration(Lattice > &Umu, + std::string file, + int two_row, + int bits32) + { + typedef Lattice > GaugeField; - typedef iLorentzColourMatrix vobj; - typedef typename vobj::scalar_object sobj; + typedef iLorentzColourMatrix vobj; + typedef typename vobj::scalar_object sobj; - FieldMetaData header; - /////////////////////////////////////////// - // Following should become arguments - /////////////////////////////////////////// - header.sequence_number = 1; - header.ensemble_id = "UKQCD"; - header.ensemble_label = "DWF"; + FieldMetaData header; + /////////////////////////////////////////// + // Following should become arguments + /////////////////////////////////////////// + header.sequence_number = 1; + header.ensemble_id = "UKQCD"; + header.ensemble_label = "DWF"; - typedef LorentzColourMatrixD fobj3D; - typedef LorentzColour2x3D fobj2D; + typedef LorentzColourMatrixD fobj3D; + typedef LorentzColour2x3D fobj2D; - GridBase *grid = Umu._grid; + GridBase *grid = Umu._grid; - GridMetaData(grid,header); - assert(header.nd==4); - GaugeStatistics(Umu,header); - MachineCharacteristics(header); + GridMetaData(grid,header); + assert(header.nd==4); + GaugeStatistics(Umu,header); + MachineCharacteristics(header); - int offset; + int offset; - truncate(file); + truncate(file); - // Sod it -- always write 3x3 double - header.floating_point = std::string("IEEE64BIG"); - header.data_type = std::string("4D_SU3_GAUGE_3x3"); - GaugeSimpleUnmunger munge; - offset = writeHeader(header,file); + // Sod it -- always write 3x3 double + header.floating_point = std::string("IEEE64BIG"); + header.data_type = std::string("4D_SU3_GAUGE_3x3"); + GaugeSimpleUnmunger munge; + offset = writeHeader(header,file); - uint32_t nersc_csum,scidac_csuma,scidac_csumb; - BinaryIO::writeLatticeObject(Umu,file,munge,offset,header.floating_point, - nersc_csum,scidac_csuma,scidac_csumb); - header.checksum = nersc_csum; - writeHeader(header,file); + uint32_t nersc_csum,scidac_csuma,scidac_csumb; + BinaryIO::writeLatticeObject(Umu,file,munge,offset,header.floating_point, + nersc_csum,scidac_csuma,scidac_csumb); + header.checksum = nersc_csum; + writeHeader(header,file); - std::cout< - uint32_t nersc_csum,scidac_csuma,scidac_csumb; - BinaryIO::readRNG(serial,parallel,file,offset,nersc_csum,scidac_csuma,scidac_csumb); + // depending on datatype, set up munger; + // munger is a function of + uint32_t nersc_csum,scidac_csuma,scidac_csumb; + BinaryIO::readRNG(serial,parallel,file,offset,nersc_csum,scidac_csuma,scidac_csumb); - if ( nersc_csum != header.checksum ) { - std::cerr << "checksum mismatch "<