2018-09-07 20:04:54 +01:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
|
|
|
Source file: Hadrons/DiskVector.hpp
|
|
|
|
|
|
|
|
Copyright (C) 2015-2018
|
|
|
|
|
|
|
|
Author: Antonin Portelli <antonin.portelli@me.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
See the full license in the file "LICENSE" in the top level distribution directory
|
|
|
|
*************************************************************************************/
|
|
|
|
/* END LEGAL */
|
|
|
|
#ifndef Hadrons_DiskVector_hpp_
|
|
|
|
#define Hadrons_DiskVector_hpp_
|
|
|
|
|
|
|
|
#include <Hadrons/Global.hpp>
|
2018-11-07 19:16:55 +00:00
|
|
|
#include <Hadrons/A2AMatrix.hpp>
|
2018-09-07 20:24:48 +01:00
|
|
|
#include <deque>
|
2018-09-07 20:04:54 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <ftw.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-10-08 19:02:00 +01:00
|
|
|
#ifdef DV_DEBUG
|
|
|
|
#define DV_DEBUG_MSG(dv, stream) LOG(Debug) << "diskvector " << (dv) << ": " << stream << std::endl
|
|
|
|
#else
|
|
|
|
#define DV_DEBUG_MSG(dv, stream)
|
|
|
|
#endif
|
|
|
|
|
2018-09-07 20:04:54 +01:00
|
|
|
BEGIN_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Abstract base class *
|
|
|
|
******************************************************************************/
|
|
|
|
template <typename T>
|
|
|
|
class DiskVectorBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef T ObjectType;
|
|
|
|
|
|
|
|
// helper for read/write vector access
|
|
|
|
class RwAccessHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RwAccessHelper(DiskVectorBase<T> &master, const unsigned int i)
|
|
|
|
: master_(master), cmaster_(master), i_(i) {}
|
|
|
|
|
|
|
|
// operator=: somebody is trying to store a vector element
|
2018-10-18 17:48:25 +01:00
|
|
|
// write to cache and tag as modified
|
2018-09-07 20:04:54 +01:00
|
|
|
T &operator=(const T &obj) const
|
|
|
|
{
|
2018-10-18 17:48:25 +01:00
|
|
|
auto &cache = *master_.cachePtr_;
|
|
|
|
auto &modified = *master_.modifiedPtr_;
|
|
|
|
auto &index = *master_.indexPtr_;
|
|
|
|
|
2018-10-08 19:02:00 +01:00
|
|
|
DV_DEBUG_MSG(&master_, "writing to " << i_);
|
2018-09-07 20:04:54 +01:00
|
|
|
master_.cacheInsert(i_, obj);
|
2018-10-18 17:48:25 +01:00
|
|
|
modified[index.at(i_)] = true;
|
2018-09-07 20:04:54 +01:00
|
|
|
|
2018-10-18 17:48:25 +01:00
|
|
|
return cache[index.at(i_)];
|
2018-09-07 20:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// implicit cast to const object reference and redirection
|
|
|
|
// to the const operator[] for read-only operations
|
|
|
|
operator const T&() const
|
|
|
|
{
|
|
|
|
return cmaster_[i_];
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
DiskVectorBase<T> &master_;
|
|
|
|
const DiskVectorBase<T> &cmaster_;
|
|
|
|
const unsigned int i_;
|
|
|
|
};
|
|
|
|
public:
|
|
|
|
DiskVectorBase(const std::string dirname, const unsigned int size = 0,
|
|
|
|
const unsigned int cacheSize = 1, const bool clean = true);
|
2018-10-17 20:25:32 +01:00
|
|
|
DiskVectorBase(DiskVectorBase<T> &&v) = default;
|
2018-09-07 20:04:54 +01:00
|
|
|
virtual ~DiskVectorBase(void);
|
|
|
|
const T & operator[](const unsigned int i) const;
|
|
|
|
RwAccessHelper operator[](const unsigned int i);
|
2018-10-08 19:02:00 +01:00
|
|
|
double hitRatio(void) const;
|
|
|
|
void resetStat(void);
|
2018-09-07 20:04:54 +01:00
|
|
|
private:
|
|
|
|
virtual void load(T &obj, const std::string filename) const = 0;
|
|
|
|
virtual void save(const std::string filename, const T &obj) const = 0;
|
|
|
|
virtual std::string filename(const unsigned int i) const;
|
|
|
|
void evict(void) const;
|
|
|
|
void fetch(const unsigned int i) const;
|
|
|
|
void cacheInsert(const unsigned int i, const T &obj) const;
|
|
|
|
void clean(void);
|
|
|
|
private:
|
2018-10-18 17:48:25 +01:00
|
|
|
std::string dirname_;
|
|
|
|
unsigned int size_, cacheSize_;
|
|
|
|
double access_{0.}, hit_{0.};
|
|
|
|
bool clean_;
|
2018-09-07 20:04:54 +01:00
|
|
|
// using pointers to allow modifications when class is const
|
|
|
|
// semantic: const means data unmodified, but cache modification allowed
|
2018-10-17 20:25:32 +01:00
|
|
|
std::unique_ptr<std::vector<T>> cachePtr_;
|
2018-10-18 17:48:25 +01:00
|
|
|
std::unique_ptr<std::vector<bool>> modifiedPtr_;
|
2018-10-17 20:25:32 +01:00
|
|
|
std::unique_ptr<std::map<unsigned int, unsigned int>> indexPtr_;
|
|
|
|
std::unique_ptr<std::stack<unsigned int>> freePtr_;
|
|
|
|
std::unique_ptr<std::deque<unsigned int>> loadsPtr_;
|
2018-09-07 20:04:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Specialisation for serialisable classes *
|
|
|
|
******************************************************************************/
|
|
|
|
template <typename T, typename Reader, typename Writer>
|
|
|
|
class SerializableDiskVector: public DiskVectorBase<T>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using DiskVectorBase<T>::DiskVectorBase;
|
|
|
|
private:
|
|
|
|
virtual void load(T &obj, const std::string filename) const
|
|
|
|
{
|
|
|
|
Reader reader(filename);
|
|
|
|
|
|
|
|
read(reader, basename(filename), obj);
|
|
|
|
}
|
2018-10-08 19:02:00 +01:00
|
|
|
|
2018-09-07 20:04:54 +01:00
|
|
|
virtual void save(const std::string filename, const T &obj) const
|
|
|
|
{
|
|
|
|
Writer writer(filename);
|
|
|
|
|
|
|
|
write(writer, basename(filename), obj);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
2018-10-08 19:02:00 +01:00
|
|
|
* Specialisation for Eigen matrices *
|
2018-09-07 20:04:54 +01:00
|
|
|
******************************************************************************/
|
2018-10-08 19:02:00 +01:00
|
|
|
template <typename T>
|
2018-11-07 19:16:55 +00:00
|
|
|
using EigenDiskVectorMat = A2AMatrix<T>;
|
2018-09-07 20:04:54 +01:00
|
|
|
|
2018-10-08 19:02:00 +01:00
|
|
|
template <typename T>
|
|
|
|
class EigenDiskVector: public DiskVectorBase<EigenDiskVectorMat<T>>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using DiskVectorBase<EigenDiskVectorMat<T>>::DiskVectorBase;
|
|
|
|
typedef EigenDiskVectorMat<T> Matrix;
|
2018-10-16 14:44:14 +01:00
|
|
|
public:
|
|
|
|
T operator()(const unsigned int i, const Eigen::Index j,
|
|
|
|
const Eigen::Index k) const
|
|
|
|
{
|
|
|
|
return (*this)[i](j, k);
|
|
|
|
}
|
2018-10-08 19:02:00 +01:00
|
|
|
private:
|
|
|
|
virtual void load(EigenDiskVectorMat<T> &obj, const std::string filename) const
|
|
|
|
{
|
2018-10-18 17:48:25 +01:00
|
|
|
std::ifstream f(filename, std::ios::binary);
|
|
|
|
uint32_t crc, check;
|
|
|
|
Eigen::Index nRow, nCol;
|
|
|
|
size_t matSize;
|
2018-11-12 15:59:11 +00:00
|
|
|
double tRead, tHash;
|
2018-10-18 17:48:25 +01:00
|
|
|
|
|
|
|
f.read(reinterpret_cast<char *>(&crc), sizeof(crc));
|
|
|
|
f.read(reinterpret_cast<char *>(&nRow), sizeof(nRow));
|
|
|
|
f.read(reinterpret_cast<char *>(&nCol), sizeof(nCol));
|
2018-10-08 19:02:00 +01:00
|
|
|
obj.resize(nRow, nCol);
|
|
|
|
matSize = nRow*nCol*sizeof(T);
|
2018-11-12 15:59:11 +00:00
|
|
|
tRead = -usecond();
|
2018-10-08 19:02:00 +01:00
|
|
|
f.read(reinterpret_cast<char *>(obj.data()), matSize);
|
2018-11-12 15:59:11 +00:00
|
|
|
tRead += usecond();
|
|
|
|
tHash = -usecond();
|
|
|
|
check = GridChecksum::crc32(obj.data(), matSize);
|
|
|
|
tHash += usecond();
|
|
|
|
DV_DEBUG_MSG(this, "Eigen read " << tRead/1.0e6 << " sec " << matSize/tRead*1.0e6/1024/1024 << " MB/s");
|
|
|
|
DV_DEBUG_MSG(this, "Eigen crc32 " << std::hex << check << std::dec
|
|
|
|
<< " " << tHash/1.0e6 << " sec " << matSize/tHash*1.0e6/1024/1024 << " MB/s");
|
2018-10-18 17:48:25 +01:00
|
|
|
if (crc != check)
|
2018-10-08 19:02:00 +01:00
|
|
|
{
|
|
|
|
HADRONS_ERROR(Io, "checksum failed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void save(const std::string filename, const EigenDiskVectorMat<T> &obj) const
|
|
|
|
{
|
2018-10-18 17:48:25 +01:00
|
|
|
std::ofstream f(filename, std::ios::binary);
|
|
|
|
uint32_t crc;
|
|
|
|
Eigen::Index nRow, nCol;
|
|
|
|
size_t matSize;
|
2018-11-12 15:59:11 +00:00
|
|
|
double tWrite, tHash;
|
2018-10-08 19:02:00 +01:00
|
|
|
|
|
|
|
nRow = obj.rows();
|
|
|
|
nCol = obj.cols();
|
|
|
|
matSize = nRow*nCol*sizeof(T);
|
2018-11-12 15:59:11 +00:00
|
|
|
tHash = -usecond();
|
2018-10-18 17:48:25 +01:00
|
|
|
crc = GridChecksum::crc32(obj.data(), matSize);
|
2018-11-12 15:59:11 +00:00
|
|
|
tHash += usecond();
|
2018-10-18 17:48:25 +01:00
|
|
|
f.write(reinterpret_cast<char *>(&crc), sizeof(crc));
|
|
|
|
f.write(reinterpret_cast<char *>(&nRow), sizeof(nRow));
|
|
|
|
f.write(reinterpret_cast<char *>(&nCol), sizeof(nCol));
|
2018-11-12 15:59:11 +00:00
|
|
|
tWrite = -usecond();
|
2018-10-08 19:02:00 +01:00
|
|
|
f.write(reinterpret_cast<const char *>(obj.data()), matSize);
|
2018-11-12 15:59:11 +00:00
|
|
|
tWrite += usecond();
|
|
|
|
DV_DEBUG_MSG(this, "Eigen write " << tWrite/1.0e6 << " sec " << matSize/tWrite*1.0e6/1024/1024 << " MB/s");
|
|
|
|
DV_DEBUG_MSG(this, "Eigen crc32 " << std::hex << crc << std::dec
|
|
|
|
<< " " << tHash/1.0e6 << " sec " << matSize/tHash*1.0e6/1024/1024 << " MB/s");
|
2018-10-08 19:02:00 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* DiskVectorBase implementation *
|
|
|
|
******************************************************************************/
|
2018-09-07 20:04:54 +01:00
|
|
|
template <typename T>
|
|
|
|
DiskVectorBase<T>::DiskVectorBase(const std::string dirname,
|
|
|
|
const unsigned int size,
|
|
|
|
const unsigned int cacheSize,
|
|
|
|
const bool clean)
|
|
|
|
: dirname_(dirname), size_(size), cacheSize_(cacheSize), clean_(clean)
|
2018-10-17 20:25:32 +01:00
|
|
|
, cachePtr_(new std::vector<T>(size))
|
2018-10-18 17:48:25 +01:00
|
|
|
, modifiedPtr_(new std::vector<bool>(size, false))
|
2018-10-17 20:25:32 +01:00
|
|
|
, indexPtr_(new std::map<unsigned int, unsigned int>())
|
|
|
|
, freePtr_(new std::stack<unsigned int>)
|
2018-09-07 20:24:48 +01:00
|
|
|
, loadsPtr_(new std::deque<unsigned int>())
|
2018-09-07 20:04:54 +01:00
|
|
|
{
|
|
|
|
struct stat s;
|
|
|
|
|
|
|
|
if(stat(dirname.c_str(), &s) == 0)
|
|
|
|
{
|
|
|
|
HADRONS_ERROR(Io, "directory '" + dirname + "' already exists")
|
|
|
|
}
|
|
|
|
mkdir(dirname);
|
2018-10-17 20:25:32 +01:00
|
|
|
for (unsigned int i = 0; i < cacheSize_; ++i)
|
|
|
|
{
|
|
|
|
freePtr_->push(i);
|
|
|
|
}
|
2018-09-07 20:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
DiskVectorBase<T>::~DiskVectorBase(void)
|
|
|
|
{
|
|
|
|
if (clean_)
|
|
|
|
{
|
|
|
|
clean();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
const T & DiskVectorBase<T>::operator[](const unsigned int i) const
|
|
|
|
{
|
2018-10-17 20:25:32 +01:00
|
|
|
auto &cache = *cachePtr_;
|
|
|
|
auto &index = *indexPtr_;
|
|
|
|
auto &freeInd = *freePtr_;
|
|
|
|
auto &loads = *loadsPtr_;
|
2018-09-07 20:04:54 +01:00
|
|
|
|
2018-10-08 19:02:00 +01:00
|
|
|
DV_DEBUG_MSG(this, "accessing " << i << " (RO)");
|
2018-09-07 20:04:54 +01:00
|
|
|
|
|
|
|
if (i >= size_)
|
|
|
|
{
|
|
|
|
HADRONS_ERROR(Size, "index out of range");
|
|
|
|
}
|
2018-10-08 19:02:00 +01:00
|
|
|
const_cast<double &>(access_)++;
|
2018-10-17 20:25:32 +01:00
|
|
|
if (index.find(i) == index.end())
|
2018-09-07 20:04:54 +01:00
|
|
|
{
|
|
|
|
// cache miss
|
2018-10-08 19:02:00 +01:00
|
|
|
DV_DEBUG_MSG(this, "cache miss");
|
2018-09-07 20:04:54 +01:00
|
|
|
fetch(i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-08 19:02:00 +01:00
|
|
|
DV_DEBUG_MSG(this, "cache hit");
|
2018-09-07 20:24:48 +01:00
|
|
|
|
|
|
|
auto pos = std::find(loads.begin(), loads.end(), i);
|
|
|
|
|
2018-10-08 19:02:00 +01:00
|
|
|
const_cast<double &>(hit_)++;
|
2018-09-07 20:24:48 +01:00
|
|
|
loads.erase(pos);
|
|
|
|
loads.push_back(i);
|
2018-09-07 20:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DV_DEBUG
|
|
|
|
std::string msg;
|
|
|
|
|
2018-09-07 20:24:48 +01:00
|
|
|
for (auto &p: loads)
|
2018-09-07 20:04:54 +01:00
|
|
|
{
|
2018-09-07 20:24:48 +01:00
|
|
|
msg += std::to_string(p) + " ";
|
2018-09-07 20:04:54 +01:00
|
|
|
}
|
2018-10-08 19:02:00 +01:00
|
|
|
DV_DEBUG_MSG(this, "in cache: " << msg);
|
2018-09-07 20:04:54 +01:00
|
|
|
#endif
|
|
|
|
|
2018-10-17 20:25:32 +01:00
|
|
|
return cache[index.at(i)];
|
2018-09-07 20:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
typename DiskVectorBase<T>::RwAccessHelper DiskVectorBase<T>::operator[](const unsigned int i)
|
|
|
|
{
|
2018-10-08 19:02:00 +01:00
|
|
|
DV_DEBUG_MSG(this, "accessing " << i << " (RW)");
|
2018-09-07 20:04:54 +01:00
|
|
|
|
|
|
|
if (i >= size_)
|
|
|
|
{
|
|
|
|
HADRONS_ERROR(Size, "index out of range");
|
|
|
|
}
|
|
|
|
|
2018-09-07 20:40:55 +01:00
|
|
|
return RwAccessHelper(*this, i);
|
2018-09-07 20:04:54 +01:00
|
|
|
}
|
|
|
|
|
2018-10-08 19:02:00 +01:00
|
|
|
template <typename T>
|
|
|
|
double DiskVectorBase<T>::hitRatio(void) const
|
|
|
|
{
|
|
|
|
return hit_/access_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void DiskVectorBase<T>::resetStat(void)
|
|
|
|
{
|
|
|
|
access_ = 0.;
|
|
|
|
hit_ = 0.;
|
|
|
|
}
|
|
|
|
|
2018-09-07 20:04:54 +01:00
|
|
|
template <typename T>
|
|
|
|
std::string DiskVectorBase<T>::filename(const unsigned int i) const
|
|
|
|
{
|
|
|
|
return dirname_ + "/elem_" + std::to_string(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void DiskVectorBase<T>::evict(void) const
|
|
|
|
{
|
2018-10-18 17:48:25 +01:00
|
|
|
auto &cache = *cachePtr_;
|
|
|
|
auto &modified = *modifiedPtr_;
|
|
|
|
auto &index = *indexPtr_;
|
|
|
|
auto &freeInd = *freePtr_;
|
|
|
|
auto &loads = *loadsPtr_;
|
2018-09-07 20:04:54 +01:00
|
|
|
|
2018-10-17 20:25:32 +01:00
|
|
|
if (index.size() >= cacheSize_)
|
2018-09-07 20:04:54 +01:00
|
|
|
{
|
2018-10-18 17:48:25 +01:00
|
|
|
unsigned int i = loads.front();
|
|
|
|
|
|
|
|
DV_DEBUG_MSG(this, "evicting " << i);
|
|
|
|
if (modified[index.at(i)])
|
|
|
|
{
|
|
|
|
DV_DEBUG_MSG(this, "element " << i << " modified, saving to disk");
|
|
|
|
save(filename(i), cache[index.at(i)]);
|
|
|
|
}
|
|
|
|
freeInd.push(index.at(i));
|
|
|
|
index.erase(i);
|
2018-09-07 20:24:48 +01:00
|
|
|
loads.pop_front();
|
2018-09-07 20:04:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void DiskVectorBase<T>::fetch(const unsigned int i) const
|
|
|
|
{
|
2018-10-18 17:48:25 +01:00
|
|
|
auto &cache = *cachePtr_;
|
|
|
|
auto &modified = *modifiedPtr_;
|
|
|
|
auto &index = *indexPtr_;
|
|
|
|
auto &freeInd = *freePtr_;
|
|
|
|
auto &loads = *loadsPtr_;
|
2018-10-17 20:25:32 +01:00
|
|
|
|
2018-09-07 20:04:54 +01:00
|
|
|
struct stat s;
|
|
|
|
|
2018-10-08 19:02:00 +01:00
|
|
|
DV_DEBUG_MSG(this, "loading " << i << " from disk");
|
2018-09-07 20:04:54 +01:00
|
|
|
|
|
|
|
evict();
|
2018-10-17 20:25:32 +01:00
|
|
|
|
2018-09-07 20:04:54 +01:00
|
|
|
if(stat(filename(i).c_str(), &s) != 0)
|
|
|
|
{
|
|
|
|
HADRONS_ERROR(Io, "disk vector element " + std::to_string(i) + " uninitialised");
|
|
|
|
}
|
2018-10-17 20:25:32 +01:00
|
|
|
index[i] = freeInd.top();
|
|
|
|
freeInd.pop();
|
|
|
|
load(cache[index.at(i)], filename(i));
|
2018-09-07 20:24:48 +01:00
|
|
|
loads.push_back(i);
|
2018-10-18 17:48:25 +01:00
|
|
|
modified[index.at(i)] = false;
|
2018-09-07 20:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void DiskVectorBase<T>::cacheInsert(const unsigned int i, const T &obj) const
|
|
|
|
{
|
2018-10-18 17:48:25 +01:00
|
|
|
auto &cache = *cachePtr_;
|
|
|
|
auto &modified = *modifiedPtr_;
|
|
|
|
auto &index = *indexPtr_;
|
|
|
|
auto &freeInd = *freePtr_;
|
|
|
|
auto &loads = *loadsPtr_;
|
2018-09-07 20:04:54 +01:00
|
|
|
|
|
|
|
evict();
|
2018-10-17 20:25:32 +01:00
|
|
|
index[i] = freeInd.top();
|
|
|
|
freeInd.pop();
|
|
|
|
cache[index.at(i)] = obj;
|
2018-09-07 20:24:48 +01:00
|
|
|
loads.push_back(i);
|
2018-10-18 17:48:25 +01:00
|
|
|
modified[index.at(i)] = false;
|
2018-09-07 20:04:54 +01:00
|
|
|
|
|
|
|
#ifdef DV_DEBUG
|
|
|
|
std::string msg;
|
|
|
|
|
2018-09-07 20:24:48 +01:00
|
|
|
for (auto &p: loads)
|
2018-09-07 20:04:54 +01:00
|
|
|
{
|
2018-09-07 20:24:48 +01:00
|
|
|
msg += std::to_string(p) + " ";
|
2018-09-07 20:04:54 +01:00
|
|
|
}
|
2018-10-08 19:02:00 +01:00
|
|
|
DV_DEBUG_MSG(this, "in cache: " << msg);
|
2018-09-07 20:04:54 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DV_DEBUG
|
|
|
|
#undef DV_DEBUG_MSG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void DiskVectorBase<T>::clean(void)
|
|
|
|
{
|
|
|
|
auto unlink = [](const char *fpath, const struct stat *sb,
|
|
|
|
int typeflag, struct FTW *ftwbuf)
|
|
|
|
{
|
|
|
|
int rv = remove(fpath);
|
|
|
|
|
|
|
|
if (rv)
|
|
|
|
{
|
|
|
|
HADRONS_ERROR(Io, "cannot remove '" + std::string(fpath) + "': "
|
|
|
|
+ std::string(std::strerror(errno)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
};
|
|
|
|
|
|
|
|
nftw(dirname_.c_str(), unlink, 64, FTW_DEPTH | FTW_PHYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
#endif // Hadrons_DiskVector_hpp_
|