mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
Hadrons: disk vector cache policy to last touch
This commit is contained in:
parent
f8abd0978b
commit
b800bb3ecb
@ -29,7 +29,7 @@ See the full license in the file "LICENSE" in the top level distribution directo
|
|||||||
#define Hadrons_DiskVector_hpp_
|
#define Hadrons_DiskVector_hpp_
|
||||||
|
|
||||||
#include <Hadrons/Global.hpp>
|
#include <Hadrons/Global.hpp>
|
||||||
#include <queue>
|
#include <deque>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <ftw.h>
|
#include <ftw.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -94,7 +94,7 @@ private:
|
|||||||
// using pointers to allow modifications when class is const
|
// using pointers to allow modifications when class is const
|
||||||
// semantic: const means data unmodified, but cache modification allowed
|
// semantic: const means data unmodified, but cache modification allowed
|
||||||
std::unique_ptr<std::map<unsigned int, T>> cachePtr_;
|
std::unique_ptr<std::map<unsigned int, T>> cachePtr_;
|
||||||
std::unique_ptr<std::queue<unsigned int>> loadsPtr_;
|
std::unique_ptr<std::deque<unsigned int>> loadsPtr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
@ -134,7 +134,7 @@ DiskVectorBase<T>::DiskVectorBase(const std::string dirname,
|
|||||||
const bool clean)
|
const bool clean)
|
||||||
: dirname_(dirname), size_(size), cacheSize_(cacheSize), clean_(clean)
|
: dirname_(dirname), size_(size), cacheSize_(cacheSize), clean_(clean)
|
||||||
, cachePtr_(new std::map<unsigned int, T>())
|
, cachePtr_(new std::map<unsigned int, T>())
|
||||||
, loadsPtr_(new std::queue<unsigned int>())
|
, loadsPtr_(new std::deque<unsigned int>())
|
||||||
{
|
{
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
|
||||||
@ -158,6 +158,7 @@ template <typename T>
|
|||||||
const T & DiskVectorBase<T>::operator[](const unsigned int i) const
|
const T & DiskVectorBase<T>::operator[](const unsigned int i) const
|
||||||
{
|
{
|
||||||
auto &cache = *cachePtr_;
|
auto &cache = *cachePtr_;
|
||||||
|
auto &loads = *loadsPtr_;
|
||||||
|
|
||||||
DV_DEBUG_MSG("accessing " << i << " (RO)");
|
DV_DEBUG_MSG("accessing " << i << " (RO)");
|
||||||
|
|
||||||
@ -175,14 +176,19 @@ const T & DiskVectorBase<T>::operator[](const unsigned int i) const
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
DV_DEBUG_MSG("cache hit");
|
DV_DEBUG_MSG("cache hit");
|
||||||
|
|
||||||
|
auto pos = std::find(loads.begin(), loads.end(), i);
|
||||||
|
|
||||||
|
loads.erase(pos);
|
||||||
|
loads.push_back(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DV_DEBUG
|
#ifdef DV_DEBUG
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
for (auto &p: cache)
|
for (auto &p: loads)
|
||||||
{
|
{
|
||||||
msg += std::to_string(p.first) + " ";
|
msg += std::to_string(p) + " ";
|
||||||
}
|
}
|
||||||
DV_DEBUG_MSG("in cache: " << msg);
|
DV_DEBUG_MSG("in cache: " << msg);
|
||||||
#endif
|
#endif
|
||||||
@ -221,7 +227,7 @@ void DiskVectorBase<T>::evict(void) const
|
|||||||
{
|
{
|
||||||
DV_DEBUG_MSG("evicting " << loads.front());
|
DV_DEBUG_MSG("evicting " << loads.front());
|
||||||
cache.erase(loads.front());
|
cache.erase(loads.front());
|
||||||
loads.pop();
|
loads.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +246,7 @@ void DiskVectorBase<T>::fetch(const unsigned int i) const
|
|||||||
HADRONS_ERROR(Io, "disk vector element " + std::to_string(i) + " uninitialised");
|
HADRONS_ERROR(Io, "disk vector element " + std::to_string(i) + " uninitialised");
|
||||||
}
|
}
|
||||||
load(cache[i], filename(i));
|
load(cache[i], filename(i));
|
||||||
loads.push(i);
|
loads.push_back(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -251,14 +257,14 @@ void DiskVectorBase<T>::cacheInsert(const unsigned int i, const T &obj) const
|
|||||||
|
|
||||||
evict();
|
evict();
|
||||||
cache[i] = obj;
|
cache[i] = obj;
|
||||||
loads.push(i);
|
loads.push_back(i);
|
||||||
|
|
||||||
#ifdef DV_DEBUG
|
#ifdef DV_DEBUG
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
for (auto &p: cache)
|
for (auto &p: loads)
|
||||||
{
|
{
|
||||||
msg += std::to_string(p.first) + " ";
|
msg += std::to_string(p) + " ";
|
||||||
}
|
}
|
||||||
DV_DEBUG_MSG("in cache: " << msg);
|
DV_DEBUG_MSG("in cache: " << msg);
|
||||||
#endif
|
#endif
|
||||||
|
@ -55,7 +55,7 @@ int main(int argc, char *argv[])
|
|||||||
GridSerialRNG rng;
|
GridSerialRNG rng;
|
||||||
Object obj, v2w, v2r, v13w, v13r;
|
Object obj, v2w, v2r, v13w, v13r;
|
||||||
|
|
||||||
SerializableDiskVector<Object, TestReader, TestWriter> v("diskvector_test", 1000, 2);
|
SerializableDiskVector<Object, TestReader, TestWriter> v("diskvector_test", 1000, 4);
|
||||||
|
|
||||||
obj.e = Enum::red;
|
obj.e = Enum::red;
|
||||||
random(rng, obj.scm);
|
random(rng, obj.scm);
|
||||||
@ -66,10 +66,24 @@ int main(int argc, char *argv[])
|
|||||||
random(rng, obj.scm);
|
random(rng, obj.scm);
|
||||||
v[6] = obj;
|
v[6] = obj;
|
||||||
random(rng, obj.scm);
|
random(rng, obj.scm);
|
||||||
|
v[7] = obj;
|
||||||
|
random(rng, obj.scm);
|
||||||
|
v[8] = obj;
|
||||||
|
random(rng, obj.scm);
|
||||||
|
v[9] = obj;
|
||||||
|
random(rng, obj.scm);
|
||||||
|
v[10] = obj;
|
||||||
|
random(rng, obj.scm);
|
||||||
|
v[11] = obj;
|
||||||
|
random(rng, obj.scm);
|
||||||
v[12] = obj;
|
v[12] = obj;
|
||||||
random(rng, obj.scm);
|
random(rng, obj.scm);
|
||||||
v[13] = obj;
|
v[13] = obj;
|
||||||
v13w = obj;
|
v13w = obj;
|
||||||
|
random(rng, obj.scm);
|
||||||
|
v[14] = obj;
|
||||||
|
random(rng, obj.scm);
|
||||||
|
v[15] = obj;
|
||||||
|
|
||||||
v2r = v[2];
|
v2r = v[2];
|
||||||
LOG(Message) << "v[2] correct? "
|
LOG(Message) << "v[2] correct? "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user