diff --git a/Grid/serialisation/BaseIO.h b/Grid/serialisation/BaseIO.h index 49406201..8890908e 100644 --- a/Grid/serialisation/BaseIO.h +++ b/Grid/serialisation/BaseIO.h @@ -30,6 +30,7 @@ Author: Guido Cossu #ifndef GRID_SERIALISATION_ABSTRACT_READER_H #define GRID_SERIALISATION_ABSTRACT_READER_H +#include #include #include #include @@ -110,6 +111,10 @@ namespace Grid { template inline typename std::enable_if::value, typename Traits::scalar_type *>::type getFirstScalar(ET &eigenTensor) { return eigenTensor.data()->begin(); } + + // Counter for resized EigenTensors (poor man's substitute for allocator) + // Defined in BinaryIO.cc + extern std::atomic_uint64_t EigenResizeCounter; } // Abstract writer/reader classes //////////////////////////////////////////// @@ -497,8 +502,11 @@ namespace Grid { typename std::enable_if::value, void>::type Reader::Reshape(ETensor &t, const std::array &dims ) { + typename ETensor::Index before = t.size(); //t.reshape( dims ); t.resize( dims ); + uint64_t diff = static_cast(( t.size() - before ) * sizeof(typename ETensor::Scalar)); + EigenIO::EigenResizeCounter.fetch_add(diff, std::memory_order_relaxed); } template diff --git a/Grid/serialisation/BinaryIO.cc b/Grid/serialisation/BinaryIO.cc index 8ddf3c6c..e01d872c 100644 --- a/Grid/serialisation/BinaryIO.cc +++ b/Grid/serialisation/BinaryIO.cc @@ -30,6 +30,9 @@ Author: paboyle NAMESPACE_BEGIN(Grid); +// Declared in BaseIO.h +std::atomic_uint64_t EigenIO::EigenResizeCounter(0); + // Writer implementation /////////////////////////////////////////////////////// BinaryWriter::BinaryWriter(const std::string &fileName) : file_(fileName, std::ios::binary|std::ios::out)