1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-06-14 05:07:05 +01:00

ILDG reader/writer works

Fill the xml header with the required information, todo.
This commit is contained in:
Guido Cossu
2016-10-24 21:57:54 +01:00
parent f415db583a
commit 47c7159177
7 changed files with 248 additions and 62 deletions

View File

@ -449,10 +449,13 @@ class BinaryIO {
return csum;
}
template<class vobj,class fobj,class munger>
static inline uint32_t readObjectParallel(Lattice<vobj> &Umu,std::string file,munger munge,int offset,const std::string &format)
{
template <class vobj, class fobj, class munger>
static inline uint32_t readObjectParallel(Lattice<vobj> &Umu,
std::string file,
munger munge,
int offset,
const std::string &format,
ILDGtype ILDG = ILDGtype()) {
typedef typename vobj::scalar_object sobj;
GridBase *grid = Umu._grid;
@ -518,9 +521,10 @@ class BinaryIO {
int myrank = grid->ThisRank();
int iorank = grid->RankFromProcessorCoor(ioproc);
if ( IOnode ) {
fin.open(file,std::ios::binary|std::ios::in);
}
if (!ILDG.is_ILDG)
if ( IOnode ) {
fin.open(file,std::ios::binary|std::ios::in);
}
//////////////////////////////////////////////////////////
// Find the location of each site and send to primary node
@ -562,8 +566,15 @@ class BinaryIO {
////////////////////////////////
if (myrank == iorank) {
fin.seekg(offset+g_idx*sizeof(fileObj));
fin.read((char *)&fileObj,sizeof(fileObj));
if (ILDG.is_ILDG){
// use C-LIME to populate the record
size_t sizeFO = sizeof(fileObj);
limeReaderSeek(ILDG.LR, g_idx*sizeFO, SEEK_SET);
int status = limeReaderReadData((void *)&fileObj, &sizeFO, ILDG.LR);
} else{
fin.seekg(offset+g_idx*sizeof(fileObj));
fin.read((char *)&fileObj,sizeof(fileObj));
}
bytes+=sizeof(fileObj);
if(ieee32big) be32toh_v((void *)&fileObj,sizeof(fileObj));
@ -681,7 +692,7 @@ class BinaryIO {
// Ideally one reader/writer per xy plane and read these contiguously
// with comms from nominated I/O nodes.
std::ofstream fout;
if (!ILDG.is_ILDG){
if (!ILDG.is_ILDG)
if (IOnode){
fout.open(file, std::ios::binary | std::ios::in | std::ios::out);
if (!fout.is_open()) {
@ -690,7 +701,7 @@ class BinaryIO {
exit(0);
}
}
}
//////////////////////////////////////////////////////////
// Find the location of each site and send to primary node
@ -753,12 +764,13 @@ class BinaryIO {
if (ieee64big) htobe64_v((void *)&fileObj, sizeof(fileObj));
if (ieee64) htole64_v((void *)&fileObj, sizeof(fileObj));
if (ILDG.is_ILDG){
size_t sizeFO = sizeof(fileObj);
int status = limeWriteRecordData((char*)&fileObj, &sizeFO, ILDG.LW);
} else{
fout.seekp(offset + g_idx * sizeof(fileObj));
fout.write((char *)&fileObj, sizeof(fileObj));
if (ILDG.is_ILDG) {
size_t sizeFO = sizeof(fileObj);
limeWriterSeek(ILDG.LW, g_idx*sizeFO, SEEK_SET);
int status = limeWriteRecordData((void *)&fileObj, &sizeFO, ILDG.LW);
} else {
fout.seekp(offset + g_idx * sizeof(fileObj));
fout.write((char *)&fileObj, sizeof(fileObj));
}
bytes += sizeof(fileObj);
}

View File

@ -87,7 +87,7 @@ struct ILDGMunger {
};
template <class fobj, class sobj>
struct ILDGSimpleUnmunger {
struct ILDGUnmunger {
void operator()(sobj &in, fobj &out, uint32_t &csum) {
for (int mu = 0; mu < 4; mu++) {
for (int i = 0; i < 3; i++) {
@ -103,20 +103,45 @@ struct ILDGSimpleUnmunger {
////////////////////////////////////////////////////////////////////////////////
// Write and read from fstream; compute header offset for payload
////////////////////////////////////////////////////////////////////////////////
enum ILDGstate {ILDGread, ILDGwrite};
class ILDGIO : public BinaryIO {
FILE *outFile;
FILE *File;
LimeWriter *LimeW;
LimeRecordHeader *LimeHeader;
LimeReader *LimeR;
std::string filename;
public:
ILDGIO(std::string file) {
outFile = fopen(file.c_str(), "w");
// check if opened correctly
ILDGIO(std::string file, ILDGstate RW) {
filename = file;
if (RW == ILDGwrite){
File = fopen(file.c_str(), "w");
// check if opened correctly
LimeW = limeCreateWriter(outFile);
LimeW = limeCreateWriter(File);
} else {
File = fopen(file.c_str(), "r");
// check if opened correctly
LimeR = limeCreateReader(File);
}
}
~ILDGIO() { fclose(outFile); }
~ILDGIO() { fclose(File); }
int createHeader(std::string message, int MB, int ME, size_t PayloadSize, LimeWriter* L){
LimeRecordHeader *h;
h = limeCreateHeader(MB, ME, const_cast<char *>(message.c_str()), PayloadSize);
int status = limeWriteRecordHeader(h, L);
if (status < 0) {
std::cerr << "ILDG Header error\n";
return status;
}
limeDestroyHeader(h);
return LIME_SUCCESS;
}
unsigned int writeHeader(ILDGField &header) {
// write header in LIME
@ -131,60 +156,86 @@ class ILDGIO : public BinaryIO {
// save the xml header here
// use the xml_writer to c++ streams in pugixml
// and convert to char message
// limeWriteRecordData(message, &nbytes, LimeW);
limeWriteRecordData(message, &nbytes, LimeW);
limeWriterCloseRecord(LimeW);
return 0;
}
unsigned int readHeader(std::string file, GridBase *grid, ILDGField &field) {
unsigned int readHeader(ILDGField &header) {
return 0;
}
template <class vsimd>
int readConfiguration(Lattice<iLorentzColourMatrix<vsimd> > &Umu,
ILDGField &header, std::string file) {
uint32_t readConfiguration(Lattice<iLorentzColourMatrix<vsimd> > &Umu) {
typedef Lattice<iLorentzColourMatrix<vsimd> > GaugeField;
typedef LorentzColourMatrixD sobjd;
typedef LorentzColourMatrixF sobjf;
typedef iLorentzColourMatrix<vsimd> itype;
typedef LorentzColourMatrix sobj;
GridBase *grid = Umu._grid;
return 0;
ILDGField header;
readHeader(header);
// now just the conf, ignore the header
std::string format = std::string("IEEE64BIG");
do {limeReaderNextRecord(LimeR);}
while (strncmp(limeReaderType(LimeR), "ildg-binary-data",16));
n_uint64_t nbytes = limeReaderBytes(LimeR);//size of this record (configuration)
ILDGtype ILDGt(true, LimeR);
// this is special for double prec data, just for the moment
uint32_t csum = BinaryIO::readObjectParallel< itype, sobjd >(
Umu, filename, ILDGMunger<sobjd, sobj>(), 0, format, ILDGt);
// Check configuration
// todo
return csum;
}
template <class vsimd>
int writeConfiguration(Lattice<iLorentzColourMatrix<vsimd> > &Umu,
ILDGField &header, std::string file) {
uint32_t writeConfiguration(Lattice<iLorentzColourMatrix<vsimd> > &Umu, std::string format) {
typedef Lattice<iLorentzColourMatrix<vsimd> > GaugeField;
typedef iLorentzColourMatrix<vsimd> vobj;
typedef typename vobj::scalar_object sobj;
typedef LorentzColourMatrixD fobj;
ILDGSimpleUnmunger<fobj, sobj> munge;
ILDGField header;
// fill the header
header.floating_point = format;
ILDGUnmunger<fobj, sobj> munge;
unsigned int offset = writeHeader(header);
BinaryIO::Uint32Checksum<vobj, fobj>(Umu, munge, header.checksum);
// Write record header
LimeRecordHeader *h;
std::cout << GridLogDebug << "ILDG Creating Header" << std::endl;
char message[] = "ildg-binary-data";
h = limeCreateHeader(1, 1, message, strlen(message));
std::cout << GridLogDebug << "ILDG Writing Header" << std::endl;
int status = limeWriteRecordHeader(h, LimeW);
if (status < 0) {
std::cerr << "ILDG Header error\n";
return 1;
}
limeDestroyHeader(h);
// Write data record header
n_uint64_t PayloadSize = sizeof(fobj) * Umu._grid->_gsites;
createHeader("ildg-binary-data", 0, 1, PayloadSize, LimeW);
ILDGtype ILDGt(true, LimeW);
uint32_t csum = BinaryIO::writeObjectParallel<vobj, fobj>(
Umu, file, munge, offset, header.floating_point, ILDGt);
Umu, filename, munge, 0, header.floating_point, ILDGt);
limeWriterCloseRecord(LimeW);
return 0;
// Last record
// the logical file name LNF
// look into documentation on how to generate this string
std::string LNF = "empty";
PayloadSize = sizeof(LNF);
createHeader("ildg-binary-lfn", 1 , 1, PayloadSize, LimeW);
limeWriteRecordData(const_cast<char*>(LNF.c_str()), &PayloadSize, LimeW);
limeWriterCloseRecord(LimeW);
return csum;
}
// format for RNG?

View File

@ -33,14 +33,16 @@ extern "C" { // for linkage
namespace Grid {
struct ILDGtype{
bool is_ILDG;
LimeWriter* LW;
ILDGtype(bool is, LimeWriter* L):is_ILDG(is),LW(L){}
ILDGtype():is_ILDG(false),LW(NULL){}
};
struct ILDGtype{
bool is_ILDG;
LimeWriter* LW;
LimeReader* LR;
ILDGtype(bool is, LimeWriter* L):is_ILDG(is),LW(L),LR(NULL){}
ILDGtype(bool is, LimeReader* L):is_ILDG(is),LW(NULL),LR(L){}
ILDGtype():is_ILDG(false),LW(NULL),LR(NULL){}
};

View File

@ -424,8 +424,8 @@ static inline void writeConfiguration(Lattice<iLorentzColourMatrix<vsimd> > &Umu
//int csum1=BinaryIO::writeObjectSerial<vobj,fobj2D>(Umu,file1,munge,offset,header.floating_point);
std::cout << GridLogMessage << " TESTING PARALLEL WRITE offsets " << offset1 << " "<< offset << std::endl;
std::cout << GridLogMessage << " TESTING PARALLEL WRITE csums " << csum1 << " "<<std::hex<< csum << std::dec<< std::endl;
//std::cout << GridLogMessage << " TESTING PARALLEL WRITE offsets " << offset1 << " "<< offset << std::endl;
//std::cout << GridLogMessage << " TESTING PARALLEL WRITE csums " << csum1 << " "<<std::hex<< csum << std::dec<< std::endl;
assert(offset1==offset);
assert(csum1==csum);
@ -436,11 +436,10 @@ static inline void writeConfiguration(Lattice<iLorentzColourMatrix<vsimd> > &Umu
NerscSimpleUnmunger<fobj3D,sobj> munge;
BinaryIO::Uint32Checksum<vobj,fobj3D>(Umu, munge,header.checksum);
offset = writeHeader(header,file);
// csum=BinaryIO::writeObjectSerial<vobj,fobj3D>(Umu,file,munge,offset,header.floating_point);
csum=BinaryIO::writeObjectParallel<vobj,fobj3D>(Umu,file,munge,offset,header.floating_point);
}
std::cout<<GridLogMessage <<"Written NERSC Configuration "<<file<< " checksum "<<std::hex<<csum<< std::dec<<" plaq "<< header.plaquette <<std::endl;
std::cout<<GridLogMessage <<"Written NERSC Configuration on "<< file << " checksum "<<std::hex<<csum<< std::dec<<" plaq "<< header.plaquette <<std::endl;
}