2018-10-15 17:25:08 +01:00
|
|
|
#ifndef Benchmark_IO_hpp_
|
|
|
|
#define Benchmark_IO_hpp_
|
|
|
|
|
|
|
|
#include <Grid/Grid.h>
|
2020-05-04 18:26:20 +01:00
|
|
|
#ifdef HAVE_LIME
|
2018-10-15 17:25:08 +01:00
|
|
|
#define MSG std::cout << GridLogMessage
|
|
|
|
#define SEP \
|
|
|
|
"============================================================================="
|
|
|
|
|
|
|
|
namespace Grid {
|
|
|
|
|
|
|
|
template <typename Field>
|
|
|
|
using WriterFn = std::function<void(const std::string, Field &)> ;
|
|
|
|
template <typename Field>
|
|
|
|
using ReaderFn = std::function<void(Field &, const std::string)>;
|
|
|
|
|
2020-10-06 17:57:00 +01:00
|
|
|
// AP 06/10/2020: Standard C version in case one is suspicious of the C++ API
|
|
|
|
//
|
|
|
|
// template <typename Field>
|
|
|
|
// void stdWrite(const std::string filestem, Field &vec)
|
|
|
|
// {
|
|
|
|
// std::string rankStr = std::to_string(vec.Grid()->ThisRank());
|
|
|
|
// std::FILE *file = std::fopen((filestem + "." + rankStr + ".bin").c_str(), "wb");
|
|
|
|
// size_t size;
|
|
|
|
// uint32_t crc;
|
|
|
|
// GridStopWatch ioWatch, crcWatch;
|
|
|
|
|
|
|
|
// size = vec.Grid()->lSites()*sizeof(typename Field::scalar_object);
|
|
|
|
// autoView(vec_v, vec, CpuRead);
|
|
|
|
// crcWatch.Start();
|
|
|
|
// crc = GridChecksum::crc32(vec_v.cpu_ptr, size);
|
|
|
|
// std::fwrite(&crc, sizeof(uint32_t), 1, file);
|
|
|
|
// crcWatch.Stop();
|
|
|
|
// MSG << "Std I/O write: Data CRC32 " << std::hex << crc << std::dec << std::endl;
|
|
|
|
// ioWatch.Start();
|
|
|
|
// std::fwrite(vec_v.cpu_ptr, sizeof(typename Field::scalar_object), vec.Grid()->lSites(), file);
|
|
|
|
// ioWatch.Stop();
|
|
|
|
// std::fclose(file);
|
|
|
|
// size *= vec.Grid()->ProcessorCount();
|
|
|
|
// MSG << "Std I/O write: Wrote " << size << " bytes in " << ioWatch.Elapsed()
|
|
|
|
// << ", performance " << size/1024./1024./(ioWatch.useconds()/1.e6)
|
|
|
|
// << " MB/s" << std::endl;
|
|
|
|
// MSG << "Std I/O write: checksum overhead " << crcWatch.Elapsed() << std::endl;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// template <typename Field>
|
|
|
|
// void stdRead(Field &vec, const std::string filestem)
|
|
|
|
// {
|
|
|
|
// std::string rankStr = std::to_string(vec.Grid()->ThisRank());
|
|
|
|
// std::FILE *file = std::fopen((filestem + "." + rankStr + ".bin").c_str(), "rb");
|
|
|
|
// size_t size;
|
|
|
|
// uint32_t crcRead, crcData;
|
|
|
|
// GridStopWatch ioWatch, crcWatch;
|
|
|
|
|
|
|
|
// size = vec.Grid()->lSites()*sizeof(typename Field::scalar_object);
|
|
|
|
// crcWatch.Start();
|
|
|
|
// std::fread(&crcRead, sizeof(uint32_t), 1, file);
|
|
|
|
// crcWatch.Stop();
|
|
|
|
// {
|
|
|
|
// autoView(vec_v, vec, CpuWrite);
|
|
|
|
// ioWatch.Start();
|
|
|
|
// std::fread(vec_v.cpu_ptr, sizeof(typename Field::scalar_object), vec.Grid()->lSites(), file);
|
|
|
|
// ioWatch.Stop();
|
|
|
|
// std::fclose(file);
|
|
|
|
// }
|
|
|
|
// {
|
|
|
|
// autoView(vec_v, vec, CpuRead);
|
|
|
|
// crcWatch.Start();
|
|
|
|
// crcData = GridChecksum::crc32(vec_v.cpu_ptr, size);
|
|
|
|
// crcWatch.Stop();
|
|
|
|
// }
|
|
|
|
// MSG << "Std I/O read: Data CRC32 " << std::hex << crcData << std::dec << std::endl;
|
|
|
|
// assert(crcData == crcRead);
|
|
|
|
// size *= vec.Grid()->ProcessorCount();
|
|
|
|
// MSG << "Std I/O read: Read " << size << " bytes in " << ioWatch.Elapsed()
|
|
|
|
// << ", performance " << size/1024./1024./(ioWatch.useconds()/1.e6)
|
|
|
|
// << " MB/s" << std::endl;
|
|
|
|
// MSG << "Std I/O read: checksum overhead " << crcWatch.Elapsed() << std::endl;
|
|
|
|
// }
|
|
|
|
|
|
|
|
template <typename Field>
|
|
|
|
void stdWrite(const std::string filestem, Field &vec)
|
|
|
|
{
|
|
|
|
std::string rankStr = std::to_string(vec.Grid()->ThisRank());
|
|
|
|
std::ofstream file(filestem + "." + rankStr + ".bin", std::ios::out | std::ios::binary);
|
|
|
|
size_t size, sizec;
|
|
|
|
uint32_t crc;
|
|
|
|
GridStopWatch ioWatch, crcWatch;
|
|
|
|
|
|
|
|
size = vec.Grid()->lSites()*sizeof(typename Field::scalar_object);
|
|
|
|
sizec = size/sizeof(char); // just in case of...
|
|
|
|
autoView(vec_v, vec, CpuRead);
|
|
|
|
crcWatch.Start();
|
|
|
|
crc = GridChecksum::crc32(vec_v.cpu_ptr, size);
|
|
|
|
file.write(reinterpret_cast<char *>(&crc), sizeof(uint32_t)/sizeof(char));
|
|
|
|
crcWatch.Stop();
|
|
|
|
MSG << "Std I/O write: Data CRC32 " << std::hex << crc << std::dec << std::endl;
|
|
|
|
ioWatch.Start();
|
|
|
|
file.write(reinterpret_cast<char *>(vec_v.cpu_ptr), sizec);
|
|
|
|
file.flush();
|
|
|
|
ioWatch.Stop();
|
|
|
|
size *= vec.Grid()->ProcessorCount();
|
|
|
|
MSG << "Std I/O write: Wrote " << size << " bytes in " << ioWatch.Elapsed()
|
|
|
|
<< ", performance " << size/1024./1024./(ioWatch.useconds()/1.e6)
|
|
|
|
<< " MB/s" << std::endl;
|
|
|
|
MSG << "Std I/O write: checksum overhead " << crcWatch.Elapsed() << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Field>
|
|
|
|
void stdRead(Field &vec, const std::string filestem)
|
|
|
|
{
|
|
|
|
std::string rankStr = std::to_string(vec.Grid()->ThisRank());
|
|
|
|
std::ifstream file(filestem + "." + rankStr + ".bin", std::ios::in | std::ios::binary);
|
|
|
|
size_t size, sizec;
|
|
|
|
uint32_t crcRead, crcData;
|
|
|
|
GridStopWatch ioWatch, crcWatch;
|
|
|
|
|
|
|
|
size = vec.Grid()->lSites()*sizeof(typename Field::scalar_object);
|
|
|
|
sizec = size/sizeof(char); // just in case of...
|
|
|
|
crcWatch.Start();
|
|
|
|
file.read(reinterpret_cast<char *>(&crcRead), sizeof(uint32_t)/sizeof(char));
|
|
|
|
crcWatch.Stop();
|
|
|
|
{
|
|
|
|
autoView(vec_v, vec, CpuWrite);
|
|
|
|
ioWatch.Start();
|
|
|
|
file.read(reinterpret_cast<char *>(vec_v.cpu_ptr), sizec);
|
|
|
|
ioWatch.Stop();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
autoView(vec_v, vec, CpuRead);
|
|
|
|
crcWatch.Start();
|
|
|
|
crcData = GridChecksum::crc32(vec_v.cpu_ptr, size);
|
|
|
|
crcWatch.Stop();
|
|
|
|
}
|
|
|
|
MSG << "Std I/O read: Data CRC32 " << std::hex << crcData << std::dec << std::endl;
|
|
|
|
assert(crcData == crcRead);
|
|
|
|
size *= vec.Grid()->ProcessorCount();
|
|
|
|
MSG << "Std I/O read: Read " << size << " bytes in " << ioWatch.Elapsed()
|
|
|
|
<< ", performance " << size/1024./1024./(ioWatch.useconds()/1.e6)
|
|
|
|
<< " MB/s" << std::endl;
|
|
|
|
MSG << "Std I/O read: checksum overhead " << crcWatch.Elapsed() << std::endl;
|
|
|
|
}
|
|
|
|
|
2018-10-15 17:25:08 +01:00
|
|
|
template <typename Field>
|
|
|
|
void limeWrite(const std::string filestem, Field &vec)
|
|
|
|
{
|
|
|
|
emptyUserRecord record;
|
2018-12-13 05:11:34 +00:00
|
|
|
ScidacWriter binWriter(vec.Grid()->IsBoss());
|
2018-10-15 17:25:08 +01:00
|
|
|
|
2020-10-06 17:57:00 +01:00
|
|
|
binWriter.open(filestem + ".lime.bin");
|
2018-10-15 17:25:08 +01:00
|
|
|
binWriter.writeScidacFieldRecord(vec, record);
|
|
|
|
binWriter.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Field>
|
|
|
|
void limeRead(Field &vec, const std::string filestem)
|
|
|
|
{
|
|
|
|
emptyUserRecord record;
|
2018-12-13 05:11:34 +00:00
|
|
|
ScidacReader binReader;
|
2018-10-15 17:25:08 +01:00
|
|
|
|
2020-10-06 17:57:00 +01:00
|
|
|
binReader.open(filestem + ".lime.bin");
|
2018-10-15 17:25:08 +01:00
|
|
|
binReader.readScidacFieldRecord(vec, record);
|
|
|
|
binReader.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void makeGrid(std::shared_ptr<GridBase> &gPt,
|
|
|
|
const std::shared_ptr<GridCartesian> &gBasePt,
|
|
|
|
const unsigned int Ls = 1, const bool rb = false)
|
|
|
|
{
|
|
|
|
if (rb)
|
|
|
|
{
|
|
|
|
if (Ls > 1)
|
|
|
|
{
|
2018-12-13 05:11:34 +00:00
|
|
|
gPt.reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, gBasePt.get()));
|
2018-10-15 17:25:08 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-13 05:11:34 +00:00
|
|
|
gPt.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(gBasePt.get()));
|
2018-10-15 17:25:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (Ls > 1)
|
|
|
|
{
|
2018-12-13 05:11:34 +00:00
|
|
|
gPt.reset(SpaceTimeGrid::makeFiveDimGrid(Ls, gBasePt.get()));
|
2018-10-15 17:25:08 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gPt = gBasePt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Field>
|
2018-12-13 05:11:34 +00:00
|
|
|
void writeBenchmark(const Coordinate &latt, const std::string filename,
|
2018-10-15 17:25:08 +01:00
|
|
|
const WriterFn<Field> &write,
|
|
|
|
const unsigned int Ls = 1, const bool rb = false)
|
|
|
|
{
|
|
|
|
auto mpi = GridDefaultMpi();
|
|
|
|
auto simd = GridDefaultSimd(latt.size(), Field::vector_type::Nsimd());
|
2018-12-13 05:11:34 +00:00
|
|
|
std::shared_ptr<GridCartesian> gBasePt(SpaceTimeGrid::makeFourDimGrid(latt, simd, mpi));
|
2018-10-15 17:25:08 +01:00
|
|
|
std::shared_ptr<GridBase> gPt;
|
|
|
|
|
|
|
|
makeGrid(gPt, gBasePt, Ls, rb);
|
|
|
|
|
|
|
|
GridBase *g = gPt.get();
|
|
|
|
GridParallelRNG rng(g);
|
|
|
|
Field vec(g);
|
|
|
|
|
|
|
|
random(rng, vec);
|
|
|
|
write(filename, vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Field>
|
2018-12-13 05:11:34 +00:00
|
|
|
void readBenchmark(const Coordinate &latt, const std::string filename,
|
2018-10-15 17:25:08 +01:00
|
|
|
const ReaderFn<Field> &read,
|
|
|
|
const unsigned int Ls = 1, const bool rb = false)
|
|
|
|
{
|
|
|
|
auto mpi = GridDefaultMpi();
|
|
|
|
auto simd = GridDefaultSimd(latt.size(), Field::vector_type::Nsimd());
|
2018-12-13 05:11:34 +00:00
|
|
|
std::shared_ptr<GridCartesian> gBasePt(SpaceTimeGrid::makeFourDimGrid(latt, simd, mpi));
|
2018-10-15 17:25:08 +01:00
|
|
|
std::shared_ptr<GridBase> gPt;
|
|
|
|
|
|
|
|
makeGrid(gPt, gBasePt, Ls, rb);
|
|
|
|
|
|
|
|
GridBase *g = gPt.get();
|
|
|
|
Field vec(g);
|
|
|
|
|
|
|
|
read(vec, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-04 18:26:20 +01:00
|
|
|
#endif //LIME
|
2018-10-15 17:25:08 +01:00
|
|
|
#endif // Benchmark_IO_hpp_
|