2018-10-15 17:25:08 +01:00
|
|
|
#ifndef Benchmark_IO_hpp_
|
|
|
|
#define Benchmark_IO_hpp_
|
|
|
|
|
|
|
|
#include <Grid/Grid.h>
|
|
|
|
|
|
|
|
#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)>;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
binWriter.open(filestem + ".bin");
|
|
|
|
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
|
|
|
|
|
|
|
binReader.open(filestem + ".bin");
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // Benchmark_IO_hpp_
|