5#ifndef LINE_SOLVERS_MVA_SOLVER_MVA_CACHE_H
6#define LINE_SOLVERS_MVA_SOLVER_MVA_CACHE_H
90 std::size_t cnode = 0;
91 for (std::size_t i = 0; i < L.
nof_nodes(); ++i)
92 if (L.
nodes[i].nodetype == NodeType::Cache) {
96 if (cnode == 0)
throw InputError(
"solver_mva_cache_analyzer: the model has no Cache node");
99 throw InputError(
"solver_mva_cache_analyzer: the Cache node has no parameters");
102 const std::size_t nan_flag = 0;
108 for (std::size_t i = 0; i < M; ++i)
109 if (L.
stations[i].nodetype == NodeType::Source) src = i + 1;
110 if (src == 0)
throw InputError(
"solver_mva_cache_analyzer: a non-reentrant cache needs a Source");
111 std::vector<T> sourceRate(R, zero);
112 for (std::size_t r = 0; r < R; ++r) {
114 if (std::isfinite(v)) sourceRate[r] = L.
rates(src - 1, r);
134 if (
opt.method ==
"exact") {
138 for (std::size_t k = 0; k < n; ++k) {
140 for (std::size_t l = 0; l < h; ++l) {
141 pij(k, l + 1) = cm.
pij(k, l);
151 "solver_mva_cache_analyzer: the RR/FIFO fixed-point approximation stops on a "
152 "tolerance and needs a transcendental T; use method 'exact' under Rational");
166 "solver_mva_cache_analyzer: the LRU / h-LRU characteristic-time approximation "
167 "solves a fixed point on a tolerance and needs a transcendental T");
169 std::size_t rd = ch.
pread.size();
170 for (std::size_t v = 0; v < ch.
pread.size(); ++v)
171 if (!ch.
pread[v].empty()) {
175 if (rd == ch.
pread.size())
176 throw InputError(
"solver_mva_cache_analyzer: no class reads the cache");
182 const std::size_t u = ch.
pread.size();
184 for (std::size_t v = 0; v < u; ++v)
185 for (std::size_t k = 0; k < n; ++k)
193 std::vector<T> mT(ch.
itemcap.size());
194 for (std::size_t l = 0; l < ch.
itemcap.size(); ++l)
204 "solver_mva_cache_analyzer: replacement policy " +
206 " has no MVA cache analyzer; RR, FIFO, LRU and h-LRU are supported");
211 std::vector<T> missRate(R, zero);
212 for (std::size_t v = 0; v < R; ++v) {
213 if (v >= ch.
pread.size() || ch.
pread[v].empty())
continue;
214 for (std::size_t k = 0; k < n; ++k)
215 missRate[v] += T(sourceRate[v] * ch.
pread[v][k] * pij(k, 0));
226 out.
C.assign(R, zero);
227 out.
X.assign(R, zero);
228 for (std::size_t r = 0; r < R; ++r) out.
Tp(src - 1, r) = sourceRate[r];
229 for (std::size_t r = 0; r < R; ++r) {
230 if (r >= ch.
hitclass.size())
continue;
232 if (hc == 0 ||
mc == 0)
continue;
233 out.
X[
mc - 1] = T(out.
X[
mc - 1] + missRate[r]);
234 out.
X[hc - 1] = T(out.
X[hc - 1] + T(sourceRate[r] - missRate[r]));
239 res.
sol.method = method;
240 res.
sol.lG = std::numeric_limits<double>::quiet_NaN();
245 for (std::size_t r = 0; r < R; ++r) {
246 if (r >= ch.
pread.size() || ch.
pread[r].empty())
continue;
247 if (!(sourceRate[r] > zero))
continue;
248 res.
missprob[r] = T(missRate[r] / sourceRate[r]);
255 if (pijlist.
rows() > 0) {
256 for (std::size_t v = 0; v < R; ++v) {
257 if (v >= ch.
pread.size() || ch.
pread[v].empty())
continue;
258 for (std::size_t l = 0; l < h; ++l) {
260 for (std::size_t k = 0; k < n; ++k) acc = T(acc + ch.
pread[v][k] * pijlist(k, l));
270 if (pijlist.
rows() > 0) {
272 }
else if (pij.
cols() == h + 1) {
280 for (std::size_t k = 0; k < n; ++k) {
282 for (std::size_t l = 0; l < h; ++l) {
284 s = T(s + cm.
pij(k, l));
Exact mean value analysis of a multi-list cache.
Cache hit and miss probabilities from the fixed-point multipliers.
TTL (characteristic-time) approximation of an h-LRU / LRU(m) cache.
TTL (characteristic-time) approximation of an LRU cache whose lists form an arbitrary access graph.
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
std::size_t nof_nodes() const
std::map< std::size_t, CacheParam< T > > nodeparam
Cache parameters by 1-based NODE index; only Cache nodes have an entry.
std::vector< Station< T > > stations
stations[k-1] is the k-th station
Matrix< T > rates
(nstations x nclasses) service rates and SCVs, with a PARALLEL disabled flag instead of MATLAB's NaN ...
std::vector< NodeDef > nodes
every node, in creation order
Isolated-cache input construction for the decomposition methods.
The option and result types every MVA analyzer shares.
CacheMvaResult< T > cache_mva(const Matrix< T > &gamma, const std::vector< int > &m)
Exact mean value analysis of a multi-list cache.
Matrix< T > cache_prob_fpi(const Matrix< T > &gamma, const std::vector< int > &m)
Cache hit and miss probabilities from the fixed-point multipliers.
Matrix< T > cache_ttl_hlru(const Matrix< T > &lambda, const std::vector< int > &m)
TTL (characteristic-time) approximation of an h-LRU / LRU(m) cache.
Matrix< T > cache_ttl_lrua(const Matrix< T > &lambda, const std::vector< Matrix< T > > &R, const std::vector< T > &m, const T &tol, unsigned maxswp=200)
TTL (characteristic-time) approximation of an LRU cache whose lists form an arbitrary access graph.
CacheIsolateResult< T > da_cache_isolate(const CacheParam< T > &ch, const std::vector< T > &lambda)
Isolated-cache input construction for the decomposition methods.
NodeType
Node kinds, with the values of MATLAB NodeType.
@ HLRU
h-LRU / LRU(m): h lists, promote i -> i+1 on a hit
@ FIFO
first in, first out
CacheResult< T > solver_mva_cache_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt)
Port of solver_mva_cache_analyzer.m for a Source-Cache-Sink model.
A queueing network and its refreshed NetworkStruct.
Return value of cache_mva, mirroring [pi,pi0,pij,x,u,E].
Matrix< T > pij
(n x h) probability that item k sits in list l
Return value of da_cache_isolate, mirroring [gamma,lambda_cache,Rcost].
std::vector< Matrix< T > > lambda_cache
(u) matrices of size n x (h+1)
Matrix< T > gamma
(n x h) access factors
std::vector< std::vector< Matrix< T > > > Rcost
(u x n) of (h+1)x(h+1)
The fields of sn.nodeparam{cache} that da_cache_isolate reads.
std::vector< int > itemcap
(h) list capacities
std::vector< std::vector< Matrix< T > > > accost
(u) x (n) of (h+1)x(h+1), or empty
std::vector< std::vector< T > > pread
(u) x (n), empty row = NaN
static constexpr double FineTol
What the cache analyzer reports beyond the [Q,U,R,T] block.
std::vector< T > hitprob
per class, NaN where the class does not read
std::vector< T > missprob
Matrix< T > itemprob
(n x h+1) per-item occupancy, column 0 = miss.
Matrix< T > hitproblist
(R x h) per-list hit fractions, access-weighted over items.
The options SolverMVA reads.
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
std::vector< std::vector< Matrix< T > > > accost
(u) x (n) of (h+1)x(h+1), or empty
std::vector< int > itemcap
std::vector< std::size_t > missclass
std::vector< std::size_t > hitclass
lang::ReplacementStrategy replacestrat
std::vector< std::vector< T > > pread
(u) x (n), empty row = NaN